Documentation

Lean.Meta.Tactic.Simp.SimpTheorems

This module contains types to manages simp theorems and sets theirof.

Overview of types in this module:

An Origin is an identifier for simp theorems which indicates roughly what action the user took which lead to this theorem existing in the simp set.

  • decl (declName : Name) (post : Bool := true) (inv : Bool := false) : Origin

    A global declaration in the environment.

  • fvar (fvarId : FVarId) : Origin

    A local hypothesis. When contextual := true is enabled, this fvar may exist in an extension of the current local context; it will not be used for rewriting by simp once it is out of scope but it may end up in the usedSimps trace.

  • stx (id : Name) (ref : Syntax) : Origin

    A proof term provided directly to a call to simp [ref, ...] where ref is the provided simp argument (of kind Parser.Tactic.simpLemma). The id is a unique identifier for the call.

  • other (name : Name) : Origin

    Some other origin. name should not collide with the other types for erasure to work correctly, and simp trace will ignore this lemma. The other origins should be preferred if possible.

Instances For

    A unique identifier corresponding to the origin.

    Equations
    Instances For

      The origin corresponding to the converse direction (thm vs. thm)

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

          The fields levelParams and proof are used to encode the proof of the simp theorem. If the proof is a global declaration c, we store Expr.const c [] at proof without the universe levels, and levelParams is set to #[] When using the lemma, we create fresh universe metavariables. Motivation: most simp theorems are global declarations, and this approach is faster and saves memory.

          The field levelParams is not empty only when we elaborate an expression provided by the user, and it contains universe metavariables. Then, we use abstractMVars to abstract the universe metavariables and create new fresh universe parameters that are stored at the field levelParams.

          • levelParams : Array Name

            It stores universe parameter names for universe polymorphic proofs. Recall that it is non-empty only when we elaborate an expression provided by the user. When proof is just a constant, we can use the universe parameter names stored in the declaration.

          • proof : Expr
          • priority : Nat
          • post : Bool
          • perm : Bool

            perm is true if lhs and rhs are identical modulo permutation of variables.

          • origin : Origin

            origin is mainly relevant for producing trace messages. It is also viewed an id used to "erase" simp theorems from SimpTheorems.

          • rfl : Bool

            rfl is true if proof is by Eq.refl, rfl or a @[defeq] theorem.

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

              Configuration for MetaM used to process global simp theorems

              Equations
              Instances For
                def Lean.Meta.mkSimpTheoremFromConst (declName : Name) (post : Bool := true) (inv : Bool := false) (prio : Nat := 1000) :

                Creates a SimpTheorem from a global theorem. Because some theorems lead to multiple SimpTheorems (in particular conjunctions), returns an array.

                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
                    def Lean.Meta.mkSimpTheoremFromExpr (id : Origin) (levelParams : Array Name) (proof : Expr) (inv : Bool := false) (post : Bool := true) (prio : Nat := 1000) (config : ConfigWithKey := simpGlobalConfig) :
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      A simp theorem or information about a declaration to unfold by simp. This is stored in the oleans to implement the simp attribute and user-defined simp sets.

                      Instances For

                        Reducible functions and projection functions should always be put in toUnfold, instead of trying to use equational theorems.

                        The simplifiers has special support for structure and class projections, and gets confused when they suddenly rewrite, so ignore equations for them

                        Equations
                        Instances For

                          Even if a function has equation theorems, we also store it in the toUnfold set in the following two cases: 1- It was defined by structural recursion and has a smart-unfolding associated declaration. 2- It is non-recursive.

                          Reason: unfoldPartialApp := true or conditional equations may not apply.

                          Remark: In the future, we are planning to disable this behavior unless unfoldPartialApp := true. Moreover, users will have to use f.eq_def if they want to force the definition to be unfolded.

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

                            Given the name of a declaration to unfold, return the SimpEntry (or entries) that implement this unfolding, using either the equational theorems, or SimpEntry.toUnfold, or both.

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

                              The theorems in a simp set.

                              Instances For
                                Equations
                                Equations
                                Instances For
                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    @[deprecated Lean.Meta.SimpTheorems.addSimpTheorem (since := "2025-06-17")]
                                    Equations
                                    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

                                          Return true if declName is tagged to be unfolded using unfoldDefinition? (i.e., without using equational theorems).

                                          Equations
                                          Instances For

                                            Register the equational theorems for the given definition.

                                            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

                                                simp [foo] should undo a previous attribute @[-simp] foo. (Note that attribute @[simp] foo does not undo a attribute @[simp] foo, see #5852)

                                                Equations
                                                Instances For
                                                  def Lean.Meta.SimpTheorems.addConst (s : SimpTheorems) (declName : Name) (post : Bool := true) (inv : Bool := false) (prio : Nat := 1000) :

                                                  Auxiliary method for adding a global declaration to a SimpTheorems datastructure.

                                                  Equations
                                                  Instances For
                                                    @[reducible, inline]

                                                    The environment extension that contains a simp set, returned by Lean.Meta.registerSimpAttr.

                                                    Use the simp set's attribute or Lean.Meta.addSimpTheorem to add theorems to the simp set. Use Lean.Meta.SimpExtension.getTheorems to get the contents.

                                                    Equations
                                                    Instances For
                                                      def Lean.Meta.addSimpTheorem (ext : SimpExtension) (declName : Name) (post inv : Bool) (attrKind : AttributeKind) (prio : Nat) :

                                                      Adds a simp theorem to a simp extension

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For
                                                        def Lean.Meta.mkSimpExt (name : Name := by exact decl_name%) :
                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For
                                                          Equations
                                                          Instances For
                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For
                                                              def Lean.Meta.SimpTheorems.add (s : SimpTheorems) (id : Origin) (levelParams : Array Name) (proof : Expr) (inv : Bool := false) (post : Bool := true) (prio : Nat := 1000) (config : ConfigWithKey := simpGlobalConfig) :

                                                              Auxiliary method for adding a local simp theorem to a SimpTheorems datastructure.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For
                                                                @[reducible, inline]

                                                                A SimpTheoremsArray is a collection of SimpTheorems. The first entry is the default simp set and possible extensions as simp args (simp [thm]), further entries are custom simp sets added a s simp arguments (simp [my_simp_set]). The array is scanned linear during rewriting. This avoids the need for efficiently merging the SimpTheorems data structure.

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