collect
collect coefficients of like powers
Calling Sequence
Parameters
Description
Examples
collect(a, x)
collect(a, x, form, func)
collect(a, x, func)
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
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 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 x1e1⁢x2e2⁢...⁢xnen.
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.
Simplifying an expression by regrouping terms
f≔a⁢ln⁡x−ln⁡x⁢x−x
collect⁡f,ln⁡x
a−x⁢ln⁡x−x
g≔int⁡x2⁢exp⁡x+exp⁡−x,x
g≔−x2ⅇx−2⁢xⅇx−2ⅇx+x2⁢ⅇx−2⁢x⁢ⅇx+2⁢ⅇx
collect⁡g,exp⁡x
x2−2⁢x+2⁢ⅇx+−x2−2⁢x−2ⅇx
Expanding a polynomial in one variable before using coeff
f≔x⁢x+1+y⁢x+1
coeff⁡f,x,1
1+y
g≔collect⁡f,x
g≔x2+1+y⁢x+y
coeff⁡g,x,1
Writing a multivariate polynomial in different forms
p≔x⁢y+a⁢x⁢y+y⁢x2−a⁢y⁢x2+x+a⁢x:
collect⁡p,x,y,recursive
−a+1⁢y⁢x2+a+1⁢y+a+1⁢x
collect⁡p,y,x,recursive
−a+1⁢x2+a+1⁢x⁢y+a+1⁢x
Note this returns a result that is order-dependent
But this does not
collect⁡p,x,y,distributed
−a+1⁢y⁢x2+a+1⁢x⁢y+a+1⁢x
Applying a function to the coefficients
f≔a3⁢x−x+a3+a
f≔a3⁢x+a3+a−x
collect⁡f,x
a3−1⁢x+a3+a
collect⁡f,x,factor
a−1⁢a2+a+1⁢x+a⁢a2+1
Collect understands positive and negative rational powers
p≔yx+2⁢zx+x13−y⁢x13
collect⁡p,x
1−y⁢x13+y+2⁢zx
Collect can simplify for general indeterminates (e.g. diff, D, sin).
DE≔diff⁡y⁡x,x,x⁢sin⁡x−diff⁡y⁡x,x⁢sin⁡y⁡x+sin⁡x⁢diff⁡y⁡x,x+sin⁡y⁡x⁢diff⁡y⁡x,x,x
DE≔ⅆ2ⅆx2y⁡x⁢sin⁡x−ⅆⅆxy⁡x⁢sin⁡y⁡x+sin⁡x⁢ⅆⅆxy⁡x+sin⁡y⁡x⁢ⅆ2ⅆx2y⁡x
collect⁡DE,diff
sin⁡x+sin⁡y⁡x⁢ⅆ2ⅆx2y⁡x+sin⁡x−sin⁡y⁡x⁢ⅆⅆxy⁡x
collect⁡DE,sin
ⅆ2ⅆx2y⁡x+ⅆⅆxy⁡x⁢sin⁡x+ⅆ2ⅆx2y⁡x−ⅆⅆxy⁡x⁢sin⁡y⁡x
Collect does not sort in general
collect⁡x3⁢y+x2⁢y3+x+3,y
x2⁢y3+x3⁢y+x+3
sort⁡,y
See Also
coeff
sort
Download Help Document