Documentation

Lean.Expr

inductive Lean.Literal:
Type
Equations
Equations
  • One or more equations did not get rendered due to their size.
inductive Lean.BinderInfo:
Type

Arguments in forallE binders can be labelled as implicit or explicit.

Each lam or forallE binder comes with a binderInfo argument (stored in ExprData). This can be set to

  • default -- (x : α)
  • implicit -- {x : α}
  • strict_implicit -- ⦃x : α⦄
  • inst_implicit -- [x : α].
  • aux_decl -- Auxillary definitions are helper methods that Lean generates. aux_decl is used for _match, _fun_match, _let_match and the self reference that appears in recursive pattern matching.

The difference between implicit {} and strict-implicit ⦃⦄ is how implicit arguments are treated that are not followed by explicit arguments. {} arguments are applied eagerly, while ⦃⦄ arguments are left partially applied:

def foo {x : Nat} : Nat := x
def bar ⦃x : Nat⦄ : Nat := x
#check foo -- foo : Nat
#check bar -- bar : ⦃x : Nat⦄ → Nat

See also the Lean manual: https://leanprover.github.io/lean4/doc/expressions.html#implicit-arguments

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
Equations
Equations
Equations
@[inline]
abbrev Lean.MData:
Type

Expression metadata. Used with the Expr.mdata constructor.

Equations
@[inline]
Equations

Cached hash code, cached results, and other data for Expr. hash : 32-bits hasFVar : 1-bit -- does it contain free variables? hasExprMVar : 1-bit -- does it contain metavariables? hasLevelMVar : 1-bit -- does it contain level metavariables? hasLevelParam : 1-bit -- does it contain level parameters? nonDepLet : 1-bit -- internal flag, for tracking whether let x := v; b is equivalent to (fun x => b) v binderInfo : 3-bits -- encoding of BinderInfo approxDepth : 8-bits -- the approximate depth is used to minimize the number of hash collisions looseBVarRange : 16-bits

Equations
Equations
@[extern c inline "(uint8_t)((#1 << 24) >> 61)"]
Equations
  • One or more equations did not get rendered due to their size.
@[extern c inline "(uint64_t)#1"]
Equations
  • One or more equations did not get rendered due to their size.
def Lean.Expr.mkData (h : UInt64) (looseBVarRange : optParam Nat 0) (approxDepth : optParam UInt32 0) (hasFVar : optParam Bool false) (hasExprMVar : optParam Bool false) (hasLevelMVar : optParam Bool false) (hasLevelParam : optParam Bool false) (bi : optParam Lean.BinderInfo Lean.BinderInfo.default) (nonDepLet : optParam Bool false) :
Equations
  • One or more equations did not get rendered due to their size.
@[inline]

Optimized version of Expr.mkData for applications.

Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Expr.mkDataForBinder (h : UInt64) (looseBVarRange : Nat) (approxDepth : UInt32) (hasFVar : Bool) (hasExprMVar : Bool) (hasLevelMVar : Bool) (hasLevelParam : Bool) (bi : Lean.BinderInfo) :
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Expr.mkDataForLet (h : UInt64) (looseBVarRange : Nat) (approxDepth : UInt32) (hasFVar : Bool) (hasExprMVar : Bool) (hasLevelMVar : Bool) (hasLevelParam : Bool) (nonDepLet : Bool) :
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.
structure Lean.FVarId:
Type
Equations
Equations
Equations
instance Lean.instForInFVarIdSetFVarId {m : Type u_1Type u_2} :
Equations
def Lean.FVarIdMap (α : Type) :
Type
Equations
Equations
Equations
  • Lean.instInhabitedFVarIdMap = { default := }
@[extern c inline "lean_ctor_get_uint64(#1, lean_ctor_num_objs(#1)*sizeof(void*))"]
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.

Does the expression contain level or expression metavariables?

Equations

The range of de-Bruijn variables that are loose. That is, bvars that are not bound by a binder. For example, bvar i has range i + 1 and an expression with no loose bvars has range 0.

Equations
@[export lean_expr_hash]
Equations
@[export lean_expr_has_fvar]
Equations
@[export lean_expr_has_mvar]
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
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.
Equations
  • One or more equations did not get rendered due to their size.

Return fun (_ : Unit), e

Equations
def Lean.mkLet (x : Lean.Name) (t : Lean.Expr) (v : Lean.Expr) (b : Lean.Expr) (nonDep : optParam Bool false) :
Equations
  • One or more equations did not get rendered due to their size.
