FLINT3.7.0-dev
Algorithm

Factoring over finite fields

Cost
Polynomial in the degrees and the number of terms in practice (randomised); the extension degree is O(log⁡p)O(\log_p) of the number of terms, and the Frobenius recombination costs O(k)O(k) coefficient powerings per factor for an extension of degree kk.

FLINT factors a polynomial A∈Fq[x1,…,xn]A \in \mathbb{F}_q[x_1, \ldots, x_n], q=pdq = p^d with a word-size prime pp, in the same stages as over the integers (see Factorisation): content removal, squarefree (separable) decomposition, reduction to a bivariate problem by evaluation, bivariate factorisation, and lifting of the bivariate factors to all variables by Hensel lifting [Wan1978] [MonTun2020] or recombination [Zas1969]. Two things differ in positive characteristic. A polynomial can have zero derivative without being constant, which the squarefree decomposition must handle; and the field can be too small to provide the evaluation points that the reduction to two variables needs. The second problem is solved by factoring over an extension field and recombining the factors found there along the orbits of the Frobenius automorphism, an idea that goes back to von zur Gathen and Kaltofen's analysis of factoring over finite fields. The implementation follows the notes of its author [Sch-mpoly].

The pipeline#

nmod_mpoly_factor_algo (and fq_nmod_mpoly_factor_algo) proceeds as follows. Throughout, factors are made monic and the leading coefficient of AA is kept as the constant of the factorisation.

  1. Content. nmod_mpoly_factor_content removes the monomial content (powers of variables dividing AA) and splits AA into factors that are primitive with respect to every variable, by repeatedly computing the content with respect to one variable.
  2. Compression. Each factor is compressed by an invertible affine change of the exponent lattice (mpoly_compression_set) so that it uses as few variables and as small exponents as possible. A randomised test on projections of its Newton polytope may prove the factor irreducible at this point (an indecomposable Newton polytope implies irreducibility [Gao2001]).
  3. Separable decomposition (nmod_mpoly_factor_separable with sep = 1): see Separable factorisation in characteristic pp. Each resulting factor gg is squarefree and satisfies, for every variable, ∂g/∂xi=0\partial g/\partial x_i = 0 or gcd⁡(g,∂g/∂xi)=1\gcd(g, \partial g / \partial x_i) = 1, with at least one nonzero derivative.
  4. Deflation by powers of pp (Deflation by powers of pp) and a permutation that puts a variable with gcd⁡(g,∂g/∂x0)=1\gcd(g, \partial g/\partial x_0) = 1 first.
  5. Irreducible factorisation of each factor: univariate factorisation (nmod_poly_factor) for one variable; bivariate factorisation (n_bpoly_mod_factor_smprime, else n_bpoly_mod_factor_lgprime) for two; for more variables, polynomials of degree 1 in x0x_0 are irreducible, those of degree 2 are split by solving a quadratic equation with nmod_mpoly_quadratic_root (Quadratics), and the others are factored by the lifting algorithms of Evaluation points and extension fields.
  6. The factors are inflated, uncompressed, and multiplied by the multiplicities of the separable decomposition.

Separable factorisation in characteristic pp#

In characteristic zero, Yun's algorithm [Yun1976] computes the squarefree decomposition from GCDs of AA with its derivatives. In characteristic pp the derivative ∂A/∂xi\partial A/\partial x_i vanishes on the terms whose exponent in xix_i is a multiple of pp, so factors of multiplicity divisible by pp, and factors that are polynomials in xipx_i^p, are invisible to it [GT1996] [Lec2008]. The following lemma deals with what remains.

Lemma 1 (pp-th roots). Let KK be a perfect field of characteristic pp, and F∈K[x1,…,xn]F \in K[x_1, \ldots, x_n] with ∂F/∂xi=0\partial F/\partial x_i = 0 for all ii. Then F=HpF = H^p, where HH is obtained from FF by dividing every exponent by pp and replacing every coefficient cc by c1/pc^{1/p}. For K=FqK = \mathbb{F}_q, c1/p=cpd−1c^{1/p} = c^{p^{d-1}}, and over Fp\mathbb{F}_p, c1/p=cc^{1/p} = c.

