Documentation

LeanCert.Tactic.Discovery

Discovery Mode: Tactics #

This module provides tactics for automatically proving existential goals using discovery algorithms:

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:

  1. Analyze the goal to find the function f and interval I.
  2. Reify f to a LeanCert AST.
  3. Execute the optimization algorithm (via evalExpr) to find the bound m.
  4. Instantiate the existential ∃ m with the found value.
  5. Call opt_bound to prove the resulting universal bound.

Helper Functions #

Parse a domain expression into a Box

Equations
Instances For

    Check if the goal is an existential bound: ∃ m, ∀ x ∈ I, f(x) ≥ m or ≤ m

    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.eval wrapped 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:

            1. Running global optimization to find the minimum m.
            2. Instantiating the existential with m.
            3. Proving the bound using opt_bound.
            Equations
            • One or more equations did not get rendered due to their size.
            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

                  Argmax/Argmin Tactics #

                  Result of analyzing an argmax goal

                  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

                          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:

                                      1. Running global optimization to find the point x where f is maximized.
                                      2. Instantiating the existential with x.
                                      3. Proving membership x ∈ I.
                                      4. Proving the universal bound using interval arithmetic.
                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      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:

                                          1. Running global optimization to find the point x where f is minimized.
                                          2. Instantiating the existential with x.
                                          3. Proving membership x ∈ I.
                                          4. Proving the universal bound using interval arithmetic.
                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            Multivariate Minimization/Maximization Tactics #

                                            Result of analyzing a multivariate existential bound goal

                                            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:

                                                  1. Running global optimization over the n-dimensional domain.
                                                  2. Instantiating the existential with the found minimum.
                                                  3. Proving the bound using interval_bound.
                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  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:

                                                      1. Running global optimization over the n-dimensional domain.
                                                      2. Instantiating the existential with the found maximum.
                                                      3. Proving the bound using interval_bound.
                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For

                                                        Roots Tactic #

                                                        Result of analyzing a root existence 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 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

                                                                      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:

                                                                            1. Checking for a sign change at the interval endpoints using interval arithmetic
                                                                            2. Applying the Intermediate Value Theorem

                                                                            The tactic automatically:

                                                                            • Reifies the function to a LeanCert AST
                                                                            • Generates an ExprSupportedCore proof
                                                                            • Generates a ContinuousOn proof (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 (no log, 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:

                                                                                1. Checking Newton contraction (derivative bounded away from 0)
                                                                                2. 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:

                                                                                  1. Using Newton contraction to verify uniqueness (derivative bounded away from 0)
                                                                                  2. 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

                                                                                    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:

                                                                                      1. Computing the integral bound using interval arithmetic
                                                                                      2. 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:

                                                                                        1. Computing the integral bound using interval arithmetic
                                                                                        2. 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

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