codegen
prep2trans
prepare a Maple procedure for translation
split
prepare a Maple procedure for automatic differentiation
horner
convert formulae in a procedure to horner form
Calling Sequence
Parameters
Description
Examples
prep2trans(f)
horner(f, x)
split(f)
split(f, x)
f
-
Maple procedure
x
list or set of symbols
The prep2trans function is used to transform certain symbolic expressions into forms suitable for translation into a target language such as C or Fortran. For example, piecewise expressions are translated into if statements, symbolic sums are translated into for loops.
The horner function takes as input a Maple procedure and a variable or list or set of variables, and converts all formulae in the procedure to Horner form in x.
The split function is used to break up certain symbolic expressions into computation sequences suitable for automatic differentiation. Long products and complicated compositions are broken up into computation sequences. If the second argument x is specified, it specifies the independent variables, the variables that the function f will be differentiated in.
The command with(codegen,prep2trans) allows the use of the abbreviated form of this command.
The command with(codegen,split) allows the use of the abbreviated form of this command.
The command with(codegen,horner) allows the use of the abbreviated form of this command.
with⁡codegen:
f := proc(x) piecewise(x<0,0,x<1,x,x>1,2-x,0) end proc;
f ≔ procxpiecewise⁡x<0,0,x<1,x,1<x,2 − x,0end proc
prep2trans⁡f
procxifx<0then0elifx<1thenxelif1<xthen2 − xelse0end ifend proc
f := proc(x) local s; sum(x^i/i!,i=0..n) end proc;
f ≔ procxlocals;sum⁡x^i/factorial⁡i,i=0..nend proc
procxlocali1,s,s1,t1;if0<−nthens1 ≔ 0elset1 ≔ 1;s1 ≔ 1;fori1tondot1 ≔ x*t1/i1;s1 ≔ s1+t1end doend if;s1end proc
f := proc(n,A) local i,j; sum(sum(A[i,j],i=1..n),j=1..n) end proc;
f ≔ procn,Alocali,j;sum⁡sum⁡A[i,j],i=1..n,j=1..nend proc
procn,Alocali,i1,i2,j,s1,s2,t1,t2;s1 ≔ 0;fori1tondos2 ≔ 0;fori2tondos2 ≔ s2+A[i2,i1]end do;s1 ≔ s1+s2end do;s1end proc
h := proc(x,y,z) 1-2*x*y-x*y^2*z*(1-x) end proc;
h ≔ procx,y,z1 − 2*x*y − x*y^2*z*1 − xend proc
horner⁡h,x
procx,y,z1+x*y^2*z − y^2*z − 2*y*xend proc
horner⁡h,x,y
procx,y,z1+−y*z − 2*y+x*y^2*z*xend proc
split⁡h
procx,y,zlocals0,s1;s0 ≔ x*z;s1 ≔ y^2*1 − x;return−s0*s1 − 2*x*y+1end proc
g := proc(x,y,t) 2*sin(x^2*y)*exp(-t^2) end proc;
g ≔ procx,y,t2*sin⁡x^2*y*exp⁡−t^2end proc
split⁡g
procx,y,tlocals0,s1;s0 ≔ x^2*y;s1 ≔ −t^2;return2*exp⁡s1*sin⁡s0end proc
split⁡g,x,y
procx,y,tlocals0;s0 ≔ x^2*y;return2*exp⁡−t^2*sin⁡s0end proc
See Also
codegen[C(deprecated)]
codegen[fortran(deprecated)]
codegen[GRADIENT]
codegen[optimize]
Download Help Document