 frontend - Maple Help

frontend

process general expression into a rational expression Calling Sequence frontend(p, x) frontend(p, x, [ts, es], arg1,..., argn) Parameters

 p - procedure x - list of arguments to p ts - (optional) set of types of subexpressions that are not frozen (default: {+, *}) es - (optional) set of subexpressions e such that any subexpression containing e is not frozen, and in any occurrence of e in x, none of its subexpressions are frozen (default: {}) argi - (optional) additional arguments to p; these arguments are not frozen Description

 • The purpose of frontend is to extend the domain of computation for many of the functions in Maple.
 • For example, the procedure used by the Maple normal function is defined to work over the domain of rational functions.  Thus, to handle more general expressions such as expressions involving $\mathrm{sin}\left(x\right)$ or $\sqrt{x}$ reasonably, frontend is used to temporarily freeze all occurrences of such expressions for unique names.  This is always valid.
 • However, it is important to understand that the zero equivalence property of the normal function is only guaranteed if the subexpressions that are frozen are algebraically independent.
 • For each item in the list x, the following algorithm is applied to determine whether it or any of its subexpressions are frozen:
 – The following are not frozen: integers; rationals; floats that are of type numeric; strings; and names that are not of type constant.
 – If the argument is one of the expressions in es, then neither it nor its subexpressions is frozen.
 – If the argument
 • is of one of the types in ts (+ and * by default), or
 • is of type ^ and the exponent is an integer, or
 • contains one of the expressions in es, as determined by has,
 then it is not frozen and the algorithm is applied recursively to its subexpressions to determine if they or their subexpressions are frozen.
 – Otherwise, the argument is frozen. That is, a unique name is substituted for it.
 • The procedure p is then evaluated with the frozen argument(s). Any frozen names occurring in the result are substituted back for their original subexpressions.
 • The frontend function does not work with functions that assign a value to the function argument(s). For example, gcdex works but not if you specify the optional arguments. • The frontend command is thread-safe as of Maple 15. Examples

Suppose we want to find out the maximum degree to which the variable $x$ occurs in the expression $a$, ignoring cases where $x$ is inside a non-polynomial function.

 > $a≔\mathrm{sin}\left(x\right)+{x}^{2}$
 ${a}{≔}{\mathrm{sin}}{}\left({x}\right){+}{{x}}^{{2}}$ (1)

The default command to use for this is degree, but it requires that its argument is a polynomial. The expression $a$ is not a polynomial because of the occurrence of $\mathrm{sin}\left(x\right)$, so straightforward application of the degree command will fail.

 > $\mathrm{degree}\left(a,x\right)$
 ${\mathrm{FAIL}}$ (2)

Using frontend freezes the sine function. As a consequence, degree now succeeds: all it sees is a polynomial.

 > $\mathrm{frontend}\left(\mathrm{degree},\left[a,x\right]\right)$
 ${2}$ (3)

Here is another example. Suppose we want to expand the square in the following expression $b$.

 > $b≔{\left(\mathrm{sin}\left(x+y\right)+\mathrm{sin}\left(x-y\right)\right)}^{2}$
 ${b}{≔}{\left({\mathrm{sin}}{}\left({x}{+}{y}\right){+}{\mathrm{sin}}{}\left({x}{-}{y}\right)\right)}^{{2}}$ (4)

Straightforward application of the expand command also expands the trigonometric expressions, which we may not want to happen.

 > $\mathrm{expand}\left(b\right)$
 ${4}{}{{\mathrm{sin}}{}\left({x}\right)}^{{2}}{}{{\mathrm{cos}}{}\left({y}\right)}^{{2}}$ (5)

If we apply frontend, it freezes the trigonometric expressions. The expand command then sees something of the form ${\left({s}_{1}+{s}_{2}\right)}^{2}$ and expands it to ${s}_{1}^{2}+2{s}_{1}{s}_{2}+{s}_{2}^{2}$, not knowing or caring that ${s}_{1}$ represents $\mathrm{sin}\left(x+y\right)$ and ${s}_{2}$ represents $\mathrm{sin}\left(x-y\right)$. Afterwards, frontend substitutes the original trigonometric expressions for the variables.

 > $\mathrm{frontend}\left(\mathrm{expand},\left[b\right]\right)$
 ${{\mathrm{sin}}{}\left({x}{+}{y}\right)}^{{2}}{+}{2}{}{\mathrm{sin}}{}\left({x}{+}{y}\right){}{\mathrm{sin}}{}\left({x}{-}{y}\right){+}{{\mathrm{sin}}{}\left({x}{-}{y}\right)}^{{2}}$ (6)

