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.
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.
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}$.
Factor[x^2 + 3, Extension -> Sqrt[-1]] did not factor. sigh
– cheeseboardqueen
Sep 26 '21 at 17:38
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.
– flinty
Sep 26 '21 at 17:40
{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)?
– cheeseboardqueen
Sep 26 '21 at 17:43
/.. 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.
– flinty
Sep 26 '21 at 17:47
Factor'sModulusoption is for integer modulus and finite fields. You could useGaussianIntegers -> TrueorExtension -> Ifor 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 withSolve. – flinty Sep 26 '21 at 17:22Times @@ ((x - #) & /@ (x /. Solve[x^2 + 1 == 0, x]))gives(-I + x) (I + x)– flinty Sep 26 '21 at 17:25Factor[x^2 + 2, Extension -> {I, Sqrt[2]}]produces(Sqrt[2] - I x)* (Sqrt[2] + I x). – user64494 Sep 26 '21 at 17:25Solve[x^2 + 1 == 0, x] /. {Rule -> Subtract, List -> Times}andRoots[x^2 + 1 == 0, x] /. {Equal -> Subtract, Or -> Times}. It's surprising to me WRI hasn't written a function to factor over theRealsandComplexes, considering the other sugary shortcuts they've provided. -- Thirdly,Product[x - Root[Function[x, #], k], {k, Exponent[#, x]}] &[x^2 + 1]. – Michael E2 Sep 26 '21 at 17:30Extension -> Ido? – cheeseboardqueen Sep 26 '21 at 17:32Extension->Sqrt[2]then it factors over the field consisting of elements $a+b\sqrt2$ for integers $a,b$. ForExtension->Ithat means we factorize over the Gaussian Integers which you can also enable withGaussianIntegers->True. – flinty Sep 26 '21 at 17:36