Algorithm Search⌘K

Proofs: Dense polynomial representation

These are the human proofs of Dense polynomial representation, at full length.

The operations on dense coefficient lists are exact and keep the lists normalized full

This proof shows: correctness.

Let RR be a commutative ring with 11. For a list a=[a0,…,an−1]a = [a_0, \ldots, a_{n-1}] of elements of RR we write ∣a∣=n|a| = n and val⁡(a)=∑i<naixi\operatorname{val}(a) = \sum_{i<n} a_i x^i, and we set ai=0a_i = 0 for i≥ni \ge n. A list is normalized when it is empty or its last entry is nonzero.

Lemma 0 (uniqueness). For each f∈R[x]f \in R[x] there is exactly one normalized list aa with val⁡(a)=f\operatorname{val}(a) = f, and then ∣a∣−1=deg⁡f|a| - 1 = \deg f (with −1-1 for f=0f = 0).

Proof. Two lists with the same value have the same entries at each position below the shorter length, and the longer one has only zero entries above it, because the coefficients of a polynomial are unique. If both lists are normalized, the longer one would end in a zero entry, unless the lengths are equal. So the lists are equal. The list of the coefficients of x0,…,xdeg⁡fx^0, \ldots, x^{\deg f} is normalized and has the value ff. □\square

Lemma 1 (NORMALIZE). NORMALIZE(c)(c) returns a normalized list with the same value as cc.

Proof. The loop of lines L1 and L2 removes only last entries that are zero, and removing a top zero entry does not change ∑cixi\sum c_i x^i. It stops when the list is empty or its last entry is nonzero, which is the definition of normalized. It stops after at most ∣c∣|c| steps, since each step shortens the list. □\square

Lemma 2 (ADD). For normalized aa and bb, ADD(a,b)(a, b) returns the normalized list of val⁡(a)+val⁡(b)\operatorname{val}(a) + \operatorname{val}(b).

Proof. Let N=max⁡(∣a∣,∣b∣)N = \max(|a|, |b|). After line L6 has run for i=0,…,N−1i = 0, \ldots, N - 1, ci=ai+bic_i = a_i + b_i for each i<Ni < N, with the convention ai=0a_i = 0 for i≥∣a∣i \ge |a|. Both operands have no terms of degree NN or more, so val⁡(c)=∑i<N(ai+bi)xi=val⁡(a)+val⁡(b)\operatorname{val}(c) = \sum_{i<N} (a_i + b_i) x^i = \operatorname{val}(a) + \operatorname{val}(b). Line L7 and Lemma 1 finish the proof. □\square

Lemma 3 (MUL). For normalized aa and bb, MUL(a,b)(a, b) returns the normalized list of val⁡(a)val⁡(b)\operatorname{val}(a) \operatorname{val}(b).

Proof. If ∣a∣=0|a| = 0 or ∣b∣=0|b| = 0, one factor is the zero polynomial, the product is zero, and line L8 returns the empty list. Otherwise let m=∣a∣m = |a|, n=∣b∣n = |b|. We show the invariant

(M) before row ii of the loop of line L10, ck=∑i′<i, 0≤k−i′<nai′bk−i′c_k = \sum_{i' < i,\ 0 \le k - i' < n} a_{i'} b_{k - i'} for each 0≤k≤m+n−20 \le k \le m + n - 2.

Initialization. For i=0i = 0 the sum is empty, and line L9 sets every ckc_k to 00.

Maintenance. Row ii runs line L12 for j=0,…,n−1j = 0, \ldots, n - 1 and adds aibja_i b_j to ci+jc_{i+j}. Each index kk gets the term with i′=ii' = i and k−i′=jk - i' = j exactly when 0≤k−i<n0 \le k - i < n, which is the new term of (M) for i+1i + 1. The index i+j≤(m−1)+(n−1)i + j \le (m - 1) + (n - 1) is in range.

Termination. After row m−1m - 1, (M) with i=mi = m gives ck=∑i+j=kaibjc_k = \sum_{i + j = k} a_i b_j, the coefficient of xkx^k in the product. Every pair (i,j)(i, j) with i<mi < m, j<nj < n has i+j≤m+n−2i + j \le m + n - 2, so no term of the product is lost. So val⁡(c)=val⁡(a)val⁡(b)\operatorname{val}(c) = \operatorname{val}(a)\operatorname{val}(b), and Lemma 1 gives a normalized result. □\square

Lemma 4 (EVALUATE). EVALUATE(a,u)(a, u) returns val⁡(a)(u)=∑j<majuj\operatorname{val}(a)(u) = \sum_{j<m} a_j u^j.

Proof. Let m=∣a∣m = |a|. We show that at the test of line L15 for the index ii (counting down from m−1m - 1 to −1-1), s=∑j=i+1m−1ajuj−i−1s = \sum_{j=i+1}^{m-1} a_j u^{j - i - 1}. For i=m−1i = m - 1 the sum is empty and line L14 sets s=0s = 0. If it holds for ii, then line L16 sets s⋅u+ai=∑j=i+1m−1ajuj−i+ai=∑j=im−1ajuj−is \cdot u + a_i = \sum_{j=i+1}^{m-1} a_j u^{j-i} + a_i = \sum_{j=i}^{m-1} a_j u^{j-i}, which is the claim for i−1i - 1. When the loop ends, i=−1i = -1, and s=∑j=0m−1ajujs = \sum_{j=0}^{m-1} a_j u^j. This uses that RR is commutative only through the identity (∑cjuj)u=∑cjuj+1(\sum c_j u^j) u = \sum c_j u^{j+1}, which holds in every associative ring. □\square

