Algorithm Search⌘K

Proofs: Yun's square-free factorization

These are the human proofs of Yun's square-free factorization, at full length.

Yun's algorithm returns the square-free factorization, at the cost of a constant number of gcds full

This proof shows: correctness.

Let FF be a field of characteristic 00 or of characteristic p>np > n, and let f∈F[x]f \in F[x] be monic of degree n≥1n \ge 1 (the implementation first divides by the leading coefficient). Let f=∏j=1kaj jf = \prod_{j=1}^{k} a_j^{\,j} be the square-free factorization, with the aja_j monic, square-free, pairwise coprime and ak≠1a_k \ne 1; it exists and is unique, as shown on the square-free factorization page.

Step 0. Each aja_j is coprime to j aj′j\, a_j'. If aj=1a_j = 1 there is nothing to show. Otherwise let qq be an irreducible factor of aja_j. Over a field of characteristic 00, q′≠0q' \ne 0 because deg⁡q≥1\deg q \ge 1. In characteristic p>np > n, q′=0q' = 0 would force qq to be a polynomial in xpx^p and so deg⁡q≥p>n\deg q \ge p > n, which is impossible. So q′≠0q' \ne 0, deg⁡q′<deg⁡q\deg q' < \deg q, and q∤q′q \nmid q'. Write aj=q ra_j = q\, r with q∤rq \nmid r, because aja_j is square-free. Then aj′=q′r+qr′a_j' = q' r + q r', and q∤q′rq \nmid q' r, so q∤aj′q \nmid a_j'. Also j≤nj \le n, so j≠0j \ne 0 in FF, and q∤jaj′q \nmid j a_j'. This holds for every irreducible factor qq of aja_j, so gcd⁡(aj,jaj′)=1\gcd(a_j, j a_j') = 1.

Notation. For 1≤i≤k+11 \le i \le k + 1 let

bi=∏j≥iaj,ei=∑j≥i(j−i+1) aj′ biaj,di=ei−bi′=∑j>i(j−i) aj′ biaj,b_i = \prod_{j \ge i} a_j, \qquad e_i = \sum_{j \ge i} (j - i + 1)\, a_j'\, \frac{b_i}{a_j}, \qquad d_i = e_i - b_i' = \sum_{j > i} (j - i)\, a_j'\, \frac{b_i}{a_j},

with bk+1=1b_{k+1} = 1. The last form of did_i uses bi′=∑j≥iaj′ bi/ajb_i' = \sum_{j \ge i} a_j'\, b_i / a_j, the product rule, and the term j=ij = i of eie_i has the factor j−i+1=1j - i + 1 = 1.

Lines L2 and L3. By the product rule, f′=∑jj aj j−1aj′∏l≠jal lf' = \sum_j j\, a_j^{\,j-1} a_j' \prod_{l \ne j} a_l^{\,l}. Let g=∏jaj j−1g = \prod_j a_j^{\,j-1}. Then f=g b1f = g\, b_1 and f′=g e1f' = g\, e_1, since jajj−1aj′∏l≠jall=g⋅jaj′b1/ajj a_j^{j-1} a_j' \prod_{l \ne j} a_l^l = g \cdot j a_j' b_1 / a_j. Also gcd⁡(b1,e1)=1\gcd(b_1, e_1) = 1: for each jj, every term of e1e_1 except the term jj is divisible by aja_j, and the term jj, jaj′b1/ajj a_j' b_1 / a_j, is coprime to aja_j by Step 0 and because the ala_l are pairwise coprime. So gcd⁡(f,f′)=ggcd⁡(b1,e1)=g\gcd(f, f') = g \gcd(b_1, e_1) = g, as gg is monic. Line L2 computes b=gb = g and line L3 computes c=f/g=b1c = f / g = b_1 and d=f′/g−c′=e1−b1′=d1d = f'/g - c' = e_1 - b_1' = d_1.

Loop invariant. At the iith test of line L4, c=bic = b_i and d=did = d_i, and the list holds a1,…,ai−1a_1, \ldots, a_{i-1}. It holds for i=1i = 1 by the previous paragraph.

Line L5. We show gcd⁡(bi,di)=ai\gcd(b_i, d_i) = a_i. Each term of did_i has j>ij > i, so its factor bi/ajb_i / a_j contains aia_i; so ai∣dia_i \mid d_i. For j>ij > i, every term of did_i other than the term jj is divisible by aja_j, and the term jj, (j−i) aj′ bi/aj(j - i)\, a_j'\, b_i / a_j, is coprime to aja_j: j−ij - i is between 11 and nn, so it is nonzero in FF, aja_j is coprime to aj′a_j' by Step 0, and aja_j is coprime to the other ala_l. So gcd⁡(aj,di)=1\gcd(a_j, d_i) = 1 for j>ij > i. Since bi=ai∏j>iajb_i = a_i \prod_{j > i} a_j with pairwise coprime factors, gcd⁡(bi,di)=ai⋅∏j>igcd⁡(aj,di/ai)=ai\gcd(b_i, d_i) = a_i \cdot \prod_{j > i} \gcd(a_j, d_i / a_i) = a_i; the gcd of aja_j with di/aid_i / a_i is 11 because it divides gcd⁡(aj,di)=1\gcd(a_j, d_i) = 1. This also covers ai=1a_i = 1.

Lines L6 to L8. Line L6 appends aia_i. Line L7 sets c=bi/ai=bi+1c = b_i / a_i = b_{i+1}. Line L8 sets d=di/ai−bi+1′d = d_i / a_i - b_{i+1}'. Now di/ai=∑j>i(j−i) aj′ bi+1/aj=∑j≥i+1(j−(i+1)+1) aj′ bi+1/aj=ei+1d_i / a_i = \sum_{j > i} (j - i)\, a_j'\, b_{i+1} / a_j = \sum_{j \ge i+1} (j - (i + 1) + 1)\, a_j'\, b_{i+1} / a_j = e_{i+1}, so d=ei+1−bi+1′=di+1d = e_{i+1} - b_{i+1}' = d_{i+1}. The invariant holds for i+1i + 1.

Termination and result. bi=1b_i = 1 exactly when aj=1a_j = 1 for all j≥ij \ge i, that is when i>ki > k, because ak≠1a_k \ne 1. So the loop runs for i=1,…,ki = 1, \ldots, k and stops with the list a1,…,aka_1, \ldots, a_k, which line L9 returns with the leading coefficient of the input. A constant input is handled before line L1.

Cost. Let ni=deg⁡bi=∑j≥ideg⁡ajn_i = \deg b_i = \sum_{j \ge i} \deg a_j. Then ∑i=1kni=∑jjdeg⁡aj=n\sum_{i=1}^{k} n_i = \sum_j j \deg a_j = n, and deg⁡di<ni\deg d_i < n_i. Iteration ii makes one gcd of two polynomials of degree at most nin_i, two exact divisions of polynomials of degree at most nin_i, and one derivative. With the Euclidean algorithm and schoolbook division these cost O(ni2)O(n_i^2), and ∑ini2≤(∑ini)2=n2\sum_i n_i^2 \le (\sum_i n_i)^2 = n^2. Lines L2 and L3 cost O(n2)O(n^2). So the total is O(n2)O(n^2) field operations. If a gcd of degree dd costs G(d)G(d) with G(d)/dG(d)/d nondecreasing, then ∑iG(ni)≤∑i(ni/n)G(n)=G(n)\sum_i G(n_i) \le \sum_i (n_i / n) G(n) = G(n), and with fast division the total is O(G(n)+M(n)log⁡n)=O(M(n)log⁡n)O(G(n) + M(n) \log n) = O(M(n) \log n) with the fast Euclidean algorithm. ■\blacksquare

Back to Yun's square-free factorization