In the final example, we use the indets command to find the indeterminates in the expression $c$. We examine several variations of how to call indets to get various results.

 > $c≔\sqrt{x}+\mathrm{sin}\left(y\right)+\mathrm{cos}\left(1\right)+{ⅇ}^{\mathrm{cos}\left(1\right)-z}$
 ${c}{≔}\sqrt{{x}}{+}{\mathrm{sin}}{}\left({y}\right){+}{\mathrm{cos}}{}\left({1}\right){+}{{ⅇ}}^{{\mathrm{cos}}{}\left({1}\right){-}{z}}$ (7)

By default, indets returns all subexpressions of $c$ that are not sums, products, or constants.

 > $\mathrm{indets}\left(c\right)$
 $\left\{{x}{,}{y}{,}{z}{,}\sqrt{{x}}{,}{{ⅇ}}^{{\mathrm{cos}}{}\left({1}\right){-}{z}}{,}{\mathrm{sin}}{}\left({y}\right)\right\}$ (8)

Let's examine what frontend does to $c$. We can do this with the following frontend call, in which we use print for the procedure p:

 > $\mathrm{frontend}\left(\mathrm{print},\left[c\right]\right)$
 ${\mathrm{O}}{+}{\mathrm{O}}{+}{\mathrm{O}}{+}{\mathrm{O}}$ (9)

We see that frontend replaces each of the four terms with a (new) variable called O. This means that in the following call, indets simply sees a sum of four variables, and returns these variables. frontend then replaces the original four terms for them.

 > $\mathrm{frontend}\left(\mathrm{indets},\left[c\right]\right)$
 $\left\{\sqrt{{x}}{,}{\mathrm{cos}}{}\left({1}\right){,}{{ⅇ}}^{{\mathrm{cos}}{}\left({1}\right){-}{z}}{,}{\mathrm{sin}}{}\left({y}\right)\right\}$ (10)

If we specify that frontend should not freeze any subexpressions of type radical, then $\sqrt{x}$ will not be frozen. Let's examine this again by using print as the procedure p.

 > $\mathrm{frontend}\left(\mathrm{print},\left[c\right],\left[\left\{\mathrm{+},\mathrm{*},\mathrm{radical}\right\}\right]\right)$
 $\sqrt{{x}}{+}{\mathrm{O}}{+}{\mathrm{O}}{+}{\mathrm{O}}$ (11)

This means that in the following call, indets sees the unfrozen expression $\sqrt{x}$ plus three variables O. It returns the three Os, $\sqrt{x}$, and $x$ itself. Then frontend substitutes the three original other terms for the Os and returns the result, as follows:

 > $\mathrm{frontend}\left(\mathrm{indets},\left[c\right],\left[\left\{\mathrm{+},\mathrm{*},\mathrm{radical}\right\}\right]\right)$
 $\left\{{x}{,}\sqrt{{x}}{,}{\mathrm{cos}}{}\left({1}\right){,}{{ⅇ}}^{{\mathrm{cos}}{}\left({1}\right){-}{z}}{,}{\mathrm{sin}}{}\left({y}\right)\right\}$ (12)

Finally, in the following call, we specify that frontend should not freeze any subexpressions that contain the expression $\mathrm{cos}\left(1\right)$. This means the term $\mathrm{cos}\left(1\right)$ by itself, but also the term ${ⅇ}^{\mathrm{cos}\left(1\right)-z}$.

 > $\mathrm{frontend}\left(\mathrm{print},\left[c\right],\left[\left\{\mathrm{+},\mathrm{*}\right\},\left\{\mathrm{cos}\left(1\right)\right\}\right]\right)$
 ${\mathrm{O}}{+}{\mathrm{O}}{+}{\mathrm{cos}}{}\left({1}\right){+}{{ⅇ}}^{{\mathrm{cos}}{}\left({1}\right){-}{z}}$ (13)

Consequently, in the corresponding indets call, the expressions $\sqrt{x}$ and $\mathrm{sin}\left(y\right)$ are frozen as new variables O, and indets can not look inside the expressions to find the separate variables $x$ and $y$. It does, however, see the expression $\mathrm{cos}\left(1\right)$, and it recognizes it as a constant that is not to be included in the set of indeterminates. It also sees the variable $z$, which is also returned.

 > $\mathrm{frontend}\left(\mathrm{indets},\left[c\right],\left[\left\{\mathrm{+},\mathrm{*}\right\},\left\{\mathrm{cos}\left(1\right)\right\}\right]\right)$
 $\left\{{z}{,}\sqrt{{x}}{,}{{ⅇ}}^{{\mathrm{cos}}{}\left({1}\right){-}{z}}{,}{\mathrm{sin}}{}\left({y}\right)\right\}$ (14)