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 / V34. The tactics of Mathlib

Mathlib.Tactic.DefEqTransformations

25 declarations. Mathlib docs · Source

Tactics that transform types into definitionally equal types

This module defines a standard wrapper that can be used to create tactics that change hypotheses and the goal to things that are definitionally equal.

It then provides a number of tactics that transform local hypotheses and/or the target.

whnf

beta_reduce

reduce

unfold_let

refold_let

unfold_projs

eta_reduce

eta_expand

eta_struct

def Lean.MVarId.changeLocalDecl' E1 #

Lean.MVarId → Lean.FVarId → Lean.Expr → optParam Bool true → Lean.MetaM Lean.MVarId

This is Lean.MVarId.changeLocalDecl but makes sure to preserve local variable order.

def Mathlib.Tactic.runDefEqTactic E1 #

(Option Lean.FVarId → Lean.Expr → Lean.MetaM Lean.Expr) →
  Option (Lean.TSyntax `Lean.Parser.Tactic.location) → String → optParam Bool true → Lean.Elab.Tactic.TacticM Unit

For the main goal, use m to transform the types of locations specified by loc?. If loc? is none, then transforms the type of target. m is provided with an expression with instantiated metavariables as well as, if the location is a local hypothesis, the fvar.

m must transform expressions to defeq expressions. If checkDefEq = true (the default) then runDefEqTactic will throw an error if the resulting expression is not definitionally equal to the original expression.

def Mathlib.Tactic.runDefEqConvTactic E1 #

(Lean.Expr → Lean.MetaM Lean.Expr) → Lean.Elab.Tactic.TacticM Unit

Like Mathlib.Tactic.runDefEqTactic but for conv mode.

def Mathlib.Tactic.tacticWhnf__ E1 #

Lean.ParserDescr

whnf at loc puts the given location into weak-head normal form. This also exists as a conv-mode tactic.

Weak-head normal form is when the outer-most expression has been fully reduced, the expression may contain subexpressions which have not been reduced.

def Mathlib.Tactic.betaReduceStx E1 #

Lean.ParserDescr

beta_reduce at loc completely beta reduces the given location. This also exists as a conv-mode tactic.

This means that whenever there is an applied lambda expression such as (fun x => f x) y then the argument is substituted into the lambda expression yielding an expression such as f y.

def Mathlib.Tactic.convBeta_reduce E1 #

Lean.ParserDescr

beta_reduce at loc completely beta reduces the given location. This also exists as a conv-mode tactic.

This means that whenever there is an applied lambda expression such as (fun x => f x) y then the argument is substituted into the lambda expression yielding an expression such as f y.

def Mathlib.Tactic.tacticReduce__ E1 #

Lean.ParserDescr

reduce at loc completely reduces the given location. This also exists as a conv-mode tactic.

This does the same transformation as the #reduce command.

def Mathlib.Tactic.unfoldFVars E1 #

Array Lean.FVarId → Lean.Expr → Lean.MetaM Lean.Expr

Unfold all the fvars from fvars in e that have local definitions (are "let-bound").

def Mathlib.Tactic.refoldFVars E1 #

Array Lean.FVarId → Option Lean.FVarId → Lean.Expr → Lean.MetaM Lean.Expr

For each fvar, looks for its body in e and replaces it with the fvar.

def Mathlib.Tactic.refoldLetStx E1 #

Lean.ParserDescr

refold_let x y z at loc looks for the bodies of local definitions x, y, and z at the given location and replaces them with x, y, or z. This is the inverse of "zeta reduction." This also exists as a conv-mode tactic.

def Mathlib.Tactic.convRefold_let___ E1 #

Lean.ParserDescr

refold_let x y z at loc looks for the bodies of local definitions x, y, and z at the given location and replaces them with x, y, or z. This is the inverse of "zeta reduction." This also exists as a conv-mode tactic.

def Mathlib.Tactic.unfoldProjs E1 #

Lean.Expr → Lean.MetaM Lean.Expr

Recursively unfold all the projection applications for class instances.

def Mathlib.Tactic.unfoldProjsStx E1 #

Lean.ParserDescr

unfold_projs at loc unfolds projections of class instances at the given location. This also exists as a conv-mode tactic.

def Mathlib.Tactic.convUnfold_projs E1 #

Lean.ParserDescr

unfold_projs at loc unfolds projections of class instances at the given location. This also exists as a conv-mode tactic.

def Mathlib.Tactic.etaReduceAll E1 #

Lean.Expr → Lean.MetaM Lean.Expr

Eta reduce everything

def Mathlib.Tactic.etaReduceStx E1 #

Lean.ParserDescr

eta_reduce at loc eta reduces all sub-expressions at the given location. This also exists as a conv-mode tactic.

For example, fun x y => f x y becomes f after eta reduction.

def Mathlib.Tactic.convEta_reduce E1 #

Lean.ParserDescr

eta_reduce at loc eta reduces all sub-expressions at the given location. This also exists as a conv-mode tactic.

For example, fun x y => f x y becomes f after eta reduction.

opaque Mathlib.Tactic.etaExpandAll E1 #

Lean.Expr → Lean.MetaM Lean.Expr

Eta expand every sub-expression in the given expression.

As a side-effect, beta reduces any pre-existing instances of eta expanded terms.

def Mathlib.Tactic.etaExpandStx E1 #

Lean.ParserDescr

eta_expand at loc eta expands all sub-expressions at the given location. It also beta reduces any applications of eta expanded terms, so it puts it into an eta-expanded "normal form." This also exists as a conv-mode tactic.

For example, if f takes two arguments, then f becomes fun x y => f x y and f x becomes fun y => f x y.

This can be useful to turn, for example, a raw HAdd.hAdd into fun x y => x + y.

def Mathlib.Tactic.convEta_expand E1 #

Lean.ParserDescr

eta_expand at loc eta expands all sub-expressions at the given location. It also beta reduces any applications of eta expanded terms, so it puts it into an eta-expanded "normal form." This also exists as a conv-mode tactic.

For example, if f takes two arguments, then f becomes fun x y => f x y and f x becomes fun y => f x y.

This can be useful to turn, for example, a raw HAdd.hAdd into fun x y => x + y.

def Mathlib.Tactic.getProjectedExpr E1 #

Lean.Expr → Lean.MetaM (Option (Lean.Name × ℕ × Lean.Expr))

Given an expression that's either a native projection or a registered projection function, gives (1) the name of the structure type, (2) the index of the projection, and (3) the object being projected.

def Mathlib.Tactic.etaStruct? E1 #

Lean.Expr → optParam Bool true → Lean.MetaM (Option Lean.Expr)

Checks if the expression is of the form S.mk x.1 ... x.n with n nonzero and S.mk a structure constructor and returns x. Each projection x.i can be either a native projection or from a projection function.

tryWhnfR controls whether to try applying whnfR to arguments when none of them are obviously projections.

Once an obviously correct projection is found, relies on the structure eta rule in isDefEq.

def Mathlib.Tactic.etaStructAll E1 #

Lean.Expr → Lean.MetaM Lean.Expr

Finds all occurrences of expressions of the form S.mk x.1 ... x.n where S.mk is a structure constructor and replaces them by x.

def Mathlib.Tactic.etaStructStx E1 #

Lean.ParserDescr

eta_struct at loc transforms structure constructor applications such as S.mk x.1 ... x.n (pretty printed as, for example, {a := x.a, b := x.b, ...}) into x. This also exists as a conv-mode tactic.

The transformation is known as eta reduction for structures, and it yields definitionally equal expressions.

For example, given x : α × β, then (x.1, x.2) becomes x after this transformation.

def Mathlib.Tactic.convEta_struct E1 #

Lean.ParserDescr

eta_struct at loc transforms structure constructor applications such as S.mk x.1 ... x.n (pretty printed as, for example, {a := x.a, b := x.b, ...}) into x. This also exists as a conv-mode tactic.

The transformation is known as eta reduction for structures, and it yields definitionally equal expressions.

For example, given x : α × β, then (x.1, x.2) becomes x after this transformation.