prep2trans - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


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

Calling Sequence

prep2trans(f)

horner(f, x)

split(f)

split(f, x)

Parameters

f

-

Maple procedure

x

-

list or set of symbols

Description

• 

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.

Examples

withcodegen:

f := proc(x) piecewise(x<0,0,x<1,x,x>1,2-x,0) end proc;

fprocxpiecewisex<0&comma;0&comma;x<1&comma;x&comma;1<x&comma;2x&comma;0end proc

(1)

prep2transf

procxifx<0then0elifx<1thenxelif1<xthen2xelse0end ifend proc

(2)

f := proc(x) local s; sum(x^i/i!,i=0..n) end proc;

fprocxlocals&semi;sumx&Hat;i&sol;factoriali&comma;i&equals;0..nend proc

(3)

prep2transf

procxlocali1&comma;s&comma;s1&comma;t1&semi;if0<&minus;nthens10elset11&semi;s11&semi;fori1tondot1x&ast;t1&sol;i1&semi;s1s1&plus;t1end doend if&semi;s1end proc

(4)

f := proc(n,A) local i,j; sum(sum(A[i,j],i=1..n),j=1..n) end proc;

fprocn&comma;Alocali&comma;j&semi;sumsumA&lsqb;i&comma;j&rsqb;&comma;i&equals;1..n&comma;j&equals;1..nend proc

(5)

prep2transf

procn&comma;Alocali&comma;i1&comma;i2&comma;j&comma;s1&comma;s2&comma;t1&comma;t2&semi;s10&semi;fori1tondos20&semi;fori2tondos2s2&plus;A&lsqb;i2&comma;i1&rsqb;end do&semi;s1s1&plus;s2end do&semi;s1end proc

(6)

h := proc(x,y,z) 1-2*x*y-x*y^2*z*(1-x) end proc;

hprocx&comma;y&comma;z12&ast;x&ast;yx&ast;y&Hat;2&ast;z&ast;1xend proc

(7)

hornerh&comma;x

procx&comma;y&comma;z1&plus;x&ast;y&Hat;2&ast;zy&Hat;2&ast;z2&ast;y&ast;xend proc

(8)

hornerh&comma;x&comma;y

procx&comma;y&comma;z1&plus;&minus;y&ast;z2&ast;y&plus;x&ast;y&Hat;2&ast;z&ast;xend proc

(9)

splith

procx&comma;y&comma;zlocals0&comma;s1&semi;s0x&ast;z&semi;s1y&Hat;2&ast;1x&semi;return&minus;s0&ast;s12&ast;x&ast;y&plus;1end proc

(10)

g := proc(x,y,t) 2*sin(x^2*y)*exp(-t^2) end proc;

gprocx&comma;y&comma;t2&ast;sinx&Hat;2&ast;y&ast;exp&minus;t&Hat;2end proc

(11)

splitg

procx&comma;y&comma;tlocals0&comma;s1&semi;s0x&Hat;2&ast;y&semi;s1&minus;t&Hat;2&semi;return2&ast;exps1&ast;sins0end proc

(12)

splitg&comma;x&comma;y

procx&comma;y&comma;tlocals0&semi;s0x&Hat;2&ast;y&semi;return2&ast;exp&minus;t&Hat;2&ast;sins0end proc

(13)

See Also

codegen[C(deprecated)]

codegen[fortran(deprecated)]

codegen[GRADIENT]

codegen[optimize]