Equations
Equations
Equations
def Lean.mkApp6 (f : Lean.Expr) (a : Lean.Expr) (b : Lean.Expr) (c : Lean.Expr) (d : Lean.Expr) (e₁ : Lean.Expr) (e₂ : Lean.Expr) :
Equations
def Lean.mkApp7 (f : Lean.Expr) (a : Lean.Expr) (b : Lean.Expr) (c : Lean.Expr) (d : Lean.Expr) (e₁ : Lean.Expr) (e₂ : Lean.Expr) (e₃ : Lean.Expr) :
Equations
def Lean.mkApp8 (f : Lean.Expr) (a : Lean.Expr) (b : Lean.Expr) (c : Lean.Expr) (d : Lean.Expr) (e₁ : Lean.Expr) (e₂ : Lean.Expr) (e₃ : Lean.Expr) (e₄ : Lean.Expr) :
Equations
def Lean.mkApp9 (f : Lean.Expr) (a : Lean.Expr) (b : Lean.Expr) (c : Lean.Expr) (d : Lean.Expr) (e₁ : Lean.Expr) (e₂ : Lean.Expr) (e₃ : Lean.Expr) (e₄ : Lean.Expr) (e₅ : Lean.Expr) :
Equations
def Lean.mkApp10 (f : Lean.Expr) (a : Lean.Expr) (b : Lean.Expr) (c : Lean.Expr) (d : Lean.Expr) (e₁ : Lean.Expr) (e₂ : Lean.Expr) (e₃ : Lean.Expr) (e₄ : Lean.Expr) (e₅ : Lean.Expr) (e₆ : Lean.Expr) :
Equations
Equations
@[export lean_expr_mk_bvar]
Equations
@[export lean_expr_mk_fvar]
Equations
@[export lean_expr_mk_mvar]
Equations
@[export lean_expr_mk_sort]
Equations
@[export lean_expr_mk_const]
Equations
@[export lean_expr_mk_app]
Equations
@[export lean_expr_mk_lambda]
Equations
@[export lean_expr_mk_forall]
Equations
@[export lean_expr_mk_let]
Equations
@[export lean_expr_mk_lit]
Equations
@[export lean_expr_mk_mdata]
Equations
@[export lean_expr_mk_proj]
Equations

mkAppN f #[a₀, ..., aₙ] ==> f a₀ a₁ .. aₙ

Equations
def Lean.mkAppRange (f : Lean.Expr) (i : Nat) (j : Nat) (args : Array Lean.Expr) :

mkAppRange f i j #[a_1, ..., a_i, ..., a_j, ... ] ==> the expression f a_i ... a_{j-1}

Equations

Same as mkApp f args but reversing args.

Equations
@[extern lean_expr_dbg_to_string]
@[extern lean_expr_quick_lt]
@[extern lean_expr_lt]
opaque Lean.Expr.lt (a : Lean.Expr) (b : Lean.Expr) :
@[extern lean_expr_eqv]

Return true iff a and b are alpha equivalent. Binder annotations are ignored.

@[extern lean_expr_equal]
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations

If the given expression is a sequence of function applications f a₁ .. aₙ, return f. Otherwise return the input expression.

Equations
Equations

Counts the number n of arguments for an expression f a₁ .. aₙ.

Equations
@[inline]

Given f a₁ a₂ ... aₙ, returns #[a₁, ..., aₙ]

Equations
@[specialize]
def Lean.Expr.withAppAux {α : Sort u_1} (k : Lean.ExprArray Lean.Exprα) :
Lean.ExprArray Lean.ExprNatα
Equations
@[inline]
def Lean.Expr.withApp {α : Sort u_1} (e : Lean.Expr) (k : Lean.ExprArray Lean.Exprα) :
α

Given e = f a₁ a₂ ... aₙ, returns k f #[a₁, ..., aₙ].

Equations
def Lean.Expr.traverseApp {M : TypeType u_1} [inst : Monad M] (f : Lean.ExprM Lean.Expr) (e : Lean.Expr) :

Given e = fn a₁ ... aₙ, runs f on fn and each of the arguments aᵢ and makes a new function application with the results.

Equations
@[inline]
def Lean.Expr.withAppRev {α : Sort u_1} (e : Lean.Expr) (k : Lean.ExprArray Lean.Exprα) :
α

Same as withApp but with arguments reversed.

Equations
Equations
Equations
@[inline]

Given f a₀ a₁ ... aₙ, returns the ith argument or panics if out of bounds.

Equations
@[inline]

Given f a₀ a₁ ... aₙ, returns the ith argument or returns v₀ if out of bounds.

Equations

Given f a₀ a₁ ... aₙ, returns true if f is a constant with name n.

