frontend
process general expression into a rational expression
Calling Sequence
Parameters
Description
Thread Safety
Examples
frontend(p, x)
frontend(p, x, [ts, es], arg1,..., argn)
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
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 sin⁡x or 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.
For more information on thread safety, see index/threadsafe.
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≔sin⁡x+x2
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 sin⁡x, so straightforward application of the degree command will fail.
degree⁡a,x
FAIL
Using frontend freezes the sine function. As a consequence, degree now succeeds: all it sees is a polynomial.
frontend⁡degree,a,x
2
Here is another example. Suppose we want to expand the square in the following expression b.
b≔sin⁡x+y+sin⁡x−y2
Straightforward application of the expand command also expands the trigonometric expressions, which we may not want to happen.
expand⁡b
4⁢sin⁡x2⁢cos⁡y2
If we apply frontend, it freezes the trigonometric expressions. The expand command then sees something of the form s1+s22 and expands it to s12+2⁢s1⁢s2+s22, not knowing or caring that s1 represents sin⁡x+y and s2 represents sin⁡x−y. Afterwards, frontend substitutes the original trigonometric expressions for the variables.
frontend⁡expand,b
sin⁡x+y2+2⁢sin⁡x+y⁢sin⁡x−y+sin⁡x−y2
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+sin⁡y+cos⁡1+exp⁡cos⁡1−z
c≔x+sin⁡y+cos⁡1+ⅇcos⁡1−z
By default, indets returns all subexpressions of c that are not sums, products, or constants.
indets⁡c
x,y,z,x,ⅇcos⁡1−z,sin⁡y
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:
frontend⁡print,c
O+O+O+O
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.
frontend⁡indets,c
x,cos⁡1,ⅇcos⁡1−z,sin⁡y
If we specify that frontend should not freeze any subexpressions of type radical, then x will not be frozen. Let's examine this again by using print as the procedure p.
frontend⁡print,c,`*`,`+`,radical
x+O+O+O
This means that in the following call, indets sees the unfrozen expression x plus three variables O. It returns the three Os, x, and x itself. Then frontend substitutes the three original other terms for the Os and returns the result, as follows:
frontend⁡indets,c,`*`,`+`,radical
x,x,cos⁡1,ⅇcos⁡1−z,sin⁡y
Finally, in the following call, we specify that frontend should not freeze any subexpressions that contain the expression cos⁡1. This means the term cos⁡1 by itself, but also the term ⅇcos⁡1−z.
frontend⁡print,c,`*`,`+`,cos⁡1
O+O+cos⁡1+ⅇcos⁡1−z
Consequently, in the corresponding indets call, the expressions x and sin⁡y 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 cos⁡1, 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.
frontend⁡indets,c,`*`,`+`,cos⁡1
z,x,ⅇcos⁡1−z,sin⁡y
See Also
freeze
Download Help Document