Literal values for Expr
.
- natVal: Nat → Lean.Literal
Natural number literal
- strVal: String → Lean.Literal
String literal
Instances For
Equations
- Lean.instInhabitedLiteral = { default := Lean.Literal.natVal default }
Equations
- Lean.instBEqLiteral = { beq := Lean.beqLiteral✝ }
Equations
- Lean.instReprLiteral = { reprPrec := Lean.reprLiteral✝ }
Equations
- (Lean.Literal.natVal a).hash = hash a
- (Lean.Literal.strVal a).hash = hash a
Instances For
Equations
- Lean.instHashableLiteral = { hash := Lean.Literal.hash }
Total order on Expr
literal values.
Natural number values are smaller than string literal values.
Equations
- (Lean.Literal.natVal val).lt (Lean.Literal.strVal val_1) = true
- (Lean.Literal.natVal v₁).lt (Lean.Literal.natVal v₂) = decide (v₁ < v₂)
- (Lean.Literal.strVal v₁).lt (Lean.Literal.strVal v₂) = decide (v₁ < v₂)
- x✝.lt x = false
Instances For
Equations
- Lean.instLTLiteral = { lt := fun (a b : Lean.Literal) => a.lt b = true }
Equations
- Lean.instDecidableLtLiteral a b = inferInstanceAs (Decidable (a.lt b = true))
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
-- Auxiliary 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.
- default: Lean.BinderInfo
Default binder annotation, e.g.
(x : α)
- implicit: Lean.BinderInfo
Implicit binder annotation, e.g.,
{x : α}
- strictImplicit: Lean.BinderInfo
Strict implicit binder annotation, e.g.,
{{ x : α }}
- instImplicit: Lean.BinderInfo
Local instance binder annotataion, e.g.,
[Decidable α]
Instances For
Equations
- Lean.instInhabitedBinderInfo = { default := Lean.BinderInfo.default }
Equations
- Lean.instBEqBinderInfo = { beq := Lean.beqBinderInfo✝ }
Equations
- Lean.instReprBinderInfo = { reprPrec := Lean.reprBinderInfo✝ }
Equations
- Lean.BinderInfo.default.hash = 947
- Lean.BinderInfo.implicit.hash = 1019
- Lean.BinderInfo.strictImplicit.hash = 1087
- Lean.BinderInfo.instImplicit.hash = 1153
Instances For
Return true
if the given BinderInfo
does not correspond to an implicit binder annotation
(i.e., implicit
, strictImplicit
, or instImplicit
).
Equations
- Lean.BinderInfo.implicit.isExplicit = false
- Lean.BinderInfo.strictImplicit.isExplicit = false
- Lean.BinderInfo.instImplicit.isExplicit = false
- x.isExplicit = true
Instances For
Equations
- Lean.instHashableBinderInfo = { hash := Lean.BinderInfo.hash }
Return true
if the given BinderInfo
is an instance implicit annotation (e.g., [Decidable α]
)
Equations
- Lean.BinderInfo.instImplicit.isInstImplicit = true
- x.isInstImplicit = false
Instances For
Return true
if the given BinderInfo
is a regular implicit annotation (e.g., {α : Type u}
)
Equations
- Lean.BinderInfo.implicit.isImplicit = true
- x.isImplicit = false
Instances For
Return true
if the given BinderInfo
is a strict implicit annotation (e.g., {{α : Type u}}
)
Equations
- Lean.BinderInfo.strictImplicit.isStrictImplicit = true
- x.isStrictImplicit = false
Instances For
Expression metadata. Used with the Expr.mdata
constructor.
Equations
Instances For
Cached hash code, cached results, and other data for Expr
.
- hash : 32-bits
- approxDepth : 8-bits -- the approximate depth is used to minimize the number of hash collisions
- 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?
- looseBVarRange : 20-bits
Remark: this is mostly an internal datastructure used to implement Expr
,
most will never have to use it.
Equations
Instances For
Equations
Equations
- c.hash = (UInt64.toUInt32 c).toUInt64
Instances For
Equations
- Lean.instBEqData_1 = { beq := fun (a b : UInt64) => a == b }
Equations
- c.approxDepth = ((UInt64.shiftRight c 32).land 255).toUInt8
Instances For
Equations
- c.looseBVarRange = (UInt64.shiftRight c 44).toUInt32
Instances For
Equations
- c.hasFVar = ((UInt64.shiftRight c 40).land 1 == 1)
Instances For
Equations
- c.hasExprMVar = ((UInt64.shiftRight c 41).land 1 == 1)
Instances For
Equations
- c.hasLevelMVar = ((UInt64.shiftRight c 42).land 1 == 1)
Instances For
Equations
- c.hasLevelParam = ((UInt64.shiftRight c 43).land 1 == 1)
Instances For
Equations
- Lean.BinderInfo.default.toUInt64 = 0
- Lean.BinderInfo.implicit.toUInt64 = 1
- Lean.BinderInfo.strictImplicit.toUInt64 = 2
- Lean.BinderInfo.instImplicit.toUInt64 = 3
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Optimized version of Expr.mkData
for applications.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Expr.mkDataForBinder h looseBVarRange approxDepth hasFVar hasExprMVar hasLevelMVar hasLevelParam = Lean.Expr.mkData h looseBVarRange approxDepth hasFVar hasExprMVar hasLevelMVar hasLevelParam
Instances For
Equations
- Lean.Expr.mkDataForLet h looseBVarRange approxDepth hasFVar hasExprMVar hasLevelMVar hasLevelParam = Lean.Expr.mkData h looseBVarRange approxDepth hasFVar hasExprMVar hasLevelMVar hasLevelParam
Instances For
Equations
- One or more equations did not get rendered due to their size.
The unique free variable identifier. It is just a hierarchical name,
but we wrap it in FVarId
to make sure they don't get mixed up with MVarId
.
This is not the user-facing name for a free variable. This information is stored
in the local context (LocalContext
). The unique identifiers are generated using
a NameGenerator
.
- name : Lake.Name
Instances For
Equations
- Lean.instInhabitedFVarId = { default := { name := default } }
Equations
- Lean.instBEqFVarId = { beq := Lean.beqFVarId✝ }
Equations
- Lean.instHashableFVarId = { hash := Lean.hashFVarId✝ }
Equations
- Lean.instReprFVarId = { reprPrec := fun (n : Lean.FVarId) (p : Nat) => reprPrec n.name p }
A set of unique free variable identifiers. This is a persistent data structure implemented using red-black trees.
Equations
- Lean.FVarIdSet = Lean.RBTree Lean.FVarId fun (x1 x2 : Lean.FVarId) => x1.name.quickCmp x2.name
Instances For
Equations
- Lean.instForInFVarIdSetFVarId = inferInstanceAs (ForIn m (Lean.RBTree Lean.FVarId fun (x1 x2 : Lean.FVarId) => x1.name.quickCmp x2.name) Lean.FVarId)
Equations
- s.insert fvarId = Lean.RBTree.insert s fvarId
Instances For
A set of unique free variable identifiers implemented using hashtables. Hashtables are faster than red-black trees if they are used linearly. They are not persistent data-structures.
Equations
Instances For
A mapping from free variable identifiers to values of type α
.
This is a persistent data structure implemented using red-black trees.
Equations
- Lean.FVarIdMap α = Lean.RBMap Lean.FVarId α fun (x1 x2 : Lean.FVarId) => x1.name.quickCmp x2.name
Instances For
Equations
- s.insert fvarId a = Lean.RBMap.insert s fvarId a
Instances For
Equations
- Lean.instEmptyCollectionFVarIdMap = inferInstanceAs (EmptyCollection (Lean.RBMap Lean.FVarId α fun (x1 x2 : Lean.FVarId) => x1.name.quickCmp x2.name))
Equations
- Lean.instInhabitedMVarId = { default := { name := default } }
Equations
- Lean.instBEqMVarId = { beq := Lean.beqMVarId✝ }
Equations
- Lean.instHashableMVarId = { hash := Lean.hashMVarId✝ }
Equations
- Lean.instReprMVarId = { reprPrec := Lean.reprMVarId✝ }
Equations
- Lean.instReprMVarId_1 = { reprPrec := fun (n : Lean.MVarId) (p : Nat) => reprPrec n.name p }
Equations
- Lean.MVarIdSet = Lean.RBTree Lean.MVarId fun (x1 x2 : Lean.MVarId) => x1.name.quickCmp x2.name
Instances For
Equations
- s.insert mvarId = Lean.RBTree.insert s mvarId
Instances For
Equations
- Lean.instForInMVarIdSetMVarId = inferInstanceAs (ForIn m (Lean.RBTree Lean.MVarId fun (x1 x2 : Lean.MVarId) => x1.name.quickCmp x2.name) Lean.MVarId)
Equations
- Lean.MVarIdMap α = Lean.RBMap Lean.MVarId α fun (x1 x2 : Lean.MVarId) => x1.name.quickCmp x2.name
Instances For
Equations
- s.insert mvarId a = Lean.RBMap.insert s mvarId a
Instances For
Equations
- Lean.instEmptyCollectionMVarIdMap = inferInstanceAs (EmptyCollection (Lean.RBMap Lean.MVarId α fun (x1 x2 : Lean.MVarId) => x1.name.quickCmp x2.name))
Equations
- Lean.instForInMVarIdMapProdMVarId = inferInstanceAs (ForIn m (Lean.RBMap Lean.MVarId α fun (x1 x2 : Lean.MVarId) => x1.name.quickCmp x2.name) (Lean.MVarId × α))
Equations
- One or more equations did not get rendered due to their size.
- (Lean.Expr.const n lvls).data = Lean.Expr.mkData (mixHash 5 (mixHash (hash n) (hash lvls))) 0 0 false false (lvls.any Lean.Level.hasMVar) (lvls.any Lean.Level.hasParam)
- (Lean.Expr.bvar idx).data = Lean.Expr.mkData (mixHash 7 (hash idx)) (idx + 1)
- (Lean.Expr.sort lvl).data = Lean.Expr.mkData (mixHash 11 (hash lvl)) 0 0 false false lvl.hasMVar lvl.hasParam
- (Lean.Expr.fvar fvarId).data = Lean.Expr.mkData (mixHash 13 (hash fvarId)) 0 0 true
- (Lean.Expr.mvar fvarId).data = Lean.Expr.mkData (mixHash 17 (hash fvarId)) 0 0 false true
- (f.app a).data = Lean.Expr.mkAppData f.data a.data
- (Lean.Expr.lit l).data = Lean.Expr.mkData (mixHash 3 (hash l))
Instances For
Lean expressions. This data structure is used in the kernel and elaborator. However, expressions sent to the kernel should not contain metavariables.
Remark: we use the E
suffix (short for Expr
) to avoid collision with keywords.
We considered using «...», but it is too inconvenient to use.
- bvar: Nat → Lean.Expr
The
bvar
constructor represents bound variables, i.e. occurrences of a variable in the expression where there is a variable binder above it (i.e. introduced by alam
,forallE
, orletE
).The
deBruijnIndex
parameter is the de-Bruijn index for the bound variable. See the Wikipedia page on de-Bruijn indices for additional information.For example, consider the expression
fun x : Nat => forall y : Nat, x = y
. Thex
andy
variables in the equality expression are constructed usingbvar
and bound to the binders introduced by the earlierlam
andforallE
constructors. Here is the correspondingExpr
representation for the same expression:.lam `x (.const `Nat []) (.forallE `y (.const `Nat []) (.app (.app (.app (.const `Eq [.succ .zero]) (.const `Nat [])) (.bvar 1)) (.bvar 0)) .default) .default
- fvar: Lean.FVarId → Lean.Expr
The
fvar
constructor represent free variables. These free variable occurrences are not bound by an earlierlam
,forallE
, orletE
constructor and its binder exists in a local context only.Note that Lean uses the locally nameless approach. See McBride and McKinna for additional details.
When "visiting" the body of a binding expression (i.e.
lam
,forallE
, orletE
), bound variables are converted into free variables using a unique identifier, and their user-facing name, type, value (forLetE
), and binder annotation are stored in theLocalContext
. - mvar: Lean.MVarId → Lean.Expr
Metavariables are used to represent "holes" in expressions, and goals in the tactic framework. Metavariable declarations are stored in the
MetavarContext
. Metavariables are used during elaboration, and are not allowed in the kernel, or in the code generator. - sort: Lean.Level → Lean.Expr
- const: Lake.Name → List Lean.Level → Lean.Expr
A (universe polymorphic) constant that has been defined earlier in the module or by another imported module. For example,
@Eq.{1}
is represented asExpr.const `Eq [.succ .zero]
, and@Array.map.{0, 0}
is represented asExpr.const `Array.map [.zero, .zero]
. - app: Lean.Expr → Lean.Expr → Lean.Expr
A function application.
For example, the natural number one, i.e.
Nat.succ Nat.zero
is represented asExpr.app (.const `Nat.succ []) (.const .zero [])
. Note that multiple arguments are represented using partial application.For example, the two argument application
f x y
is represented asExpr.app (.app f x) y
. - lam: Lake.Name → Lean.Expr → Lean.Expr → Lean.BinderInfo → Lean.Expr
- forallE: Lake.Name → Lean.Expr → Lean.Expr → Lean.BinderInfo → Lean.Expr
A dependent arrow
(a : α) → β)
(aka forall-expression) whereβ
may dependent ona
. Note that this constructor is also used to represent non-dependent arrows whereβ
does not depend ona
.For example:
- letE: Lake.Name → Lean.Expr → Lean.Expr → Lean.Expr → Bool → Lean.Expr
Let-expressions.
IMPORTANT: The
nonDep
flag is for "local" use only. That is, a module should not "trust" its value for any purpose. In the intended use-case, the compiler will set this flag, and be responsible for maintaining it. Other modules may not preserve its value while applying transformations.Given an environment, a metavariable context, and a local context, we say a let-expression
let x : t := v; e
is non-dependent when it is equivalent to(fun x : t => e) v
. In contrast, the dependent let-expressionlet n : Nat := 2; fun (a : Array Nat n) (b : Array Nat 2) => a = b
is type correct, but(fun (n : Nat) (a : Array Nat n) (b : Array Nat 2) => a = b) 2
is not.The let-expression
let x : Nat := 2; Nat.succ x
is represented asExpr.letE `x (.const `Nat []) (.lit (.natVal 2)) (.app (.const `Nat.succ []) (.bvar 0)) true
- lit: Lean.Literal → Lean.Expr
Natural number and string literal values.
They are not really needed, but provide a more compact representation in memory for these two kinds of literals, and are used to implement efficient reduction in the elaborator and kernel. The "raw" natural number
2
can be represented asExpr.lit (.natVal 2)
. Note that, it is definitionally equal to:Expr.app (.const `Nat.succ []) (.app (.const `Nat.succ []) (.const `Nat.zero []))
- mdata: Lean.MData → Lean.Expr → Lean.Expr
Metadata (aka annotations).
We use annotations to provide hints to the pretty-printer, store references to
Syntax
nodes, position information, and save information for elaboration procedures (e.g., we use theinaccessible
annotation during elaboration to markExpr
s that correspond to inaccessible patterns).Note that
Expr.mdata data e
is definitionally equal toe
. - proj: Lake.Name → Nat → Lean.Expr → Lean.Expr
Projection-expressions. They are redundant, but are used to create more compact terms, speedup reduction, and implement eta for structures. The type of
struct
must be an structure-like inductive type. That is, it has only one constructor, is not recursive, and it is not an inductive predicate. The kernel and elaborators check whether thetypeName
matches the type ofstruct
, and whether the (zero-based) index is valid (i.e., it is smaller than the number of constructor fields). When exporting Lean developments to other systems,proj
can be replaced withtypeName
.rec
applications.Example, given
a : Nat × Bool
,a.1
is represented as.proj `Prod 0 a
Instances For
Equations
- Lean.instInhabitedExpr = { default := Lean.Expr.bvar default }
Equations
- Lean.instReprExpr = { reprPrec := Lean.reprExpr✝ }
The constructor name for the given expression. This is used for debugging purposes.
Equations
- (Lean.Expr.bvar a).ctorName = "bvar"
- (Lean.Expr.fvar a).ctorName = "fvar"
- (Lean.Expr.mvar a).ctorName = "mvar"
- (Lean.Expr.sort a).ctorName = "sort"
- (Lean.Expr.const a a_1).ctorName = "const"
- (a.app a_1).ctorName = "app"
- (Lean.Expr.lam a a_1 a_2 a_3).ctorName = "lam"
- (Lean.Expr.forallE a a_1 a_2 a_3).ctorName = "forallE"
- (Lean.Expr.letE a a_1 a_2 a_3 a_4).ctorName = "letE"
- (Lean.Expr.lit a).ctorName = "lit"
- (Lean.Expr.mdata a a_1).ctorName = "mdata"
- (Lean.Expr.proj a a_1 a_2).ctorName = "proj"
Instances For
Equations
- Lean.Expr.instHashable = { hash := Lean.Expr.hash }
Return true
if e
contains free variables.
This is a constant time operation.
Equations
- e.hasFVar = e.data.hasFVar
Instances For
Return true
if e
contains expression metavariables.
This is a constant time operation.
Equations
- e.hasExprMVar = e.data.hasExprMVar
Instances For
Return true
if e
contains universe (aka Level
) metavariables.
This is a constant time operation.
Equations
- e.hasLevelMVar = e.data.hasLevelMVar
Instances For
Return true if e
contains universe level parameters.
This is a constant time operation.
Equations
- e.hasLevelParam = e.data.hasLevelParam
Instances For
Return the approximated depth of an expression. This information is used to compute
the expression hash code, and speedup comparisons.
This is a constant time operation. We say it is approximate because it maxes out at 255
.
Equations
- e.approxDepth = e.data.approxDepth.toUInt32
Instances For
Return the binder information if e
is a lambda or forall expression, and .default
otherwise.
Equations
- (Lean.Expr.forallE binderName binderType body bi).binderInfo = bi
- (Lean.Expr.lam binderName binderType body bi).binderInfo = bi
- e.binderInfo = Lean.BinderInfo.default
Instances For
Export functions.
Equations
Instances For
Instances For
Instances For
Equations
Instances For
Instances For
Equations
- e.looseBVarRangeEx = e.data.looseBVarRange
Instances For
Equations
Instances For
mkConst declName us
return .const declName us
.
Equations
- Lean.mkConst declName us = Lean.Expr.const declName us
Instances For
Return the type of a literal value.
Equations
- (Lean.Literal.natVal a).type = Lean.mkConst `Nat
- (Lean.Literal.strVal a).type = Lean.mkConst `String
Instances For
Equations
Instances For
.fvar fvarId
is now the preferred form.
This function is seldom used, free variables are often automatically created using the
telescope functions (e.g., forallTelescope
and lambdaTelescope
) at MetaM
.
Equations
- Lean.mkFVar fvarId = Lean.Expr.fvar fvarId
Instances For
.mvar mvarId
is now the preferred form.
This function is seldom used, metavariables are often created using functions such
as mkFresheExprMVar
at MetaM
.
Equations
- Lean.mkMVar mvarId = Lean.Expr.mvar mvarId
Instances For
.proj structName idx struct
is now the preferred form.
Equations
- Lean.mkProj structName idx struct = Lean.Expr.proj structName idx struct
Instances For
.lam x t b bi
is now the preferred form.
Equations
- Lean.mkLambda x bi t b = Lean.Expr.lam x t b bi
Instances For
.forallE x t b bi
is now the preferred form.
Equations
- Lean.mkForall x bi t b = Lean.Expr.forallE x t b bi
Instances For
Return Unit -> type
. Do not confuse with Thunk type
Equations
- Lean.mkSimpleThunkType type = Lean.mkForall Lean.Name.anonymous Lean.BinderInfo.default (Lean.mkConst `Unit) type
Instances For
Return fun (_ : Unit), e
Equations
- Lean.mkSimpleThunk type = Lean.mkLambda `_ Lean.BinderInfo.default (Lean.mkConst `Unit) type
Instances For
.letE x t v b nonDep
is now the preferred form.
Equations
- Lean.mkLet x t v b nonDep = Lean.Expr.letE x t v b nonDep
Instances For
Equations
- Lean.mkApp4 f a b c d = Lean.mkAppB (Lean.mkAppB f a b) c d
Instances For
Equations
- Lean.mkApp5 f a b c d e = Lean.mkApp (Lean.mkApp4 f a b c d) e
Instances For
Equations
- Lean.mkApp6 f a b c d e₁ e₂ = Lean.mkAppB (Lean.mkApp4 f a b c d) e₁ e₂
Instances For
Equations
- Lean.mkApp7 f a b c d e₁ e₂ e₃ = Lean.mkApp3 (Lean.mkApp4 f a b c d) e₁ e₂ e₃
Instances For
Equations
- Lean.mkApp8 f a b c d e₁ e₂ e₃ e₄ = Lean.mkApp4 (Lean.mkApp4 f a b c d) e₁ e₂ e₃ e₄
Instances For
Equations
- Lean.mkApp9 f a b c d e₁ e₂ e₃ e₄ e₅ = Lean.mkApp5 (Lean.mkApp4 f a b c d) e₁ e₂ e₃ e₄ e₅
Instances For
Equations
- Lean.mkApp10 f a b c d e₁ e₂ e₃ e₄ e₅ e₆ = Lean.mkApp6 (Lean.mkApp4 f a b c d) e₁ e₂ e₃ e₄ e₅ e₆
Instances For
Return a natural number literal used in the frontend. It is a OfNat.ofNat
application.
Recall that all theorems and definitions containing numeric literals are encoded using
OfNat.ofNat
applications in the frontend.
Equations
- Lean.mkNatLit n = Lean.mkApp3 (Lean.mkConst `OfNat.ofNat [Lean.levelZero]) (Lean.mkConst `Nat) (Lean.mkRawNatLit n) (Lean.mkApp (Lean.mkConst `instOfNatNat) (Lean.mkRawNatLit n))
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
- Lean.mkLambdaEx n d b bi = Lean.mkLambda n bi d b
Instances For
Equations
- Lean.mkForallEx n d b bi = Lean.mkForall n bi d b
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
mkAppN f #[a₀, ..., aₙ]
constructs the application f a₀ a₁ ... aₙ
.
Equations
- Lean.mkAppN f args = Array.foldl Lean.mkApp f args
Instances For
mkAppRange f i j #[a_1, ..., a_i, ..., a_j, ... ]
==> the expression f a_i ... a_{j-1}
Equations
- Lean.mkAppRange f i j args = Lean.mkAppRangeAux j args i f
Instances For
Same as mkApp f args
but reversing args
.
Equations
- Lean.mkAppRev fn revArgs = Array.foldr (fun (a r : Lean.Expr) => Lean.mkApp r a) fn revArgs
Instances For
A total order for expressions. We say it is quick because it first compares the hashcodes.
A total order for expressions that takes the structure into account (e.g., variable names).
Return true iff a
and b
are alpha equivalent.
Binder annotations are ignored.
Equations
- Lean.Expr.instBEq = { beq := Lean.Expr.eqv }
Return true
iff a
and b
are equal.
Binder names and annotations are taken into account.
Return true
if the given expression is of the form .sort (.succ .zero)
.
Equations
- (Lean.Expr.sort Lean.Level.zero.succ).isType0 = true
- x.isType0 = false
Instances For
Return true
if the given expression is .sort .zero
Equations
- (Lean.Expr.sort Lean.Level.zero).isProp = true
- x.isProp = false
Instances For
Return true
if the given expression is a bound variable.
Equations
- (Lean.Expr.bvar deBruijnIndex).isBVar = true
- x.isBVar = false
Instances For
Return true
if the given expression is a metavariable.
Equations
- (Lean.Expr.mvar mvarId).isMVar = true
- x.isMVar = false
Instances For
Return true
if the given expression is a free variable.
Equations
- (Lean.Expr.fvar fvarId).isFVar = true
- x.isFVar = false
Instances For
Return true
if the given expression is a constant.
Equations
- (Lean.Expr.const declName us).isConst = true
- x.isConst = false
Instances For
Return true
if the given expression is a constant of the given name.
Examples:
Equations
- (Lean.Expr.const n us).isConstOf x = (n == x)
- x✝.isConstOf x = false
Instances For
Return true
if the given expression is a forall-expression aka (dependent) arrow.
Equations
- (Lean.Expr.forallE binderName binderType body binderInfo).isForall = true
- x.isForall = false
Instances For
Return true
if the given expression is a lambda abstraction aka anonymous function.
Equations
- (Lean.Expr.lam binderName binderType body binderInfo).isLambda = true
- x.isLambda = false
Instances For
Return true
if the given expression is a forall or lambda expression.
Equations
- (Lean.Expr.lam binderName binderType body binderInfo).isBinding = true
- (Lean.Expr.forallE binderName binderType body binderInfo).isBinding = true
- x.isBinding = false
Instances For
Return true
if the given expression is a let-expression.
Equations
- (Lean.Expr.letE declName type value body nonDep).isLet = true
- x.isLet = false
Instances For
Return true
if the given expression is a metadata.
Equations
- (Lean.Expr.mdata data expr).isMData = true
- x.isMData = false
Instances For
Return true
if the given expression is a literal value.
Equations
- (Lean.Expr.lit a).isLit = true
- x.isLit = false
Instances For
Equations
- (fn.app arg).appFn! = fn
- x.appFn! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.appFn!" 893 15 "application expected"
Instances For
Equations
- (fn.app arg).appArg! = arg
- x.appArg! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.appArg!" 897 15 "application expected"
Instances For
Equations
- (Lean.Expr.mdata data b).appFn!' = b.appFn!'
- (f.app arg).appFn!' = f
- x.appFn!' = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.appFn!'" 902 17 "application expected"
Instances For
Equations
- (Lean.Expr.mdata data b).appArg!' = b.appArg!'
- (f.app arg).appArg!' = arg
- x.appArg!' = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.appArg!'" 907 17 "application expected"
Instances For
Equations
- (Lean.Expr.sort u).sortLevel! = u
- x.sortLevel! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.sortLevel!" 919 14 "sort expected"
Instances For
Equations
- (Lean.Expr.lit a).litValue! = a
- x.litValue! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.litValue!" 923 13 "literal expected"
Instances For
Equations
- (Lean.Expr.lit (Lean.Literal.natVal val)).isRawNatLit = true
- x.isRawNatLit = false
Instances For
Equations
- (Lean.Expr.lit (Lean.Literal.natVal val)).rawNatLit? = some val
- x.rawNatLit? = none
Instances For
Equations
- (Lean.Expr.lit (Lean.Literal.strVal val)).isStringLit = true
- x.isStringLit = false
Instances For
Equations
Instances For
Equations
- (Lean.Expr.const declName us).constName! = declName
- x.constName! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.constName!" 943 17 "constant expected"
Instances For
Equations
- (Lean.Expr.const declName us).constName? = some declName
- x.constName? = none
Instances For
If the expression is a constant, return that name. Otherwise return Name.anonymous
.
Equations
- e.constName = e.constName?.getD Lean.Name.anonymous
Instances For
Equations
- (Lean.Expr.const declName us).constLevels! = us
- x.constLevels! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.constLevels!" 955 18 "constant expected"
Instances For
Equations
- (Lean.Expr.bvar deBruijnIndex).bvarIdx! = deBruijnIndex
- x.bvarIdx! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.bvarIdx!" 959 16 "bvar expected"
Instances For
Equations
- (Lean.Expr.fvar fvarId).fvarId! = fvarId
- x.fvarId! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.fvarId!" 963 14 "fvar expected"
Instances For
Equations
- (Lean.Expr.mvar mvarId).mvarId! = mvarId
- x.mvarId! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.mvarId!" 967 14 "mvar expected"
Instances For
Equations
- (Lean.Expr.forallE binderName binderType body bi).bindingName! = binderName
- (Lean.Expr.lam binderName binderType body bi).bindingName! = binderName
- x.bindingName! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.bindingName!" 972 23 "binding expected"
Instances For
Equations
- (Lean.Expr.forallE binderName binderType body bi).bindingDomain! = binderType
- (Lean.Expr.lam binderName binderType body bi).bindingDomain! = binderType
- x.bindingDomain! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.bindingDomain!" 977 23 "binding expected"
Instances For
Equations
- (Lean.Expr.forallE binderName binderType body bi).bindingBody! = body
- (Lean.Expr.lam binderName binderType body bi).bindingBody! = body
- x.bindingBody! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.bindingBody!" 982 23 "binding expected"
Instances For
Equations
- (Lean.Expr.forallE binderName binderType body bi).bindingInfo! = bi
- (Lean.Expr.lam binderName binderType body bi).bindingInfo! = bi
- x.bindingInfo! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.bindingInfo!" 987 24 "binding expected"
Instances For
Equations
- (Lean.Expr.letE declName type value body nonDep).letName! = declName
- x.letName! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.letName!" 991 17 "let expression expected"
Instances For
Equations
- (Lean.Expr.letE declName type value body nonDep).letType! = type
- x.letType! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.letType!" 995 19 "let expression expected"
Instances For
Equations
- (Lean.Expr.letE declName type value body nonDep).letValue! = value
- x.letValue! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.letValue!" 999 21 "let expression expected"
Instances For
Equations
- (Lean.Expr.letE declName type value body nonDep).letBody! = body
- x.letBody! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.letBody!" 1003 23 "let expression expected"
Instances For
Equations
- (Lean.Expr.mdata data expr).consumeMData = expr.consumeMData
- x.consumeMData = x
Instances For
Equations
- (Lean.Expr.mdata data expr).mdataExpr! = expr
- x.mdataExpr! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.mdataExpr!" 1011 17 "mdata expression expected"
Instances For
Equations
- (Lean.Expr.proj typeName idx struct).projExpr! = struct
- x.projExpr! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.projExpr!" 1015 18 "proj expression expected"
Instances For
Equations
- (Lean.Expr.proj typeName idx struct).projIdx! = idx
- x.projIdx! = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.projIdx!" 1019 18 "proj expression expected"
Instances For
Return the "body" of a forall expression.
Example: let e
be the representation for forall (p : Prop) (q : Prop), p ∧ q
, then
getForallBody e
returns .app (.app (.const `And []) (.bvar 1)) (.bvar 0)
Equations
- (Lean.Expr.forallE binderName binderType body binderInfo).getForallBody = body.getForallBody
- x.getForallBody = x
Instances For
Equations
- Lean.Expr.getForallBodyMaxDepth n.succ (Lean.Expr.forallE binderName binderType b binderInfo) = Lean.Expr.getForallBodyMaxDepth n b
- Lean.Expr.getForallBodyMaxDepth 0 x = x
- Lean.Expr.getForallBodyMaxDepth x✝ x = x
Instances For
Given a sequence of nested foralls (a₁ : α₁) → ... → (aₙ : αₙ) → _
,
returns the names [a₁, ... aₙ]
.
Equations
- (Lean.Expr.forallE binderName binderType body binderInfo).getForallBinderNames = binderName :: body.getForallBinderNames
- x.getForallBinderNames = []
Instances For
Given f a₀ a₁ ... aₙ
, returns true if f
is a constant with name n
.
Equations
- e.isAppOf n = match e.getAppFn with | Lean.Expr.const c us => c == n | x => false
Instances For
Given f a₁ ... aᵢ
, returns true if f
is a constant
with name n
and has the correct number of arguments.
Equations
Instances For
Similar to isAppOfArity
but skips Expr.mdata
.
Equations
- (Lean.Expr.mdata data b).isAppOfArity' x✝ x = b.isAppOfArity' x✝ x
- (Lean.Expr.const c us).isAppOfArity' x 0 = (c == x)
- (f.app arg).isAppOfArity' x a.succ = f.isAppOfArity' x a
- x✝¹.isAppOfArity' x✝ x = false
Instances For
Counts the number n
of arguments for an expression f a₁ .. aₙ
.
Equations
- e.getAppNumArgs = Lean.Expr.getAppNumArgsAux e 0
Instances For
Like Lean.Expr.getAppFn
but assumes the application has up to maxArgs
arguments.
If there are any more arguments than this, then they are returned by getAppFn
as part of the function.
In particular, if the given expression is a sequence of function applications f a₁ .. aₙ
,
returns f a₁ .. aₖ
where k
is minimal such that n - k ≤ maxArgs
.
Equations
- Lean.Expr.getBoundedAppFn maxArgs'.succ (f.app arg) = Lean.Expr.getBoundedAppFn maxArgs' f
- Lean.Expr.getBoundedAppFn x✝ x = x
Instances For
Given f a₁ a₂ ... aₙ
, returns #[a₁, ..., aₙ]
Equations
- e.getAppArgs = Lean.Expr.getAppArgsAux e (mkArray e.getAppNumArgs (Lean.mkSort Lean.levelZero)) (e.getAppNumArgs - 1)
Instances For
Like Lean.Expr.getAppArgs
but returns up to maxArgs
arguments.
In particular, given f a₁ a₂ ... aₙ
, returns #[aₖ₊₁, ..., aₙ]
where k
is minimal such that the size of this array is at most maxArgs
.
Equations
- Lean.Expr.getBoundedAppArgs maxArgs e = Lean.Expr.getBoundedAppArgsAux e (mkArray (min maxArgs e.getAppNumArgs) (Lean.mkSort Lean.levelZero)) (min maxArgs e.getAppNumArgs)
Instances For
Same as getAppArgs
but reverse the output array.
Equations
- e.getAppRevArgs = Lean.Expr.getAppRevArgsAux e (Array.mkEmpty e.getAppNumArgs)
Instances For
Equations
- Lean.Expr.withAppAux k (f.app a) x✝ x = Lean.Expr.withAppAux k f (x✝.set! x a) (x - 1)
- Lean.Expr.withAppAux k x✝¹ x✝ x = k x✝¹ x✝
Instances For
Given e = f a₁ a₂ ... aₙ
, returns k f #[a₁, ..., aₙ]
.
Equations
- e.withApp k = Lean.Expr.withAppAux k e (mkArray e.getAppNumArgs (Lean.mkSort Lean.levelZero)) (e.getAppNumArgs - 1)
Instances For
Given f a_1 ... a_n
, returns #[a_1, ..., a_n]
.
Note that f
may be an application.
The resulting array has size n
even if f.getAppNumArgs < n
.
Equations
- e.getAppArgsN n = Lean.Expr.getAppArgsN.loop n e (mkArray n (Lean.mkSort Lean.levelZero))
Instances For
Equations
- Lean.Expr.getAppArgsN.loop 0 x✝ x = x
- Lean.Expr.getAppArgsN.loop i.succ (f.app a) x = Lean.Expr.getAppArgsN.loop i f (x.set! i a)
- Lean.Expr.getAppArgsN.loop x✝¹ x✝ x = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.getAppArgsN.loop" 1158 27 "too few arguments at"
Instances For
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
- Lean.Expr.traverseApp f e = e.withApp fun (fn : Lean.Expr) (args : Array Lean.Expr) => Seq.seq (Lean.mkAppN <$> f fn) fun (x : Unit) => Array.mapM f args
Instances For
Same as withApp
but with arguments reversed.
Equations
- e.withAppRev k = Lean.Expr.withAppRevAux k e (Array.mkEmpty e.getAppNumArgs)
Instances For
Equations
- (fn.app a).getRevArg! 0 = a
- (f.app arg).getRevArg! i.succ = f.getRevArg! i
- x✝.getRevArg! x = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.getRevArg!" 1199 20 "invalid index"
Instances For
Similar to getRevArg!
but skips mdata
Equations
- (Lean.Expr.mdata data a).getRevArg!' x = a.getRevArg!' x
- (fn.app a).getRevArg!' 0 = a
- (f.app arg).getRevArg!' i.succ = f.getRevArg!' i
- x✝.getRevArg!' x = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.getRevArg!'" 1206 20 "invalid index"
Instances For
Return true
if e
is a non-dependent arrow.
Remark: the following function assumes e
does not have loose bound variables.
Equations
- (Lean.Expr.forallE binderName binderType body binderInfo).isArrow = !body.hasLooseBVars
- e.isArrow = false
Instances For
Return true if e
contains the loose bound variable bvarIdx
in an explicit parameter, or in the range if tryRange == true
.
Equations
Instances For
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
.
Instances For
Instantiates the loose bound variables in e
using the subst
array,
where a loose Expr.bvar i
at "binding depth" d
is instantiated with subst[i - d]
if 0 <= i - d < subst.size
,
and otherwise it is replaced with Expr.bvar (i - subst.size)
; non-loose bound variables are not touched.
If we imagine all expressions as being able to refer to the infinite list of loose bound variables ..., 3, 2, 1, 0 in that order,
then conceptually instantiate
is instantiating the last n
of these and reindexing the remaining ones.
Warning: instantiate
uses the de Bruijn indexing to index the subst
array, which might be the reverse order from what you might expect.
See also Lean.Expr.instantiateRev
.
Terminology. The "binding depth" of a subexpression is the number of bound variables available to that subexpression
by virtue of being in the bodies of Expr.forallE
, Expr.lam
, and Expr.letE
expressions.
A bound variable Expr.bvar i
is "loose" if its de Bruijn index i
is not less than its binding depth.)
About instantiation. Instantiation isn't mere substitution.
When an expression from subst
is being instantiated, its internal loose bound variables have their de Bruijn indices incremented
by the binding depth of the replaced loose bound variable.
This is necessary for the substituted expression to still refer to the correct binders after instantiation.
Similarly, the reason loose bound variables not instantiated using subst
have their de Bruijn indices decremented like Expr.bvar (i - subst.size)
is that instantiate
can be used to eliminate binding expressions internal to a larger expression,
and this adjustment keeps these bound variables referring to the same binders.
Instantiates loose bound variable 0
in e
using the expression subst
,
where in particular a loose Expr.bvar i
at binding depth d
is instantiated with subst
if i = d
,
and otherwise it is replaced with Expr.bvar (i - 1)
; non-loose bound variables are not touched.
If we imagine all expressions as being able to refer to the infinite list of loose bound variables ..., 3, 2, 1, 0 in that order,
then conceptually instantiate1
is instantiating the last one of these and reindexing the remaining ones.
This function is equivalent to instantiate e #[subst]
, but it avoids allocating an array.
See the documentation for Lean.Expr.instantiate
for a description of instantiation.
In short, during instantiation the loose bound variables in subst
have their own de Bruijn indices updated to account
for the binding depth of the replaced loose bound variable.
Instantiates the loose bound variables in e
using the subst
array.
This is equivalent to Lean.Expr.instantiate e subst.reverse
, but it avoids reversing the array.
In particular, rather than instantiating Expr.bvar i
with subst[i - d]
it instantiates with subst[subst.size - 1 - (i - d)]
,
where d
is the binding depth.
This function instantiates with the "forwards" indexing scheme.
For example, if e
represents the expression fun x y => x + y
,
then instantiateRev e.bindingBody!.bindingBody! #[a, b]
yields a + b
.
The instantiate
function on the other hand would yield b + a
, since de Bruijn indices count outwards.
Similar to Lean.Expr.instantiate
, but considers only the substitutions subst
in the range [beginIdx, endIdx)
.
Function panics if beginIdx <= endIdx <= subst.size
does not hold.
This function is equivalent to instantiate e (subst.extract beginIdx endIdx)
, but it does not allocate a new array.
This instantiates with the "backwards" indexing scheme.
See also Lean.Expr.instantiateRevRange
, which instantiates with the "forwards" indexing scheme.
Similar to Lean.Expr.instantiateRev
, but considers only the substitutions subst
in the range [beginIdx, endIdx)
.
Function panics if beginIdx <= endIdx <= subst.size
does not hold.
This function is equivalent to instantiateRev e (subst.extract beginIdx endIdx)
, but it does not allocate a new array.
This instantiates with the "forwards" indexing scheme (see the docstring for Lean.Expr.instantiateRev
for an example).
See also Lean.Expr.instantiateRange
, which instantiates with the "backwards" indexing scheme.
Replace occurrences of the free variable fvarId
in e
with v
Equations
- e.replaceFVarId fvarId v = e.replaceFVar (Lean.mkFVar fvarId) v
Instances For
Equations
- Lean.Expr.instToString = { toString := Lean.Expr.dbgToString }
Returns true when the expression does not have any sub-expressions.
Equations
- (Lean.Expr.const declName us).isAtomic = true
- (Lean.Expr.sort u).isAtomic = true
- (Lean.Expr.bvar deBruijnIndex).isAtomic = true
- (Lean.Expr.lit a).isAtomic = true
- (Lean.Expr.mvar mvarId).isAtomic = true
- (Lean.Expr.fvar fvarId).isAtomic = true
- x.isAtomic = false
Instances For
Equations
- Lean.mkDecIsTrue pred proof = Lean.mkAppB (Lean.mkConst `Decidable.isTrue) pred proof
Instances For
Equations
- Lean.mkDecIsFalse pred proof = Lean.mkAppB (Lean.mkConst `Decidable.isFalse) pred proof
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
- Lean.instInhabitedExprStructEq = { default := { val := default } }
Equations
- Lean.instCoeExprExprStructEq = { coe := Lean.ExprStructEq.mk }
Equations
- { val := e₁ }.beq { val := e₂ } = e₁.equal e₂
Instances For
Equations
- { val := e }.hash = e.hash
Instances For
Equations
- Lean.ExprStructEq.instBEq = { beq := Lean.ExprStructEq.beq }
Equations
- Lean.ExprStructEq.instHashable = { hash := Lean.ExprStructEq.hash }
Equations
- Lean.ExprStructEq.instToString = { toString := fun (e : Lean.ExprStructEq) => toString e.val }
Equations
Instances For
Equations
Instances For
mkAppRevRange f b e args == mkAppRev f (revArgs.extract b e)
Equations
- f.mkAppRevRange beginIdx endIdx revArgs = Lean.Expr.mkAppRevRangeAux revArgs beginIdx f endIdx
Instances For
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
Supposet
is(fun x y => t x y) a b c d
, thenargs := t.getAppRev
is#[d, c, b, a]
, andbetaRev (fun x y => t x y) #[d, c, b, a]
ist 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
- f.betaRev revArgs useZeta preserveMData = if (revArgs.size == 0) = true then f else let sz := revArgs.size; Lean.Expr.betaRev.go revArgs useZeta preserveMData sz f 0
Instances For
Count the number of lambdas at the head of the given expression.
Equations
- (Lean.Expr.lam binderName binderType b binderInfo).getNumHeadLambdas = b.getNumHeadLambdas + 1
- (Lean.Expr.mdata data b).getNumHeadLambdas = b.getNumHeadLambdas
- x.getNumHeadLambdas = 0
Instances For
Return true if the given expression is the function of an expression that is target for (head) beta reduction.
If useZeta = true
, then let
-expressions are visited. That is, it assumes
that zeta-reduction (aka let-expansion) is going to be used.
See isHeadBetaTarget
.
Equations
- Lean.Expr.isHeadBetaTargetFn useZeta (Lean.Expr.lam binderName binderType b binderInfo) = true
- Lean.Expr.isHeadBetaTargetFn useZeta (Lean.Expr.letE declName type v b nonDep) = (useZeta && Lean.Expr.isHeadBetaTargetFn useZeta b)
- Lean.Expr.isHeadBetaTargetFn useZeta (Lean.Expr.mdata data b) = Lean.Expr.isHeadBetaTargetFn useZeta b
- Lean.Expr.isHeadBetaTargetFn useZeta x = false
Instances For
(fun x => e) a
==> e[x/a]
.
Equations
- e.headBeta = if Lean.Expr.isHeadBetaTargetFn false e.getAppFn = true then e.getAppFn.betaRev e.getAppRevArgs else e
Instances For
Return true if the given expression is a target for (head) beta reduction.
If useZeta = true
, then let
-expressions are visited. That is, it assumes
that zeta-reduction (aka let-expansion) is going to be used.
Equations
- e.isHeadBetaTarget useZeta = (e.isApp && Lean.Expr.isHeadBetaTargetFn useZeta e.getAppFn)
Instances For
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
- e.etaExpanded? = Lean.Expr.etaExpandedAux e 0
Instances For
Similar to etaExpanded?
, but only succeeds if ₙ ≥ 1
.
Equations
- (Lean.Expr.lam binderName binderType body binderInfo).etaExpandedStrict? = Lean.Expr.etaExpandedAux body 1
- x.etaExpandedStrict? = none
Instances For
Return true
if e
is of the form semiOutParam _
Equations
- e.isSemiOutParam = e.isAppOfArity `semiOutParam 1
Instances For
Remove outParam
, optParam
, and autoParam
applications/annotations from e
.
Note that it does not remove nested annotations.
Examples:
- Given
e
of the formoutParam (optParam Nat b)
,consumeTypeAnnotations e = b
. - Given
e
of the formNat → outParam (optParam Nat b)
,consumeTypeAnnotations e = e
.
Remove metadata annotations and outParam
, optParam
, and autoParam
applications/annotations from e
.
Note that it does not remove nested annotations.
Examples:
- Given
e
of the formoutParam (optParam Nat b)
,cleanupAnnotations e = b
. - Given
e
of the formNat → outParam (optParam Nat b)
,cleanupAnnotations e = e
.
Similar to appFn
, but also applies cleanupAnnotations
to resulting function.
This function is used compile the match_expr
term.
Equations
- (fn.app a).appFnCleanup x = fn.cleanupAnnotations
Instances For
Equations
- e.isFalse = e.cleanupAnnotations.isConstOf `False
Instances For
Equations
- e.isTrue = e.cleanupAnnotations.isConstOf `True
Instances For
Checks if an expression is a "natural number numeral in normal form",
i.e. of type Nat
, and explicitly of the form OfNat.ofNat n
where n
matches .lit (.natVal n)
for some literal natural number n
.
and if so returns n
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checks if an expression is an "integer numeral in normal form",
i.e. of type Nat
or Int
, and either a natural number numeral in normal form (as specified by nat?
),
or the negation of a positive natural number numberal in normal form,
and if so returns the integer.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return true iff e
contains a free variable which satisfies p
.
Equations
- e.hasAnyFVar p = Lean.Expr.hasAnyFVar.visit p e
Instances For
Instances For
Return true
if e
contains the given free variable.
Equations
- e.containsFVar fvarId = e.hasAnyFVar fun (x : Lean.FVarId) => x == fvarId
Instances For
The update functions try to avoid allocating new values using pointer equality.
Note that if the update*!
functions are used under a match-expression,
the compiler will eliminate the double-match.
Equations
- (fn.app arg).updateApp! newFn newArg = Lean.mkApp newFn newArg
- e.updateApp! newFn newArg = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateApp!" 1674 15 "application expected"
Instances For
Equations
- (Lean.Expr.fvar fvarId).updateFVar! fvarIdNew = if (fvarId == fvarIdNew) = true then Lean.Expr.fvar fvarId else Lean.Expr.fvar fvarIdNew
- e.updateFVar! fvarIdNew = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateFVar!" 1679 20 "fvar expected"
Instances For
Equations
- (Lean.Expr.const declName us).updateConst! newLevels = Lean.mkConst declName newLevels
- e.updateConst! newLevels = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateConst!" 1690 17 "constant expected"
Instances For
Equations
- (Lean.Expr.sort u).updateSort! newLevel = Lean.mkSort newLevel
- e.updateSort! newLevel = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateSort!" 1701 14 "level expected"
Instances For
Equations
- (Lean.Expr.mdata data expr).updateMData! newExpr = Lean.mkMData data newExpr
- e.updateMData! newExpr = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateMData!" 1712 17 "mdata expected"
Instances For
Equations
- (Lean.Expr.proj typeName idx struct).updateProj! newExpr = Lean.mkProj typeName idx newExpr
- e.updateProj! newExpr = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateProj!" 1723 18 "proj expected"
Instances For
Equations
- (Lean.Expr.forallE binderName binderType body binderInfo).updateForall! newBinfo newDomain newBody = Lean.mkForall binderName newBinfo newDomain newBody
- e.updateForall! newBinfo newDomain newBody = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateForall!" 1738 23 "forall expected"
Instances For
Equations
- (Lean.Expr.forallE binderName binderType body binderInfo).updateForallE! newDomain newBody = (Lean.Expr.forallE binderName binderType body binderInfo).updateForall! binderInfo newDomain newBody
- e.updateForallE! newDomain newBody = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateForallE!" 1743 24 "forall expected"
Instances For
Equations
- (Lean.Expr.lam binderName binderType body binderInfo).updateLambda! newBinfo newDomain newBody = Lean.mkLambda binderName newBinfo newDomain newBody
- e.updateLambda! newBinfo newDomain newBody = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateLambda!" 1758 19 "lambda expected"
Instances For
Equations
- (Lean.Expr.lam binderName binderType body binderInfo).updateLambdaE! newDomain newBody = (Lean.Expr.lam binderName binderType body binderInfo).updateLambda! binderInfo newDomain newBody
- e.updateLambdaE! newDomain newBody = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateLambdaE!" 1763 20 "lambda expected"
Instances For
Equations
- (Lean.Expr.letE declName type value body nonDep).updateLet! newType newVal newBody = Lean.Expr.letE declName newType newVal newBody nonDep
- e.updateLet! newType newVal newBody = panicWithPosWithDecl "Lean.Expr" "Lean.Expr.updateLet!" 1778 22 "let expression expected"
Instances For
Eta reduction. If e
is of the form (fun x => f x)
, then return f
.
Annotate e
with the given option.
The information is stored using metadata around e
.
Equations
- e.setOption optionName val = Lean.mkMData (Lean.KVMap.set Lean.MData.empty optionName val) e
Instances For
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.
- e.setAppPPExplicit = e
Instances For
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.
- e.setAppPPExplicitForExposingMVars = e
Instances For
Returns true if e
is a let_fun
expression, which is an expression of the form letFun v f
.
Ideally f
is a lambda, but we do not require that here.
Warning: if the let_fun
is applied to additional arguments (such as in (let_fun f := id; id) 1
), this function returns false
.
Equations
- e.isLetFun = e.isAppOfArity `letFun 4
Instances For
Recognizes a let_fun
expression.
For let_fun n : t := v; b
, returns some (n, t, v, b)
, which are the first four arguments to Lean.Expr.letE
.
Warning: if the let_fun
is applied to additional arguments (such as in (let_fun f := id; id) 1
), this function returns none
.
let_fun
expressions are encoded as letFun v (fun (n : t) => b)
.
They can be created using Lean.Meta.mkLetFun
.
If in the encoding of let_fun
the last argument to letFun
is eta reduced, this returns Name.anonymous
for the binder name.
Equations
- (((((Lean.Expr.const `letFun us).app t).app _β).app v).app (Lean.Expr.lam binderName binderType body binderInfo)).letFun? = some (binderName, t, v, body)
- (((((Lean.Expr.const `letFun us).app t).app _β).app v).app f).letFun? = some (Lean.Name.anonymous, t, v, f.app (Lean.Expr.bvar 0))
- e.letFun? = none
Instances For
Like Lean.Expr.letFun?
, but handles the case when the let_fun
expression is possibly applied to additional arguments.
Returns those arguments in addition to the values returned by letFun?
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Maps f
on each immediate child of the given expression.
Equations
- One or more equations did not get rendered due to their size.
- Lean.Expr.traverseChildren f (Lean.Expr.mdata data b) = (Lean.Expr.mdata data b).updateMData! <$> f b
- Lean.Expr.traverseChildren f (l.app r) = Seq.seq (Seq.seq (pure (l.app r).updateApp!) fun (x : Unit) => f l) fun (x : Unit) => f r
- Lean.Expr.traverseChildren f (Lean.Expr.proj typeName idx b) = (Lean.Expr.proj typeName idx b).updateProj! <$> f b
- Lean.Expr.traverseChildren f x = pure x
Instances For
e.foldlM f a
folds the monadic function f
over the subterms of the expression e
,
with initial value a
.
Equations
- Lean.Expr.foldlM f init e = Prod.snd <$> (Lean.Expr.traverseChildren (fun (e' : Lean.Expr) (a : α) => Prod.mk e' <$> f a e') e).run init
Instances For
Returns the size of e
as a tree, i.e. nodes reachable via multiple paths are counted multiple
times.
This is a naive implementation that visits shared subterms multiple times instead of caching their sizes. It is primarily meant for debugging.
Equations
- (Lean.Expr.forallE binderName d b binderInfo).sizeWithoutSharing = 1 + d.sizeWithoutSharing + b.sizeWithoutSharing
- (Lean.Expr.lam binderName d b binderInfo).sizeWithoutSharing = 1 + d.sizeWithoutSharing + b.sizeWithoutSharing
- (Lean.Expr.mdata data e).sizeWithoutSharing = 1 + e.sizeWithoutSharing
- (Lean.Expr.letE declName t v b nonDep).sizeWithoutSharing = 1 + t.sizeWithoutSharing + v.sizeWithoutSharing + b.sizeWithoutSharing
- (f.app a).sizeWithoutSharing = 1 + f.sizeWithoutSharing + a.sizeWithoutSharing
- (Lean.Expr.proj typeName idx e).sizeWithoutSharing = 1 + e.sizeWithoutSharing
- (Lean.Expr.lit a).sizeWithoutSharing = 1
- (Lean.Expr.const declName us).sizeWithoutSharing = 1
- (Lean.Expr.sort u).sizeWithoutSharing = 1
- (Lean.Expr.mvar mvarId).sizeWithoutSharing = 1
- (Lean.Expr.fvar fvarId).sizeWithoutSharing = 1
- (Lean.Expr.bvar deBruijnIndex).sizeWithoutSharing = 1
Instances For
Annotate e
with the given annotation name kind
.
It uses metadata to store the annotation.
Equations
- Lean.mkAnnotation kind e = Lean.mkMData (Lean.KVMap.empty.insert kind (Lean.DataValue.ofBool true)) e
Instances For
Return some e'
if e = mkAnnotation kind e'
Equations
- Lean.annotation? kind (Lean.Expr.mdata data expr) = if (Lean.KVMap.size data == 1 && Lean.KVMap.getBool data kind) = true then some expr else none
- Lean.annotation? kind e = none
Instances For
Auxiliary annotation used to mark terms marked with the "inaccessible" annotation .(t)
and
_
in patterns.
Equations
- Lean.mkInaccessible e = Lean.mkAnnotation `_inaccessible e
Instances For
Return some e'
if e = mkInaccessible e'
.
Equations
- Lean.inaccessible? e = Lean.annotation? `_inaccessible e
Instances For
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.
- Lean.patternWithRef? p = none
Instances For
Equations
- Lean.isPatternWithRef p = (Lean.patternWithRef? p).isSome
Instances For
Annotate the pattern p
with stx
. This is an auxiliary annotation
for producing better hover information.
Equations
- Lean.mkPatternWithRef p stx = if (Lean.patternWithRef? p).isSome = true then p else Lean.mkMData (Lean.KVMap.empty.insert Lean.patternRefAnnotationKey (Lean.DataValue.ofSyntax stx)) p
Instances For
Return some p
if e
is an annotated pattern (inaccessible?
or patternWithRef?
)
Equations
- Lean.patternAnnotation? e = match Lean.inaccessible? e with | some e => some e | x => match Lean.patternWithRef? e with | some (fst, e) => some e | x => none
Instances For
Annotate e
with the LHS annotation. The delaborator displays
expressions of the form lhs = rhs
as lhs
when they have this annotation.
This is used to implement the infoview for the conv
mode.
This version of mkLHSGoal
does not check that the argument is an equality.
Equations
- Lean.mkLHSGoalRaw e = Lean.mkAnnotation `_lhsGoal e
Instances For
Return some lhs
if e = mkLHSGoal e'
, where e'
is of the form lhs = rhs
.
Equations
- Lean.isLHSGoal? e = match Lean.annotation? `_lhsGoal e with | none => none | some e => if e.isAppOfArity `Eq 3 = true then some e.appFn!.appArg! else none
Instances For
Polymorphic operation for generating unique/fresh free variable identifiers.
It is available in any monad m
that implements the interface MonadNameGenerator
.
Instances For
Polymorphic operation for generating unique/fresh metavariable identifiers.
It is available in any monad m
that implements the interface MonadNameGenerator
.
Instances For
Polymorphic operation for generating unique/fresh universe metavariable identifiers.
It is available in any monad m
that implements the interface MonadNameGenerator
.
Instances For
Make an n-ary And
application. mkAndN []
returns True
.
Equations
- Lean.mkAndN [] = Lean.mkConst `True
- Lean.mkAndN [p] = p
- Lean.mkAndN (p :: ps) = Lean.mkAnd p (Lean.mkAndN ps)
Instances For
Constants for Nat typeclasses.
Equations
- Lean.Nat.mkInstAdd = Lean.mkConst `instAddNat
Instances For
Equations
Instances For
Equations
- Lean.Nat.mkInstSub = Lean.mkConst `instSubNat
Instances For
Equations
Instances For
Equations
- Lean.Nat.mkInstMul = Lean.mkConst `instMulNat
Instances For
Equations
Instances For
Equations
- Lean.Nat.mkInstDiv = Lean.mkConst `Nat.instDiv
Instances For
Equations
Instances For
Equations
- Lean.Nat.mkInstMod = Lean.mkConst `Nat.instMod
Instances For
Equations
Instances For
Equations
- Lean.Nat.mkInstNatPow = Lean.mkConst `instNatPowNat
Instances For
Equations
Instances For
Equations
Instances For
Equations
- Lean.Nat.mkInstLT = Lean.mkConst `instLTNat
Instances For
Equations
- Lean.Nat.mkInstLE = Lean.mkConst `instLENat
Instances For
Given a : Nat
, returns Nat.succ a
Equations
- Lean.mkNatSucc a = Lean.mkApp (Lean.mkConst `Nat.succ) a
Instances For
Given a b : Nat
, returns a + b
Equations
- Lean.mkNatAdd a b = Lean.mkApp2 Lean.natAddFn a b
Instances For
Given a b : Nat
, returns a - b
Equations
- Lean.mkNatSub a b = Lean.mkApp2 Lean.natSubFn a b
Instances For
Given a b : Nat
, returns a * b
Equations
- Lean.mkNatMul a b = Lean.mkApp2 Lean.natMulFn a b
Instances For
Given a b : Nat
, return a ≤ b
Equations
- Lean.mkNatLE a b = Lean.mkApp2 Lean.natLEPred a b
Instances For
Given a b : Nat
, return a = b
Equations
- Lean.mkNatEq a b = Lean.mkApp2 Lean.natEqPred a b