apply - Maple Help

apply

construct a function expression

 Calling Sequence apply(p, rest)

Parameters

 p - expression (e.g., a procedure or name) to be applied rest - (optional) expression sequence of arguments to be passed to p

Description

 • The apply(p, rest) calling sequence returns the expression $p\left(\mathrm{rest}\right)$.
 • Using unapply, the apply procedure satisfies the functional equation apply(unapply(p, v), op(v)) = p.
 • If p has special evaluation rules, then these rules are not respected.

Examples

 > $\mathrm{apply}\left(g\right)$
 ${g}{}\left(\right)$ (1)
 > $\mathrm{apply}\left(f,s\right)$
 ${f}{}\left({s}\right)$ (2)
 > $\mathrm{apply}\left(f,s,t,u,v\right)$
 ${f}{}\left({s}{,}{t}{,}{u}{,}{v}\right)$ (3)
 > $\mathrm{apply}\left(\mathrm{sin},\mathrm{\pi }\right)$
 ${0}$ (4)
 > $\mathrm{map}\left(\mathrm{apply},\left[\mathrm{sin},\mathrm{cos},\mathrm{tan}\right],\mathrm{\pi }\right)$
 $\left[{0}{,}{-1}{,}{0}\right]$ (5)
 > $\mathrm{apply}\left(\left[\mathrm{sin},\mathrm{cos},\mathrm{tan}\right],\mathrm{\pi }\right)$
 $\left[{0}{,}{-1}{,}{0}\right]$ (6)
 > $\mathrm{apply}\left(\mathrm{unapply}\left(\left[{x}^{2},\mathrm{exp}\left(x\right),x\right],x\right),2\right)$
 $\left[{4}{,}{{ⅇ}}^{{2}}{,}{2}\right]$ (7)
 > $\mathrm{apply}\left(\mathrm{unapply}\left({x}^{2}+{y}^{2},\left[x,y\right]\right),a,b\right)$
 ${{a}}^{{2}}{+}{{b}}^{{2}}$ (8)
 > map(proc(n)     description "an anonymous and recursive procedure";         (x -> apply(x, x))(f -> proc(p, c)                                     if c > n then                                             p                                     else                                             (f(f))(p * c, 1 + c)                                     end if                                 end proc)(1, 1)     end proc, [\$ 1 .. 10]);
 $\left[{1}{,}{2}{,}{6}{,}{24}{,}{120}{,}{720}{,}{5040}{,}{40320}{,}{362880}{,}{3628800}\right]$ (9)

An example of special evaluation rules. The command Typesetting[Typeset] is an internal command that receives a Maple expression, and returns an expression used by the GUI for typesetting purposes. The output usually looks just like the input, but it is a very different expression:

 > $\mathrm{Typesetting}\left[\mathrm{Typeset}\right]\left(\mathrm{sqrt}\left(x\right)\right)$
 $\sqrt{{x}}$ (10)
 > $\mathrm{lprint}\left(\mathrm{Typesetting}\left[\mathrm{Typeset}\right]\left(\mathrm{sqrt}\left(x\right)\right)\right)$
 Typesetting:-msqrt(Typesetting:-mi("x"))

The first argument to Typeset has type uneval, signifying that it is not evaluated before being passed to Typesetting[Typeset]. In the previous example, that means we can assign something to $x$ (say, $5$), but still get a typeset square root of $x$ rather than of $5$.

 > $x≔5$
 ${x}{≔}{5}$ (11)
 > $\mathrm{Typesetting}\left[\mathrm{Typeset}\right]\left(\mathrm{sqrt}\left(x\right)\right)$
 $\sqrt{{x}}$ (12)

If we want $x$ to evaluate to $5$ before typesetting occurs, we can use the apply command.

 > $\mathrm{apply}\left(\mathrm{Typesetting}\left[\mathrm{Typeset}\right],\mathrm{sqrt}\left(x\right)\right)$
 $\sqrt{{5}}$ (13)