1
$\begingroup$

This question already has an answer here:

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?

$\endgroup$

marked as duplicate by Carl Woll, José Antonio Díaz Navas, m_goldberg, Community Mar 7 '18 at 2:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ 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:22
  • 1
    $\begingroup$ Extension->Allworks not for lower versions like MMA 8.0. $\endgroup$ – Akku14 Mar 6 '18 at 16:48
  • $\begingroup$ And Extension->All is over the complex numbers, not over the reals. $\endgroup$ – Akku14 Mar 6 '18 at 17:01
  • $\begingroup$ @Daniel, might it be possible to be able to use Extension -> All, but excluding certain numbers like I? $\endgroup$ – J. M. will be back soon Mar 6 '18 at 21:11
  • $\begingroup$ @J.M. Offhand I don't see a way to do that. $\endgroup$ – Daniel Lichtblau Mar 6 '18 at 23:38
2
$\begingroup$

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])

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

Improved answer:

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)}          *)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.