Equations

Given f a₁ ... aᵢ, returns true if f is a constant with name n and has the correct number of arguments.

Similar to isAppOfArity but skips Expr.mdata.

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
Equations
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
Equations
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
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
Equations
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.
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.
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.
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
@[extern lean_expr_has_loose_bvar]
opaque Lean.Expr.hasLooseBVar (e : Lean.Expr) (bvarIdx : Nat) :

Return true if e contains the loose bound variable bvarIdx in an explicit parameter, or in the range if tryRange == true.

Equations
@[extern lean_expr_lower_loose_bvars]

Lower the loose bound variables >= s in e by d. That is, a loose bound variable bvar i. i >= s is mapped into bvar (i-d).

Remark: if s < d, then result is e

@[extern lean_expr_lift_loose_bvars]

Lift loose bound variables >= s in e by d.

inferImplicit e numParams considerRange updates the first numParams parameter binder annotations of the e forall type. It marks any parameter with an explicit binder annotation if there is another explicit arguments that depends on it or the resulting type if considerRange == true.

Remark: we use this function to infer the bind annotations of inductive datatype constructors, and structure projections. When the {} annotation is used in these commands, we set considerRange == false.

@[extern lean_expr_instantiate]

Instantiate the loose bound variables in e using subst. That is, a loose Expr.bvar i is replaced with subst[i].

@[extern lean_expr_instantiate1]
@[extern lean_expr_instantiate_rev]

Similar to instantiate, but Expr.bvar i is replaced with subst[subst.size - i - 1]

@[extern lean_expr_instantiate_range]
opaque Lean.Expr.instantiateRange (e : Lean.Expr) (beginIdx : Nat) (endIdx : Nat) (xs : Array Lean.Expr) :

Similar to instantiate, but consider only the variables xs in the range [beginIdx, endIdx). Function panics if beginIdx <= endIdx <= xs.size does not hold.

@[extern lean_expr_instantiate_rev_range]
opaque Lean.Expr.instantiateRevRange (e : Lean.Expr) (beginIdx : Nat) (endIdx : Nat) (xs : Array Lean.Expr) :

Similar to instantiateRev, but consider only the variables xs in the range [beginIdx, endIdx). Function panics if beginIdx <= endIdx <= xs.size does not hold.

@[extern lean_expr_abstract]

Replace free (or meta) variables xs with loose bound variables.

@[extern lean_expr_abstract_range]

Similar to abstract, but consider only the first min n xs.size entries in xs.

Replace occurrences of the free variable fvar in e with v

Equations

Replace occurrences of the free variable fvarId in e with v

Equations

Replace occurrences of the free variables fvars in e with vs

Equations

Returns true when the expression does not have any sub-expressions.

Equations
  • One or more equations did not get rendered due to their size.
Equations
Equations
@[inline]
abbrev Lean.ExprMap (α : Type) :
Type
Equations
@[inline]
abbrev Lean.PersistentExprMap (α : Type) :
Type
Equations
@[inline]
abbrev Lean.ExprSet:
Type
Equations
Equations
Equations
@[inline]
abbrev Lean.ExprStructMap (α : Type) :
Type
Equations
def Lean.Expr.mkAppRevRange (f : Lean.Expr) (beginIdx : Nat) (endIdx : Nat) (revArgs : Array Lean.Expr) :

mkAppRevRange f b e args == mkAppRev f (revArgs.extract b e)

Equations
def Lean.Expr.betaRev (f : Lean.Expr) (revArgs : Array Lean.Expr) (useZeta : optParam Bool false) (preserveMData : optParam Bool false) :

If f is a lambda expression, than "beta-reduce" it using revArgs. This function is often used with getAppRev or withAppRev. Examples:

  • betaRev (fun x y => t x y) #[] ==> fun x y => t x y
  • betaRev (fun x y => t x y) #[a] ==> fun y => t a y
  • betaRev (fun x y => t x y) #[a, b] ==> t b a
  • betaRev (fun x y => t x y) #[a, b, c, d] ==> t d c b a Suppose t is (fun x y => t x y) a b c d, then args := t.getAppRev is #[d, c, b, a], and betaRev (fun x y => t x y) #[d, c, b, a] is t a b c d.

If useZeta is true, the function also performs zeta-reduction (reduction of let binders) to create further opportunities for beta reduction.

Equations
partial def Lean.Expr.betaRev.go (revArgs : Array Lean.Expr) (useZeta : optParam Bool false) (preserveMData : optParam Bool false) (sz : Nat) (e : Lean.Expr) (i : Nat) :

