|
|
|
|
Quick Links
Understanding XL
In depth
Other projects
|
XLR: Extensible Language and Runtime
|
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: It is easy to understand that it's convenient to let the compiler transform that into the actual machine code.I = K*exp(-alpha*t)*sin(beta*t) On the other hand, if what you are interested is the rate of change of said oscillator, you cannot write the mathematical expression: Instead, you need to expand it manually, yielding something ugly like:dI = d(K*exp(-alpha*t)*sin(beta*t))/dt 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.dI := K * exp (- (alpha * t)) * (beta * cos (beta * t)) - K * (alpha * exp (- (alpha * t))) * sin (beta * t)) 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.
|
Copyright 2006 Christophe de Dinechin (Blog)
E-mail: XL Mailing List (polluted by spam, unfortunately)