### 9.1.10 Factoring

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

- 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 ℚ.

factor(x^4-1)

| ⎛ ⎝ | 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 several ways.

Using cfactor:

cfactor(x^4-1

or, using factor with adding i to the extension field:

factor(x^4-1,i)

or, using factor in complex mode:

factor(x^4-1)

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

Factor x4+1 over ℚ.

factor(x^4+1)

x4+1 |  |  |  |  |  |  |  |  |  |

Indeed, x4+1 has no factor with rational coefficients.

Factor x4+1 over ℚ[i]. Using complex mode:

cfactor(x^4+1)

| ⎛ ⎝ | 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 the complex box in the CAS configuration:

solve(x^4+1,x)

| ⎡ ⎢ ⎢ ⎣ |
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:

factor(x^4+1,sqrt(2))

| ⎛ ⎜ ⎝ | x2− | √ |
2
| x+1 | ⎞ ⎟ ⎠ | ⎛ ⎜ ⎝ | x2+ | √ |
2
| x+1 | ⎞ ⎟ ⎠

To factor over ℂ input:

cfactor(x^4+1,sqrt(2))

or put Xcas back in complex mode.