Analytical Differentiation
This example shows how Symbolic Tools uses the Maple kernel to carry out analytical differentiation, and then to create and compile a GAUSS proc that has the same functionality. This is the basis for Automatic Differentiation.
The process of creating a proc based on symbolic code is a one line operation - symproc. This command takes four arguments - the proc name, the input argument(s), the output required, and the code. The code ( txt ) is GAUSS, with the gradp function overloaded to permit a symbolic second argument. The call to symproc executes the code in the Maple kernel, creates the equivalent GAUSS proc, and compiles the proc, so that it can be called immediately - as shown below.
library symbolic; // define the library
call symstate(reset); // turns on symbolic processing
proc difsin; endp; // dummy proc
txt = "
slist = {x,y};
llf = sin(x*y)^2;
llfg = gradp(llf,slist);
";
call symproc("difsin","x,y","llfg",txt); // create and compile the proc
rslt = difsin(1,2); // execute the proc
"rslt\n" rslt;
The proc that is created by the symproc command :
proc difsin(x,y);
local t0, t1, t2, t3, t4,
unknown;
unknown = zeros(rows(y),2);
t1 = x .* y;
t2 = sin(t1);
t3 = cos(t1);
t4 = t2 .* t3;
unknown[.,1+0] = 2.0 .* t4 .* y;
unknown[.,1+1] = 2.0 .* t4 .* x;
retp(unknown);
endp;
The output from this example is :
rslt -1.5136050 -0.75680251