Algorithm Search⌘K

Proofs: Sparse polynomial representation

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

Correctness of sparse distributed addition and heap multiplication full

This proof shows: correctness.

Setting. RR is a commutative ring and >> is a monomial order on the monomials of R[x1,…,xn]R[x_1, \ldots, x_n]: a total order with xα>xβ⇒xα+γ>xβ+γx^\alpha > x^\beta \Rightarrow x^{\alpha+\gamma} > x^{\beta+\gamma}. A list [(α1,c1),…,(αt,ct)][(\alpha_1, c_1), \ldots, (\alpha_t, c_t)] meets (D) when xα1>⋯>xαtx^{\alpha_1} > \cdots > x^{\alpha_t} and all ci≠0c_i \ne 0.

Lemma 1 (uniqueness). Each polynomial pp has exactly one list that meets (D). Proof. The monomials with nonzero coefficient in pp form a finite set, and the order is total, so there is exactly one strictly decreasing listing of them. The coefficients are those of pp. □\square

So it is enough to show that each operation returns a list that meets (D) and whose terms sum to the right polynomial.

ADD. Let ff and gg meet (D). Loop invariant at line A2: hh meets (D); every monomial in hh is larger than every monomial of f[i..]f[i..] and of g[j..]g[j..]; and hh represents the part of f+gf + g on the monomials larger than both LM⁡(f[i])\operatorname{LM}(f[i]) and LM⁡(g[j])\operatorname{LM}(g[j]) (with a missing entry treated as below every monomial). It holds at the start with hh empty. In case A3, LM⁡(f[i])\operatorname{LM}(f[i]) is larger than every monomial left in gg, so the coefficient of that monomial in f+gf + g is that of ff, which is nonzero, and it is smaller than every monomial of hh; appending keeps (D) and the invariant. Case A4 is symmetric. In case A5 to A7 the monomial occurs in both, its coefficient in f+gf + g is uu, and it is appended exactly when u≠0u \ne 0. Each step increases i+ji + j, so the loop ends. At line A8 one list is exhausted, the rest of the other list is smaller than everything in hh and has nonzero coefficients that equal those of f+gf + g, so the output meets (D) and equals f+gf + g. □\square

MUL. Let f=[(αi,ai)]i≤sf = [(\alpha_i, a_i)]_{i \le s} and g=[(βj,bj)]j≤tg = [(\beta_j, b_j)]_{j \le t} meet (D), with s,t≥1s, t \ge 1 (line L1 handles the empty case, since the product with 00 is 00). Write Pij=aibjxαi+βjP_{ij} = a_i b_j x^{\alpha_i + \beta_j} and μij=xαi+βj\mu_{ij} = x^{\alpha_i + \beta_j}. Then fg=∑i,jPijfg = \sum_{i,j} P_{ij}. By compatibility, μi1>μi2>⋯>μit\mu_{i1} > \mu_{i2} > \cdots > \mu_{it} for each row ii.

Invariant (H). At line L4, for each row ii there is a number ji∈{1,…,t+1}j_i \in \{1, \ldots, t+1\} such that the products Pi1,…,Pi,ji−1P_{i1}, \ldots, P_{i, j_i - 1} have been used (each exactly once), the others have not, and the heap holds exactly one entry (μiji,i,ji)(\mu_{i j_i}, i, j_i) for each row with ji≤tj_i \le t, and nothing else. Line L2 sets ji=1j_i = 1 for all rows. One pass of the loop extracts the entry of some row ii, uses PijiP_{i j_i} and, at line L9, inserts the entry of the next column if there is one. So (H) holds again with jij_i increased by 1.

Order of extraction. Let MM be the monomial extracted in some pass. Each unused product PklP_{kl} has l≥jkl \ge j_k, so μkl≤μkjk≤M\mu_{kl} \le \mu_{k j_k} \le M, because MM is the maximum of the heap. Every product used later is unused now, so its monomial is at most MM. Hence the extracted monomials form a non-increasing sequence M1≥M2≥⋯≥MstM_1 \ge M_2 \ge \cdots \ge M_{st}, and all products with the same monomial are extracted in consecutive passes.

Invariant (O). After each pass, hh is a list of pairs with strictly decreasing monomials; all pairs except the last have nonzero coefficient; and hh represents exactly the sum of the used products. Before the first pass hh is empty. In a pass with monomial MM: if the last monomial of hh is MM, line L7 adds the new product to it, and the sum is still right. Otherwise MM is smaller than the last monomial of hh, by the order of extraction; the run of products with that last monomial is complete, so its coefficient is final, and line L8 deletes it if it is zero, which changes no sum. Then (M,c)(M, c) is appended, and the monomials stay strictly decreasing. So (O) holds.

Termination and result. Each pass uses one product and no product is used twice, so the loop runs exactly stst times. Then all products are used, and by (O) hh represents ∑Pij=fg\sum P_{ij} = fg. The coefficient of each monomial μ\mu in hh is the sum of all PijP_{ij} with μij=μ\mu_{ij} = \mu, which is the coefficient of μ\mu in fgfg. Every pair except the last has a nonzero coefficient, and line L10 deletes the last if it is zero. So the output meets (D), and by Lemma 1 it is the representation of fgfg. □\square

Cost. By (H) the heap has at most ss entries at all times. There are stst extractions and at most st−sst - s insertions, each with O(log⁡s)O(\log s) comparisons of monomials, and stst coefficient products and at most stst additions. Swapping the factors so that s≤ts \le t does not change the product, because RR is commutative.

mul_term. For a term cxγc x^\gamma, the list [(αi+γ,cci)][(\alpha_i + \gamma, c c_i)] is strictly decreasing by compatibility, and it represents cxγfc x^\gamma f. Dropping the entries with cci=0c c_i = 0 gives (D). ■\blacksquare

Back to Sparse polynomial representation