Documentation

Lean.SubExpr

A position of a subexpression in an expression.

We use a simple encoding scheme for expression positions Pos: every Expr constructor has at most 3 direct expression children. Considering an expression's type to be one extra child as well, we can injectively map a path of childIdxs to a natural number by computing the value of the 4-ary representation 1 :: childIdxs, since n-ary representations without leading zeros are unique. Note that pos is initialized to 1 (case childIdxs == []).

See also SubExpr.

Equations
Instances For

The coordinate 3 = maxChildren - 1 is reserved to denote the type of the expression.

Equations

The Pos representing the root subexpression.

Equations

The coordinate deepest in the Pos.

Equations
Equations
def Lean.SubExpr.Pos.push (p : Pos) (c : Nat) :
Equations
  • One or more equations did not get rendered due to their size.
partial def Lean.SubExpr.Pos.foldl {α : Type} (f : αNatα) (init : α) (p : Pos) :
α

Fold over the position starting at the root and heading to the leaf

partial def Lean.SubExpr.Pos.foldr {α : Type} (f : Natαα) (p : Pos) (init : α) :
α

Fold over the position starting at the leaf and heading to the root

partial def Lean.SubExpr.Pos.foldlM {α : Type} [Inhabited α] {M : TypeType u_1} [Monad M] (f : αNatM α) (init : α) (p : Pos) :
M α

monad-fold over the position starting at the root and heading to the leaf

partial def Lean.SubExpr.Pos.foldrM {α : Type} {M : TypeType u_1} [Monad M] (f : NatαM α) (p : Pos) (init : α) :
M α

monad-fold over the position starting at the leaf and finishing at the root.

Equations
def Lean.SubExpr.Pos.all (pred : NatBool) (p : Pos) :

Returns true if pred is true for each coordinate in p.

Equations

Creates a subexpression Pos from an array of 'coordinates'. Each coordinate is a number {0,1,2} expressing which child subexpression should be explored. The first coordinate in the array corresponds to the root of the expression tree.

Equations

Decodes a subexpression Pos as a sequence of coordinates cs : Array Nat. See Pos.ofArray for details. cs[0] is the coordinate for the root expression.

Equations
Equations
  • p.pushBindingDomain = p.push 0
Equations
  • p.pushBindingBody = p.push 1
Equations
  • p.pushLetVarType = p.push 0
Equations
  • p.pushLetValue = p.push 1
Equations
  • p.pushLetBody = p.push 2
Equations
  • p.pushAppFn = p.push 0
Equations
  • p.pushAppArg = p.push 1
Equations
  • p.pushProj = p.push 0
def Lean.SubExpr.Pos.pushNaryArg (numArgs argIdx : Nat) (p : Pos) :
Equations
Equations
Equations
Equations
Equations
Equations

Returns true if the selected subexpression is the topmost one.

Equations
  • s.isRoot = s.pos.isRoot
@[reducible, inline]
abbrev Lean.SubExpr.PosMap (α : Type u) :

Map from subexpr positions to values.

Equations
Equations
  • { expr := Lean.Expr.forallE binderName binderType b binderInfo, pos := p }.bindingBody! = { expr := b, pos := p.pushBindingBody }
  • { expr := Lean.Expr.lam binderName binderType b binderInfo, pos := p }.bindingBody! = { expr := b, pos := p.pushBindingBody }
  • x✝.bindingBody! = panicWithPosWithDecl "Lean.SubExpr" "Lean.SubExpr.bindingBody!" 179 9 "subexpr is not a binder"
Equations
  • { expr := Lean.Expr.forallE binderName binderType b binderInfo, pos := p }.bindingDomain! = { expr := binderType, pos := p.pushBindingDomain }
  • { expr := Lean.Expr.lam binderName binderType b binderInfo, pos := p }.bindingDomain! = { expr := binderType, pos := p.pushBindingDomain }
  • x✝.bindingDomain! = panicWithPosWithDecl "Lean.SubExpr" "Lean.SubExpr.bindingDomain!" 184 9 "subexpr is not a binder"

A location within a goal.

Instances For

A location within a goal state. It identifies a specific goal together with a GoalLocation within it.

Instances For
def Lean.Expr.traverseAppWithPos {M : TypeType u_1} [Monad M] (visit : SubExpr.PosExprM Expr) (p : SubExpr.Pos) (e : Expr) :

Same as Expr.traverseApp but also includes a SubExpr.Pos argument for tracking subexpression position.

Equations