joinprocs - Maple Help

codegen

 joinprocs
 Join the body of two or more Maple procedures together

 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

 > $\mathrm{with}\left(\mathrm{codegen},\mathrm{joinprocs},\mathrm{optimize},\mathrm{renamevar}\right):$
 > 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:
 > $J≔\mathrm{joinprocs}\left(\left[f,g\right]\right)$
 ${J}{≔}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{,}{\mathrm{resultf}}{,}{\mathrm{resultg}}{,}{t}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{≔}{\mathrm{exp}}{}\left({−}{x}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{≔}{x}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultf}}{≔}{t}{*}{e}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{≔}{\mathrm{exp}}{}\left({−}{x}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{≔}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultg}}{≔}{t}{*}{e}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultf}}{,}{\mathrm{resultg}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > $\mathrm{optimize}\left(J\right)$
 ${\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{e1}}{,}{t}{,}{\mathrm{t1}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{e1}}{≔}{\mathrm{exp}}{}\left({−}{x}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t1}}{≔}{x}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{≔}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t1}}{*}{\mathrm{e1}}{,}{t}{*}{\mathrm{e1}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > $\mathrm{joinprocs}\left(\left[f,g\right],\mathrm{result_type}=\mathrm{array}\right)$
 ${\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{,}{\mathrm{result}}{,}{t}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{result}}{≔}{\mathrm{array}}{}\left({1}{..}{2}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{≔}{\mathrm{exp}}{}\left({−}{x}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{≔}{x}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{result}}{[}{1}{]}{≔}{t}{*}{e}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{≔}{\mathrm{exp}}{}\left({−}{x}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{≔}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{result}}{[}{2}{]}{≔}{t}{*}{e}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{result}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (3)
 > f := proc(n,a::numeric) 1-a^n end proc:
 > g := proc(n,b::numeric) b^n end proc:
 > $\mathrm{joinprocs}\left(\left[f,g\right],\mathrm{result_type}=\mathrm{list}\right)$
 ${\mathbf{proc}}\left({n}{,}{a}{,}{b}{::}{\mathrm{numeric}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultf}}{,}{\mathrm{resultg}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultf}}{≔}{1}{-}{a}{^}{n}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultg}}{≔}{b}{^}{n}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left[{\mathrm{resultf}}\right]{,}\left[{\mathrm{resultg}}\right]\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (4)
 > $g≔\mathrm{renamevar}\left(b=a,g\right)$
 ${g}{≔}{\mathbf{proc}}\left({n}{,}{a}{::}{\mathrm{numeric}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{a}{^}{n}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (5)
 > $J≔\mathrm{joinprocs}\left(\left[f,g\right],\mathrm{result_type}=\mathrm{list}\right)$
 ${J}{≔}{\mathbf{proc}}\left({n}{,}{a}{::}{\mathrm{numeric}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultf}}{,}{\mathrm{resultg}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultf}}{≔}{1}{-}{a}{^}{n}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultg}}{≔}{a}{^}{n}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left[{\mathrm{resultf}}\right]{,}\left[{\mathrm{resultg}}\right]\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (6)
 > $\mathrm{optimize}\left(J\right)$
 ${\mathbf{proc}}\left({n}{,}{a}{::}{\mathrm{numeric}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t1}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t1}}{≔}{a}{^}{n}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left[{1}{-}{\mathrm{t1}}\right]{,}\left[{\mathrm{t1}}\right]\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (7)