codegen - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : codegen Package : codegen/joinprocs

codegen

  

joinprocs

  

Join the body of two or more Maple procedures together

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

joinprocs(F)

joinprocs(F, result_type = t)

Parameters

F

-

list of Maple procedures

t

-

one of seq (default), list, or array

Description

• 

The joinprocs function takes as input a list of Maple procedures. It outputs a single Maple procedure J which returns the values computed by all procedures in F.  It simply concatenates the code appearing in the body of the procedures together. The purpose of the joinprocs procedure is to allow one to optimize the code in the procedures in F together.

• 

The formal parameters in the resulting procedure J are determined by taking the union of the names of the formal parameters in all procedures and the relative order of the parameters is preserved.  A parameter in one procedure is considered the same as a parameter in another if the two parameters have the same name, thus position is considered irrelevant.  If the parameters in two procedures have different names, and it is desired to consider them the same, the codegen[renamevar] command may be used.

• 

By default, the procedure J returns a sequence of all the values computed by the procedures in the list F.  The optional argument result_type=list, result_type=array, or result_type=seq specifies that the results are to be returned in a list, array, or sequence respectively.

• 

If a procedure in F contains a return statement before the last statement, for example in a nested loop, it will not be removed in the resulting code J. Hence evaluation of J may not evaluate all the codes in F.

• 

The command with(codegen,joinprocs) allows the use of the abbreviated form of this command.

Examples

withcodegen,joinprocs,optimize,renamevar:

f := proc(x,y) local e,t; e := exp(-x); t := x^2; t*e end proc:

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

Jjoinprocsf,g

J:=procx,ylocale,resultf,resultg,t;e:=exp−x;t:=x^2;resultf:=t*e;e:=exp−x;t:=y^2;resultg:=t*e;returnresultf,resultgend proc

(1)

optimizeJ

procx,ylocale1,t,t1;e1:=exp−x;t1:=x^2;t:=y^2;returnt1*e1,t*e1end proc

(2)

joinprocsf,g,result_type=array

procx,ylocale,result,t;result:=array1..2;e:=exp−x;t:=x^2;result[1]:=t*e;e:=exp−x;t:=y^2;result[2]:=t*e;returnresultend proc

(3)

f := proc(n,a::numeric) 1-a^n end proc:

g := proc(n,b::numeric) b^n end proc:

joinprocsf,g,result_type=list

procn,a,b::numericlocalresultf,resultg;resultf:=1a^n;resultg:=b^n;returnresultf,resultgend proc

(4)

grenamevarb=a,g

g:=procn,a::numerica^nend proc

(5)

Jjoinprocsf,g,result_type=list

J:=procn,a::numericlocalresultf,resultg;resultf:=1a^n;resultg:=a^n;returnresultf,resultgend proc

(6)

optimizeJ

procn,a::numericlocalt1;t1:=a^n;return1t1,t1end proc

(7)

See Also

codegen[optimize]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam