Factor polynomial

I want to factor(x^5 + x + 1) into (x^3 - x^2 + 1)(x^2 + x + 1). Wolfram can do it, is there a Julia package that can?

AbstractAlgebra.jl has a function called factor but I can’t figure out how to use it.

Polynomials.jl has a FactoredPolynomial but it doesn’t do what I’m looking for either

julia> convert(FactoredPolynomial, Polynomial([1,0,0,0,1,1]))
FactoredPolynomial((x + 0.5000000000000002 + 0.8660254037844388im) * (x - 0.6623589786223729 - 0.5622795120623012im) * (x + 1.3247179572447456 - 5.605801581444737e-17im) * (x + 0.5000000000000001 - 0.8660254037844386im) * (x - 0.662358978622373 + 0.5622795120623013im))

I would do the following:

julia> using Nemo

Welcome to Nemo version 0.43.0

Nemo comes with absolutely no warranty whatsoever

julia> R, x = QQ["x"]
(Univariate polynomial ring in x over QQ, x)

julia> factor(x^5 + x + 1)
1 * (x^3 - x^2 + 1) * (x^2 + x + 1)
4 Likes

Is there a way to get irrational coefficients?

I want to factor(a^4 + b^4) into (a^2 + b^2 + √2*a*b) * (a^2 + b^2 - √2*a*b).

Or imaginary coefficients, to factor(a^2 + b^2) into (a - im*b)(a + im*b))?

Don’t have time rn to try out a specific example, but perhaps the functionality is here:

1 Like

Linking a related post with a solution using Hecke.jl.

2 Likes

Here the complete example:

julia> using Hecke

julia> Qx, x = QQ[:x]; K, sqrt2 = number_field(x^2 - 2, "√2");

julia> Kab, (a, b) = K[:a, :b];

julia> factor(a^4 + b^4)
1 * (a^2 - √2*a*b + b^2) * (a^2 + √2*a*b + b^2)

This works if you know the “irrationalities” that will pop up.

There is also a model to work with the set of all algebraic numbers (roots of things etc).

julia> K = algebraic_closure(QQ);

julia> Kab, (a, b) = K[:a, :b];

julia> factor(a^2 + b^2)
1 * (a + Root -1.00000*im of x^2 + 1*b) * (a + Root 1.00000*im of x^2 + 1*b)

(But the printing is not nice. This is (a - im*b)*(a - im*b), but it prints im as Root -1.0... of x^2 + 1.)

3 Likes