Proofs: Sparse polynomial representation
These are the human proofs of Sparse polynomial representation, at full length.
The sparse operations return the normalized term list of the exact result full
This proof shows: correctness.
Let be a commutative ring. A list meets (S) when and every , and .
Lemma 1 (uniqueness). Two lists that meet (S) and have the same value are equal.
Proof. The coefficient of in is if and if is not an exponent of , because the exponents are distinct. So the set of exponents of is the set of with a nonzero coefficient in , and the coefficients are the coefficients of . Both are determined by the value, and the order is fixed by (S).
So it suffices to show that each operation returns a list that meets (S) and has the right value.
ADD. Let and meet (S), with and terms. Consider the statement :
- meets (S);
- , the sum of the terms already read;
- every exponent in is less than if , and less than if ;
- the exponents of and are all less than if and less than if .
Initialization. At line L1, and is empty, so all four parts hold.
Maintenance. Assume at line L2 with and .
- Case line L3, . The term is appended. By part 3 its exponent is larger than all exponents in , and , so still meets (S). Part 2 holds for . For part 3, the new last exponent is less than by (S) for , and less than by the case. For part 4, and , and the old terms were already below both bounds, since .
- Case line L4 is symmetric.
- Case lines L5 to L8, . The two terms add to . If , the term is appended; its exponent is larger than all of by part 3, so (S) holds. If , nothing is appended and the value changes by . In both cases part 2 holds for . Parts 3 and 4 hold because and by (S) for and .
Termination. Each pass increases by at least , and , so the loop stops after at most passes, with or .
End. Say (the case is symmetric). Then line L9 appends , and the tail of is empty. By part 3, every exponent of is less than , and the tail is increasing with nonzero coefficients, so the result meets (S). By part 2, its value is . for ADD.
MUL. For each , the final value of is over the pairs of terms of and of with , since line M4 adds each such product once and no other. This sum is the coefficient of in . Every exponent with a nonzero coefficient in the product is a key of , because a nonzero sum has a nonzero term. Line M5 returns the keys with , each once, in increasing order. So the result meets (S) and has the value of the product.
EVALUATE. Let the terms be . Claim: before the pass for term of line E2, , (or when ) and . At line E1 this holds with and . In the pass, by (S) (and ), so line E3 sets , line E4 sets , and line E5 adds to . After the last pass, . Binary powering computes correctly by the identity .
Derivative and scalar multiple. Both map the term with exponent to a term with exponent or , a strictly increasing map on the exponents, so the order of (S) is kept. Terms whose new coefficient is are dropped, so the coefficients are nonzero. The value is and , by linearity.