%mathpiper,def="Expand"

/* Expand expands polynomials.
 */
10 # Expand(expr_CanBeUni) <-- NormalForm(MakeUni(expr));
20 # Expand(_expr) <-- expr;

10 # Expand(expr_CanBeUni(var),_var) <-- NormalForm(MakeUni(expr,var));
20 # Expand(_expr,_var) <-- expr;

%/mathpiper



%mathpiper_docs,name="Expand",categories="User Functions;Polynomials (Operations)"
*CMD Expand --- transform a polynomial to an expanded form
*STD
*CALL
	Expand(expr)
	Expand(expr, var)
	Expand(expr, varlist)

*PARMS

{expr} -- a polynomial expression

{var} -- a variable

{varlist} -- a list of variables

*DESC

This command brings a polynomial in expanded form, in which
polynomials are represented in the form 
$c0 + c1*x + c2*x^2 + ... + c[n]*x^n$. In this form, it is easier to test whether a polynomial is
zero, namely by testing whether all coefficients are zero.

If the polynomial "expr" contains only one variable, the first
calling sequence can be used. Otherwise, the second form should be
used which explicitly mentions that "expr" should be considered as a
polynomial in the variable "var". The third calling form can be used
for multivariate polynomials. Firstly, the polynomial "expr" is
expanded with respect to the first variable in "varlist". Then the
coefficients are all expanded with respect to the second variable, and
so on.

*E.G.

In> PrettyPrinterSet("PrettyForm");
	
	True

In> Expand((1+x)^5);
	
	 5        4         3         2
	x  + 5 * x  + 10 * x  + 10 * x  + 5 * x + 1

In> Expand((1+x-y)^2, x);
	
	 2                                2
	x  + 2 * ( 1 - y ) * x + ( 1 - y )

In> Expand((1+x-y)^2, {x,y});
	
	 2                         2
	x  + ( -2 * y + 2 ) * x + y  - 2 * y + 1
	

*SEE ExpandBrackets
%/mathpiper_docs