Proof. The coefficient of xe/xix^e / x_i in ∂F/∂xi\partial F/\partial x_i is eicee_i c_e, so ∂F/∂xi=0\partial F/\partial x_i = 0 means that p∣eip \mid e_i whenever ce≠0c_e \ne 0. Thus F=∑ecexeF = \sum_e c_e x^{e} with all exponents divisible by pp. As the Frobenius map u↦upu \mapsto u^p is a ring endomorphism in characteristic pp, Hp=∑e(ce1/p)pxe=FH^p = \sum_e (c_e^{1/p})^p x^{e} = F. In Fq\mathbb{F}_q, cpd=cc^{p^d} = c, so c1/p=cpd−1c^{1/p} = c^{p^{d-1}}.

_nmod_mpoly_factor_separable works as follows on a monic primitive AA. For each variable in turn (choosing first the variable whose derivative has the fewest terms), it runs Yun's algorithm with respect to that variable on the current cofactor CC: with G=∂C/∂xG = \partial C/\partial x, C←gcd⁡(C,G)C \gets \gcd(C, G), W=Cold/CW = C_{\mathrm{old}}/C, V=G/CV = G/C, and while V−∂W/∂x≠0V - \partial W/\partial x \ne 0 and the multiplicity kk is less than p−1p - 1, the factor of multiplicity kk is gcd⁡(W,V−∂W/∂x)\gcd(W, V - \partial W/\partial x). The factors found are split further against the derivatives with respect to the remaining variables, to obtain the property of step 3. When all variables have been processed, the remaining CC has zero derivative in every variable; with pkp^k the largest power of pp dividing all its exponents, C=DpkC = D^{p^k} by Lemma 1, DD is computed by deflation (and, over Fq\mathbb{F}_q, by the coefficient map c↦cpjc \mapsto c^{p^{j}} with j≡−k(modd)j \equiv -k \pmod d), its separable decomposition is computed recursively and raised to the power pkp^k, and the two decompositions are merged into one with pairwise coprime bases by GCDs.

Deflation by powers of pp#

After the separable decomposition, a factor gg may still have all its exponents in some variables divisible by a power of pp, for example g=xp−yg = x^p - y. FLINT divides the exponents of each variable xix_i by the largest power psip^{s_i} of pp dividing all of them, factors the deflated polynomial hh (so that g=h(x1ps1,…,xnpsn)g = h(x_1^{p^{s_1}}, \ldots, x_n^{p^{s_n}})) and inflates the factors. This is correct because of the following lemma.

Lemma 2. Let KK be a perfect field of characteristic pp, and f∈K[x,y1,…,ym]f \in K[x, y_1, \ldots, y_m] irreducible with ∂f/∂yj≠0\partial f/\partial y_j \ne 0 for some jj. Then f(xp,y1,…,ym)f(x^p, y_1, \ldots, y_m) is irreducible.

Proof. Write F=f(xp,y)F = f(x^p, y) and let σ\sigma be the automorphism of K[x,z1,…,zm]K[x, z_1, \ldots, z_m] that maps each coefficient cc to c1/pc^{1/p} and fixes the variables. In K[x,z]K[x, z] with zip=yiz_i^p = y_i, the Frobenius gives F(x,zp)=σ(f)(x,z)pF(x, z^p) = \sigma(f)(x, z)^p, and σ(f)(x,z)\sigma(f)(x, z) is irreducible. Suppose F=GHF = GH in K[x,y]K[x, y]. Then G(x,zp)H(x,zp)=σ(f)(x,z)pG(x, z^p) H(x, z^p) = \sigma(f)(x, z)^p, so by unique factorisation G(x,zp)=c σ(f)(x,z)aG(x, z^p) = c\, \sigma(f)(x, z)^a for a unit cc and some 0≤a≤p0 \le a \le p. The left side has zero derivative with respect to zjz_j, while the derivative of the right side is ac σ(f)a−1∂σ(f)/∂zja c\, \sigma(f)^{a-1} \partial \sigma(f)/\partial z_j, where ∂σ(f)/∂zj=σ(∂f/∂yj)(x,z)≠0\partial \sigma(f) / \partial z_j = \sigma(\partial f/\partial y_j)(x, z) \ne 0. Hence p∣ap \mid a, that is a∈{0,p}a \in \{0, p\}, and GG or HH is a unit.

Corollary 3. Let gg be squarefree, and hh obtained by dividing the exponents of some variables by powers of pp as above, with at least one variable undeflated. If h=∏ifih = \prod_i f_i is the irreducible factorisation, so is g=∏ifi(x1ps1,…,xnpsn)g = \prod_i f_i(x_1^{p^{s_1}}, \ldots, x_n^{p^{s_n}}).

