Documentation

LeanCert.Tactic.IntervalAuto

Automated Interval Arithmetic Tactics #

This file provides smart tactics that automatically:

  1. Reify Lean expressions to LeanCert AST (Phase 1)
  2. Generate ExprSupportedCore proofs (Phase 2)
  3. Apply the appropriate verification theorem and close the goal (Phase 3)

Main tactics #

Usage #

-- Automatically proves the bound
example : ∀ x ∈ I01, x * x + Real.sin x ≤ 2 := by
  interval_bound

-- With custom Taylor depth for exp
example : ∀ x ∈ I01, Real.exp x ≤ 3 := by
  interval_bound { taylorDepth := 20 }

Design notes #

The tactic detects the goal structure:

Check if LeanCert debug mode is enabled

Equations
Instances For

    Goal Normalization #

    theorem LeanCert.Tactic.Auto.forall_arrow_of_Icc {α : Type u_1} [Preorder α] {lo hi : α} {P : αProp} :
    (∀ xSet.Icc lo hi, P x)∀ (x : α), lo xx hiP x

    Bridge: Set.Icc bound to arrow chain (lo ≤ x → x ≤ hi).

    theorem LeanCert.Tactic.Auto.forall_arrow_of_Icc_rev {α : Type u_1} [Preorder α] {lo hi : α} {P : αProp} :
    (∀ xSet.Icc lo hi, P x)xhi, lo xP x

    Bridge: Set.Icc bound to reversed arrow chain (x ≤ hi → lo ≤ x).

    theorem LeanCert.Tactic.Auto.forall_and_of_Icc {α : Type u_1} [Preorder α] {lo hi : α} {P : αProp} :
    (∀ xSet.Icc lo hi, P x)∀ (x : α), lo x x hiP x

    Bridge: Set.Icc bound to conjunctive domain (lo ≤ x ∧ x ≤ hi).

    theorem LeanCert.Tactic.Auto.forall_and_of_Icc_rev {α : Type u_1} [Preorder α] {lo hi : α} {P : αProp} :
    (∀ xSet.Icc lo hi, P x)∀ (x : α), x hi lo xP x

    Bridge: Set.Icc bound to reversed conjunctive domain (x ≤ hi ∧ lo ≤ x).

    Normalize common goal patterns for interval tactics.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      The interval_norm tactic.

      Normalizes inequalities, subtraction, rational division, and domain syntax to reduce goal-shape variation before parsing.

      Equations
      Instances For

        Rational Extraction Helpers #

        Utilities for extracting rational numbers from Lean expressions representing real number literals or coercions.

        Try to extract a rational value from a Lean expression that represents a real number. Handles: Rat.cast, OfNat.ofNat, Nat.cast, Int.cast, negations, and divisions. Also handles direct ℚ expressions as a fallback.

        Build an IntervalRat expression from two rational expressions and their Lean representations

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Goal Analysis #

          Utilities for analyzing the goal structure to determine which theorem to apply.

          Information about interval source

          Instances For
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Result of analyzing a bound goal

              Instances For
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  Try to parse a goal as a bound goal

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    Equations
                    Instances For

                      Extract (lhs, rhs) from an LE.le application.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Extract lower bound lo from lo ≤ x.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Extract upper bound hi from x ≤ hi.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Extract bounds from conjunction form lo ≤ x ∧ x ≤ hi.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For

                              Build IntervalInfo from explicit lo/hi bounds.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                Extract the interval from a membership expression

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  Try to convert a Set.Icc expression to an IntervalRat with full info

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Diagnostic Helpers for Shadow Computation #

                                    Run shadow computation to diagnose why a proof failed

                                    Equations
                                    Instances For

                                      Shared Diagnostic Helpers #

                                      Format goal context for diagnostic output, showing both normal and detailed forms

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        Analyze goal structure and report what was found vs expected

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          Suggest next actions based on failure type

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            def LeanCert.Tactic.Auto.mkDiagnosticReport (tacticName : String) (goalType : Lean.Expr) (failureType : String) (additionalInfo : Option Lean.MessageData := none) :

                                            Create a full diagnostic report for a failed tactic

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For

                                              Main Tactic Implementation #

                                              The main interval_bound tactic implementation

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For

                                                Try to extract the rational from a bound expression (possibly coerced to ℝ)

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For

                                                  Try to extract AST from an Expr.eval application, or reify if it's a raw expression

                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  Instances For

                                                    Try to generate ExprSupportedCore proof, falling back to ExprSupportedWithInv if needed. Returns (supportProof, useWithInv) where useWithInv is true if we used WithInv.

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For

                                                      Prove ∀ x ∈ I, f x ≤ c

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For

                                                        Prove ∀ x ∈ I, c ≤ f x

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For

                                                          Prove ∀ x ∈ I, f x < c

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For

                                                            Prove ∀ x ∈ I, c < f x

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              Tactic Syntax #

                                                              The certify_bound tactic.

                                                              Automatically proves bounds on expressions using interval arithmetic.

                                                              Usage:

                                                              • certify_bound - uses adaptive precision (tries depths 10, 15, 20, 25, 30)
                                                              • certify_bound 20 - uses fixed Taylor depth of 20

                                                              Supports goals of the form:

                                                              • ∀ x ∈ I, f x ≤ c
                                                              • ∀ x ∈ I, c ≤ f x
                                                              • ∀ x ∈ I, f x < c
                                                              • ∀ x ∈ I, c < f x

                                                              Note: interval_bound is an alias for backward compatibility.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For

                                                                Backward-compatible alias for certify_bound

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For

                                                                  Multivariate Bounds Tactic #

                                                                  The multivariate_bound tactic handles goals with multiple quantified variables:

                                                                  This uses the global optimization theorems (verify_global_upper_bound/verify_global_lower_bound) from Validity/Bounds.lean, which operate over Box (List IntervalRat) domains.

                                                                  Information about a quantified variable and its interval

                                                                  • varName : Lean.Name

                                                                    Variable name

                                                                  • varType : Lean.Expr

                                                                    Variable type

                                                                  • intervalRat : Lean.Expr

                                                                    Extracted interval (lo, hi rationals and their expressions)

                                                                  • loExpr : Lean.Expr

                                                                    Original lower bound expression for Set.Icc

                                                                  • hiExpr : Lean.Expr

                                                                    Original upper bound expression for Set.Icc

                                                                  • lo :

                                                                    Low bound as rational

                                                                  • hi :

                                                                    High bound as rational

                                                                  Instances For
                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For
                                                                      Equations
                                                                      • One or more equations did not get rendered due to their size.
                                                                      Instances For

                                                                        Result of analyzing a multivariate bound goal

                                                                        Instances For
                                                                          Equations
                                                                          • One or more equations did not get rendered due to their size.
                                                                          Instances For

                                                                            Recursively parse a multivariate bound goal, collecting variables and intervals. This processes all quantifiers within nested withLocalDeclD scopes so that fvars remain valid for mkLambdaFVars.

                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For
                                                                              partial def LeanCert.Tactic.Auto.parseMultivariateBoundGoal.collect (extractLowerBound extractUpperBound : Lean.ExprLean.ExprLean.MetaM (Option Lean.Expr)) (extractBoundsFromAnd : Lean.ExprLean.ExprLean.MetaM (Option (Lean.Expr × Lean.Expr))) (mkVarIntervalInfoFromBounds : Lean.ExprLean.ExprLean.ExprLean.MetaM (Option VarIntervalInfo)) (memCandidates : Lean.ExprLean.MetaM (Array Lean.Expr)) (e : Lean.Expr) (acc : Array VarIntervalInfo) (fvars : Array Lean.Expr) :

                                                                              Build a Box expression (List IntervalRat) from an array of VarIntervalInfo

                                                                              Equations
                                                                              Instances For
                                                                                def LeanCert.Tactic.Auto.multivariateBoundCore (maxIters : ) (tolerance : ) (useMonotonicity : Bool) (taylorDepth : ) :

                                                                                The main multivariate_bound tactic implementation

                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.
                                                                                Instances For

                                                                                  Extract rational bound from possible coercion (reusing logic from intervalBoundCore)

                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For

                                                                                    Fetch local variable expressions in the order of VarIntervalInfo.

                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For

                                                                                      Build an environment function ρ from a list of variables.

                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      Instances For
                                                                                        def LeanCert.Tactic.Auto.multivariateBoundCore.proveMultivariateLe (goal : Lean.MVarId) (vars : Array VarIntervalInfo) (func bound : Lean.Expr) (maxIters : ) (tolerance : ) (useMonotonicity : Bool) (taylorDepth : ) :

                                                                                        Prove ∀ x₁ ∈ I₁, ..., ∀ xₙ ∈ Iₙ, f(x) ≤ c using verify_global_upper_bound

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For
                                                                                          def LeanCert.Tactic.Auto.multivariateBoundCore.proveMultivariateGe (goal : Lean.MVarId) (vars : Array VarIntervalInfo) (func bound : Lean.Expr) (maxIters : ) (tolerance : ) (useMonotonicity : Bool) (taylorDepth : ) :

                                                                                          Prove ∀ x₁ ∈ I₁, ..., ∀ xₙ ∈ Iₙ, c ≤ f(x) using verify_global_lower_bound

                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For

                                                                                            The multivariate_bound tactic.

                                                                                            Automatically proves bounds on multivariate expressions using global optimization.

                                                                                            Usage:

                                                                                            • multivariate_bound - uses defaults (1000 iterations, tolerance 1/1000, Taylor depth 10)
                                                                                            • multivariate_bound 2000 - uses 2000 iterations

                                                                                            Supports goals of the form:

                                                                                            • ∀ x ∈ I, ∀ y ∈ J, f(x,y) ≤ c
                                                                                            • ∀ x ∈ I, ∀ y ∈ J, c ≤ f(x,y)
                                                                                            Equations
                                                                                            • One or more equations did not get rendered due to their size.
                                                                                            Instances For

                                                                                              Global Optimization Tactic #

                                                                                              The opt_bound tactic handles goals of the form:

                                                                                              This uses global branch-and-bound optimization with optional monotonicity pruning.

                                                                                              Skip through foralls (from ≥ binder notation) to get to the final comparison

                                                                                              Result of analyzing a global bound goal

                                                                                              Instances For
                                                                                                Equations
                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                Instances For

                                                                                                  Check if expression is Expr.eval (checking both short and full names)

                                                                                                  Equations
                                                                                                  Instances For

                                                                                                    Check if name ends with Expr.eval

                                                                                                    Equations
                                                                                                    Instances For

                                                                                                      Try to parse an already-intro'd goal as a global optimization bound. After intro ρ hρ hzero, the goal should be a comparison: Expr.eval ρ e ≤ c or c ≤ Expr.eval ρ e

                                                                                                      Equations
                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                      Instances For
                                                                                                        def LeanCert.Tactic.Auto.mkGlobalOptConfigExpr (maxIters : ) (tolerance : ) (useMonotonicity : Bool) (taylorDepth : ) :

                                                                                                        Build a GlobalOptConfig expression

                                                                                                        Equations
                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                        Instances For
                                                                                                          def LeanCert.Tactic.Auto.optBoundCore (maxIters : ) (useMonotonicity : Bool) (taylorDepth : ) :

                                                                                                          The main opt_bound tactic implementation

                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          Instances For

                                                                                                            Prove ExprSupportedCore goal by generating the proof

                                                                                                            Equations
                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                            Instances For

                                                                                                              The opt_bound tactic.

                                                                                                              Automatically proves global bounds on expressions over boxes using branch-and-bound optimization.

                                                                                                              Usage:

                                                                                                              • opt_bound - uses defaults (1000 iterations, no monotonicity, Taylor depth 10)
                                                                                                              • opt_bound 2000 - uses 2000 iterations
                                                                                                              • opt_bound 1000 mono - enables monotonicity pruning

                                                                                                              Supports goals of the form:

                                                                                                              • ∀ ρ, Box.envMem ρ B → (∀ i, i ≥ B.length → ρ i = 0) → c ≤ Expr.eval ρ e
                                                                                                              • ∀ ρ, Box.envMem ρ B → (∀ i, i ≥ B.length → ρ i = 0) → Expr.eval ρ e ≤ c
                                                                                                              Equations
                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                              Instances For

                                                                                                                Root Finding Tactic #

                                                                                                                The root_bound tactic handles goals related to root finding:

                                                                                                                Result of analyzing a root finding goal

                                                                                                                Instances For
                                                                                                                  Equations
                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                  Instances For

                                                                                                                    Try to parse a goal as a root finding goal

                                                                                                                    Equations
                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                    Instances For
                                                                                                                      Equations
                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                      Instances For
                                                                                                                        Equations
                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                        Instances For
                                                                                                                          Equations
                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                          Instances For
                                                                                                                            Equations
                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                            Instances For
                                                                                                                              Equations
                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                              Instances For

                                                                                                                                Extract the interval from a membership expression

                                                                                                                                Equations
                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                Instances For

                                                                                                                                  The main root_bound tactic implementation

                                                                                                                                  Equations
                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                  Instances For

                                                                                                                                    Try to extract AST from an Expr.eval application, or reify if it's a raw expression

                                                                                                                                    Equations
                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                    Instances For

                                                                                                                                      Try to convert Set.Icc to IntervalRat for root_bound

                                                                                                                                      Equations
                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                      Instances For

                                                                                                                                        Prove ∀ x ∈ I, f x ≠ 0 using verify_no_root

                                                                                                                                        Equations
                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                        Instances For

                                                                                                                                          The root_bound tactic.

                                                                                                                                          Automatically proves root-related properties using interval arithmetic.

                                                                                                                                          Usage:

                                                                                                                                          • root_bound - uses default Taylor depth of 10
                                                                                                                                          • root_bound 20 - uses Taylor depth of 20

                                                                                                                                          Supports goals of the form:

                                                                                                                                          • ∀ x ∈ I, f x ≠ 0 (proves no root exists in interval)
                                                                                                                                          Equations
                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                          Instances For

                                                                                                                                            Point Inequality Tactic (interval_decide) #

                                                                                                                                            The interval_decide tactic proves point inequalities like Real.exp 1 ≤ 3 by transforming them into singleton interval bounds ∀ x ∈ Set.Icc c c, f x ≤ b and using the existing interval_bound machinery.

                                                                                                                                            Parse a point inequality goal and extract lhs, rhs, and inequality type. Returns (lhs, rhs, isStrict, isReversed) where:

                                                                                                                                            • isStrict: true for < or >, false for ≤ or ≥
                                                                                                                                            • isReversed: true for ≥ or > (need to flip the comparison)
                                                                                                                                            Equations
                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                            Instances For

                                                                                                                                              Try to collect all constant rational values from an expression. Returns the list of rational constants found (for building the singleton interval).

                                                                                                                                              Try to prove a closed expression bound directly using certificate verification. For goals like Real.pi ≤ 4 where the expression doesn't contain any variables, we can directly use verify_upper_bound/verify_lower_bound with a singleton interval.

                                                                                                                                              Equations
                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                              Instances For

                                                                                                                                                The interval_decide tactic implementation. Transforms f(c) ≤ b into ∀ x ∈ [c,c], f(x) ≤ b and uses interval_bound.

                                                                                                                                                Equations
                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                Instances For
                                                                                                                                                  Equations
                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                  Instances For

                                                                                                                                                    Subdivision-aware bound proving #

                                                                                                                                                    The interval_bound_subdiv tactic uses interval subdivision when the direct approach fails. This helps with tight bounds where interval arithmetic has excessive width due to the dependency problem (when a variable appears multiple times, we lose correlation).

                                                                                                                                                    Subdivision works because:

                                                                                                                                                    1. Narrower intervals → tighter bounds
                                                                                                                                                    2. May subdivide near critical points, reducing dependency

                                                                                                                                                    The interval_bound_subdiv tactic.

                                                                                                                                                    Like interval_bound, but uses interval subdivision when the direct approach fails. This can help with tight bounds where the dependency problem causes excessive width.

                                                                                                                                                    Usage:

                                                                                                                                                    • interval_bound_subdiv - uses default Taylor depth 10 and max subdivision depth 3
                                                                                                                                                    • interval_bound_subdiv 20 - uses Taylor depth 20
                                                                                                                                                    • interval_bound_subdiv 20 5 - uses Taylor depth 20 and max subdivision depth 5
                                                                                                                                                    Equations
                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                    Instances For

                                                                                                                                                      Adaptive Branch-and-Bound Tactic #

                                                                                                                                                      The interval_bound_adaptive tactic uses branch-and-bound global optimization for bound verification. Unlike interval_bound_subdiv which does subdivision at the proof level (many native_decide calls), this tactic does subdivision at the computation level (single native_decide).

                                                                                                                                                      This is more efficient for cases requiring many subdivisions.

                                                                                                                                                      The interval_bound_adaptive tactic.

                                                                                                                                                      Uses branch-and-bound global optimization for bound verification. This does adaptive subdivision at the computation level (single native_decide) rather than at the proof level (multiple native_decide calls).

                                                                                                                                                      Usage:

                                                                                                                                                      • interval_bound_adaptive - uses default max iterations (200)
                                                                                                                                                      • interval_bound_adaptive 500 - uses 500 max iterations

                                                                                                                                                      More efficient than interval_bound_subdiv for cases requiring many subdivisions.

                                                                                                                                                      Equations
                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                      Instances For

                                                                                                                                                        Unified Interval Tactic #

                                                                                                                                                        The interval_auto tactic automatically routes to the appropriate tactic based on goal structure:

                                                                                                                                                        Unified tactic that handles both point inequalities and quantified bounds.

                                                                                                                                                        • interval_auto - uses adaptive precision
                                                                                                                                                        • interval_auto 20 - uses fixed Taylor depth of 20

                                                                                                                                                        This is the recommended entry point for interval arithmetic proofs.

                                                                                                                                                        Equations
                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                        Instances For