# Factoring: factor cfactor

### 5.12.10 Factoring: factor cfactor

The factor and cfactor commands factor expressions over their coefficient fields or extensions of their fields. (See also Section 5.27.16.)

- factor takes one mandatory argument and one optional argument:
  - expr, an expression or a list of expressions.
  - Optionally, α, to specify an extension field.
- factor(expr) returns expr factored over the field of its coefficients, with the addition of i in complex mode (see Section 2.5.5). If sqrt is enabled in the Cas configuration (see Section 2.5.7), polynomials of order 2 are factorized in complex mode or in real mode if the discriminant is positive.
  factor(expr,α) returns expr factored over F[α], where F is the field of coefficients of expr.
- cfactor factors like factor, except the field includes i whether in real or complex mode.

#### Examples.

- Factor x4−1 over ℚ.
  Input:
  factor(x^4-1)
  Output:

  ⎛ ⎝ | x−1 | ⎞ ⎠ | ⎛ ⎝ | x+1 | ⎞ ⎠ | ⎛ ⎝ | x2+1 | ⎞ ⎠

  The coefficients are rationals, hence the factors are polynomials with rationals coefficients.
- Factor x4−1 over ℚ[i].
  This can be done in a number of ways.
  - Using cfactor.
    Input:
    cfactor(x^4-1
  - Using factor with adding i to the extension field.
    Input:
    factor(x^4-1,i)
  - Using factor in complex mode.
    Input (in complex mode):
    factor(x^4-1)
    In all cases, the result will be:
    Output:

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

- Factor x4+1 over ℚ
  Input:
  factor(x^4+1)
  Output:

  x4+1

  Indeed x4+1 has no factor with rational coefficients.
- Factor x4+1 over ℚ[i].
  Using complex mode:
  Input:
  cfactor(x^4+1)
  Output:

  | ⎛ ⎝ | x2+i | ⎞ ⎠ | ⎛ ⎝ | x2−i | ⎞ ⎠

- Factor x4+1 over ℝ.
  You have to provide the square root required for extending the rationals. In order to do that with the help of Xcas, first check complex in the cas configuration:
  Input:
  solve(x^4+1,x)
  Output:

  ⎡
  ⎢
  ⎢
  ⎣

  1
  2

  √

  2

  ⎛
  ⎝

  1−i

  ⎞
  ⎠

  ,−

  1
  2

  √

  2

  ⎛
  ⎝

  1−i

  ⎞
  ⎠

  ,−

  1
  2

  √

  2

  ⎛
  ⎝

  1−i

  ⎞
  ⎠

  i,

  1
  2

  √

  2

  ⎛
  ⎝

  1−i

  ⎞
  ⎠

  i

  ⎤
  ⎥
  ⎥
  ⎦

  The roots depend on √2, and so will be in ℚ[√2]. Putting Xcas back in real mode, either check the sqrt box in the Cas configuration or:
  Input:
  factor(x^4+1,sqrt(2))
  Output:

  ⎛
  ⎜
  ⎝

  x2−

  √

  2

  x+1

  ⎞
  ⎟
  ⎠

  ⎛
  ⎜
  ⎝

  x2+

  √

  2

  x+1

  ⎞
  ⎟
  ⎠

  To factor over ℂ, put Xcas back in complex mode or input cfactor(x^4+1,sqrt(2)).