Automated Interval Arithmetic Tactics #
This file provides smart tactics that automatically:
- Reify Lean expressions to LeanCert AST (Phase 1)
- Generate ExprSupportedCore proofs (Phase 2)
- Apply the appropriate verification theorem and close the goal (Phase 3)
Main tactics #
interval_bound- Automatically prove bounds using interval arithmetic
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:
∀ x ∈ I, f x ≤ c→ usesverify_upper_bound∀ x ∈ I, c ≤ f x→ usesverify_lower_bound
Check if LeanCert debug mode is enabled
Equations
- isLeanCertDebugEnabled = do let __do_lift ← Lean.getOptions pure (Lean.KVMap.getBool __do_lift `leancert.debug)
Instances For
Goal Normalization #
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
- LeanCert.Tactic.Auto.intervalNormTac = Lean.ParserDescr.node `LeanCert.Tactic.Auto.intervalNormTac 1024 (Lean.ParserDescr.nonReservedSymbol "interval_norm" false)
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
- intervalRat : Lean.Expr
The IntervalRat expression to use in proofs
If converted from Set.Icc, contains (lo, hi, loRatExpr, hiRatExpr, leProof, origLoExpr, origHiExpr)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Result of analyzing a bound goal
- forallLe
(varName : Lean.Name)
(interval : IntervalInfo)
(func bound : Lean.Expr)
: BoundGoal
∀ x ∈ I, f x ≤ c
- forallGe
(varName : Lean.Name)
(interval : IntervalInfo)
(func bound : Lean.Expr)
: BoundGoal
∀ x ∈ I, c ≤ f x
- forallLt
(varName : Lean.Name)
(interval : IntervalInfo)
(func bound : Lean.Expr)
: BoundGoal
∀ x ∈ I, f x < c
- forallGt
(varName : Lean.Name)
(interval : IntervalInfo)
(func bound : Lean.Expr)
: BoundGoal
∀ x ∈ I, c < f x
Instances For
Equations
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
- One or more equations did not get rendered due to their size.
- LeanCert.Tactic.Auto.runShadowDiagnostic boundGoal _goalType = pure (Lean.toMessageData "(Could not parse goal for diagnostics)")
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
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:
∀ x ∈ I, ∀ y ∈ J, f(x, y) ≤ c∀ x ∈ I, ∀ y ∈ J, c ≤ f(x, y)
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
- forallLe
(vars : Array VarIntervalInfo)
(func bound : Lean.Expr)
: MultivariateBoundGoal
∀ x₁ ∈ I₁, ..., ∀ xₙ ∈ Iₙ, f(x₁,...,xₙ) ≤ c
- forallGe
(vars : Array VarIntervalInfo)
(func bound : Lean.Expr)
: MultivariateBoundGoal
∀ x₁ ∈ I₁, ..., ∀ xₙ ∈ Iₙ, c ≤ f(x₁,...,xₙ)
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
Build a Box expression (List IntervalRat) from an array of VarIntervalInfo
Equations
- LeanCert.Tactic.Auto.mkBoxExpr infos = Lean.Meta.mkListLit (Lean.mkConst `LeanCert.Core.IntervalRat) (Array.map (fun (x : LeanCert.Tactic.Auto.VarIntervalInfo) => x.intervalRat) infos).toList
Instances For
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
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
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:
∀ ρ, 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
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
- globalGe
(box expr bound : Lean.Expr)
: GlobalBoundGoal
∀ ρ ∈ B, (zero extension) → c ≤ f(ρ)
- globalLe
(box expr bound : Lean.Expr)
: GlobalBoundGoal
∀ ρ ∈ B, (zero extension) → f(ρ) ≤ c
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if name ends with Expr.eval
Equations
- LeanCert.Tactic.Auto.isExprEvalName name = `Expr.eval.isSuffixOf name
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
Build a GlobalOptConfig expression
Equations
- One or more equations did not get rendered due to their size.
Instances For
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 iterationsopt_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:
∀ x ∈ I, f x ≠ 0(no root exists) - uses verify_no_root
Equations
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 10root_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:
- Narrower intervals → tighter bounds
- 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 3interval_bound_subdiv 20- uses Taylor depth 20interval_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:
- Point inequalities (e.g.,
Real.pi ≤ 4) →interval_decide - Quantified bounds (e.g.,
∀ x ∈ I, f x ≤ c) →interval_bound
Unified tactic that handles both point inequalities and quantified bounds.
interval_auto- uses adaptive precisioninterval_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.