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
]
Your example:
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])
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)
$\endgroup$ – Daniel Lichtblau Mar 6 '18 at 15:22Extension->All
works not for lower versions like MMA 8.0. $\endgroup$ – Akku14 Mar 6 '18 at 16:48Extension->All
is over the complex numbers, not over the reals. $\endgroup$ – Akku14 Mar 6 '18 at 17:01Extension -> All
, but excluding certain numbers likeI
? $\endgroup$ – J. M.'s ennui♦ Mar 6 '18 at 21:11