Algorithm Search⌘K

Proofs: Berlekamp's factorization algorithm

These are the human proofs of Berlekamp's factorization algorithm, at full length.

BERLEKAMP returns the irreducible factors of a square-free polynomial full

This proof shows: correctness.

Let pp be a prime, Fp=Z/pZ\mathbb{F}_p = \mathbb{Z}/p\mathbb{Z}, and f=q1⋯qr∈Fp[x]f = q_1 \cdots q_r \in \mathbb{F}_p[x] monic of degree nn with distinct monic irreducible qiq_i. Let A=Fp[x]/(f)A = \mathbb{F}_p[x]/(f), and identify a polynomial vv of degree less than nn with its coefficient vector and with its class in AA. The Berlekamp algebra is B={v∈A:vp=v}B = \{ v \in A : v^p = v \}.

Lemma 1 (BB is the left null space). vp mod f=vQv^p \bmod f = v Q, so B={v:v(Q−I)=0}B = \{ v : v (Q - I) = 0 \}.

Proof. In characteristic pp, (y+z)p=yp+zp(y + z)^p = y^p + z^p, and cp=cc^p = c for c∈Fpc \in \mathbb{F}_p by Fermat's little theorem. So vp=(∑ivixi)p=∑ivixpiv^p = \left(\sum_i v_i x^i\right)^p = \sum_i v_i x^{p i}. Reducing modulo ff replaces xpix^{p i} by row ii of QQ, so vp mod f=∑iviQi=vQv^p \bmod f = \sum_i v_i Q_i = v Q. □\square

Lemma 2 (structure). The map χ(v)=(v mod q1,…,v mod qr)\chi(v) = (v \bmod q_1, \ldots, v \bmod q_r) is a bijection from BB onto Fpr\mathbb{F}_p^r, where Fp\mathbb{F}_p is the set of constants in each Ki=Fp[x]/(qi)K_i = \mathbb{F}_p[x]/(q_i). In particular dim⁡B=r\dim B = r.

Proof. The qiq_i are pairwise coprime, so by the Chinese remainder theorem χ\chi is a ring isomorphism from AA onto ∏iKi\prod_i K_i, and vp=vv^p = v holds in AA exactly when it holds in every KiK_i. Each KiK_i is a field, so yp−yy^p - y has at most pp roots in KiK_i, and the pp constants are roots by Fermat's little theorem. So the solutions in KiK_i are exactly the constants, and χ(B)=Fpr\chi(B) = \mathbb{F}_p^r. χ\chi is Fp\mathbb{F}_p-linear, so dim⁡B=r\dim B = r. □\square

Write si(v)∈Fps_i(v) \in \mathbb{F}_p for the constant with v≡si(v)(modqi)v \equiv s_i(v) \pmod{q_i}.

Lemma 3 (one gcd step). Let hh be a monic product of some of the qiq_i, and v∈Bv \in B. Then the nonconstant gcd⁡(v−s,h)\gcd(v - s, h) for s∈Fps \in \mathbb{F}_p are the products ∏{qi∣h:si(v)=s}\prod \{ q_i \mid h : s_i(v) = s \} over the values ss that occur, so they form a partition of the factors of hh.

Proof. For qi∣hq_i \mid h, qi∣v−sq_i \mid v - s exactly when s=si(v)s = s_i(v). As hh is square-free, gcd⁡(v−s,h)\gcd(v - s, h) is the product of the qi∣hq_i \mid h with qi∣v−sq_i \mid v - s. Each qi∣hq_i \mid h lies in exactly one of these gcds. □\square

Basis. Line L2 returns rr vectors that form a basis of the left null space, which is BB by Lemma 1 and has dimension rr by Lemma 2. The vector 11 is in BB, since row 00 of QQ is (1,0,…,0)(1, 0, \ldots, 0); the elimination returns it first because column 00 of (Q−I)T(Q - I)^T is zero.

Invariant. After each pass of the loop at line L4, with the basis vectors v2,…,vjv_2, \ldots, v_j used so far, the list of pieces is a list of monic polynomials that partitions {q1,…,qr}\{ q_1, \ldots, q_r \}, and two factors qa,qbq_a, q_b are in the same piece if and only if sa(vt)=sb(vt)s_a(v_t) = s_b(v_t) for all 2≤t≤j2 \le t \le j.

Proof. Before the loop, the list of pieces is [f][f], and the condition over an empty set of tt is true. In a pass with vjv_j, Lemma 3 replaces each piece hh by its parts with equal si(vj)s_i(v_j), which refines the partition exactly by the new condition. A piece of degree 11 that the implementation keeps unchanged has one factor, so it satisfies the condition trivially. □\square

The loop stops with irreducible pieces. If the loop runs through all j≤rj \le r, then two factors qa≠qbq_a \ne q_b in the same piece would have sa(vt)=sb(vt)s_a(v_t) = s_b(v_t) for all tt, including t=1t = 1, where v1=1v_1 = 1. Since the vtv_t span BB, sa(v)=sb(v)s_a(v) = s_b(v) for every v∈Bv \in B. But by Lemma 2 there is v∈Bv \in B with χ(v)=ea\chi(v) = e_a, the vector with 11 at aa and 00 elsewhere, which has sa(v)=1≠0=sb(v)s_a(v) = 1 \ne 0 = s_b(v). So every piece has one factor. If the loop stops early because there are rr pieces, then the partition into rr nonempty parts of a set of size rr also has one factor per piece. The loop has at most r−1r - 1 passes, and each pass computes finitely many gcds, so it stops, and line L10 returns q1,…,qrq_1, \ldots, q_r. ■\blacksquare

Back to Berlekamp's factorization algorithm