# How to factor real polynomials over complex field

I'd like to factor polynomials over the complex field. For example, how do I factor x^2+1 over $$\mathbb{C}$$?

Factor[x^2+1] and Factor[x^2+1, Modulus->Complexes] didn't work.

• Factor's Modulus option is for integer modulus and finite fields. You could use GaussianIntegers -> True or Extension -> I for the Gaussian integers a+bi where a,b are integers - see here. But that's not $\mathbb{C}$. Factoring polynomials over $\mathbb{C}$ is just a matter of finding all the complex roots with Solve. Sep 26, 2021 at 17:22
• ^ i.e Times @@ ((x - #) & /@ (x /. Solve[x^2 + 1 == 0, x])) gives (-I + x) (I + x) Sep 26, 2021 at 17:25
• I'd like to add an example: Factor[x^2 + 2, Extension -> {I, Sqrt[2]}] produces (Sqrt[2] - I x)* (Sqrt[2] + I x). Sep 26, 2021 at 17:25
• @cheeseboardqueen read this about field extensions . Suppose you use Extension->Sqrt[2] then it factors over the field consisting of elements $a+b\sqrt2$ for integers $a,b$. For Extension->I that means we factorize over the Gaussian Integers which you can also enable with GaussianIntegers->True. Sep 26, 2021 at 17:36
• Does this answer your question? Factoring polynomials to factors involving complex coefficients Jun 26, 2022 at 22:16

Theoretically right, but sometimes sloooow:

factorComplete[poly_] := With[{var = Variables[poly]},
Factor[
poly,
Extension -> ToNumberField[
SolveValues[poly == 0, First@var],
All][[1, 1]] (* extract generator *)
] /;
Length@var == 1 && PolynomialQ[poly, x]
];
factorComplete[x^2 + 1]

(*  (-I + x) (I + x)  *)


Faster:

factorComplete2[poly_] := With[{var = Variables[poly]},
Module[{factors, coeff},
factors = Solve[poly == 0, First@var];
coeff = Coefficient[poly, First[var]^Length[factors]];
coeff (Times @@ Flatten[factors /. Rule -> Subtract])
] /; Length@var == 1 && PolynomialQ[poly, x]
];
factorComplete2[x^5 + x + 1] // ToRadicals


\eqalign{ \left(x+\sqrt[3]{-1}\right) & \left(x-(-1)^{2/3}\right) \cr & \left(x-\frac{1-i \sqrt{3}}{3\ 2^{2/3} \sqrt[3]{25-3 \sqrt{69}}}-\frac{1}{6} \left(1+i \sqrt{3}\right) \sqrt[3]{\frac{1}{2} \left(25-3 \sqrt{69}\right)}-\frac{1}{3}\right) \cr & \left(x-\frac{1+i \sqrt{3}}{3\ 2^{2/3} \sqrt[3]{25-3 \sqrt{69}}}-\frac{1}{6} \left(1-i \sqrt{3}\right) \sqrt[3]{\frac{1}{2} \left(25-3 \sqrt{69}\right)}-\frac{1}{3}\right) \cr & \left(x+\frac{1}{3} \left(-1+\sqrt[3]{\frac{2}{25-3 \sqrt{69}}}+\sqrt[3]{\frac{1}{2} \left(25-3 \sqrt{69}\right)}\right)\right) \cr}

I just tried Factor[x^2 + 1, Extension -> Sqrt[-1]] and it worked!!

Edit: See comments below. It didn't work over $$\mathbb{C}$$.

• Try it on other real polynomials. Sep 26, 2021 at 17:36
• I this what it's doing there is that it's factoring over $\mathbb{Q}[i]$ and not $\mathbb{C}$ unfortunately because Factor[x^2 + 3, Extension -> Sqrt[-1]] did not factor. sigh Sep 26, 2021 at 17:38
• This won't work: Factor[x^3 + 1, Extension -> Sqrt[-1]] you'll get two factors $(1 + x)$ and $(1 - x + x^2)$ which is irreducible in the Gaussian integers (your field extension). Instead you should use Solve to find all the roots a,b,c,d.... and then express the factors as (x-a)(x-b)(x-c)(x-d).... etc to fully factor in $\mathbb{C}$. This has already been shown in the comments. Sep 26, 2021 at 17:40
• @flinty Is that what {Rule -> Subtract, List -> Times} and {Equal -> Subtract, Or -> Times} is doing then? To be more specific that "subtract" creates the difference, "list" lists the factors, and "times" is the function (multiplication)? Sep 26, 2021 at 17:43
• @cheeseboardqueen those are rules used in a replacement /.. It converts Solve's solutions of the form List[List[Rule[x,a],List[Rule[x,b]],...] into a product (x-a)(x-b)... or more fully Times[Subtract[x,a],Subtract[x,b],...] so yes that's answer finds the roots with Solve and then builds an expression of the fully $\mathbb{C}$-factored polynomial. Sep 26, 2021 at 17:47