Algorithm Search⌘K

Proofs: Dense polynomial (recursive dense representation)

These are the human proofs of Dense polynomial (recursive dense representation), at full length.

The recursive dense operations keep the invariant, and pseudo-division is correct full

This proof shows: correctness, termination.

Let RR be a commutative ring with a zero test. A value over RR is a list c=[c0,…,cm−1]c = [c_0, \ldots, c_{m-1}] standing for ∑icixi∈R[x]\sum_i c_i x^i \in R[x]. When R=S[y]R = S[y] is itself represented in this way, operations in RR are the operations of this page one level down. We prove each statement for RR given that it holds for the coefficient ring; for the base ring, such as Z\mathbb{Z} or Q\mathbb{Q}, the operations are exact by assumption. This is an induction on the number of variables.

Lemma 1 (NORMALIZE). NORMALIZE(c)(c) returns the longest prefix of cc whose last entry is nonzero, or the empty list, and it represents the same polynomial.

Proof. Lines L7 and L8 remove entries from the end while the last one is zero. The removed entries are coefficients equal to 0, so the polynomial does not change. When the loop stops, the list is empty or its last entry is nonzero. Each pass removes one entry, so it stops after at most mm passes. By the induction hypothesis, an entry of a polynomial ring is zero exactly when it is the empty list, so the zero test is correct at every level. □\square

Lemma 2 (ADD and MUL). ADD(a,b)(a, b) and MUL(a,b)(a, b) represent a+ba + b and abab and meet (N).

Proof. Line L1 sets ci=ai+bic_i = a_i + b_i, with ai=0a_i = 0 for i≥mi \ge m and bi=0b_i = 0 for i≥ni \ge n; this is the definition of the sum, coefficient by coefficient. For MUL, if one factor is zero the product is zero (line L3). Otherwise, line L5 adds aibja_i b_j to ci+jc_{i+j} once for each pair (i,j)(i, j), so at the end ck=∑i+j=kaibjc_k = \sum_{i + j = k} a_i b_j, the coefficient of xkx^k in abab, for 0≤k≤m+n−20 \le k \le m + n - 2; there are no terms of higher degree. The sums and products of coefficients are correct and meet (N) one level down by the induction hypothesis. Lemma 1 gives (N) at the top level. □\square

Scaling, negation, evaluation by Horner's rule and the derivative are similar: each computes the defining formula entry by entry and then normalizes.

Theorem (pseudo-division). Let b≠0b \ne 0, deg⁡a=m−1\deg a = m - 1, deg⁡b=n−1\deg b = n - 1 and ℓ=LC⁡(b)\ell = \operatorname{LC}(b). PSEUDO-DIVMOD(a,b)(a, b) terminates and returns q,rq, r with ℓmax⁡(m−n+1,0)a=qb+r\ell^{\max(m - n + 1, 0)} a = q b + r and deg⁡r<deg⁡b\deg r < \deg b.

Proof. Write E=max⁡(m−n+1,0)E = \max(m - n + 1, 0) and let kk count the passes of the loop of line L10. We claim that at the test of line L10,

ℓka=qb+r,e=E−k,deg⁡r≤m−1−k.\ell^{k} a = q b + r, \qquad e = E - k, \qquad \deg r \le m - 1 - k .

At the start k=0k = 0, q=0q = 0, r=ar = a and e=Ee = E (line L9), so the claim holds. Suppose it holds and the body runs, so deg⁡r≥deg⁡b\deg r \ge \deg b and r≠0r \ne 0. Let δ=deg⁡r−deg⁡b≥0\delta = \deg r - \deg b \ge 0 and t=LC⁡(r)xδt = \operatorname{LC}(r) x^\delta (line L11). Line L12 gives the new values q′=ℓq+tq' = \ell q + t and r′=ℓr−tbr' = \ell r - t b. Then

q′b+r′=ℓqb+tb+ℓr−tb=ℓ(qb+r)=ℓk+1a.q' b + r' = \ell q b + t b + \ell r - t b = \ell (q b + r) = \ell^{k+1} a .

The coefficient of xdeg⁡rx^{\deg r} in r′r' is ℓLC⁡(r)−LC⁡(r)ℓ=0\ell \operatorname{LC}(r) - \operatorname{LC}(r) \ell = 0, because RR is commutative, and r′r' has no term of higher degree, because ℓr\ell r has degree deg⁡r\deg r and tbt b has degree δ+deg⁡b=deg⁡r\delta + \deg b = \deg r. So deg⁡r′≤deg⁡r−1≤m−1−(k+1)\deg r' \le \deg r - 1 \le m - 1 - (k + 1). Line L13 sets e=E−(k+1)e = E - (k + 1). The claim holds for k+1k + 1.

Since deg⁡r\deg r falls by at least one in each pass and the loop runs only while deg⁡r≥n−1\deg r \ge n - 1, starting from deg⁡r=m−1\deg r = m - 1, there are at most m−n+1m - n + 1 passes when m≥nm \ge n, and none when m<nm < n. So the loop terminates with k≤Ek \le E, e=E−k≥0e = E - k \ge 0 and deg⁡r<deg⁡b\deg r < \deg b. Line L14 returns ℓeq\ell^e q and ℓer\ell^e r, and

ℓeq b+ℓer=ℓeℓka=ℓEa,\ell^{e} q\, b + \ell^{e} r = \ell^{e} \ell^{k} a = \ell^{E} a,

while scaling does not raise the degree of rr. This is the stated identity. □\square

Uniqueness. If ℓ\ell is not a zero divisor of RR, the pair (q,r)(q, r) is unique: if ℓEa=qb+r=q1b+r1\ell^E a = q b + r = q_1 b + r_1 with deg⁡r,deg⁡r1<deg⁡b\deg r, \deg r_1 < \deg b, then (q−q1)b=r1−r(q - q_1) b = r_1 - r. If q≠q1q \ne q_1, the left side has degree at least deg⁡b\deg b, because its leading coefficient is LC⁡(q−q1) ℓ≠0\operatorname{LC}(q - q_1)\, \ell \ne 0, while the right side has smaller degree. So q=q1q = q_1 and r=r1r = r_1. Polynomial rings over Z\mathbb{Z} or a field have no zero divisors, so this applies to every level of the recursive representation over such a base. ■\blacksquare

Back to Dense polynomial (recursive dense representation)