CANTOR-ZASSENHAUS returns the complete factorization and stops with probability one full
This proof shows: correctness.
Let p be a prime, Fp=Z/pZ, and f∈Fp[x] nonzero with c=lc(f). We use two facts from the pages on the stages. DISTINCT-DEGREE(s), for monic square-free s, returns the pairs (g,d) with g=1 the product of the irreducible factors of s of degree d. EQUAL-DEGREE(g,d), for such g, returns the irreducible factors of g and stops with probability 1.
Lemma 1 (derivative). Let u=∏qqeq be monic with distinct monic irreducible q. Then gcd(u,u′)=∏p∤eqqeq−1∏p∣eqqeq.
Proof. Fix one q and write u=qet with q∤t. Then u′=qe−1(eq′t+qt′). If p∣e, the first term is zero and qe∣u′. If p∤e, then q∤eq′t: q∤t, and q′=0 has degree less than degq, since an irreducible q with q′=0 would be a p-th power (∑jajpxj)p. So qe−1 is the exact power of q that divides u′. Taking the minimum with eq for every q gives the claim. □
Lemma 2 (p-th roots). If every exponent of v=∑iaixi is a multiple of p, then v=(∑jajpxj)p.
Proof. In characteristic p, (y+z)p=yp+zp, and ap=a for a∈Fp by Fermat's little theorem. So (∑jajpxj)p=∑jajppxjp=∑jajpxjp=v. □
Invariant of the work list. We prove by induction on the pushes: for every pair (u,k) on the work list, k=pj for some j≥0, and u=∏qeq/k, the product over the irreducible q∣f with pj∣eq, where eq is the multiplicity of q in f.
Base. At line L1, (f/c,1) has this form with j=0.
Step. Let (u,k) with k=pj be popped at line L3, and write ϵq=eq/k for the multiplicities in u. By Lemma 1, line L3 gives v=∏p∤ϵqqϵq−1∏p∣ϵqqϵq and w=u/v=∏p∤ϵqq. Claim: before the test at line L4,
w=p∤ϵq, ϵq≥i∏q,v=p∤ϵq, ϵq≥i∏qϵq−ip∣ϵq∏qϵq. This holds for i=1. At line L5, every q∣w has p∤ϵq, and q∣v exactly when ϵq>i, so y=∏p∤ϵq, ϵq>iq and s=∏p∤ϵq, ϵq=iq. Line L9 then makes w=y and divides each exponent ϵq−i≥1 in v by one factor q, which is the claim for i+1.
The loop ends when w=1, that is, when no q with p∤ϵq has ϵq≥i. Then v=∏p∣ϵqqϵq. All exponents of v as a polynomial are multiples of p, since v is the p-th power of ∏p∣ϵqqϵq/p, and by Lemma 2 and unique factorization, the p-th root at line L10 is ∏p∣ϵqqϵq/p=∏pj+1∣eqqeq/(pk). So the pushed pair (⋅,pk) has the claimed form with j+1. □
Output. In the step above, each q with pj∣eq and p∤eq/pj is in s exactly once, at i=ϵq=eq/k. Then s is monic and square-free, so by the facts on DISTINCT-DEGREE and EQUAL-DEGREE, lines L7 and L8 append (q,ik)=(q,eq), and only such pairs. Every irreducible q∣f has a unique j with pj∣eq and p∤eq/pj, and the pair with k=pj is on the work list by the invariant, since pj′∣eq for all j′≤j. So the result lists every (q,eq) exactly once, and line L11 returns c and this list. Then f=c∏qqeq.
Termination. For a pushed pair with k=pj, degu≤n/pj, so j≤logpn for u=1, and a pair is pushed only if v=1. So at most logpn+1 pairs are popped. In the inner loop at line L4, i grows by one per step, and w=1 as soon as i exceeds every ϵq, so it stops after at most degu steps. Each call of EQUAL-DEGREE stops with probability 1. So the algorithm stops with probability 1. ■