The areas / V01. The language of Mathlib
Mathlib.Lean.Expr.Basic
46 declarations. Mathlib docs · Source
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
Declarations about Expr
def Lean.BinderInfo.brackets E1 #
Lean.BinderInfo → String × String
The brackets corresponding to a given BinderInfo.
def Lean.ConstantInfo.isDef E1 #
Lean.ConstantInfo → Bool
Checks whether this ConstantInfo is a definition.
def Lean.ConstantInfo.isThm E1 #
Lean.ConstantInfo → Bool
Checks whether this ConstantInfo is a theorem.
def Lean.ConstantInfo.updateConstantVal E1 #
Lean.ConstantInfo → Lean.ConstantVal → Lean.ConstantInfo
Update ConstantVal (the data common to all constructors of ConstantInfo)
in a ConstantInfo.
def Lean.ConstantInfo.updateName E1 #
Lean.ConstantInfo → Lean.Name → Lean.ConstantInfo
Update the name of a ConstantInfo.
def Lean.ConstantInfo.updateType E1 #
Lean.ConstantInfo → Lean.Expr → Lean.ConstantInfo
Update the type of a ConstantInfo.
def Lean.ConstantInfo.updateLevelParams E1 #
Lean.ConstantInfo → List Lean.Name → Lean.ConstantInfo
Update the level parameters of a ConstantInfo.
def Lean.ConstantInfo.updateAll E1 #
Lean.ConstantInfo → List Lean.Name → Lean.ConstantInfo
Update the mutual-block all field of a ConstantInfo.
This applies to declaration kinds where ConstantInfo.all is stored directly.
def Lean.ConstantInfo.updateValue E1 #
Lean.ConstantInfo → Lean.Expr → Lean.ConstantInfo
Update the value of a ConstantInfo, if it has one.
def Lean.ConstantInfo.toDeclaration! E1 #
Lean.ConstantInfo → Lean.Declaration
Turn a ConstantInfo into a declaration.
def Lean.mkConst' E1 #
Lean.Name → Lean.MetaM Lean.Expr
Same as mkConst, but with fresh level metavariables.
def Lean.Expr.bvarIdx? E1 #
Lean.Expr → Option ℕ
def Lean.Expr.getAppApps E1 #
Lean.Expr → Array Lean.Expr
Given f a b c, return #[f a, f a b, f a b c].
Each entry in the array is an Expr.app,
and this array has the same length as the one returned by Lean.Expr.getAppArgs.
def Lean.Expr.eraseProofs E1 #
Lean.Expr → Lean.MetaM Lean.Expr
Erase proofs in an expression by replacing them with sorrys.
This function replaces all proofs in the expression
and in the types that appear in the expression
by sorryAxs.
The resulting expression has the same type as the old one.
It is useful, e.g., to verify if the proof-irrelevant part of a definition depends on a variable.
def Lean.Expr.type? E1 #
Lean.Expr → Option Lean.Level
If an Expr has the form Type u, then return some u, otherwise none.
opaque Lean.Expr.isAppOrForallOfConstP E1 #
(Lean.Name → Bool) → Lean.Expr → Bool
Returns true if type is an application of a constant decl for which p decl is true, or a
forall with return type of the same form (i.e. of the form ∀ (x₀ : X₀) (x₁ : X₁) ⋯, decl .. where
p decl).
Runs cleanupAnnotations on type and forallE bodies, and ignores metadata in applications.
def Lean.Expr.isAppOrForallOfConst E1 #
Lean.Name → Lean.Expr → Bool
Returns true if type is an application of a constant declName, or a
forall with return type of the same form (i.e. of the form ∀ (x₀ : X₀) (x₁ : X₁) ⋯, declName ..).
Runs cleanupAnnotations on type and forallE bodies, and ignores metadata in applications.
def Lean.Expr.getUnusedForallInstanceBinderIdxsWhere E1 #
(Lean.Expr → Bool) → Lean.Expr → Array ℕ
Gets the indices i (in ascending order) of the binders of a nested .forallE,
(x₀ : A₀) → (x₁ : A₁) → ⋯ → X, such that
- the binder
[xᵢ : Aᵢ]hasinstImplicitbinderInfo p Aᵢistrue- The rest of the type
(xᵢ₊₁ : Aᵢ₊₁) → ⋯ → Xdoes not depend onxᵢ. (It's in this sense thatxᵢ : Aᵢis "unused".)
Note that the argument to p may have loose bvars. This is a performance optimization.
This function runs cleanupAnnotations on each expression before examining it.
We see through lets, and do not increment the index when doing so. This behavior is compatible
with forallBoundedTelescope.
opaque Lean.Expr.hasInstanceBinderOf E1 #
(Lean.Expr → Bool) → Lean.Expr → Bool
Returns true if e includes a forallE instance binder that satisfies p.
Cleans up annotations before traversing nested forallEs, and sees through lets.
def Lean.Expr.letDepth E1 #
Lean.Expr → ℕ
Counts the immediate depth of a nested let expression.
def Lean.Expr.ensureHasNoMVars E1 #
Lean.Expr → Lean.MetaM Unit
Check that an expression contains no metavariables (after instantiation).
def Lean.Expr.ofNat E1 #
Lean.Expr → ℕ → Lean.MetaM Lean.Expr
Construct the term of type α for a given natural number
(doing typeclass search for the OfNat instance required).
def Lean.Expr.ofInt E1 #
Lean.Expr → ℤ → Lean.MetaM Lean.Expr
Construct the term of type α for a given integer
(doing typeclass search for the OfNat and Neg instances required).
opaque Lean.Expr.numeral? E1 #
Lean.Expr → Option ℕ
Return some n if e is one of the following
- a nat literal (numeral)
Nat.zeroNat.succ xwhereisNumeral xOfNat.ofNat _ x _whereisNumeral x
def Lean.Expr.zero? E1 #
Lean.Expr → Bool
Test if an expression is either Nat.zero, or OfNat.ofNat 0.
def Lean.Expr.ne?' E1 #
Lean.Expr → Option (Lean.Expr × Lean.Expr × Lean.Expr)
Tests is if an expression matches either x ≠ y or ¬ (x = y).
If it matches, returns some (type, x, y).
def Lean.Expr.le? E1 #
Lean.Expr → Option (Lean.Expr × Lean.Expr × Lean.Expr)
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.
def Lean.Expr.lt? E1 #
Lean.Expr → Option (Lean.Expr × Lean.Expr × Lean.Expr)
Lean.Expr.lt? 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.
def Lean.Expr.sides? E1 #
Lean.Expr → Option (Lean.Expr × Lean.Expr × Lean.Expr × Lean.Expr)
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?.
def Lean.Expr.isSorryAx E1 #
Lean.Expr → Bool
Returns true if the provided Expr is exactly of the form sorryAx _ _.
This is the form produced by the sorry term/tactic.
Contrast with Lean.Expr.isSorry, which additionally returns true for any function application of
sorry/sorryAx (including e.g. sorryAx α true x y z).
def Lean.Expr.modifyAppArgM E1 #
{M : Type → Type u} → [Functor M] → [Pure M] → (Lean.Expr → M Lean.Expr) → Lean.Expr → M Lean.Expr
def Lean.Expr.modifyRevArg E1 #
(Lean.Expr → Lean.Expr) → ℕ → Lean.Expr → Lean.Expr
def Lean.Expr.modifyArg E1 #
(Lean.Expr → Lean.Expr) → (e : Lean.Expr) → ℕ → optParam ℕ e.getAppNumArgs → Lean.Expr
Given f a₀ a₁ ... aₙ₋₁, runs modifier on the ith argument or
returns the original expression if out of bounds.
def Lean.Expr.setArg E1 #
(e : Lean.Expr) → ℕ → Lean.Expr → optParam ℕ e.getAppNumArgs → Lean.Expr
Given f a₀ a₁ ... aₙ₋₁, sets the argument on the ith argument to x or
returns the original expression if out of bounds.
def Lean.Expr.getRevArg? E1 #
Lean.Expr → ℕ → Option Lean.Expr
def Lean.Expr.getArg? E1 #
(e : Lean.Expr) → ℕ → optParam ℕ e.getAppNumArgs → Option Lean.Expr
Given f a₀ a₁ ... aₙ₋₁, returns the ith argument or none if out of bounds.
def Lean.Expr.modifyArgM E1 #
{M : Type → Type u} →
[Monad M] → (Lean.Expr → M Lean.Expr) → (e : Lean.Expr) → ℕ → optParam ℕ e.getAppNumArgs → M Lean.Expr
Given f a₀ a₁ ... aₙ₋₁, runs modifier on the ith argument.
An argument n may be provided which says how many arguments we are expecting e to have.
def Lean.Expr.renameBVar E1 #
Lean.Expr → Lean.Name → Lean.Name → Lean.Expr
Traverses an expression e and renames bound variables named old to new.
def Lean.Expr.getBinderName E1 #
Lean.Expr → Lean.MetaM (Option Lean.Name)
getBinderName e returns some n if e is an expression of the form ∀ n, ...
and none otherwise.
def Lean.Expr.mapForallBinderNames E1 #
Lean.Expr → (Lean.Name → Lean.Name) → Lean.Expr
Map binder names in a nested forall (a₁ : α₁) → ... → (aₙ : αₙ) → _
def Lean.Expr.mkDirectProjection E1 #
Lean.Expr → Lean.Name → Lean.MetaM Lean.Expr
If e has a structure as type with field fieldName, mkDirectProjection e fieldName creates
the projection expression e.fieldName
def Lean.Expr.mkProjection E1 #
Lean.Expr → Lean.Name → Lean.MetaM Lean.Expr
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
def Lean.Expr.reduceProjStruct? E1 #
Lean.Expr → Lean.MetaM (Option Lean.Expr)
If e is a projection of the structure constructor, reduce the projection.
Otherwise returns none. If this function detects that expression is ill-typed, throws an error.
For example, given Prod.fst (x, y), returns some x.
def Lean.Expr.containsConst E1 #
Lean.Expr → (Lean.Name → Bool) → Bool
Returns true if e contains a name n where p n is true.
def Lean.Expr.forallNot_of_notExists E1 #
Lean.Expr → Lean.Expr → Lean.MetaM (Lean.Expr × Lean.Expr)
Given (hNotEx : Not ex) where ex is of the form Exists x, p x,
return a forall x, Not (p x) and a proof for it.
This function handles nested existentials.
def Lean.getFieldsToParents E1 #
Lean.Environment → Lean.Name → Array Lean.Name
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.