Discovery Mode: Tactics #
This module provides tactics for automatically proving existential goals using discovery algorithms:
interval_minimize- Prove∃ m, ∀ x ∈ I, f(x) ≥ mby finding the minimuminterval_maximize- Prove∃ M, ∀ x ∈ I, f(x) ≤ Mby finding the maximuminterval_roots- Prove∃ x ∈ I, f(x) = 0by finding roots (Stub)
Usage #
-- Automatically find and prove a lower bound exists
example : ∃ m : ℚ, ∀ x ∈ I01, x^2 + Real.sin x ≥ m := by
interval_minimize
-- Find a root (Not fully implemented yet)
example : ∃ x ∈ Icc (-2 : ℝ) 2, x^3 - x = 0 := by
interval_roots
Implementation #
The tactics:
- Analyze the goal to find the function
fand intervalI. - Reify
fto a LeanCert AST. - Execute the optimization algorithm (via
evalExpr) to find the boundm. - Instantiate the existential
∃ mwith the found value. - Call
opt_boundto prove the resulting universal bound.
Instances For
Helper Functions #
Parse a domain expression into a Box
Equations
- LeanCert.Tactic.Discovery.parseDomainToBox domainExpr = do let e ← Lean.Meta.evalExpr LeanCert.Core.IntervalRat (Lean.mkConst `LeanCert.Core.IntervalRat) domainExpr pure [e]
Instances For
Check if the goal is an existential bound: ∃ m, ∀ x ∈ I, f(x) ≥ m or ≤ m
- minimize (varName : Lean.Name) (varType domain func : Lean.Expr) : ExistentialBoundGoal
- maximize (varName : Lean.Name) (varType domain func : Lean.Expr) : ExistentialBoundGoal
Instances For
Parse an existential bound goal. Supports goals of the form:
∃ m, ∀ x ∈ I, f(x) ≥ m(minimize)∃ M, ∀ x ∈ I, f(x) ≤ M(maximize)
The function f can be:
- A raw Lean expression like
x * x + Real.sin x - An
Expr.evalwrapped expression
Auto-reification will convert raw expressions to LeanCert AST.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Helper Functions #
Try to extract AST from an Expr.eval application, or reify if it's a raw expression.
This enables automatic reification - users can write standard math like x * x + sin x
without needing to wrap in Expr.eval.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Domain normalization helpers #
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.
Minimization Tactic #
The interval_minimize tactic implementation
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_minimize tactic.
Proves goals of the form ∃ m, ∀ x ∈ I, f(x) ≥ m by:
- Running global optimization to find the minimum
m. - Instantiating the existential with
m. - Proving the bound using
opt_bound.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- LeanCert.Tactic.Discovery.elabIntervalMinimize stx = LeanCert.Tactic.Discovery.intervalMinimizeCore (match stx[1].getOptional? with | some n => n.toNat | none => 10)
Instances For
Maximization Tactic #
The interval_maximize tactic implementation
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_maximize tactic.
Proves goals of the form ∃ M, ∀ x ∈ I, f(x) ≤ M.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- LeanCert.Tactic.Discovery.elabIntervalMaximize stx = LeanCert.Tactic.Discovery.intervalMaximizeCore (match stx[1].getOptional? with | some n => n.toNat | none => 10)
Instances For
Argmax/Argmin Tactics #
Result of analyzing an argmax goal
- argmax
(varName : Lean.Name)
(domain func : Lean.Expr)
: ArgmaxGoal
∃ x ∈ I, ∀ y ∈ I, f(y) ≤ f(x)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Try to parse a goal as an argmax goal: ∃ x ∈ I, ∀ y ∈ I, f(y) ≤ f(x)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract the interval from a membership expression x ∈ I
Equations
- One or more equations did not get rendered due to their size.
Instances For
Result of analyzing an argmin goal
- argmin
(varName : Lean.Name)
(domain func : Lean.Expr)
: ArgminGoal
∃ x ∈ I, ∀ y ∈ I, f(x) ≤ f(y)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Try to parse a goal as an argmin goal: ∃ x ∈ I, ∀ y ∈ I, f(x) ≤ f(y)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract the interval from a membership expression x ∈ I
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if a function expression is wrapped in Expr.eval
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_argmax tactic implementation
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_argmax tactic.
Proves goals of the form ∃ x ∈ I, ∀ y ∈ I, f(y) ≤ f(x) by:
- Running global optimization to find the point x where f is maximized.
- Instantiating the existential with x.
- Proving membership x ∈ I.
- Proving the universal bound using interval arithmetic.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- LeanCert.Tactic.Discovery.elabIntervalArgmax stx = LeanCert.Tactic.Discovery.intervalArgmaxCore (match stx[1].getOptional? with | some n => n.toNat | none => 10)
Instances For
The interval_argmin tactic implementation
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_argmin tactic.
Proves goals of the form ∃ x ∈ I, ∀ y ∈ I, f(x) ≤ f(y) by:
- Running global optimization to find the point x where f is minimized.
- Instantiating the existential with x.
- Proving membership x ∈ I.
- Proving the universal bound using interval arithmetic.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- LeanCert.Tactic.Discovery.elabIntervalArgmin stx = LeanCert.Tactic.Discovery.intervalArgminCore (match stx[1].getOptional? with | some n => n.toNat | none => 10)
Instances For
Multivariate Minimization/Maximization Tactics #
Result of analyzing a multivariate existential bound goal
- minimize
(varType : Lean.Expr)
(vars : Array Auto.VarIntervalInfo)
(func : Lean.Expr)
: MultivariateExistentialGoal
∃ m, ∀ x ∈ I, ∀ y ∈ J, ..., f(...) ≥ m (minimize)
- maximize
(varType : Lean.Expr)
(vars : Array Auto.VarIntervalInfo)
(func : Lean.Expr)
: MultivariateExistentialGoal
∃ M, ∀ x ∈ I, ∀ y ∈ J, ..., f(...) ≤ M (maximize)
Instances For
Parse a multivariate existential bound goal. Supports goals of the form:
∃ m, ∀ x ∈ I, ∀ y ∈ J, f(x,y) ≥ m(minimize)∃ M, ∀ x ∈ I, ∀ y ∈ J, f(x,y) ≤ M(maximize)
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_minimize_mv tactic implementation for multivariate goals
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_minimize_mv tactic.
Proves multivariate goals of the form ∃ m, ∀ x ∈ I, ∀ y ∈ J, f(x,y) ≥ m by:
- Running global optimization over the n-dimensional domain.
- Instantiating the existential with the found minimum.
- Proving the bound using
interval_bound.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- LeanCert.Tactic.Discovery.elabIntervalMinimizeMv stx = LeanCert.Tactic.Discovery.intervalMinimizeMvCore (match stx[1].getOptional? with | some n => n.toNat | none => 10)
Instances For
The interval_maximize_mv tactic implementation for multivariate goals
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_maximize_mv tactic.
Proves multivariate goals of the form ∃ M, ∀ x ∈ I, ∀ y ∈ J, f(x,y) ≤ M by:
- Running global optimization over the n-dimensional domain.
- Instantiating the existential with the found maximum.
- Proving the bound using
interval_bound.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- LeanCert.Tactic.Discovery.elabIntervalMaximizeMv stx = LeanCert.Tactic.Discovery.intervalMaximizeMvCore (match stx[1].getOptional? with | some n => n.toNat | none => 10)
Instances For
Roots Tactic #
Result of analyzing a root existence goal
- existsRoot
(varName : Lean.Name)
(interval func : Lean.Expr)
: RootExistsGoal
∃ x ∈ I, f x = 0
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 existence goal: ∃ x ∈ I, f(x) = 0
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
- LeanCert.Tactic.Discovery.parseRootExistsGoal.mkSetIccFromBounds loExpr hiExpr = Lean.Meta.mkAppM `Set.Icc #[loExpr, hiExpr]
Instances For
Extract the interval from a membership expression x ∈ I
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract function from f(x) = 0
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_roots tactic implementation
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_roots tactic.
Proves goals of the form ∃ x ∈ I, f(x) = 0 by:
- Checking for a sign change at the interval endpoints using interval arithmetic
- Applying the Intermediate Value Theorem
The tactic automatically:
- Reifies the function to a LeanCert AST
- Generates an
ExprSupportedCoreproof - Generates a
ContinuousOnproof (automatic for supported expressions) - Verifies the sign change certificate using
native_decide
Usage:
example : ∃ x ∈ Icc (0 : ℝ) 2, x^2 - 2 = 0 := by
interval_roots
Limitations:
- Only works for expressions in
ExprSupportedCore(nolog,inv) - Requires a sign change at the endpoints (IVT condition)
- If there's no sign change, the tactic will fail
Equations
- One or more equations did not get rendered due to their size.
Instances For
Unique Root Tactic #
Parse a unique root goal: ∃! x, x ∈ I ∧ f(x) = 0
Equations
- One or more equations did not get rendered due to their size.
Instances For
Core implementation for interval_unique_root tactic.
Proves ∃! x ∈ I, f(x) = 0 by:
- Checking Newton contraction (derivative bounded away from 0)
- Applying verify_unique_root_computable theorem
Uses the fully computable verify_unique_root_computable theorem which only
requires checkNewtonContractsCore. This allows native_decide to work
without noncomputable Real functions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_unique_root tactic.
Proves goals of the form ∃! x ∈ I, f(x) = 0 by:
- Using Newton contraction to verify uniqueness (derivative bounded away from 0)
- Applying the Intermediate Value Theorem for existence
Usage:
example : ∃! x ∈ I_1_2, Expr.eval (fun _ => x) (x² - 2) = 0 := by
interval_unique_root
Requirements:
- Function must be in
ExprSupported(const, var, add, mul, neg, sin, cos, exp only) - Newton step must contract (derivative doesn't contain 0)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- LeanCert.Tactic.Discovery.elabIntervalUniqueRoot stx = LeanCert.Tactic.Discovery.intervalUniqueRootCore (match stx[1].getOptional? with | some n => n.toNat | none => 10)
Instances For
Integration Tactic #
Extract components from integration goal: ∫ x in lo..hi, f(x) ∈ bound returns (lo, hi, integral, bound)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Core implementation for interval_integrate tactic.
Proves goals of the form ∫ x in (I.lo)...(I.hi), f(x) ∈ bound by:
- Computing the integral bound using interval arithmetic
- Proving the computed bound contains the integral
The goal must be exactly of the form: ∫ x in (I.lo:ℝ)..(I.hi:ℝ), Expr.eval (fun _ => x) e ∈ integrateInterval1Core e I cfg
Equations
- One or more equations did not get rendered due to their size.
Instances For
The interval_integrate tactic.
Proves goals of the form ∫ x in (I.lo)...(I.hi), f(x) ∈ bound by:
- Computing the integral bound using interval arithmetic
- Applying the integrateInterval1Core_correct theorem
Usage:
example : ∫ x in (0:ℝ)..1, x ∈ Validity.Integration.integrateInterval1Core (Expr.var 0) ⟨0, 1, by norm_num⟩ default := by
interval_integrate
Limitations:
- The bound must exactly match
integrateInterval1Core e I cfg - The function must be in
ExprSupportedCore(no log, inv)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- LeanCert.Tactic.Discovery.elabIntervalIntegrate stx = LeanCert.Tactic.Discovery.intervalIntegrateCore (match stx[1].getOptional? with | some n => n.toNat | none => 10)
Instances For
Discover Tactic #
The discover tactic - generic discovery.
Analyzes the goal and applies the appropriate discovery tactic.
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
Exploration Command #
Equations
- One or more equations did not get rendered due to their size.
Instances For
Syntax for signed integer: either a nat or -nat
Equations
Instances For
Equations
- LeanCert.Tactic.Discovery.signedInt_ = Lean.ParserDescr.node `LeanCert.Tactic.Discovery.signedInt_ 1022 (Lean.ParserDescr.const `num)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Parse a signedInt syntax to Int
Equations
- One or more equations did not get rendered due to their size.
Instances For
The #explore command analyzes a function on an interval.
Usage:
#explore (Expr.sin (Expr.var 0)) on [0, 7]
#explore (Expr.cos (Expr.var 0)) on [-1, 2]
Output includes:
- Range bounds
- Global minimum/maximum
- Root detection (sign changes)
Note: Bounds must be integer literals (positive or negative).
Equations
- One or more equations did not get rendered due to their size.