Proof. Each fif_i has nonzero derivative with respect to some undeflated variable: otherwise fif_i is a polynomial in the pp-th powers of the undeflated variables, and its inflation is a polynomial in pp-th powers of all variables, hence a pp-th power by Lemma 1, contradicting squarefreeness of gg. Deflating one variable and one power of pp at a time, Lemma 2 shows that each inflated fif_i stays irreducible.

Quadratics#

Let A=aX2+bX+cA = a X^2 + b X + c with a,b,c∈R=Fq[x1,…,xn]a, b, c \in R = \mathbb{F}_q[x_1, \ldots, x_n] be squarefree and primitive in X=x0X = x_0. It is reducible if and only if it has a factor of degree 1 in XX. Since aA=Y2+bY+aca A = Y^2 + b Y + ac with Y=aXY = aX, and the roots Y=arY = a r of this monic polynomial, rr a root of AA, are integral over the unique factorisation domain RR, the polynomial AA is reducible if and only if Y2+bY+acY^2 + bY + ac has a root y∈Ry \in R; then AA is the product of (a/g)X−y/g(a/g) X - y/g and gX−cg/yg X - cg/y with g=gcd⁡(a,y)g = \gcd(a, y). In odd characteristic y=(−b+b2−4ac)/2y = (-b + \sqrt{b^2 - 4ac})/2, and the square root is computed by the heap algorithm of Square roots. In characteristic 2 there is no such formula, and FLINT solves the equation Y2+AY=BY^2 + AY = B (signs do not matter) directly, term by term, by an algorithm from Schultz's notes [Sch-mpoly] that simplifies §§4–5 of Cherly, Gallardo, Vaserstein and Wheland [CGVW1998], whose method divides by polynomials and does not preserve sparsity.

Let A,B∈R=F2k[x1,…,xn]A, B \in R = \mathbb{F}_{2^k}[x_1, \ldots, x_n] with A,B≠0A, B \ne 0 (if A=0A = 0 the root is B\sqrt{B}, if B=0B = 0 it is 0), and write lt(A)=aM\mathrm{lt}(A) = a M with a∈F2ka \in \mathbb{F}_{2^k} and MM a monomial. If Y0Y_0 is a root, so is Y0+AY_0 + A, and the coefficients of MM in Y0Y_0 and Y0+AY_0 + A differ by aa, so at most one of them equals aa: we may look for a root in which the coefficient of MM is not aa.

Lemma 4 (Leading term of a root). Let Y0Y_0 be a root of Y2+AY=BY^2 + AY = B in which the coefficient of MM is not aa, and let m=γ xμm = \gamma\, x^{\mu} be its leading term. Then exactly one of the following holds:

  1. lm(B)>M2\mathrm{lm}(B) > M^2: then xμ>Mx^\mu > M and m=lt(B)m = \sqrt{\mathrm{lt}(B)}, which requires lm(B)\mathrm{lm}(B) to be a square;
  2. lm(B)=M2\mathrm{lm}(B) = M^2: then xμ=Mx^\mu = M and m=aζMm = a \zeta M with ζ2+ζ=lc(B)/a2\zeta^2 + \zeta = \mathrm{lc}(B)/a^2;
  3. lm(B)<M2\mathrm{lm}(B) < M^2: then xμ<Mx^\mu < M and m=lt(B)/lt(A)m = \mathrm{lt}(B) / \mathrm{lt}(A), which requires this quotient to be a monomial smaller than MM.

Moreover Y0+mY_0 + m is a root of Y2+AY=B+m2+AmY^2 + AY = B + m^2 + Am, the leading monomial of B+m2+AmB + m^2 + Am is smaller than that of BB, and the coefficient of MM in Y0+mY_0 + m is not aa (in case 2 it is zero).

