Documentation

LeanPool.ConwaySoifer.Certificates.IntPoly

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):

@[reducible, inline]

Dense integer coefficients in increasing degree order; trailing zeros are retained.

Equations
Instances For

    Computable operations #

    Coefficientwise addition of dense integer polynomials.

    Equations
    Instances For

      Multiply every polynomial coefficient by an integer scalar.

      Equations
      Instances For

        Subtract dense integer coefficient lists.

        Equations
        Instances For

          Multiplication by x.

          Equations
          Instances For

            Product (literal recursion; see the length conventions above).

            Equations
            Instances For

              Remove the leading (lowest-degree) zero coefficients: strip p = (j, q) with p = x ^ j q.

              Equations
              Instances For

                comp p a e d = Σ_j c_j d ^ (n-j) (a + e t) ^ j where n = p.length - 1; the affine substitution x = (a + e t) / d cleared of denominators.

                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
                  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
                    Instances For

                      Detect a nonpositive endpoint Bernstein coefficient before attempting bisection.

                      Equations
                      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
                            def ConwaySoifer.Certificates.posOn (p : IPoly) (a b d : ℤ) (fuel : ℕ) :

                            p > 0 on [a/d, b/d] ∩ (0, ∞): strip the factor x ^ j, then posOn' on the quotient.

                            Equations
                            Instances For

                              Semantics #

                              noncomputable def ConwaySoifer.Certificates.evalR :
                              IPoly → ℝ → ℝ

                              Horner evaluation over the reals.

                              Equations
                              Instances For
                                @[simp]
                                theorem ConwaySoifer.Certificates.IPoly.evalR_cons (c : ℤ) (p : IPoly) (x : ℝ) :
                                evalR (c :: p) x = ↑c + x * evalR p x
                                theorem ConwaySoifer.Certificates.IPoly.evalR_smul (c : ℤ) (p : IPoly) (x : ℝ) :
                                evalR (smul c p) x = ↑c * evalR p x
                                theorem ConwaySoifer.Certificates.IPoly.cast_ipow (b : ℤ) (n : ℕ) :
                                ↑(ipow b n) = ↑b ^ n

                                Lengths #

                                theorem ConwaySoifer.Certificates.IPoly.comp_ne_nil (p : IPoly) (a e d : ℤ) (hp : p ≠ []) :
                                p.comp a e d ≠ []

                                Homogeneous (Bernstein) evaluation #

                                noncomputable def ConwaySoifer.Certificates.IPoly.evalH :
                                IPoly → ℝ → ℝ → ℝ

                                evalH b s t = Σ_k b_k t ^ k s ^ (n-k) with n = b.length - 1.

                                Equations
                                Instances For
                                  theorem ConwaySoifer.Certificates.IPoly.evalH_add (p q : IPoly) (hlen : List.length p = List.length q) (s t : ℝ) :
                                  (p.add q).evalH s t = p.evalH s t + q.evalH s t
                                  theorem ConwaySoifer.Certificates.IPoly.evalH_smul (c : ℤ) (p : IPoly) (s t : ℝ) :
                                  (smul c p).evalH s t = ↑c * p.evalH s t
                                  theorem ConwaySoifer.Certificates.IPoly.evalH_nonneg (b : IPoly) (h : b.allNonneg = true) {s t : ℝ} (hs : 0 ≤ s) (ht : 0 ≤ t) :
                                  0 ≤ b.evalH s t
                                  theorem ConwaySoifer.Certificates.IPoly.evalH_pos (b : IPoly) (h : b.allPos = true) (hb : b ≠ []) {s t : ℝ} (hs : 0 ≤ s) (ht : 0 ≤ t) (hst : 0 < s + t) :
                                  0 < b.evalH s t

                                  Affine substitution #

                                  theorem ConwaySoifer.Certificates.IPoly.evalR_comp (p : IPoly) (a e d : ℤ) (hd : ↑d ≠ 0) (t : ℝ) :
                                  ↑d * evalR (p.comp a e d) t = ↑d ^ List.length p * evalR p ((↑a + ↑e * t) / ↑d)
                                  theorem ConwaySoifer.Certificates.exists_param (a b d : ℤ) (hd : 0 < d) (x : ℝ) (hlo : ↑a / ↑d ≤ x) (hhi : x ≤ ↑b / ↑d) :
                                  ∃ (t : ℝ), 0 ≤ t ∧ t ≤ 1 ∧ ↑a + ↑(b - a) * t = ↑d * x
                                  theorem ConwaySoifer.Certificates.bern_comp_nonneg_sound (p : IPoly) (a b d : ℤ) (h : (p.comp a (b - a) d).bern.allNonneg = true) (hd : 0 < d) (x : ℝ) (hlo : ↑a / ↑d ≤ x) (hhi : x ≤ ↑b / ↑d) :
                                  0 ≤ evalR p x
                                  theorem ConwaySoifer.Certificates.bern_comp_pos_sound (q : IPoly) (hq : q ≠ []) (a b d : ℤ) (h : (q.comp a (b - a) d).bern.allPos = true) (hd : 0 < d) (x : ℝ) (hlo : ↑a / ↑d ≤ x) (hhi : x ≤ ↑b / ↑d) :
                                  0 < evalR q x
                                  theorem ConwaySoifer.Certificates.half_lo (a d : ℤ) (x : ℝ) (hlo : ↑a / ↑d ≤ x) :
                                  ↑(2 * a) / ↑(2 * d) ≤ x
                                  theorem ConwaySoifer.Certificates.half_hi (b d : ℤ) (x : ℝ) (hhi : x ≤ ↑b / ↑d) :
                                  x ≤ ↑(2 * b) / ↑(2 * d)
                                  theorem ConwaySoifer.Certificates.nonnegOn_sound (p : IPoly) (a b d : ℤ) (fuel : ℕ) (h : nonnegOn p a b d fuel = true) (hd : 0 < d) (x : ℝ) (hlo : ↑a / ↑d ≤ x) (hhi : x ≤ ↑b / ↑d) :
                                  0 ≤ evalR p x
                                  theorem ConwaySoifer.Certificates.posOn'_sound (q : IPoly) (hq : q ≠ []) (a b d : ℤ) (fuel : ℕ) (h : posOn' q a b d fuel = true) (hd : 0 < d) (x : ℝ) (hlo : ↑a / ↑d ≤ x) (hhi : x ≤ ↑b / ↑d) :
                                  0 < evalR q x
                                  theorem ConwaySoifer.Certificates.posOn_sound (p : IPoly) (a b d : ℤ) (fuel : ℕ) (h : posOn p a b d fuel = true) (hd : 0 < d) (x : ℝ) (hx : 0 < x) (hlo : ↑a / ↑d ≤ x) (hhi : x ≤ ↑b / ↑d) :
                                  0 < evalR p x

                                  Consecutive interval chains and rational split points #

                                  @[reducible, inline]

                                  Rational number n/m with m > 0, as a pair.

                                  Equations
                                  Instances For
                                    def ConwaySoifer.Certificates.chainCheck (f : ℤ → ℤ → ℤ → Bool) (hi : IRat) :
                                    IRat → List (ℤ × ℤ × ℤ) → Bool

                                    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

                                        Build exact adjacent rational intervals between supplied split points.

                                        Equations
                                        Instances For
                                          def ConwaySoifer.Certificates.nonnegOnSplit (p : IPoly) (a b d : ℤ) (fuel : ℕ) (pts : List IRat) :

                                          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.
                                          Instances For
                                            theorem ConwaySoifer.Certificates.rat_eq_of_cross {a b c d : ℤ} (hb : 0 < b) (hd : 0 < d) (h : a * d = c * b) :
                                            ↑a / ↑b = ↑c / ↑d
                                            theorem ConwaySoifer.Certificates.chainCheck_sound (f : ℤ → ℤ → ℤ → Bool) (hi : IRat) (hhi : 0 < hi.2) (x : ℝ) (hx : x ≤ ↑hi.1 / ↑hi.2) (pieces : List (ℤ × ℤ × ℤ)) (cur : IRat) :
                                            0 < cur.2 → chainCheck f hi cur pieces = true → ↑cur.1 / ↑cur.2 ≤ x → ∃ (a' : ℤ) (b' : ℤ) (d' : ℤ), 0 < d' ∧ f a' b' d' = true ∧ ↑a' / ↑d' ≤ x ∧ x ≤ ↑b' / ↑d'
                                            theorem ConwaySoifer.Certificates.nonnegOnSplit_sound (p : IPoly) (a b d : ℤ) (fuel : ℕ) (pts : List IRat) (h : nonnegOnSplit p a b d fuel pts = true) (hd : 0 < d) (x : ℝ) (hlo : ↑a / ↑d ≤ x) (hhi : x ≤ ↑b / ↑d) :
                                            0 ≤ evalR p x