Page: (symbolic)Top, Next: (cpl)CHARbyCHAR, Prev: (parallel), Up: (cpl)Library

Symbolic differentiation

The symbolic.cpl library adds symbolic differentiation capabilities to CPL. Symbolic differentiation is seamlessly integrated in the compiler, and happens at compile time: any desired symbolic derivatives are determined during compilation, and inlined in the generated code. Contrary to most other symbolic-differentiation environments, therefore, the purpose is not so much to generate user-readable derivatives as to generate (hopefully efficient) code. Symbolic manipulation operates upon and generates symbolic expressions, which can be assigned a symbolic name using the == operator and, like any r.h.s. of this operator, may contain yet undefined variables. At the later position where a symbolic expression or variable appears in an executable statement, code for it is actually generated just as in (cpl)Deferred assignment. If all the necessary declarations have not appeared before this later point, a compilation error results. The derivative of a symbolic expression with respect to a symbolic variable <svname> (which is not allowed to contain an underscore in its name) is denoted by either D_<svname>( <symbolic expression> ) or D( <symbolic expression> , <svname> ) When the latter form is used, <svname> may also be an array element (in the usual indexed notation). Higher derivatives and more general compound differential operators, which take an expression as their argument, can be #define'd ((cpl)C preprocessor). For example: #define laplacian(f) D_x(D_x(f))+D_y(D_y(f))+D_z(D_z(f)) A mechanism is provided to associate a derivative with a user-defined expression (or more generally to override automatic differentiation): if a variable named D_<svname>_<vname> is declared, it will be preferentially used as the value of the derivative of variable <vname> with respect to variable <svname> wherever needed. If no such variable is declared and <vname> was previously defined as a symbolic expression, its derivative will be automatically generated. If <vname> is undefined, an error will result. If <vname> was declared as an ordinary CPL VARIABLE (or CONSTANT) rather than as a symbolic expression, it will be treated as a constant whose derivative is zero. As a side effect, variable names starting with D_ are reserved and should not be defined for other purposes when symbolic.cpl is in USE.