Integer polynomials and verified Bernstein sign checkers #
Vendored from SevenTriangles/Certificates/IntPoly.lean (commit b17ca52a), with an early
failure test (endNeg) inside the bisection and, at the end of the file, consecutive interval
chains (chainCheck) and nonnegativity with explicit rational split points (nonnegOnSplit).
IPoly := List Int is a dense coefficient list, lowest degree first. Every operation below is
computable, uses only structural recursion (or explicit fuel), and is meant to be unfolded by the
kernel inside decide +kernel proofs. The semantic layer (evalR) is noncomputable and the two
soundness theorems nonnegOn_sound / posOn_sound are the only trusted statements.
Length conventions (they matter: Bernstein coefficients depend on the formal degree, i.e. on the list length, so trailing zeros are never trimmed):
add p qhas lengthmax p.length q.length;smul c p,sub p qfollow;mulis the literal recursionmul [] q = [],mul (a :: p) q = add (smul a q) (0 :: mul p q): lengthp.length + q.length - 1for nonempty factors, andmul p [] = [0, …, 0](p.lengthzeros). Consequentlycomp p a e dof a nonemptyphas lengthp.length + 1(one trailing zero: the Bernstein test is degree-elevated by one). The Python exporter reproduces exactly this ("literal mode"); do not "optimise" the representation without changing both sides;pascal nhas lengthn + 1;bern phas the same length asp;strip p = (j, q)withp = x ^ j * qandqeither empty or with nonzero constant term.
Dense integer coefficients in increasing degree order; trailing zeros are retained.
Equations
Instances For
Computable operations #
Coefficientwise addition of dense integer polynomials.
Equations
- ConwaySoifer.Certificates.IPoly.add [] x✝ = x✝
- x✝.add [] = x✝
- ConwaySoifer.Certificates.IPoly.add (a :: p) (b :: q) = (a + b) :: ConwaySoifer.Certificates.IPoly.add p q
Instances For
Multiply every polynomial coefficient by an integer scalar.
Equations
Instances For
Subtract dense integer coefficient lists.
Equations
- p.sub q = p.add (ConwaySoifer.Certificates.IPoly.smul (-1) q)
Instances For
Product (literal recursion; see the length conventions above).
Equations
Instances For
Row n of Pascal's triangle, i.e. the coefficients of (1 + x) ^ n.
Equations
Instances For
Coefficients of p in the (unnormalised) Bernstein basis t ^ k (1-t) ^ (n-k), n = p.length - 1.
Equations
Instances For
Structural integer exponentiation.
Equations
Instances For
Test that every integer coefficient is nonnegative.
Equations
Instances For
Test that every integer coefficient is strictly positive.
Equations
Instances For
Σ_j c_j num ^ j den ^ (N-j) (with truncated subtraction); equals den ^ N * p (num/den)
whenever
N ≥ p.length - 1. Used only for exact sign comparisons inside the untrusted search.
Equations
- ConwaySoifer.Certificates.evalScaledN [] x✝² x✝¹ x✝ = 0
- ConwaySoifer.Certificates.evalScaledN (c :: p) x✝² x✝¹ x✝ = c * ConwaySoifer.Certificates.IPoly.ipow x✝¹ x✝ + x✝² * ConwaySoifer.Certificates.evalScaledN p x✝² x✝¹ (x✝ - 1)
Instances For
The first or last Bernstein coefficient (the values at the ends of the interval) is negative: bisection cannot succeed. Only an optimisation of the search; soundness never uses it.
Equations
- ConwaySoifer.Certificates.endNeg c = match List.head? c, List.getLast? c with | some x, some y => decide (x < 0) || decide (y < 0) | x, x_1 => false
Instances For
Detect a nonpositive endpoint Bernstein coefficient before attempting bisection.
Equations
- ConwaySoifer.Certificates.endNonpos c = match List.head? c, List.getLast? c with | some x, some y => decide (x ≤ 0) || decide (y ≤ 0) | x, x_1 => false
Instances For
p ≥ 0 on [a/d, b/d], by Bernstein coefficients with adaptive bisection.
Equations
Instances For
q > 0 on [a/d, b/d], by strictly positive Bernstein coefficients (needs q ≠ []).
Equations
Instances For
Semantics #
Horner evaluation over the reals.
Equations
- ConwaySoifer.Certificates.evalR [] x✝ = 0
- ConwaySoifer.Certificates.evalR (c :: p) x✝ = ↑c + x✝ * ConwaySoifer.Certificates.evalR p x✝
Instances For
Lengths #
Homogeneous (Bernstein) evaluation #
evalH b s t = Σ_k b_k t ^ k s ^ (n-k) with n = b.length - 1.
Equations
- ConwaySoifer.Certificates.IPoly.evalH [] x✝¹ x✝ = 0
- ConwaySoifer.Certificates.IPoly.evalH (c :: cs) x✝¹ x✝ = ↑c * x✝¹ ^ cs.length + x✝ * ConwaySoifer.Certificates.IPoly.evalH cs x✝¹ x✝
Instances For
Affine substitution #
Consecutive interval chains and rational split points #
Rational number n/m with m > 0, as a pair.
Equations
Instances For
chainCheck f hi cur pieces: pieces = [(a₁, b₁, d₁), …] are consecutive rational intervals
[aᵢ/dᵢ, bᵢ/dᵢ] (all dᵢ > 0) starting at cur, ending at hi, and f aᵢ bᵢ dᵢ holds on
each. Endpoint equality is tested by cross-multiplication.
Equations
Instances For
The consecutive pieces of [cur, b/d] cut at the split points pts (each n/m, m > 0),
produced by the untrusted search.
Equations
Instances For
Nonnegativity on [a/d, b/d] with explicit split points: trusted only through
chainCheck and nonnegOn on each piece.
Equations
- One or more equations did not get rendered due to their size.