Documentation

Lean.Meta.Tactic.Lets

Tactics to manipulate let expressions #

let extraction #

Extracting lets means to locate let/haves in a term and to extract them from the term, extending the local context with new declarations in the process. A related process is lifting lets, which means to move let/haves toward the root of a term.

  • decl : LocalDecl

    An ldecl with nondep := false.

  • isLet : Bool

    If true, is a let, if false, is a have. Used in lift mode.

Instances For
    • givenNames : List Name

      Names to use for local definitions for the extracted lets.

    • Saved declarations for the extracted lets.

    • Map from let values to fvars. To support the merge option.

    Instances For

      Returns true if nextName? would return a name.

      Equations
      Instances For

        Gets the next name to use for extracted lets

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

          Generate a name to use for a new local declaration, derived possibly from the given binder name. Returns none iff hasNextName is false.

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

            Returns 'true' if e does not depend on any of the fvars in fvars.

            Equations
            Instances For

              Returns whether a let-like expression with the given type and value is extractable, given the list fvars of binders that inhibit extraction.

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

                Adds the decl to the decls list. Assumes that decl is an ldecl with nondep := false.

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

                  Removes and returns all local declarations that (transitively) depend on fvar.

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

                    Ensures that the given local declarations are in context. Runs k in that context.

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

                      Closes all the local declarations in e, creating let and have expressions. Does not require that any of the declarations are in context. Assumes that e contains no metavariables with local contexts that contain any of these metavariables (the extraction procedure creates no new metavariables, so this is the case).

                      This should not be used when closing lets for new goal metavariables, since

                      1. The goal contains the decls in its local context, violating the assumption.
                      2. We need to use true lets in that case, since tactics may zeta-delta reduce these declarations.
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Makes sure the declaration for fvarId is marked with isLet := true. Used in lift + merge mode to ensure that, after merging, if any version was a let then it's a let rather than a have.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          def Lean.Meta.ExtractLets.withDeclInContext {α : Type} (fvarId : FVarId) (k : M α) :
                          M α

                          Ensures that the given fvarId is in context by adding decls from the state. Simplification: since we are not recording which decls depend on which, but we do know all dependencies come before a particular decl, we add all the decls up to and including fvarId.

                          Used for merge feature.

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

                            Initializes the valueMap with all the local definitions that aren't implementation details. Used for merge feature when useContext is enabled.

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

                              Returns true if the expression contains a let expression or a have. Its purpose is to be a check for whether a subexpression can be skipped.

                              Equations
                              Instances For
                                partial def Lean.Meta.ExtractLets.extractCore (fvars : List Expr) (e : Expr) (topLevel : Bool := false) :

                                Extracts lets from e.

                                • fvars is an array of all the local variables from going under binders, used to detect whether an expression is extractable. Extracted lets do not have their fvarids in this list. This is not part of the cache key since it's an optimization and in principle derivable.
                                • topLevel is whether we are still looking at the top-level expression. The body of an extracted top-level let is also considered to be top-level. This is part of the cache key since it affects what is extracted.

                                Note: the return value may refer to fvars that are not in the current local context, but they are in the decls list.

                                partial def Lean.Meta.ExtractLets.extractCore.extractBinder (fvars : List Expr) (n : Name) (t b : Expr) (i : BinderInfo) (mk : ExprExprExpr) :
                                partial def Lean.Meta.ExtractLets.extractCore.extractLetLike (fvars : List Expr) (e : Expr) (isLet : Bool) (n : Name) (t v b : Expr) (topLevel : Bool) :

                                Main entry point for extracting lets.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  def Lean.Meta.extractLets {m : TypeType u_1} {α : Type} [Monad m] [MonadControlT MetaM m] (es : Array Expr) (givenNames : List Name) (k : Array FVarIdArray ExprList Namem α) (config : ExtractLetsConfig := { }) :
                                  m α

                                  Extracts let and have expressions into local definitions, evaluating k at the post-extracted expressions and the extracted fvarids, within a context containing those local declarations.

                                  • The givenNames is a list of explicit names to use for extracted local declarations. If a name is _ (or if there is no provided given name and config.onlyGivenNames is true) then uses a hygienic name based on the existing binder name.
                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Lifts let and have expressions in the given expression as far out as possible.

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

                                      Extracts let and have expressions from the target, returning FVarIds for the extracted let declarations along with the new goal.

                                      • The givenNames is a list of explicit names to use for extracted local declarations. If a name is _ (or if there is no provided given name and config.onlyGivenNames is true) then uses a hygienic name based on the existing binder name.
                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        def Lean.MVarId.extractLetsLocalDecl (mvarId : MVarId) (fvarId : FVarId) (givenNames : List Name) (config : Meta.ExtractLetsConfig := { }) :

                                        Like Lean.MVarId.extractLets but extracts lets from a local declaration. If the local declaration has a value, then both its type and value are modified.

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

                                          Lifts let and have expressions in target as far out as possible. Throws an exception if nothing is lifted.

                                          Like Lean.MVarId.extractLets, but top-level lets are not added to the local context.

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

                                            Like Lean.MVarId.liftLets but lifts lets in a local declaration. If the local declaration has a value, then both its type and value are modified.

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

                                              Let-to-have transformation #

                                              A meta tactic version of Lean.Meta.letToHave.

                                              def Lean.MVarId.letToHave (mvarId : MVarId) (failIfUnchanged : Bool := true) :

                                              Transforms lets to haves in the target. Throws an error if no progress is made.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For
                                                def Lean.MVarId.letToHaveLocalDecl (mvarId : MVarId) (fvarId : FVarId) (failIfUnchanged : Bool := true) :

                                                Transforms lets to haves in the type of fvarId. Throws an error if no progress is made.

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