# Polynomial factorization over number fields that are extensions of the rationals [duplicate]

I want to factor some polynomials into irreducible terms, but not only limited to integers.

If I evaluate Factor[x^4+1], it will generate nothing.

But in fact I can factor it into two quadratic terms, which is

$\qquad -(-1 + \sqrt2 x - x^2) (1 + \sqrt2 x + x^2)$.

According to the Wolfram Language documentation, one can obtain the above factorization by extending the domain.

Factor[x^4 + 1, Extension -> {Sqrt[2]}]


But how can I know there is a coefficient of $\sqrt2$?

Is there any straight forward way to factor the polynomial over the real numbers?

• In[1064]:= Factor[x^4 + 1, Extension -> All] Out[1064]= (-(-1)^(1/4) + x) ((-1)^(1/4) + x) (-(-1)^(3/4) + x) ((-1)^(3/4) + x) – Daniel Lichtblau Mar 6 '18 at 15:22
• Extension->Allworks not for lower versions like MMA 8.0. – Akku14 Mar 6 '18 at 16:48
• And Extension->All is over the complex numbers, not over the reals. – Akku14 Mar 6 '18 at 17:01
• @Daniel, might it be possible to be able to use Extension -> All, but excluding certain numbers like I? – J. M. will be back soon Mar 6 '18 at 21:11
• @J.M. Offhand I don't see a way to do that. – Daniel Lichtblau Mar 6 '18 at 23:38

Polynomials with real coefficients have either real roots, or complex roots that come in conjugate pairs. Suppose $r$ and $\bar{r}$ are complex conjugates, then:

(x - r)(x - Conjugate[r]) == x^2 - 2 Re[r] x + Abs[r]^2 //FullSimplify


True

The function realFactor uses the above:

realFactor[poly_, x_] := With[
{
real = Flatten @ Values @ Solve[poly == 0, x, Reals],
complex = Flatten @ Values @ Solve[poly == 0 && Im[x]>0, x]
},
Times @@ Join[
x - real,
x^2 - 2 Re[#]x + Abs[#]^2& /@ complex
] //RootReduce
]


realFactor[x^4 + 1, x]


(1 - Sqrt[2] x + x^2) (1 + Sqrt[2] x + x^2)

More complicated examples:

realFactor[x^5 + 1, x]
realFactor[x^6 + x + 1, x]


(1 + x) (1 + 1/2 (-1 - Sqrt[5]) x + x^2) (1 + 1/2 (-1 + Sqrt[5]) x + x^2)

(x^2 + x Root[1 - 27 #1^3 - 18 #1^4 - 12 #1^5 - 26 #1^9 + 10 #1^10 + #1^15 &, 3] + Root[-1 + #1^3 + #1^4 + #1^5 + 2 #1^6 + #1^7 - 2 #1^9 - 2 #1^10 - #1^12 + #1^15 &, 1]) (x^2 + x Root[1 - 27 #1^3 - 18 #1^4 - 12 #1^5 - 26 #1^9 + 10 #1^10 + #1^15 &, 2] + Root[-1 + #1^3 + #1^4 + #1^5 + 2 #1^6 + #1^7 - 2 #1^9 - 2 #1^10 - #1^12 + #1^15 &, 2]) (x^2 + x Root[1 - 27 #1^3 - 18 #1^4 - 12 #1^5 - 26 #1^9 + 10 #1^10 + #1^15 &, 1] + Root[-1 + #1^3 + #1^4 + #1^5 + 2 #1^6 + #1^7 - 2 #1^9 - 2 #1^10 - #1^12 + #1^15 &, 3])

• So, there is no inner-built function? If so, can I add it to Mathematica just like Factor[] or Solve[]? – user155860 Mar 7 '18 at 2:21

Find all roots and add conjugate complex roots to get all real factorisations.

sr = Select[Root[x^5 + 1, #] & /@ Range[5], Im[#] == 0 &]

(*   {-1}   *)

si = Select[Root[x^5 + 1, #] & /@ Range[5], Im[#] != 0 &]

(*   {Root[1 - #1 + #1^2 - #1^3 + #1^4 &, 1],
Root[1 - #1 + #1^2 - #1^3 + #1^4 &, 2],
Root[1 - #1 + #1^2 - #1^3 + #1^4 &, 3],
Root[1 - #1 + #1^2 - #1^3 + #1^4 &, 4]}   *)

pa = Plus @@ # & /@ Partition[si, 2]

Factor[x^5 + 1, Extension -> {#}] & /@ Union[sr, pa] //ToRadicals // Union

(*    {-(1/4) (1 + x) (-2 + (1 + Sqrt[5]) x - 2 x^2) (2 + (-1 + Sqrt[5]) x + 2 x^2),
(1 + x) (1 - x + x^2 - x^3 + x^4)}          *)