AngouriMath

Try it live

Navigation

← Back to list of members

Factor​(AngouriMath.​Entity,​AngouriMath.​Entity.​Variable)

 Method (no overloads)

Summary

expr written as a product of powers of polynomials
irreducible over the rationals, or null where that could not
be settled.

Parameter "expr"

The polynomial to factorise.

Parameter "variable"

The variable it is a polynomial in.

Returns

The factorisation; the input itself where it is irreducible over the
rationals, which is an answer and not a refusal; or null where expr is not a polynomial in
variable with rational or polynomial coefficients, or where
the question is past what the factoriser will do.

Remarks

In one variable, Zassenhaus: square-free decomposition, Berlekamp's
factorisation modulo a prime, Hensel lifting to a power of it above Mignotte's
bound, and recombination — and the factors are multiplied back and compared with
the input before they are returned. The degree bound is 32.
In more than one, the content in variable — the common
divisor of the coefficients, which is a polynomial in the other variables — is
taken out first. What remains is factored by Kronecker's substitution,
which writes the exponent vector as a numeral in mixed radix and reads a
one-variable factorisation back, while the image's degree, the product of the
radices less one, is at most 32. Past that, Hensel lifting along an evaluation
homomorphism
: the polynomial is factored at a point and the factorisation
lifted back. In three or more variables the lift brings back one variable at a
time, each to its own degree, after Wang; a leading coefficient that is a
polynomial in the others is first made monic, by L ^ (n - 1) · f(x / L).
Where that declines, the variables other than variable are
substituted into one, in mixed radix again, and lifted as two, while that image's
degree is at most 127. The lifts need an image with no repeated factor, so a
polynomial with one has its square-free part factored instead and the
multiplicities put back by division. The greatest common divisor that part needs is
taken by evaluation at a large integer, after Char, Geddes and Gonnet, and by the
subresultant sequence where that declines.
A refusal is possible and a wrong answer is not. Every candidate factor is
checked by exact division before it is kept, and the assembled factors are divided
back into the input.

Example

Console.WriteLine(MathS.Polynomials.Factor("x ^ 4 - 5 * x ^ 2 + 4", "x"));
// (x + 1) * (x + 2) * (x - 2) * (x - 1)
            
Console.WriteLine(MathS.Polynomials.Factor("x ^ 3 - 3 * x ^ 2 + 3 * x - 1", "x"));
// (x - 1) ^ 3
            
Console.WriteLine(MathS.Polynomials.Factor("x ^ 2 + 1", "x"));
// x ^ 2 + 1        -- irreducible over Q, which is an answer
            
Console.WriteLine(MathS.Polynomials.Factor("x * y + y", "x"));
// y * (x + 1)      -- the content in x is taken out first
            
Console.WriteLine(MathS.Polynomials.Factor("x ^ 2 - y ^ 2", "x"));
// (x + y) * (x - y)
            
Console.WriteLine(MathS.Polynomials.Factor("x ^ 3 - (y + z) ^ 3", "x"));
// (x - y - z) * (x ^ 2 + x * y + x * z + y ^ 2 + 2 * y * z + z ^ 2)
            
Console.WriteLine(MathS.Polynomials.Factor("(y * x ^ 2 + z * w) * (x - y - w) * (z * x + 1)", "x"));
// -1 * (w - x + y) * (x * z + 1) * (w * z + x ^ 2 * y)

























Angouri © 2019-2026 · Project's repo · Site's repo · Octicons · Transparency · 6091 pages online