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

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

> 

with⁡codegen:

> 

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

f ≔ procxpiecewise⁡x<0&comma;0&comma;x<1&comma;x&comma;1<x&comma;2 − x&comma;0end proc

(1)
> 

prep2trans⁡f

procxifx<0then0elifx<1thenxelif1<xthen2 − xelse0end ifend proc

(2)
> 

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

f ≔ procxlocals&semi;sum⁡x&Hat;i&sol;factorial⁡i&comma;i&equals;0..nend proc

(3)
> 

prep2trans⁡f

procxlocali1&comma;s&comma;s1&comma;t1&semi;if0<&minus;nthens1 ≔ 0elset1 ≔ 1&semi;s1 ≔ 1&semi;fori1tondot1 ≔ x&ast;t1&sol;i1&semi;s1 ≔ s1&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;

f ≔ procn&comma;Alocali&comma;j&semi;sum⁡sum⁡A&lsqb;i&comma;j&rsqb;&comma;i&equals;1..n&comma;j&equals;1..nend proc

(5)
> 

prep2trans⁡f

procn&comma;Alocali&comma;i1&comma;i2&comma;j&comma;s1&comma;s2&comma;t1&comma;t2&semi;s1 ≔ 0&semi;fori1tondos2 ≔ 0&semi;fori2tondos2 ≔ s2&plus;A&lsqb;i2&comma;i1&rsqb;end do&semi;s1 ≔ s1&plus;s2end do&semi;s1end proc

(6)
> 

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

h ≔ procx&comma;y&comma;z1 − 2&ast;x&ast;y − x&ast;y&Hat;2&ast;z&ast;1 − xend proc

(7)
> 

horner⁡h&comma;x

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

(8)
> 

horner⁡h&comma;x&comma;y

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

(9)
> 

split⁡h

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

(10)
> 

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

g ≔ procx&comma;y&comma;t2&ast;sin⁡x&Hat;2&ast;y&ast;exp⁡&minus;t&Hat;2end proc

(11)
> 

split⁡g

procx&comma;y&comma;tlocals0&comma;s1&semi;s0 ≔ x&Hat;2&ast;y&semi;s1 ≔ &minus;t&Hat;2&semi;return2&ast;exp⁡s1&ast;sin⁡s0end proc

(12)
> 

split⁡g&comma;x&comma;y

procx&comma;y&comma;tlocals0&semi;s0 ≔ x&Hat;2&ast;y&semi;return2&ast;exp⁡&minus;t&Hat;2&ast;sin⁡s0end proc

(13)

See Also

codegen[C(deprecated)]

codegen[fortran(deprecated)]

codegen[GRADIENT]

codegen[optimize]