Proof. In characteristic 2, Y02Y_0^2 is the sum of the squares of the terms of Y0Y_0, so its leading term is m2=γ2x2μm^2 = \gamma^2 x^{2\mu}, while the leading term of AY0A Y_0 is aγMxμa \gamma M x^\mu. If xμ>Mx^\mu > M, the first dominates and lt(B)=m2\mathrm{lt}(B) = m^2; if xμ<Mx^\mu < M, the second does and lt(B)=lt(A)m\mathrm{lt}(B) = \mathrm{lt}(A) m. If xμ=Mx^\mu = M, the two have the same monomial and their sum is (γ2+aγ)M2(\gamma^2 + a\gamma) M^2, which is nonzero because γ≠0,a\gamma \ne 0, a; it equals lt(B)\mathrm{lt}(B), and ζ=γ/a\zeta = \gamma/a satisfies ζ2+ζ=lc(B)/a2\zeta^2 + \zeta = \mathrm{lc}(B)/a^2. In the three cases lm(B)\mathrm{lm}(B) is x2μ>Mxμ>M2x^{2\mu} > M x^{\mu} > M^2, M2M^2, or Mxμ<M2M x^\mu < M^2, so the case is determined by lm(B)\mathrm{lm}(B), and mm is determined by lt(B)\mathrm{lt}(B) (in case 2 up to the two roots ζ\zeta, ζ+1\zeta + 1). Finally (Y0+m)2+A(Y0+m)=B+m2+Am(Y_0 + m)^2 + A(Y_0 + m) = B + m^2 + Am, and m2+Amm^2 + Am has leading term lt(B)\mathrm{lt}(B) by the above.

Algorithm 1: Quadratic equations in characteristic 2

Input: nonzero A,B∈F2k[x1,…,xn]A, B \in \mathbb{F}_{2^k}[x_1, \ldots, x_n]. Output: YY with Y2+AY=BY^2 + AY = B, or "no root".

  1. Set Y=0Y = 0 and E=BE = B.
  2. While E≠0E \ne 0: determine mm from lt(E)\mathrm{lt}(E) by the case of Lemma 4 that applies, using case 1 only while all terms of YY are larger than MM, and case 3 once a term ≤M\le M has been chosen; if the required square root, quadratic root or monomial quotient does not exist, return "no root". Set Y←Y+mY \gets Y + m and E←E+m2+AmE \gets E + m^2 + Am.
  3. Return YY.

By Lemma 4 and induction, if a root exists the algorithm finds one, term by term; if it returns YY, then E=0E = 0 and YY is a root. The leading monomial of EE decreases strictly, so the terms of YY form a strictly decreasing sequence of monomials, which is finite because a monomial ordering is a well-ordering; so the algorithm terminates also when there is no root. The terms of EE are produced in decreasing order by a heap, as in Heap division, merging BB, the products AmA m and the squares m2m^2 (no cross terms appear in characteristic 2), so the heap has at most ℓA+2\ell_A + 2 entries and the cost is that of a heap division with ℓAℓY\ell_A \ell_Y products.

Case 2 needs a root of ζ2+ζ=c\zeta^2 + \zeta = c in F2k\mathbb{F}_{2^k}.

Lemma 5 (Artin–Schreier equations in characteristic 2). Let Tr(c)=∑i=0k−1c2i\mathrm{Tr}(c) = \sum_{i=0}^{k-1} c^{2^i} be the absolute trace of F2k\mathbb{F}_{2^k}. The equation ζ2+ζ=c\zeta^2 + \zeta = c has a root if and only if Tr(c)=0\mathrm{Tr}(c) = 0, and then, for any uu with Tr(u)=1\mathrm{Tr}(u) = 1,

ζ=∑i=1k−1c2i∑j=0i−1u2j\zeta = \sum_{i=1}^{k-1} c^{2^i} \sum_{j=0}^{i-1} u^{2^j}

