Home | About | Partners | Contact Us

SourceForge Logo

Quick Links
Home
News
Status
Building XL
XL Mailing List

Understanding XL
Conceptual overview
XL examples
Inside XL
Concept Programming

In depth
Browse GIT
Bugs
SourceForge Info
Contact

Other projects
GNU Project
The Mozart Project

XLR: Extensible Language and Runtime

The art of turning ideas into code

Symbolic Differentiation in XL

Prev: Ada-style Tasking

Up

Next: GUI description

There are a few problems which are best expressed using the derivative of a function, for instance in domains such as economics or mechanical engineering. However, with traditional programming languages, the code will not contain a representation of the original concept (a derivative), but directly the derived form.

So, in C, if you think about the output of a damped oscillator, you can write a quasi-mathematical notation, something like:

I = K*exp(-alpha*t)*sin(beta*t)
It is easy to understand that it's convenient to let the compiler transform that into the actual machine code.

On the other hand, if what you are interested is the rate of change of said oscillator, you cannot write the mathematical expression:

dI = d(K*exp(-alpha*t)*sin(beta*t))/dt
Instead, you need to expand it manually, yielding something ugly like:
dI := K * exp (- (alpha * t)) * (beta * cos (beta * t)) - K * (alpha * exp (- (alpha * t))) * sin (beta * t))
The code above is ugly because it doesn't represent the concept. It doesn't indicate that a derivative was computed (except maybe in a comment), and the computation is not automated, so it is error prone.

So far, nobody really expected the compiler to perform the differentiation for you, even if cheap pocket calculators like the HP-48 have been capable of doing this incredible feat for maybe 10 years... But why not?

With XL, a simple language extension makes it possible to write code exactly like the above. Moreover, the extension is not very complicated. The plug-in simply describes the various transformation used to perform a symbolic differentiation.

Prev: Ada-style Tasking

Up

Next: GUI description


Copyright 2008 Christophe de Dinechin (Blog)
E-mail: XL Mailing List (polluted by spam, unfortunately)