 collect - Maple Help

collect

collect coefficients of like powers Calling Sequence collect(a, x) collect(a, x, form, func) collect(a, x, func) Parameters

 a - expression x - indeterminate, or a list or set of indeterminates, or an unevaluated function form - (optional) name; recursive (default) or distributed func - (optional) procedure Description

 • The collect function views a as a general polynomial in x.  It collects all the coefficients with the same rational power of x.  This includes positive and negative powers, and fractional powers.  Note that the resulting expression is not necessarily sorted by powers of x.  To sort a polynomial see the sort function.
 • There are four main purposes for using collect. Firstly, to "simplify" an expression by factoring out all terms of like powers in some indeterminate. Secondly, to expand a polynomial in a variable before applying the coeff function. Thirdly, to write a multivariate polynomial in different forms. Fourthly, to apply a function to the coefficients of a polynomial. The examples below show each of these uses.
 • The second argument x can be a single indeterminate (univariate case) or a list or set of indeterminates x1, x2, ..., xn (multivariate case).  Sets can only be used if the distributed form is specified (see below).  The indeterminates can be names or unevaluated function calls but not sums or products or fractional powers.  To collect fractional powers, for example $\sqrt{x}$ just collect x.
 • Two forms for the result are available.  The form is specified by the optional argument form. It may be the name recursive (the default) or the name distributed.
 • The recursive form is obtained by first collecting the coefficients in x1, then for each coefficient in x1, collecting the coefficients in x2 and so on. If the indeterminates are specified as a set, their order is controlled by Maple and the results might differ from session to session. The distributed form is the form obtained by collecting the coefficients of ${\mathrm{x1}}^{\mathrm{e1}}{\mathrm{x2}}^{\mathrm{e2}}...{\mathrm{xn}}^{\mathrm{en}}$.
 • A function may be specified using the optional argument func. It is applied to the coefficients of the collected result. Often simplify or factor will be used.
 • The following shorthand is supported:  often one wants to collect all the derivatives in an expression, or all the sine and cosines present in an expression.  If func is a name then collect(expr, func) will collect expr with respect to functions whose name is func. Examples

Simplifying an expression by regrouping terms

 > $f≔a\mathrm{ln}\left(x\right)-\mathrm{ln}\left(x\right)x-x$
 ${f}{≔}{a}{}{\mathrm{ln}}{}\left({x}\right){-}{\mathrm{ln}}{}\left({x}\right){}{x}{-}{x}$ (1)
 > $\mathrm{collect}\left(f,\mathrm{ln}\left(x\right)\right)$
 $\left({a}{-}{x}\right){}{\mathrm{ln}}{}\left({x}\right){-}{x}$ (2)
 > $g≔\mathrm{int}\left({x}^{2}\left(\mathrm{exp}\left(x\right)+\mathrm{exp}\left(-x\right)\right),x\right)$
 ${g}{≔}{-}\frac{{{x}}^{{2}}}{{{ⅇ}}^{{x}}}{-}\frac{{2}{}{x}}{{{ⅇ}}^{{x}}}{-}\frac{{2}}{{{ⅇ}}^{{x}}}{+}{{x}}^{{2}}{}{{ⅇ}}^{{x}}{-}{2}{}{x}{}{{ⅇ}}^{{x}}{+}{2}{}{{ⅇ}}^{{x}}$ (3)
 > $\mathrm{collect}\left(g,\mathrm{exp}\left(x\right)\right)$
 $\left({{x}}^{{2}}{-}{2}{}{x}{+}{2}\right){}{{ⅇ}}^{{x}}{+}\frac{{-}{{x}}^{{2}}{-}{2}{}{x}{-}{2}}{{{ⅇ}}^{{x}}}$ (4)

Expanding a polynomial in one variable before using coeff

 > $f≔x\left(x+1\right)+y\left(x+1\right)$
 ${f}{≔}{x}{}\left({x}{+}{1}\right){+}{y}{}\left({x}{+}{1}\right)$ (5)
 > $\mathrm{coeff}\left(f,x,1\right)$
 ${1}{+}{y}$ (6)
 > $g≔\mathrm{collect}\left(f,x\right)$
 ${g}{≔}{{x}}^{{2}}{+}\left({1}{+}{y}\right){}{x}{+}{y}$ (7)
 > $\mathrm{coeff}\left(g,x,1\right)$
 ${1}{+}{y}$ (8)

Writing a multivariate polynomial in different forms

 > $p≔xy+axy+y{x}^{2}-ay{x}^{2}+x+ax:$
 > $\mathrm{collect}\left(p,\left[x,y\right],\mathrm{recursive}\right)$
 $\left({-}{a}{+}{1}\right){}{y}{}{{x}}^{{2}}{+}\left(\left({a}{+}{1}\right){}{y}{+}{a}{+}{1}\right){}{x}$ (9)
 > $\mathrm{collect}\left(p,\left[y,x\right],\mathrm{recursive}\right)$
 $\left(\left({-}{a}{+}{1}\right){}{{x}}^{{2}}{+}\left({a}{+}{1}\right){}{x}\right){}{y}{+}\left({a}{+}{1}\right){}{x}$ (10)

