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.GRewrite.Core

19 declarations. Mathlib docs · Source

The generalized rewriting tactic

This module defines the core of the grw/grewrite tactic.

This file provides two implementations of the tactic:

  1. The simple implementation uses kabstract to determine where to rewrite, and then calls MVarId.gcongr to prove that the rewrite is valid. This is used by nth_grw and grw +useKAbstract.
  2. The more sophisticated implementation has its own congruence loop, applying gcongr lemmas to create the replacement expression, and to prove that this is related to the original expression. This supports the use of strict inequalities to change the strictness in the goal. This is used by grw and apply_rw.

theorem Mathlib.Tactic.GRewrite.Config.mk.inj E1 #

∀ {toConfig : Lean.Meta.Rewrite.Config} {useRewrite implicationHyp useKAbstract : Bool}
  {toConfig_1 : Lean.Meta.Rewrite.Config} {useRewrite_1 implicationHyp_1 useKAbstract_1 : Bool},
  { toConfig := toConfig, useRewrite := useRewrite, implicationHyp := implicationHyp, useKAbstract := useKAbstract } =
      { toConfig := toConfig_1, useRewrite := useRewrite_1, implicationHyp := implicationHyp_1,
        useKAbstract := useKAbstract_1 } →
    toConfig = toConfig_1 ∧
      useRewrite = useRewrite_1 ∧ implicationHyp = implicationHyp_1 ∧ useKAbstract = useKAbstract_1

def Mathlib.Tactic.GRewrite.GRewriteResult.ctorIdx E1 #

Mathlib.Tactic.GRewrite.GRewriteResult → ℕ

theorem Mathlib.Tactic.GRewrite.GRewriteResult.mk.inj E1 #

∀ {eNew impProof : Lean.Expr} {mvarIds : List Lean.MVarId} {lctx? : Option Lean.LocalContext}
  {eNew_1 impProof_1 : Lean.Expr} {mvarIds_1 : List Lean.MVarId} {lctx?_1 : Option Lean.LocalContext},
  { eNew := eNew, impProof := impProof, mvarIds := mvarIds, lctx? := lctx? } =
      { eNew := eNew_1, impProof := impProof_1, mvarIds := mvarIds_1, lctx? := lctx?_1 } →
    eNew = eNew_1 ∧ impProof = impProof_1 ∧ mvarIds = mvarIds_1 ∧ lctx? = lctx?_1

def Mathlib.Tactic.GRewrite.Config.ctorIdx E1 #

Mathlib.Tactic.GRewrite.Config → ℕ

theorem Mathlib.Tactic.GRewrite.GRewriteResult.mk.injEq E0 #

∀ (eNew impProof : Lean.Expr) (mvarIds : List Lean.MVarId) (lctx? : Option Lean.LocalContext)
  (eNew_1 impProof_1 : Lean.Expr) (mvarIds_1 : List Lean.MVarId) (lctx?_1 : Option Lean.LocalContext),
  ({ eNew := eNew, impProof := impProof, mvarIds := mvarIds, lctx? := lctx? } =
      { eNew := eNew_1, impProof := impProof_1, mvarIds := mvarIds_1, lctx? := lctx?_1 }) =
    (eNew = eNew_1 ∧ impProof = impProof_1 ∧ mvarIds = mvarIds_1 ∧ lctx? = lctx?_1)

theorem Mathlib.Tactic.GRewrite.Config.mk.injEq E0 #

∀ (toConfig : Lean.Meta.Rewrite.Config) (useRewrite implicationHyp useKAbstract : Bool)
  (toConfig_1 : Lean.Meta.Rewrite.Config) (useRewrite_1 implicationHyp_1 useKAbstract_1 : Bool),
  ({ toConfig := toConfig, useRewrite := useRewrite, implicationHyp := implicationHyp, useKAbstract := useKAbstract } =
      { toConfig := toConfig_1, useRewrite := useRewrite_1, implicationHyp := implicationHyp_1,
        useKAbstract := useKAbstract_1 }) =
    (toConfig = toConfig_1 ∧
      useRewrite = useRewrite_1 ∧ implicationHyp = implicationHyp_1 ∧ useKAbstract = useKAbstract_1)

structure Mathlib.Tactic.GRewrite.GRewriteResult E1 #

Type

The result returned by Lean.MVarId.grewrite.

ctor Mathlib.Tactic.GRewrite.GRewriteResult.mk E0 #

Lean.Expr → Lean.Expr → List Lean.MVarId → Option Lean.LocalContext → Mathlib.Tactic.GRewrite.GRewriteResult

abbrev Mathlib.Tactic.GRewrite.GRewriteResult.eNew E1 #

Mathlib.Tactic.GRewrite.GRewriteResult → Lean.Expr

The rewritten expression

abbrev Mathlib.Tactic.GRewrite.GRewriteResult.impProof E1 #

Mathlib.Tactic.GRewrite.GRewriteResult → Lean.Expr

The proof of the implication. The direction depends on the argument forwardImp.

abbrev Mathlib.Tactic.GRewrite.GRewriteResult.mvarIds E1 #

Mathlib.Tactic.GRewrite.GRewriteResult → List Lean.MVarId

The new side goals

abbrev Mathlib.Tactic.GRewrite.GRewriteResult.lctx? E1 #

Mathlib.Tactic.GRewrite.GRewriteResult → Option Lean.LocalContext

The outermost local context in which the rewrite makes sense. If the rewrite does not involve bound variables, this is none. This is used for fixing the generated info tree, so that the "Expected Type" is displayed correctly.

structure Mathlib.Tactic.GRewrite.Config E1 #

Type

Configures the behavior of the rewrite and rw tactics.

ctor Mathlib.Tactic.GRewrite.Config.mk E0 #

Lean.Meta.Rewrite.Config → Bool → Bool → Bool → Mathlib.Tactic.GRewrite.Config

abbrev Mathlib.Tactic.GRewrite.Config.toConfig E1 #

Mathlib.Tactic.GRewrite.Config → Lean.Meta.Rewrite.Config

abbrev Mathlib.Tactic.GRewrite.Config.useRewrite E1 #

Mathlib.Tactic.GRewrite.Config → Bool

When useRewrite = true, switch to using the default rewrite tactic when the goal is and equality or iff.

abbrev Mathlib.Tactic.GRewrite.Config.implicationHyp E1 #

Mathlib.Tactic.GRewrite.Config → Bool

When implicationHyp = true, interpret the rewrite rule as an implication.

abbrev Mathlib.Tactic.GRewrite.Config.useKAbstract E1 #

Mathlib.Tactic.GRewrite.Config → Bool

Whether to use kabstract to find the rewrites locations.

def Lean.MVarId.grewrite E1 #

Lean.MVarId →
  Lean.Expr →
    Lean.Expr →
      Array (Lean.MVarId × Array Lean.LocalDecl) →
        Bool → Bool → Mathlib.Tactic.GRewrite.Config → Lean.MetaM Mathlib.Tactic.GRewrite.GRewriteResult

Rewrite e using the relation hrel : x ~ y, and construct an implication proof using the gcongr tactic to discharge this goal.

if forwardImp = true, we prove that e → eNew; otherwise eNew → e.

If symm = false, we rewrite e to eNew := e[x/y]; otherwise eNew := e[y/x].

The code aligns with Lean.MVarId.rewrite as much as possible.