Apply the given arguments to f, beta-reducing if f is a lambda expression. See docstring for betaRev for examples.

Equations

If e is of the form (fun x₁ ... xₙ => f x₁ ... xₙ) and f does not contain x₁, ..., xₙ, then return some f. Otherwise, return none.

It assumes e does not have loose bound variables.

Remark: may be 0

Equations

Similar to etaExpanded?, but only succeeds if ₙ ≥ 1.

Equations
@[export lean_is_out_param]
Equations
@[export lean_expr_consume_type_annotations]
@[inline]

Return true iff e contains a free variable which statisfies p.

Equations
Equations
@[extern lean_expr_update_app]
Equations
@[inline]
Equations
  • One or more equations did not get rendered due to their size.
@[extern lean_expr_update_const]
Equations
@[inline]
Equations
  • One or more equations did not get rendered due to their size.
@[extern lean_expr_update_sort]
Equations
@[inline]
Equations
  • One or more equations did not get rendered due to their size.
@[extern lean_expr_update_proj]
Equations
@[extern lean_expr_update_mdata]
Equations
@[inline]
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
Equations
  • One or more equations did not get rendered due to their size.
@[extern lean_expr_update_forall]
def Lean.Expr.updateForall (e : Lean.Expr) (newBinfo : Lean.BinderInfo) (newDomain : Lean.Expr) (newBody : Lean.Expr) (h : Lean.Expr.isForall e = true) :
Equations
@[inline]
def Lean.Expr.updateForall! (e : Lean.Expr) (newBinfo : Lean.BinderInfo) (newDomain : Lean.Expr) (newBody : Lean.Expr) :
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Expr.updateForallE! (e : Lean.Expr) (newDomain : Lean.Expr) (newBody : Lean.Expr) :
Equations
  • One or more equations did not get rendered due to their size.
@[extern lean_expr_update_lambda]
def Lean.Expr.updateLambda (e : Lean.Expr) (newBinfo : Lean.BinderInfo) (newDomain : Lean.Expr) (newBody : Lean.Expr) (h : Lean.Expr.isLambda e = true) :
Equations
@[inline]
def Lean.Expr.updateLambda! (e : Lean.Expr) (newBinfo : Lean.BinderInfo) (newDomain : Lean.Expr) (newBody : Lean.Expr) :
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Expr.updateLambdaE! (e : Lean.Expr) (newDomain : Lean.Expr) (newBody : Lean.Expr) :
Equations
  • One or more equations did not get rendered due to their size.
@[extern lean_expr_update_let]
def Lean.Expr.updateLet (e : Lean.Expr) (newType : Lean.Expr) (newVal : Lean.Expr) (newBody : Lean.Expr) (h : Lean.Expr.isLet e = true) :
Equations
@[inline]
def Lean.Expr.updateLet! (e : Lean.Expr) (newType : Lean.Expr) (newVal : Lean.Expr) (newBody : Lean.Expr) :
Equations
  • One or more equations did not get rendered due to their size.
Equations
def Lean.Expr.setOption {α : Type} (e : Lean.Expr) (optionName : Lean.Name) [inst : Lean.KVMap.Value α] (val : α) :

Annotate e with the given option.

Equations

Annotate e with pp.explicit := true The delaborator uses pp options.

Equations

If e is an application f a_1 ... a_n annotate f, a_1 ... a_n with pp.explicit := false, and annotate e with pp.explicit := true.

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

Similar for setAppPPExplicit, but only annotate children with pp.explicit := false if e does not contain metavariables.

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

Auxiliary annotation used to mark terms marked with the "inaccessible" annotation .(t) and _ in patterns.

Equations

During elaboration expressions corresponding to pattern matching terms are annotated with Syntax objects. This function returns some (stx, p') if p is the pattern p' annotated with stx

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

Annotate the pattern p with stx. This is an auxiliary annotation for producing better hover information.

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

Return some p if e is an annotated pattern (inaccessible? or patternWithRef?)

Equations

Annotate e with the LHS annotation. The delaborator displays expressions of the form lhs = rhs as lhs when they have this annotation.

Equations
Equations
def Lean.mkFreshFVarId {m : TypeType} [inst : Monad m] [inst : Lean.MonadNameGenerator m] :
Equations
  • Lean.mkFreshFVarId = do let a ← Lean.mkFreshId pure { name := a }
def Lean.mkFreshMVarId {m : TypeType} [inst : Monad m] [inst : Lean.MonadNameGenerator m] :
Equations
  • Lean.mkFreshMVarId = do let a ← Lean.mkFreshId pure { name := a }
Equations