is a root. If F2k=F2[θ]/(P)\mathbb{F}_{2^k} = \mathbb{F}_2[\theta]/(P) with k≥2k \ge 2, then u=1/(θP′(θ))u = 1/(\theta P'(\theta)) has trace 1.

Proof. The map ζ↦ζ2+ζ\zeta \mapsto \zeta^2 + \zeta is F2\mathbb{F}_2-linear with kernel F2\mathbb{F}_2, so its image has 2k−12^{k-1} elements; it lies in the kernel of the trace, because Tr(ζ2)=Tr(ζ)\mathrm{Tr}(\zeta^2) = \mathrm{Tr}(\zeta), and the trace is onto, so the image is the kernel of the trace [LN1997, Ch. 2]. For the formula, let Ui=∑j<iu2jU_i = \sum_{j < i} u^{2^j}, so that Ui2=Ui+1+uU_i^2 = U_{i+1} + u, U1=uU_1 = u and Uk=Tr(u)=1U_k = \mathrm{Tr}(u) = 1. Then ζ2=∑i=2kc2i(Ui+u)\zeta^2 = \sum_{i=2}^{k} c^{2^i}(U_i + u), and in ζ2+ζ\zeta^2 + \zeta the terms with 2≤i≤k−12 \le i \le k-1 cancel, leaving c2kUk+c2U1+u∑i=2kc2i=c+u Tr(c)=cc^{2^k} U_k + c^2 U_1 + u \sum_{i=2}^{k} c^{2^i} = c + u \,\mathrm{Tr}(c) = c. For uu: the partial fraction decomposition 1/(xP(x))=P(0)−1/x+∑ρ(ρP′(ρ))−1/(x−ρ)1/(xP(x)) = P(0)^{-1}/x + \sum_\rho (\rho P'(\rho))^{-1}/(x - \rho) over the roots ρ\rho of PP, multiplied by xx and compared at x→∞x \to \infty, gives ∑ρ1/(ρP′(ρ))=−1/P(0)=1\sum_\rho 1/(\rho P'(\rho)) = -1/P(0) = 1, and the left side is the trace of 1/(θP′(θ))1/(\theta P'(\theta)).

fq_nmod_mpoly_quadratic_root and nmod_mpoly_quadratic_root (to which fmpz_mod_mpoly_quadratic_root reduces for a word-size modulus) implement this: in odd characteristic by a square root, in characteristic 2 by Algorithm 1 with the static heap function _fq_nmod_mpoly_quadratic_root_heap and the trace formula of Lemma 5. Over F2\mathbb{F}_2 itself case 2 never applies, since Tr(1)=1\mathrm{Tr}(1) = 1. The factoring code uses them for squarefree factors of degree 2 in the main variable (_apply_quadratic).

Evaluation points and extension fields#

To factor a squarefree AA in n≥3n \ge 3 variables, the lifting algorithms choose a point α=(α2,…,αn−1)\alpha = (\alpha_2, \ldots, \alpha_{n-1}) and factor the bivariate image A(x0,x1,α)A(x_0, x_1, \alpha). The point must keep the leading coefficient in x0x_0 nonzero and the image separable in x0x_0, and Wang's method needs in addition that the factors of the leading coefficient stay distinguishable. These conditions fail on the zero set of nonzero polynomials, so over a large field random points work with high probability (Lemma 1 of GCDs over small finite fields). Over a small field they may all fail, and the bivariate factorisation itself needs a value y=αy = \alpha for which the univariate image is separable.

FLINT therefore tries, in order: points in Fp\mathbb{F}_p (smprime), points in an extension Fpk\mathbb{F}_{p^k} with pk≤106p^k \le 10^6, where field arithmetic uses Zech logarithms (medprime, via fq_zech_mpoly), and points in extensions of any degree (lgprime, via fq_nmod_mpoly). The extension degree starts at about max⁡(2,1+log⁡pℓ)\max(2, 1 + \log_p \ell) for ℓ\ell terms (half that for Wang's and Zassenhaus's methods) and is increased each time the algorithm runs out of points. In the bivariate algorithm, n_bpoly_mod_factor_lgprime reduces yy modulo irreducible polynomials m(y)m(y) of increasing degree and lifts mm-adically instead of (y−α)(y-\alpha)-adically.

A factorisation over Fqk\mathbb{F}_{q^k} is turned into one over Fq\mathbb{F}_q as follows.

Theorem 6 (Frobenius orbits). Let f∈Fq[x1,…,xn]f \in \mathbb{F}_q[x_1, \ldots, x_n] be irreducible and separable, that is, gcd⁡(f,∂f/∂xi)=1\gcd(f, \partial f/\partial x_i) = 1 for some ii with ∂f/∂xi≠0\partial f/\partial x_i \ne 0, and let ϕ\phi be the automorphism c↦cqc \mapsto c^q of L=FqkL = \mathbb{F}_{q^k} over Fq\mathbb{F}_q, acting on L[x1,…,xn]L[x_1, \ldots, x_n] through the coefficients. Then the monic irreducible factors of ff in L[x1,…,xn]L[x_1, \ldots, x_n] are pairwise distinct and form a single orbit {g,ϕ(g),…,ϕr−1(g)}\{g, \phi(g), \ldots, \phi^{r-1}(g)\} under ϕ\phi, with r∣kr \mid k, and f=lc(f)∏j=0r−1ϕj(g)f = \mathrm{lc}(f) \prod_{j=0}^{r-1} \phi^j(g).

Proof. ff remains separable over LL, because gcd⁡(f,∂f/∂xi)=1\gcd(f, \partial f/\partial x_i) = 1 over LL by Lemma 2 of GCDs over small finite fields; so ff is squarefree over LL and its monic irreducible factors g1,…,gsg_1, \ldots, g_s are distinct. Since ϕ\phi fixes ff and is a ring automorphism preserving monicity, it permutes the gig_i. Let OO be the orbit of g1g_1 and PP the product of the polynomials in OO. Then ϕ(P)=P\phi(P) = P, so PP has coefficients in Fq\mathbb{F}_q (the fixed field of ϕ\phi), and PP divides ff in Fq[x1,…,xn]\mathbb{F}_q[x_1, \ldots, x_n] (division by a monic polynomial is the same over Fq\mathbb{F}_q and over LL). As ff is irreducible over Fq\mathbb{F}_q, P=f/lc(f)P = f/\mathrm{lc}(f), so all factors lie in OO. The orbit length divides the order kk of ϕ\phi.

Hence, for a squarefree AA factored over Fq\mathbb{F}_q via its factors g1,…,gsg_1, \ldots, g_s over Fqk\mathbb{F}_{q^k}, the irreducible factors over Fq\mathbb{F}_q are the products over the orbits. FLINT computes them by taking a factor tt, applying ϕ\phi to its coefficients k−1k - 1 times, removing each conjugate ϕj(t)\phi^j(t) from the list of remaining factors, and multiplying the orbit together; the product has coefficients in Fq\mathbb{F}_q and is mapped back.

Bivariate factorisation#

Over Q\mathbb{Q}, an irreducible bivariate polynomial stays irreducible under a generic specialisation y=y0y = y_0, so a univariate image usually has as many factors as the polynomial itself and recombination is cheap (Dense bivariate factorisation). Over a finite field this fails: a univariate image of an irreducible polynomial typically splits into several factors, and recombination needs a better method than trying subsets [BHKS2009]. n_bpoly_mod_factor_smprime factors A∈Fp[y][x]A \in \mathbb{F}_p[y][x], separable in xx, as follows:

  1. Remove the content in Fp[y]\mathbb{F}_p[y].
  2. For α=0,1,2,…\alpha = 0, 1, 2, \ldots with deg⁡xA(x,α)=deg⁡xA\deg_x A(x, \alpha) = \deg_x A, factor A(x,α)A(x, \alpha) with nmod_poly_factor, record the degrees of the factors for the degree pruning of Lemma 5 of Factorisation (which may prove AA irreducible), and skip α\alpha if the image is not squarefree. Of the first two good points, keep the one with fewer factors.
  3. Shift y←y+αy \gets y + \alpha, make AA monic in xx as a power series in yy, and lift the rr monic local factors to g1,…,gr∈Fp[[y]][x]g_1, \ldots, g_r \in \mathbb{F}_p[[y]][x] modulo yλy^\lambda.
  4. Find the true factors as products of the gig_i by linear algebra over Fp\mathbb{F}_p, increasing λ\lambda until this succeeds.

The linear algebra is the function field version of van Hoeij's method [vHo2002; BHKS2009], with the logarithmic derivative bounds used by Lecerf [Lec2006]. For AA of degree dd in xx, let HH be the smallest concave function on [0,d][0, d] with H(i)≥deg⁡y[xi]AH(i) \ge \deg_y [x^i] A whenever [xi]A≠0[x^i] A \ne 0, the upper boundary of the Newton polygon of AA with respect to deg⁡y\deg_y (mpoly_bivar_cld_bounds).

Lemma 7 (Logarithmic derivative bounds). If F∈K[y][x]F \in K[y][x] divides AA, then deg⁡y[xi](A ∂xF/F)≤H(i+1)\deg_y [x^i] \bigl(A \, \partial_x F / F\bigr) \le H(i + 1) for 0≤i<d0 \le i < d.

Proof. Write A=FGA = FG, so that A ∂xF/F=G ∂xFA\, \partial_x F/F = G\, \partial_x F. Newton polygons with respect to the valuation −deg⁡y-\deg_y are additive under multiplication (Dumas' theorem, the one-variable case of Ostrowski's theorem of Irreducibility from the Newton polytope), so HH is the sup-convolution H(n)=max⁡a+b=n(HG(a)+HF(b))H(n) = \max_{a + b = n} (H_G(a) + H_F(b)) of the corresponding functions for GG and FF. Since [xb]∂xF=(b+1)[xb+1]F[x^b] \partial_x F = (b+1) [x^{b+1}] F, the coefficient of xix^i in G ∂xFG\, \partial_x F has degree in yy at most max⁡a+b=i(HG(a)+HF(b+1))≤H(i+1)\max_{a + b = i} (H_G(a) + H_F(b + 1)) \le H(i + 1).

Let ℓi=(A/gi) ∂xgi mod yλ\ell_i = (A / g_i) \, \partial_x g_i \bmod y^\lambda. If FF is a true factor with F≡lc⁡x(F)∏i∈SgiF \equiv \operatorname{lc}_x(F) \prod_{i \in S} g_i, the logarithmic derivative of the product gives ∑i∈Sℓi≡A ∂xF/F\sum_{i \in S} \ell_i \equiv A\, \partial_x F / F, so by Lemma 7 the coefficients of yjxiy^j x^i in ∑ieiℓi\sum_i e_i \ell_i vanish for H(i+1)<j<λH(i + 1) < j < \lambda when e∈{0,1}re \in \{0, 1\}^r is the indicator vector of SS. These coefficients are linear forms in ee over Fp\mathbb{F}_p, and the indicator vectors of the irreducible factors of AA lie in their common kernel. FLINT keeps a basis of this kernel in reduced row echelon form, starting from the identity matrix and intersecting with the kernel of the new equations (nmod_mat_init_nullspace_tr, tested with nmod_mat_is_reduced) as the precision grows:

  • if the kernel has dimension 1, AA is irreducible, since the indicator vectors of its irreducible factors are linearly independent and lie in the kernel;
  • if the reduced basis consists of 0-1 vectors with exactly one 1 in each column, its rows partition the local factors, and the candidate factors are the products over the rows, multiplied by lc⁡x(A)\operatorname{lc}_x(A), reduced modulo ydeg⁡yA+1y^{\deg_y A + 1} and made primitive; they are tested by division, and if a test fails, products of two candidates are tried as well;
  • otherwise the precision is increased.

When groups of local factors are known to belong together, they are multiplied together and the lifting continues with fewer factors. Each returned factor is verified by division, so the result is correct whatever the precision. n_bpoly_mod_factor_lgprime does the same with y−αy - \alpha replaced by an irreducible polynomial m(y)m(y) of increasing degree, for fields without good points: AA is factored over Fp[y]/(m)\mathbb{F}_p[y]/(m) and the factors are lifted mm-adically. The fq_nmod versions n_fq_bpoly_factor_smprime and n_fq_bpoly_factor_lgprime are analogous.

Leading coefficients over a finite field#

Wang's method (Wang's method) assigns the factors of ℓ=lc⁡x0(A)\ell = \operatorname{lc}_{x_0}(A) to the factors of AA by looking at prime numbers that divide the values Lj(α)L_j(\alpha) of the factors of ℓ\ell. Over a finite field the values are field elements and there are no primes; moreover a univariate image of an irreducible polynomial is usually reducible, so lifting from a univariate factorisation would require recombination. FLINT therefore replaces the evaluation point by a curve: each variable xix_i, i≥1i \ge 1, is replaced by a random polynomial xi=αi+βiY+γiY2+⋯x_i = \alpha_i + \beta_i Y + \gamma_i Y^2 + \cdots in a new variable YY, and A(x0,α(Y))A(x_0, \alpha(Y)) is factored as a bivariate polynomial in Fp[Y][x0]\mathbb{F}_p[Y][x_0] [Sch-mpoly]. Irreducible polynomials in Fp[Y]\mathbb{F}_p[Y] play the role of the primes, and the proof of Lemma 5 of Multivariate Hensel lifting applies with Z\mathbb{Z} replaced by Fp[Y]\mathbb{F}_p[Y]: if an irreducible q(Y)q(Y) divides Lj(α(Y))L_j(\alpha(Y)) but neither the content of the bivariate image nor the other Lk(α(Y))L_k(\alpha(Y)), the exponent of LjL_j in the leading coefficient of the ii-th factor is the multiplicity of qq in the leading coefficient of the ii-th bivariate factor times the content, divided by the multiplicity of qq in Lj(α(Y))L_j(\alpha(Y)).

nmod_mpoly_factor_lcc_wang checks the sequential form of the condition (each monic Lj(α(Y))L_j(\alpha(Y)) must keep a factor of positive degree after removing its common factors with the content and with L1(α(Y)),…,Lj−1(α(Y))L_1(\alpha(Y)), \ldots, L_{j-1}(\alpha(Y))) and computes the exponents with n_poly_mod_remove. The lifting itself starts from the factors at Y=0Y = 0, which are the images of the bivariate factors at the point (α1,…,αn)(\alpha_1, \ldots, \alpha_n); since they come from a bivariate factorisation, they correspond to the factors of AA much more often than the factors of an arbitrary univariate image would. If the bivariate image is irreducible, so is AA, because the substitution preserves the degree in x0x_0. nmod_mpoly_factor_irred_smprime_wang tries a few random curves through each random point α\alpha (one at which the degrees are preserved and the univariate image is squarefree), raising the degree of the curves in YY from 1 up to 9 as attempts fail, before giving up.

Choosing among the methods#

For a factor with at least three variables after deflation, nmod_mpoly_factor_algo with all methods enabled first factors the leading coefficient in x0x_0 (needed by Wang's and Zippel's methods). It then computes the density ℓ/(D+nn)\ell / \binom{D + n}{n} of the factor (ℓ\ell terms, total degree DD, nn variables) and tries in order:

  • density above 0.005: Wang over Fp\mathbb{F}_p, Wang over Fpk\mathbb{F}_{p^k} (medprime), sparse lifting over Fp\mathbb{F}_p, sparse lifting medprime; otherwise the same with sparse lifting first;
  • density above 0.001: Wang lgprime, then sparse lifting lgprime; otherwise the other order;
  • Zassenhaus's method over Fp\mathbb{F}_p, medprime and lgprime, as a last resort (and first if the leading coefficient cannot be factored).

The first method that succeeds determines the factorisation. Over Fq\mathbb{F}_q, fq_nmod_mpoly_factor_algo has the same structure with only the smprime and lgprime levels, the extensions being presented through the embeddings of fq_nmod_mpoly.h and the orbits taken under c↦cqc \mapsto c^q. fmpz_mod_mpoly_factor_algo calls nmod_mpoly_factor_algo for a word-size modulus and uses only the smprime level otherwise.

Use in FLINT#

Referenced from#

References#

  • [Wan1978] P. S. Wang. An improved multivariate polynomial factoring algorithm. Mathematics of Computation 32 (1978), 1215–1231. https://doi.org/10.1090/S0025-5718-1978-0568284-3
  • [MonTun2020] M. Monagan and B. Tuncer. The complexity of sparse Hensel lifting and sparse polynomial factorization. Journal of Symbolic Computation 99 (2020), 189–230. https://doi.org/10.1016/j.jsc.2019.05.001
  • [Zas1969] H. Zassenhaus. On Hensel factorization, I. Journal of Number Theory 1 (1969), 291–311. https://doi.org/10.1016/0022-314X(69)90047-X
  • [Sch-mpoly] D. Schultz. Algorithms for multivariate polynomials. Notes in the FLINT source tree, src/mpoly/doc/MPolyAlgorithms.tex.
  • [Gao2001] S. Gao. Absolute irreducibility of polynomials via Newton polytopes. Journal of Algebra 237 (2001), 501–520. https://doi.org/10.1006/jabr.2000.8586
  • [Yun1976] D. Y. Y. Yun. On square-free decomposition algorithms. Proceedings of the 1976 ACM Symposium on Symbolic and Algebraic Computation (SYMSAC '76), 26–35. https://doi.org/10.1145/800205.806320
  • [GT1996] P. Gianni and B. Trager. Square-free algorithms in positive characteristic. Applicable Algebra in Engineering, Communication and Computing 7 (1996), 1–14.
  • [Lec2008] G. Lecerf. Fast separable factorization and applications. Applicable Algebra in Engineering, Communication and Computing 19:2 (2008), 135–160.
  • [CGVW1998] J. Cherly, L. Gallardo, L. Vaserstein and E. Wheland. Solving quadratic equations over polynomial rings of characteristic two. Publicacions Matemàtiques 42:1 (1998), 131–142.
  • [LN1997] R. Lidl and H. Niederreiter. Finite Fields. Second edition, Encyclopedia of Mathematics and its Applications 20, Cambridge University Press, 1997.
  • [BHKS2009] K. Belabas, M. van Hoeij, J. Klüners and A. Steel. Factoring polynomials over global fields. Journal de Théorie des Nombres de Bordeaux 21 (2009), 15–39. https://doi.org/10.5802/jtnb.655
  • [vHo2002] M. van Hoeij. Factoring polynomials and the knapsack problem. Journal of Number Theory 95 (2002), 167–189. https://doi.org/10.1006/jnth.2001.2763
  • [Lec2006] G. Lecerf. Sharp precision in Hensel lifting for bivariate polynomial factorization. Mathematics of Computation 75 (2006), 921–933.
Cite this page

The FLINT team, “Factoring over finite fields,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/multivariate/modp-factoring.html (generated 2026-11-02).