Note this returns a result that is order-dependent

 > $\mathrm{collect}\left(p,\left\{x,y\right\},\mathrm{recursive}\right)$
 $\left({-}{a}{+}{1}\right){}{y}{}{{x}}^{{2}}{+}\left(\left({a}{+}{1}\right){}{y}{+}{a}{+}{1}\right){}{x}$ (11)

But this does not

 > $\mathrm{collect}\left(p,\left\{x,y\right\},\mathrm{distributed}\right)$
 $\left({-}{a}{+}{1}\right){}{y}{}{{x}}^{{2}}{+}\left({a}{+}{1}\right){}{x}{}{y}{+}\left({a}{+}{1}\right){}{x}$ (12)
 > $\mathrm{collect}\left(p,\left[x,y\right],\mathrm{distributed}\right)$
 $\left({-}{a}{+}{1}\right){}{y}{}{{x}}^{{2}}{+}\left({a}{+}{1}\right){}{x}{}{y}{+}\left({a}{+}{1}\right){}{x}$ (13)

Applying a function to the coefficients

 > $f≔{a}^{3}x-x+{a}^{3}+a$
 ${f}{≔}{{a}}^{{3}}{}{x}{+}{{a}}^{{3}}{+}{a}{-}{x}$ (14)
 > $\mathrm{collect}\left(f,x\right)$
 $\left({{a}}^{{3}}{-}{1}\right){}{x}{+}{{a}}^{{3}}{+}{a}$ (15)
 > $\mathrm{collect}\left(f,x,\mathrm{factor}\right)$
 $\left({a}{-}{1}\right){}\left({{a}}^{{2}}{+}{a}{+}{1}\right){}{x}{+}{a}{}\left({{a}}^{{2}}{+}{1}\right)$ (16)

Collect understands positive and negative rational powers

 > $p≔\frac{y}{x}+\frac{2z}{x}+{x}^{\frac{1}{3}}-y{x}^{\frac{1}{3}}$
 ${p}{≔}\frac{{y}}{{x}}{+}\frac{{2}{}{z}}{{x}}{+}{{x}}^{{1}}{{3}}}{-}{y}{}{{x}}^{{1}}{{3}}}$ (17)
 > $\mathrm{collect}\left(p,x\right)$
 $\left({1}{-}{y}\right){}{{x}}^{{1}}{{3}}}{+}\frac{{y}{+}{2}{}{z}}{{x}}$ (18)

Collect can simplify for general indeterminates (e.g. diff, D, sin).

 > $\mathrm{DE}≔\mathrm{diff}\left(y\left(x\right),x,x\right)\mathrm{sin}\left(x\right)-\mathrm{diff}\left(y\left(x\right),x\right)\mathrm{sin}\left(y\left(x\right)\right)+\mathrm{sin}\left(x\right)\mathrm{diff}\left(y\left(x\right),x\right)+\mathrm{sin}\left(y\left(x\right)\right)\mathrm{diff}\left(y\left(x\right),x,x\right)$
 ${\mathrm{DE}}{≔}\left(\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{x}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right)\right){}{\mathrm{sin}}{}\left({x}\right){-}\left(\frac{{ⅆ}}{{ⅆ}{x}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right)\right){}{\mathrm{sin}}{}\left({y}{}\left({x}\right)\right){+}{\mathrm{sin}}{}\left({x}\right){}\left(\frac{{ⅆ}}{{ⅆ}{x}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right)\right){+}{\mathrm{sin}}{}\left({y}{}\left({x}\right)\right){}\left(\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{x}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right)\right)$ (19)
 > $\mathrm{collect}\left(\mathrm{DE},\mathrm{diff}\right)$
 $\left({\mathrm{sin}}{}\left({x}\right){+}{\mathrm{sin}}{}\left({y}{}\left({x}\right)\right)\right){}\left(\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{x}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right)\right){+}\left({\mathrm{sin}}{}\left({x}\right){-}{\mathrm{sin}}{}\left({y}{}\left({x}\right)\right)\right){}\left(\frac{{ⅆ}}{{ⅆ}{x}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right)\right)$ (20)
 > $\mathrm{collect}\left(\mathrm{DE},\mathrm{sin}\right)$
 $\left(\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{x}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right){+}\frac{{ⅆ}}{{ⅆ}{x}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right)\right){}{\mathrm{sin}}{}\left({x}\right){+}\left(\frac{{{ⅆ}}^{{2}}}{{ⅆ}{{x}}^{{2}}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right){-}\frac{{ⅆ}}{{ⅆ}{x}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({x}\right)\right){}{\mathrm{sin}}{}\left({y}{}\left({x}\right)\right)$ (21)

Collect does not sort in general

 > $\mathrm{collect}\left({x}^{3}y+{x}^{2}{y}^{3}+x+3,y\right)$
 ${{x}}^{{2}}{}{{y}}^{{3}}{+}{{x}}^{{3}}{}{y}{+}{x}{+}{3}$ (22)
 > $\mathrm{sort}\left(,y\right)$
 ${{x}}^{{2}}{}{{y}}^{{3}}{+}{{x}}^{{3}}{}{y}{+}{x}{+}{3}$ (23)