# Collect terms by powers of a variable (collect)

Group the terms of an expression by powers of a variable.

## How to write it

### collect(expr, x)

**expr**

Any expression: a number, a formula, a list or a matrix. Takes an expression.

**x**

The variable to collect by. Takes a variable.

## Examples

- $\displaystyle x^{2} y+x^{2} z+x = x^{2} (y+z)+x$

  `collect(x^2 y + x^2 z + x, x)`

  In the solver, `collect(x^2 y + x^2 z + x, x)` gives `x^2*(y + z) + x`.

  [Open in the solver](https://hilberon.com/?q=collect%28x%5E2%20y%20%2B%20x%5E2%20z%20%2B%20x%2C%20x%29)

## Related functions

- [complex_expand](https://hilberon.com/library/complex_expand)

  Expand an expression assuming its variables are real.
- [coefficients](https://hilberon.com/library/coefficients)

  List the coefficients of a polynomial, constant term first.
- [cyclotomic](https://hilberon.com/library/cyclotomic)

  Cyclotomic polynomial of a given order.
- [cancel](https://hilberon.com/library/cancel)

  Cancel the common factors of a fraction.
- [degree](https://hilberon.com/library/degree)

  Degree of a polynomial in a variable.
- [apart](https://hilberon.com/library/apart)

  Split a rational expression into partial fractions.

---
Source: https://hilberon.com/library/collect