Lemma 5 (DIVMOD). Let aa and bb be normalized, n=∣b∣≥1n = |b| \ge 1, and let bn−1b_{n-1} be a unit of RR. Then DIVMOD(a,b)(a, b) returns normalized lists qq and rr with val⁡(a)=val⁡(q)val⁡(b)+val⁡(r)\operatorname{val}(a) = \operatorname{val}(q)\operatorname{val}(b) + \operatorname{val}(r) and ∣r∣≤n−1|r| \le n - 1, that is deg⁡r<deg⁡b\deg r < \deg b. These qq and rr are the only polynomials with these properties.

Proof. Let m=∣a∣m = |a|. If m<nm < n, the loop of line L20 does not run, qq is empty, r=ar = a has at most n−1n - 1 entries, and val⁡(a)=0⋅val⁡(b)+val⁡(a)\operatorname{val}(a) = 0 \cdot \operatorname{val}(b) + \operatorname{val}(a). Let m≥nm \ge n. Write Qk=∑j>kqjxjQ_k = \sum_{j > k} q_j x^j for the part of the quotient that is set before step kk (so Qm−nQ_{m-n} is 00). We show the invariant

(D) before step kk of the loop of line L20, val⁡(a)=Qkval⁡(b)+val⁡(r)\operatorname{val}(a) = Q_k \operatorname{val}(b) + \operatorname{val}(r) and rj=0r_j = 0 for each j≥k+nj \ge k + n.

Initialization. For k=m−nk = m - n, line L18 sets r=ar = a and Qk=0Q_k = 0, and rj=0r_j = 0 for j≥mj \ge m because ∣r∣=m|r| = m.

Maintenance. Step kk sets t=rk+n−1vt = r_{k+n-1} v (line L21), stores qk=tq_k = t (line L22), and subtracts t xkval⁡(b)t\, x^k \operatorname{val}(b) from val⁡(r)\operatorname{val}(r) in lines L23 and L24: the entry rk+jr_{k+j} loses tbjt b_j for j=0,…,n−1j = 0, \ldots, n - 1. Then Qk−1=Qk+txkQ_{k-1} = Q_k + t x^k, and

Qk−1val⁡(b)+val⁡(rnew)=Qkval⁡(b)+txkval⁡(b)+val⁡(rold)−txkval⁡(b)=val⁡(a).Q_{k-1}\operatorname{val}(b) + \operatorname{val}(r_{\text{new}}) = Q_k \operatorname{val}(b) + t x^k \operatorname{val}(b) + \operatorname{val}(r_{\text{old}}) - t x^k \operatorname{val}(b) = \operatorname{val}(a).

The entry at k+n−1k + n - 1 becomes rk+n−1−t bn−1=rk+n−1−rk+n−1v bn−1=0r_{k+n-1} - t\, b_{n-1} = r_{k+n-1} - r_{k+n-1} v\, b_{n-1} = 0, since vbn−1=1v b_{n-1} = 1. The entries at j≥k+nj \ge k + n are not touched and stay zero. So rj=0r_j = 0 for j≥(k−1)+nj \ge (k - 1) + n, which is (D) for k−1k - 1.

Termination. After step k=0k = 0, (D) holds with Q−1=val⁡(q)Q_{-1} = \operatorname{val}(q) and rj=0r_j = 0 for j≥n−1j \ge n - 1. So val⁡(r)=val⁡(r0,…,rn−2)\operatorname{val}(r) = \operatorname{val}(r_0, \ldots, r_{n-2}), which is what line L25 keeps, and val⁡(a)=val⁡(q)val⁡(b)+val⁡(r[0..n−2])\operatorname{val}(a) = \operatorname{val}(q)\operatorname{val}(b) + \operatorname{val}(r[0..n-2]). Lemma 1 normalizes both lists without a change of value, and the remainder list has at most n−1n - 1 entries.

Uniqueness. Suppose val⁡(a)=qb+r=q′b+r′\operatorname{val}(a) = q b + r = q' b + r' with deg⁡r,deg⁡r′<deg⁡b=n−1\deg r, \deg r' < \deg b = n - 1. Then (q−q′)b=r′−r(q - q') b = r' - r. If q≠q′q \ne q', the top coefficient of (q−q′)b(q - q') b is lc⁡(q−q′)bn−1\operatorname{lc}(q - q') b_{n-1}, which is nonzero because bn−1b_{n-1} is a unit (if c bn−1=0c\, b_{n-1} = 0 then c=c bn−1v=0c = c\, b_{n-1} v = 0). So deg⁡((q−q′)b)≥n−1>deg⁡(r′−r)\deg((q - q') b) \ge n - 1 > \deg(r' - r), a contradiction. Hence q=q′q = q' and then r=r′r = r'. By Lemma 0 the normalized lists are also unique. □\square

Lemma 6 (derivative and scalar multiple). The list [1⋅a1,…,(n−1)⋅an−1][1 \cdot a_1, \ldots, (n-1) \cdot a_{n-1}] has the value ∑i≥1iaixi−1\sum_{i \ge 1} i a_i x^{i-1}, the formal derivative, and [sa0,…,san−1][s a_0, \ldots, s a_{n-1}] has the value sval⁡(a)s \operatorname{val}(a). After NORMALIZE both are normalized by Lemma 1. □\square

Theorem. Each operation of the dense representation takes normalized lists to a normalized list (or pair of lists) whose value is the exact result in R[x]R[x], and by Lemma 0 the length of each result is its degree plus one.

Proof. Lemmas 2 to 6, with subtraction as ADD of aa and the list [−b0,…,−bn−1][-b_0, \ldots, -b_{n-1}], which is normalized because −bn−1≠0-b_{n-1} \ne 0 when bn−1≠0b_{n-1} \ne 0. ■\blacksquare

Back to Dense polynomial representation