Documentation

Lean.Meta.Sym.Pattern

This module implements efficient pattern matching and unification module for the symbolic simulation framework (Sym). The design prioritizes performance by using a two-phase approach:

Phase 1 (Syntactic Matching) #

Phase 2 (Pending Constraints) #

Key design decisions: #

Instances For
    Equations
    Instances For

      Creates a Pattern from the type of a theorem.

      The pattern is constructed by stripping leading universal quantifiers from the theorem's type. Each quantified variable becomes a pattern variable, with its type recorded in varTypes and whether it is a type class instance recorded in isInstance. The remaining type after stripping quantifiers becomes the pattern expression.

      Universe level parameters are replaced with fresh unification variables (prefixed with _uvar).

      If num? is some n, at most n leading quantifiers are stripped. If num? is none, all leading quantifiers are stripped.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Lean.Meta.Sym.mkPatternFromExpr (e : Expr) (levelParams : List Name := []) (num? : Option Nat := none) :
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[inline]
          def Lean.Meta.Sym.mkPatternFromDeclWithKey {α : Type} (declName : Name) (selectKey : ExprMetaM (Expr × α)) :

          Creates a Pattern from a theorem, using the supplied selection function to extract the key from the theorem's result type.

          This function is used to implement mkEqPatternFromDecl. Like mkPatternFromDecl, this strips all leading universal quantifiers, recording variable types and instance status. However, instead of using the entire resulting type as the pattern, it uses the selection function to extract the key.

          For a theorem ∀ x₁ ... xₙ, type, returns a pattern matching the first component of selectKey type with n pattern variables.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            @[inline]
            def Lean.Meta.Sym.mkPatternFromExprWithKey {α : Type} (e : Expr) (levelParams : List Name := []) (selectKey : ExprMetaM (Expr × α)) :

            Like mkPatternFromDeclWithKey, but for a complex proof expression instead of the declaration of a theorem.

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

              Creates a Pattern from an equational theorem, using the left-hand side of the equation. It also returns the right-hand side of the equation

              Like mkPatternFromDecl, this strips all leading universal quantifiers, recording variable types and instance status. However, instead of using the entire resulting type as the pattern, it extracts just the LHS of the equation.

              For a theorem ∀ x₁ ... xₙ, lhs = rhs, returns a pattern matching lhs with n pattern variables. Throws an error if the theorem's conclusion is not an equality.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def Lean.Meta.Sym.isDefEqS (t s : Expr) (unify zetaDelta : Bool := true) (mvarsNew mvarsToCheckType : Array MVarId := #[]) :

                A lightweight structural definitional equality for the symbolic simulation framework. Unlike the full isDefEq, it avoids expensive operations while still supporting Miller pattern unification.

                Equations
                Instances For
                  Instances For

                    Attempts to match expression e against pattern p using purely syntactic matching.

                    Returns some result if matching succeeds, where result contains:

                    • us: Level assignments for the pattern's universe variables
                    • args: Expression assignments for the pattern's bound variables

                    Matching fails if:

                    • The term contains metavariables (use unify? instead)
                    • Structural mismatch after reducible unfolding

                    Instance arguments are deferred for later synthesis. Proof arguments are skipped via proof irrelevance.

                    Equations
                    Instances For

                      Attempts to unify expression e against pattern p, allowing metavariables in e.

                      Returns some result if unification succeeds, where result contains:

                      • us: Level assignments for the pattern's universe variables
                      • args: Expression assignments for the pattern's bound variables

                      Unlike match?, this handles terms containing metavariables by deferring constraints to Phase 2 unification. Use this when matching against goal expressions that may contain unsolved metavariables.

                      Instance arguments are deferred for later synthesis. Proof arguments are skipped via proof irrelevance.

                      Equations
                      Instances For