3
$\begingroup$

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.

$\endgroup$
8
  • 2
    $\begingroup$ 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. $\endgroup$
    – flinty
    Sep 26, 2021 at 17:22
  • 1
    $\begingroup$ ^ i.e Times @@ ((x - #) & /@ (x /. Solve[x^2 + 1 == 0, x])) gives (-I + x) (I + x) $\endgroup$
    – flinty
    Sep 26, 2021 at 17:25
  • $\begingroup$ I'd like to add an example: Factor[x^2 + 2, Extension -> {I, Sqrt[2]}] produces (Sqrt[2] - I x)* (Sqrt[2] + I x). $\endgroup$
    – user64494
    Sep 26, 2021 at 17:25
  • 1
    $\begingroup$ @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. $\endgroup$
    – flinty
    Sep 26, 2021 at 17:36
  • 3
    $\begingroup$ Does this answer your question? Factoring polynomials to factors involving complex coefficients $\endgroup$
    – Michael E2
    Jun 26, 2022 at 22:16

2 Answers 2

1
$\begingroup$

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}$$

$\endgroup$
0
$\begingroup$

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

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

$\endgroup$
6
  • $\begingroup$ Try it on other real polynomials. $\endgroup$
    – Michael E2
    Sep 26, 2021 at 17:36
  • $\begingroup$ 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 $\endgroup$ Sep 26, 2021 at 17:38
  • 2
    $\begingroup$ 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. $\endgroup$
    – flinty
    Sep 26, 2021 at 17:40
  • $\begingroup$ @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)? $\endgroup$ Sep 26, 2021 at 17:43
  • 1
    $\begingroup$ @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. $\endgroup$
    – flinty
    Sep 26, 2021 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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