The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V01. The language of Mathlib

Mathlib.Lean.Meta.KAbstractPositions

3 declarations. Mathlib docs · Source

Find the positions of a pattern in an expression

This file defines some tools for dealing with subexpressions and occurrence numbers. This is used for creating a rw tactic call that rewrites a selected expression.

viewKAbstractSubExpr takes an expression and a position in the expression, and returns the subexpression together with an optional occurrence number that would be required to find the subexpression using kabstract (which is what rw uses to find the position of the rewrite)

rw can fail if the motive is not type correct. kabstractIsTypeCorrect checks whether this is the case.

def Lean.Meta.kabstractPositions E1 #

Lean.Expr → Lean.Expr → Lean.MetaM (Array Lean.SubExpr.Pos)

Return the positions that kabstract would abstract for pattern p in expression e. i.e. the positions that unify with p.

def Lean.Meta.viewKAbstractSubExpr E1 #

Lean.Expr → Lean.SubExpr.Pos → Lean.MetaM (Option (Lean.Expr × Option ℕ))

Return the subexpression at position pos in e together with an occurrence number that allows the expression to be found by kabstract. Return none when the subexpression contains loose bound variables.

def Lean.Meta.kabstractIsTypeCorrect E1 #

Lean.Expr → Lean.Expr → Lean.SubExpr.Pos → Lean.MetaM Bool

Determine whether the result of abstracting subExpr from e at position pos results in a well-typed expression. This is important if you want to rewrite at this position.

Here is an example of what goes wrong with an ill-typed kabstract result:

example (h : [5] ≠ []) : List.getLast [5] h = 5 := by
  rw [show [5] = [5] from rfl] -- tactic 'rewrite' failed, motive is not type correct