# Factoring: collect

### 5.27.16 Factoring: collect

The collect command factors polynomials over their coefficient fields or extensions of the fields.

- collect takes one mandatory and one optional argument:
  - P, a polynomial or a list of polynomials.
  - Optionally, α, a number, such as √n, determining an extension field to the field of coefficients of P.
- collect(P ⟨ ,α⟩) returns the factored form of the polynomial (or list of polynomials), where the factorization is done over the field of coefficients (such as ℚ) or the smallest extension field containing α (e.g. ℚ[α]). In complex mode (see Section 2.5.7), the field is complexified.

The factor command (see 5.12.10) will also factor polynomials over their coefficient fields (or extensions of it), but will further factor each factor of degree 2 if Sqrt is checked in the cas configuration.

#### Examples.

- Factor x2−4 over the integers, Input:
  collect(x^2-4)
  Output (in real mode):

  ⎛ ⎝ | x−2 | ⎞ ⎠ | ⎛ ⎝ | x+2 | ⎞ ⎠

- Factor x2+4 over the integers: Input:
  collect(x^2+4)
  Output (in real mode):

  x2+4

  Output (in complex mode):

  ⎛ ⎝ | x+2i | ⎞ ⎠ | ⎛ ⎝ | x−2i | ⎞ ⎠

- Factor x2−2 over the rationals: Input:
  collect(x^2-2)
  Output (in real mode):

  x2−2

  But if you input:
  collect(sqrt(2)*(x^2-2))
  you get: Output:

  √

  2

  ⎛
  ⎜
  ⎝

  x−

  √

  2

  ⎞
  ⎟
  ⎠

  ⎛
  ⎜
  ⎝

  x+

  √

  2

  ⎞
  ⎟
  ⎠

- Factor x3−2x2+1 and x2−x over the rationals. Input:
  collect([x^3-2*x^2+1,x^2-x])
  Output:

  ⎡ ⎣ | ⎛ ⎝ | x−1 | ⎞ ⎠ | ⎛ ⎝ | x2−x−1 | ⎞ ⎠ | ,x | ⎛ ⎝ | x−1 | ⎞ ⎠ | ⎤ ⎦

  but:
  Input:
  collect((x^3-2*x^2+1)*sqrt(5))
  Output:

  √

  5

  ⎛
  ⎜
  ⎜
  ⎝

  x+

  −

  √

  5

  −1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  ⎛
  ⎝

  x−1

  ⎞
  ⎠

  ⎛
  ⎜
  ⎜
  ⎝

  x+

  √

  5

  −1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  or:
  Input:
  collect(x^3-2*x^2+1,sqrt(5))
  Output:

  ⎛
  ⎜
  ⎜
  ⎝

  x+

  −

  √

  5

  −1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  ⎛
  ⎝

  x−1

  ⎞
  ⎠

  ⎛
  ⎜
  ⎜
  ⎝

  x+

  √

  5

  −1

  2

  ⎞
  ⎟
  ⎟
  ⎠