
expand - expansion of an expression

Calling sequence:
expand(expr)
expand(expr, expr_1 ...)

Parameter:
expr     --  expression
expr_1   --  expression

Overloading:

1

Summary:

expand expands the algebraic expression expr. The most important use of
expand is the multiplication of products in sums.  Furthermore the powers
of sums are multiplied as long as they are positive integers. Products in the
divisors of fractions are not multiplied.

With the optional parameters expr_1, ...  etc. the expansion of certain
sub-expressions of expr can be prevented:  if these expressions are given
as parameters then the sub-expressions of expr that correspond to these
expressions are not expanded.  More exactly the following occurs: in expr

the sub-expressions expr_1 ...  are parallelly substitutedwith auxiliary
variables (see subs), then expr is expanded.  In the expanded expression
the auxiliary variables are then replaced by the original expressions.

The expansion of functions can be controlled by the user's own expansion
routines. For this the function to be expanded must have a function environment
in which a procedure is entered as an attribute under the index "expand"
(compare to the function funcattr ).  This procedure is called by expand
as soon as this function environment occurs as the zero operand in a sub-
expression of expr.  The procedure is called with the operands of the sub-
expression as arguments.  The operands are not expanded before the call
of the expansion routine.  The result of the expansion routine is also not
expanded.

Furthermore for domains that are not basic types user expansion routines
can also be given. These must be entered under the index "expand" in the
domain. The routine is called if an element of the domain is contained in the
expression to be expanded. The domain element is entered as argument, its
result is not expanded.  If no expansion routine is given for a domain then
the domain elements are processed as constants on expansion.

expand is a kernel function.

>>  expand((x+1)*(y+z));

      y+z+x*y+x*z

>>  expand((x+1)/(y+z));

      1/(y+z)+x/(y+z)

>>  expand((x+1)*(y+z), x+1);

      y*(x+1)+z*(x+1)

>>  expand((x+y)^(z+2));

      x*y*(x+y)^z*2+x^2*(x+y)^z+y^2*(x+y)^z

>>  expand((x+y)^(z-2));

      (x+y)^(-2)*(x+y)^z

>>  sin:= funcattr(sin, "expand", proc(x)
        local a,b;
    begin
        x:= expand(x);
        if type(x) = "_plus" then
          a:= op(x,1); b:= x - a;
          expand(sin(a)*cos(b)+cos(a)*sin(b))
        else
          sin(x)
        end_if
    end_proc):
    expand(sin(a*(b+c)));

      cos(a*b)*sin(a*c)+cos(a*c)*sin(a*b)

>>  expand(sin(a+b)*c);

      c*cos(a)*sin(b)+c*cos(b)*sin(a)

See also:  funcattr , subs

