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.Util.AtLocation

18 declarations. Mathlib docs · Source

Rewriting at specified locations

Many metaprograms have the following general structure: the input is an expression e and the output is a new expression e', together with a proof that e = e'.

This file provides convenience functions to turn such a metaprogram into a variety of tactics: using the metaprogram to modify the goal, a specified hypothesis, or (via Tactic.Location) a combination of these.

abbrev Mathlib.Tactic.BehaviorIfUnchanged.ctorElimType E1 #

{motive : Mathlib.Tactic.BehaviorIfUnchanged → Sort u} → ℕ → Sort (max 1 u)

def Mathlib.Tactic.BehaviorIfUnchanged.ctorIdx E1 #

Mathlib.Tactic.BehaviorIfUnchanged → ℕ

def Mathlib.Tactic.instInhabitedBehaviorIfUnchanged.default E1 #

Mathlib.Tactic.BehaviorIfUnchanged

def Lean.Elab.Tactic.withNondepPropLocation E1 #

Lean.Elab.Tactic.Location →
  (Lean.FVarId → Lean.Elab.Tactic.TacticM Unit) →
    Lean.Elab.Tactic.TacticM Unit → (Lean.MVarId → Lean.Elab.Tactic.TacticM Unit) → Lean.Elab.Tactic.TacticM Unit

Runs the given atLocal and atTarget methods on each of the locations selected by the given loc.

  • If loc is a list of locations, runs at each specified hypothesis (and finally the goal if ⊢ is included), and fails if any of the tactic applications fail. If an earlier location closes the goal, later unused locations are an error.
  • If loc is *, runs at the target and at the nondependent Prop hypotheses in reversed order (those produced by Lean.MVarId.getNondepPropHyps), calling failed if no location succeeds.

The implementation adapts Lean.Elab.Tactic.withLocation with a restricted wildcard.

def Lean.Elab.Tactic.mapNondepPropLocation E1 #

{α : Type} →
  Lean.Elab.Tactic.Location →
    (Lean.FVarId → Lean.Elab.Tactic.TacticM α) → Lean.Elab.Tactic.TacticM α → Lean.Elab.Tactic.TacticM (Array α)

Collect the values from running the atLocal and atTarget methods on each of the locations selected by the given loc.

  • If loc is a list of locations, collects the results of running at each specified hypothesis (and finally the goal if ⊢ is included), and fails if any of the applications fail.
  • If loc is *, collects the results of running at the target and at the nondependent Prop hypotheses (those produced by Lean.MVarId.getNondepPropHyps). Locations where the application fails are skipped, so the result can be empty.

inductive Mathlib.Tactic.BehaviorIfUnchanged E1 #

Type

Different settings of communicating about a tactic which made no progress: do nothing (keep silent), print a warning or throw an error.

ctor Mathlib.Tactic.BehaviorIfUnchanged.silent E0 #

Mathlib.Tactic.BehaviorIfUnchanged

Stay silent if this action has no effect.

ctor Mathlib.Tactic.BehaviorIfUnchanged.warning E0 #

Mathlib.Tactic.BehaviorIfUnchanged

Log a warning if this action has no effect.

ctor Mathlib.Tactic.BehaviorIfUnchanged.error E0 #

Mathlib.Tactic.BehaviorIfUnchanged

Throw an error if this action has no effect.

instance Mathlib.Tactic.instReprBehaviorIfUnchanged E0 #

Repr Mathlib.Tactic.BehaviorIfUnchanged

instance Mathlib.Tactic.instBEqBehaviorIfUnchanged E0 #

BEq Mathlib.Tactic.BehaviorIfUnchanged

def Mathlib.Tactic.instBEqBehaviorIfUnchanged.beq E1 #

Mathlib.Tactic.BehaviorIfUnchanged → Mathlib.Tactic.BehaviorIfUnchanged → Bool

def Mathlib.Tactic.instReprBehaviorIfUnchanged.repr E1 #

Mathlib.Tactic.BehaviorIfUnchanged → ℕ → Std.Format

instance Mathlib.Tactic.instInhabitedBehaviorIfUnchanged E0 #

Inhabited Mathlib.Tactic.BehaviorIfUnchanged

def Mathlib.Tactic.transformAtTarget E1 #

(Lean.Expr → ReaderT Lean.Meta.Simp.Context Lean.MetaM Lean.Meta.Simp.Result) →
  String →
    Mathlib.Tactic.BehaviorIfUnchanged → Lean.MVarId → ReaderT Lean.Meta.Simp.Context Lean.MetaM (Option Lean.MVarId)

Use the procedure m to rewrite the provided goal.

Assumes proc is not surrounded by backticks.

def Mathlib.Tactic.transformAtLocalDecl E1 #

(Lean.Expr → ReaderT Lean.Meta.Simp.Context Lean.MetaM Lean.Meta.Simp.Result) →
  String →
    Mathlib.Tactic.BehaviorIfUnchanged →
      Bool → Lean.FVarId → Lean.MVarId → ReaderT Lean.Meta.Simp.Context Lean.MetaM (Option Lean.MVarId)

Use the procedure m to rewrite hypothesis fvarId.

The simpTheorems of the simp-context carried with m will be modified to remove fvarId; this ensures that if the procedure m involves rewriting by this SimpTheoremsArray, then, e.g., h : x = y is not transformed (by rewriting h) to True.

Assumes proc is not surrounded by backticks.

def Mathlib.Tactic.transformAtLocation E1 #

(Lean.Expr → ReaderT Lean.Meta.Simp.Context Lean.MetaM Lean.Meta.Simp.Result) →
  String →
    Lean.Elab.Tactic.Location →
      optParam Mathlib.Tactic.BehaviorIfUnchanged Mathlib.Tactic.BehaviorIfUnchanged.error →
        optParam Bool false → optParam Lean.Meta.Simp.Context default → Lean.Elab.Tactic.TacticM Unit

Use the procedure m to transform at specified locations (hypotheses and/or goal).

Assumes proc is not surrounded by backticks.

def Mathlib.Tactic.transformAtNondepPropLocation E1 #

(Lean.Expr → ReaderT Lean.Meta.Simp.Context Lean.MetaM Lean.Meta.Simp.Result) →
  String →
    Lean.Elab.Tactic.Location →
      optParam Mathlib.Tactic.BehaviorIfUnchanged Mathlib.Tactic.BehaviorIfUnchanged.error →
        optParam Bool false → optParam Lean.Meta.Simp.Context default → Lean.Elab.Tactic.TacticM Unit

Use the procedure m to transform at specified locations (hypotheses and/or goal).

In the wildcard case (*), filter out all dependent and/or non-Prop hypotheses.

Assumes proc is not surrounded by backticks.