Additional operations on Expr and related types #
This file defines basic operations on the types expr, name, declaration, level, environment.
This file is mostly for non-tactics.
Declarations about BinderInfo
#
The brackets corresponding to a given BinderInfo
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Declarations about name
#
Build a name from components. For example from_components [`foo, `bar]
becomes
`foo.bar
.
It is the inverse of Name.components
on list of names that have single components.
Instances For
Auxiliary for Name.fromComponents
Equations
- Lean.Name.fromComponents.go x [] = x
- Lean.Name.fromComponents.go x (s :: rest) = Lean.Name.fromComponents.go (Lean.Name.updatePrefix s x) rest
Instances For
Update the last component of a name.
Equations
- Lean.Name.updateLast f x = match x with | Lean.Name.str n s => Lean.Name.str n (f s) | n => n
Instances For
Get the last field of a name as a string. Doesn't raise an error when the last component is a numeric field.
Equations
- Lean.Name.getString x = match x with | Lean.Name.str pre s => s | Lean.Name.num pre n => toString n | Lean.Name.anonymous => ""
Instances For
nm.splitAt n
splits a name nm
in two parts, such that the second part has depth n
, i.e.
(nm.splitAt n).2.getNumParts = n
(assuming nm.getNumParts ≥ n
).
Example: splitAt `foo.bar.baz.back.bat 1 = (`foo.bar.baz.back, `bat)
.
Equations
- Lean.Name.splitAt nm n = match List.splitAt n (Lean.Name.componentsRev nm) with | (nm2, nm1) => (Lean.Name.fromComponents (List.reverse nm1), Lean.Name.fromComponents (List.reverse nm2))
Instances For
isPrefixOf? pre nm
returns some post
if nm = pre ++ post
.
Note that this includes the case where nm
has multiple more namespaces.
If pre
is not a prefix of nm
, it returns none
.
Equations
- Lean.Name.isPrefixOf? pre Lean.Name.anonymous = if (pre == Lean.Name.anonymous) = true then some Lean.Name.anonymous else none
- Lean.Name.isPrefixOf? pre (Lean.Name.num p' a) = if (pre == Lean.Name.num p' a) = true then some Lean.Name.anonymous else Option.map (fun x => Lean.Name.num x a) (Lean.Name.isPrefixOf? pre p')
- Lean.Name.isPrefixOf? pre (Lean.Name.str p' s) = if (pre == Lean.Name.str p' s) = true then some Lean.Name.anonymous else Option.map (fun x => Lean.Name.str x s) (Lean.Name.isPrefixOf? pre p')
Instances For
Lean 4 makes declarations which are technically not internal
(that is, head string does not start with _
) but which sometimes should
be treated as such. For example, the to_additive
attribute needs to
transform proof_1
constants generated by Lean.Meta.mkAuxDefinitionFor
.
This might be better fixed in core, but until then, this method can act
as a polyfill. This method only looks at the name to decide whether it is probably internal.
Note: this declaration also occurs as shouldIgnore
in the Lean 4 file test/lean/run/printDecls
.
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
The union of two NameSet
s.
Equations
- Lean.NameSet.append s t = Lean.RBMap.mergeBy (fun x x x => ()) s t
Instances For
Equations
- Lean.NameSet.instAppendNameSet = { append := Lean.NameSet.append }
Checks whether this ConstantInfo
is a definition,
Equations
- Lean.ConstantInfo.isDef x = match x with | Lean.ConstantInfo.defnInfo val => true | x => false
Instances For
Checks whether this ConstantInfo
is a theorem,
Equations
- Lean.ConstantInfo.isThm x = match x with | Lean.ConstantInfo.thmInfo val => true | x => false
Instances For
Update ConstantVal
(the data common to all constructors of ConstantInfo
)
in a ConstantInfo
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Update the name of a ConstantInfo
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Update the type of a ConstantInfo
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Update the level parameters of a ConstantInfo
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Update the value of a ConstantInfo
, if it has one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Turn a ConstantInfo
into a declaration.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Same as mkConst
, but with fresh level metavariables.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Declarations about Expr
#
If the expression is a constant, return that name. Otherwise return Name.anonymous
.
Equations
Instances For
Equations
- Lean.Expr.bvarIdx? x = match x with | Lean.Expr.bvar idx => some idx | x => none
Instances For
Return the function (name) and arguments of an application.
Equations
- Lean.Expr.getAppFnArgs e = Lean.Expr.withApp e fun e a => (Lean.Expr.constName e, a)
Instances For
Like Expr.getUsedConstants
, but produce a NameSet
.
Equations
- Lean.Expr.getUsedConstants' e = Lean.Expr.foldConsts e ∅ fun c cs => Lean.NameSet.insert cs c
Instances For
Turn an expression that is a natural number literal into a natural number.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Turn an expression that is a constructor of Int
applied to a natural number literal
into an integer.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if an expression is an "integer in normal form", i.e. either a natural number in normal form, or the negation of one, and if so returns the integer.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if an expression is a "rational in normal form",
i.e. either an integer number in normal form,
or n / d
where n
is an integer in normal form, d
is a natural number in normal form,
d ≠ 1
, and n
and d
are coprime (in particular, we check that (mkRat n d).den = d
).
If so returns the rational number.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Test if an expression represents an explicit number written in normal form:
- A "natural number in normal form" is an expression
OfNat.ofNat n
, even if it is not of typeℕ
, as long asn
is a literal. - An "integer in normal form" is an expression which is either a natural number in number form,
or
-n
, wheren
is a natural number in normal form. - A "rational in normal form" is an expressions which is either an integer in normal form,
or
n / d
wheren
is an integer in normal form,d
is a natural number in normal form,d ≠ 1
, andn
andd
are coprime (in particular, we check that(mkRat n d).den = d
).
Equations
Instances For
If an Expr
has form .fvar n
, then returns some n
, otherwise none
.
Equations
- Lean.Expr.fvarId? x = match x with | Lean.Expr.fvar n => some n | x => none
Instances For
isConstantApplication e
checks whether e
is syntactically an application of the form
(fun x₁ ⋯ xₙ => H) y₁ ⋯ yₙ
where H
does not contain the variable xₙ
. In other words,
it does a syntactic check that the expression does not depend on yₙ
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Counts the immediate depth of a nested let
expression.
Equations
- Lean.Expr.letDepth (Lean.Expr.letE declName type value b nonDep) = Lean.Expr.letDepth b + 1
- Lean.Expr.letDepth x = 0
Instances For
Check that an expression contains no metavariables (after instantiation).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Construct the term of type α
for a given natural number
(doing typeclass search for the OfNat
instance required).
Equations
- Lean.Expr.ofNat α n = Lean.Meta.mkAppOptM `OfNat.ofNat #[some α, some (Lean.mkRawNatLit n), none]
Instances For
Construct the term of type α
for a given integer
(doing typeclass search for the OfNat
and Neg
instances required).
Equations
- Lean.Expr.ofInt α x = match x with | Int.ofNat n => Lean.Expr.ofNat α n | Int.negSucc n => do let __do_lift ← Lean.Expr.ofNat α (n + 1) Lean.Meta.mkAppM `Neg.neg #[__do_lift]
Instances For
Return some n
if e
is one of the following
- A nat literal (numeral)
Nat.zero
Nat.succ x
whereisNumeral x
OfNat.ofNat _ x _
whereisNumeral x
Test if an expression is either Nat.zero
, or OfNat.ofNat 0
.
Equations
- Lean.Expr.zero? e = match Lean.Expr.numeral? e with | some 0 => true | x => false
Instances For
Tests is if an expression matches either x ≠ y
or ¬ (x = y)
.
If it matches, returns some (type, x, y)
.
Equations
- Lean.Expr.ne?' e = HOrElse.hOrElse (Lean.Expr.ne? e) fun x => Lean.Expr.not? e >>= Lean.Expr.eq?
Instances For
Lean.Expr.le? e
takes e : Expr
as input.
If e
represents a ≤ b
, then it returns some (t, a, b)
, where t
is the Type of a
,
otherwise, it returns none
.
Equations
- Lean.Expr.le? p = do let __discr ← Lean.Expr.app4? p `LE.le match __discr with | (type, fst, lhs, rhs) => pure (type, lhs, rhs)
Instances For
Given a proposition ty
that is an Eq
, Iff
, or HEq
, returns (tyLhs, lhs, tyRhs, rhs)
,
where lhs : tyLhs
and rhs : tyRhs
,
and where lhs
is related to rhs
by the respective relation.
See also Lean.Expr.iff?
, Lean.Expr.eq?
, and Lean.Expr.heq?
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Expr.modifyAppArgM modifier x = match x with | Lean.Expr.app f a => Lean.mkApp f <$> modifier a | e => pure e
Instances For
Equations
- Lean.Expr.modifyAppArg modifier = Lean.Expr.modifyAppArgM modifier
Instances For
Equations
- Lean.Expr.modifyRevArg modifier 0 = Lean.Expr.modifyAppArg modifier
- Lean.Expr.modifyRevArg modifier (Nat.succ i) = Lean.Expr.modifyAppArg (Lean.Expr.modifyRevArg modifier i)
Instances For
Given f a₀ a₁ ... aₙ₋₁
, runs modifier
on the i
th argument or
returns the original expression if out of bounds.
Equations
- Lean.Expr.modifyArg modifier e i n = Lean.Expr.modifyRevArg modifier (n - i - 1) e
Instances For
Equations
- Lean.Expr.getRevArg? x x = match x, x with | Lean.Expr.app fn a, 0 => some a | Lean.Expr.app f arg, Nat.succ i => some (Lean.Expr.getRevArg! f i) | x, x_1 => none
Instances For
Given f a₀ a₁ ... aₙ₋₁
, returns the i
th argument or none if out of bounds.
Equations
- Lean.Expr.getArg? e i n = Lean.Expr.getRevArg? e (n - i - 1)
Instances For
Given f a₀ a₁ ... aₙ₋₁
, runs modifier
on the i
th argument.
An argument n
may be provided which says how many arguments we are expecting e
to have.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Traverses an expression e
and renames bound variables named old
to new
.
Equations
- Lean.Expr.renameBVar (Lean.Expr.app fn arg) old new = Lean.Expr.app (Lean.Expr.renameBVar fn old new) (Lean.Expr.renameBVar arg old new)
- Lean.Expr.renameBVar (Lean.Expr.lam n ty bd bi) old new = Lean.Expr.lam (if (n == old) = true then new else n) (Lean.Expr.renameBVar ty old new) (Lean.Expr.renameBVar bd old new) bi
- Lean.Expr.renameBVar (Lean.Expr.forallE n ty bd bi) old new = Lean.Expr.forallE (if (n == old) = true then new else n) (Lean.Expr.renameBVar ty old new) (Lean.Expr.renameBVar bd old new) bi
- Lean.Expr.renameBVar e old new = e
Instances For
getBinderName e
returns some n
if e
is an expression of the form ∀ n, ...
and none
otherwise.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Annotates a binderIdent
with the binder information from an fvar
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
If e
has a structure as type with field fieldName
, mkDirectProjection e fieldName
creates
the projection expression e.fieldName
Equations
- One or more equations did not get rendered due to their size.
Instances For
If e
has a structure as type with field fieldName
(either directly or in a parent
structure), mkProjection e fieldName
creates the projection expression e.fieldName
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns true if e
contains a name n
where p n
is true.
Equations
- Lean.Expr.containsConst e p = Option.isSome (Lean.Expr.find? (fun x => match x with | Lean.Expr.const n us => p n | x => false) e)
Instances For
Rewrites e
via some eq
, producing a proof e = e'
for some e'
.
Rewrites with a fresh metavariable as the ambient goal. Fails if the rewrite produces any subgoals.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Rewrites the type of e
via some eq
, then moves e
into the new type via Eq.mp
.
Rewrites with a fresh metavariable as the ambient goal. Fails if the rewrite produces any subgoals.
Equations
- Lean.Expr.rewriteType e eq = do let __do_lift ← Lean.Meta.inferType e let __do_lift ← Lean.Expr.rewrite __do_lift eq Lean.Meta.mkEqMP __do_lift e
Instances For
Return all names appearing in the type or value of a ConstantInfo
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Get the projections that are projections to parent structures. Similar to getParentStructures
,
except that this returns the (last component of the) projection names instead of the parent names.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return the name of the module in which a declaration was defined.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return the names of the modules in which constants used in the specified declaration were defined.
Note that this will not account for tactics and syntax used in the declaration, so the results may not suffice as imports.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return the names of the modules in which constants used in the current file were defined.
Note that this will not account for tactics and syntax used in the file, so the results may not suffice as imports.
Equations
- One or more equations did not get rendered due to their size.