Documentation

Lean.Meta.Transform

  • done (e : Expr) : TransformStep

    Return expression without visiting any subexpressions.

  • visit (e : Expr) : TransformStep

    Visit expression (which should be different from current expression) instead. The new expression e is passed to pre again.

  • continue (e? : Option Expr := none) : TransformStep

    Continue transformation with the given expression (defaults to current expression). For pre, this means visiting the children of the expression. For post, this is equivalent to returning done.

Instances For
    def Lean.Core.transform {m : TypeType} [Monad m] [MonadLiftT CoreM m] [MonadControlT CoreM m] (input : Expr) (pre : Exprm TransformStep := fun (x : Expr) => pure TransformStep.continue) (post : Exprm TransformStep := fun (e : Expr) => pure (TransformStep.done e)) :

    Transform the expression input using pre and post.

    • First pre is invoked with the current expression and recursion is continued according to the TransformStep result. In all cases, the expression contained in the result, if any, must be definitionally equal to the current expression.
    • After recursion, if any, post is invoked on the resulting expression.

    The term s in both pre s and post s may contain loose bound variables. So, this method is not appropriate for if one needs to apply operations (e.g., whnf, inferType) that do not handle loose bound variables. Consider using Meta.transform to avoid loose bound variables.

    This method is useful for applying transformations such as beta-reduction and delta-reduction.

    Equations
    Instances For
      @[inline]
      def Lean.Meta.transformWithCache {m : TypeType} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m] (input : Expr) (cache : Std.HashMap ExprStructEq Expr) (pre : Exprm TransformStep := fun (x : Expr) => pure TransformStep.continue) (post : Exprm TransformStep := fun (e : Expr) => pure (TransformStep.done e)) (usedLetOnly skipConstInApp : Bool := false) :

      Similar to Meta.transform, but allows the use of a pre-existing cache.

      Warnings:

      • For the cache to be valid, it must always use the same pre and post functions.
      • It is important that there are no other references to cache when it is passed to transformWithCache, to avoid unnecessary copying of the hash map.
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        partial def Lean.Meta.transformWithCache.visit {m : TypeType} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m] (pre : Exprm TransformStep := fun (x : Expr) => pure TransformStep.continue) (post : Exprm TransformStep := fun (e : Expr) => pure (TransformStep.done e)) (usedLetOnly skipConstInApp : Bool := false) (x✝ : STWorld IO.RealWorld m) :
        partial def Lean.Meta.transformWithCache.visit.visitPost {m : TypeType} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m] (pre : Exprm TransformStep := fun (x : Expr) => pure TransformStep.continue) (post : Exprm TransformStep := fun (e : Expr) => pure (TransformStep.done e)) (usedLetOnly skipConstInApp : Bool := false) (x✝ : STWorld IO.RealWorld m) :
        partial def Lean.Meta.transformWithCache.visit.visitLambda {m : TypeType} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m] (pre : Exprm TransformStep := fun (x : Expr) => pure TransformStep.continue) (post : Exprm TransformStep := fun (e : Expr) => pure (TransformStep.done e)) (usedLetOnly skipConstInApp : Bool := false) (x✝ : STWorld IO.RealWorld m) :
        partial def Lean.Meta.transformWithCache.visit.visitForall {m : TypeType} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m] (pre : Exprm TransformStep := fun (x : Expr) => pure TransformStep.continue) (post : Exprm TransformStep := fun (e : Expr) => pure (TransformStep.done e)) (usedLetOnly skipConstInApp : Bool := false) (x✝ : STWorld IO.RealWorld m) :
        partial def Lean.Meta.transformWithCache.visit.visitLet {m : TypeType} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m] (pre : Exprm TransformStep := fun (x : Expr) => pure TransformStep.continue) (post : Exprm TransformStep := fun (e : Expr) => pure (TransformStep.done e)) (usedLetOnly skipConstInApp : Bool := false) (x✝ : STWorld IO.RealWorld m) :
        def Lean.Meta.transform {m : TypeType} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m] (input : Expr) (pre : Exprm TransformStep := fun (x : Expr) => pure TransformStep.continue) (post : Exprm TransformStep := fun (e : Expr) => pure (TransformStep.done e)) (usedLetOnly skipConstInApp : Bool := false) :

        Similar to Core.transform, but terms provided to pre and post do not contain loose bound variables. So, it is safe to use any MetaM method at pre and post.

        Warning: pre and post should not depend on variables in the local context introduced by transform. This is in order to allow aggressive caching.

        If skipConstInApp := true, then for an expression mkAppN (.const f) args, the subexpression .const f is not visited again. Put differently: every .const f is visited once, with its arguments if present, on its own otherwise.

        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

            Zeta reduces only the provided fvars, beta reducing the substitutions.

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

              Unfold definitions and theorems in e that are not in the current environment, but are in biggerEnv.

              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