The areas / V34. The tactics of Mathlib
Mathlib.Tactic.DepRewrite
65 declarations. Mathlib docs · Source
Dependent rewrite tactic
theorem Mathlib.Tactic.DepRewrite.Context.mk.inj E1 #
∀ {cfg : Mathlib.Tactic.DepRewrite.Config} {p x h : Lean.Expr} {Δ : Array (Lean.FVarId × Lean.Expr)}
{δ : Std.HashSet Lean.FVarId} {pHeadIdx : Lean.HeadIndex} {pNumArgs : ℕ} {cfg_1 : Mathlib.Tactic.DepRewrite.Config}
{p_1 x_1 h_1 : Lean.Expr} {Δ_1 : Array (Lean.FVarId × Lean.Expr)} {δ_1 : Std.HashSet Lean.FVarId}
{pHeadIdx_1 : Lean.HeadIndex} {pNumArgs_1 : ℕ},
{ cfg := cfg, p := p, x := x, h := h, Δ := Δ, δ := δ, pHeadIdx := pHeadIdx, pNumArgs := pNumArgs } =
{ cfg := cfg_1, p := p_1, x := x_1, h := h_1, Δ := Δ_1, δ := δ_1, pHeadIdx := pHeadIdx_1,
pNumArgs := pNumArgs_1 } →
cfg = cfg_1 ∧ p = p_1 ∧ x = x_1 ∧ h = h_1 ∧ Δ = Δ_1 ∧ δ = δ_1 ∧ pHeadIdx = pHeadIdx_1 ∧ pNumArgs = pNumArgs_1
theorem Mathlib.Tactic.DepRewrite.Context.mk.injEq E0 #
∀ (cfg : Mathlib.Tactic.DepRewrite.Config) (p x h : Lean.Expr) (Δ : Array (Lean.FVarId × Lean.Expr))
(δ : Std.HashSet Lean.FVarId) (pHeadIdx : Lean.HeadIndex) (pNumArgs : ℕ) (cfg_1 : Mathlib.Tactic.DepRewrite.Config)
(p_1 x_1 h_1 : Lean.Expr) (Δ_1 : Array (Lean.FVarId × Lean.Expr)) (δ_1 : Std.HashSet Lean.FVarId)
(pHeadIdx_1 : Lean.HeadIndex) (pNumArgs_1 : ℕ),
({ cfg := cfg, p := p, x := x, h := h, Δ := Δ, δ := δ, pHeadIdx := pHeadIdx, pNumArgs := pNumArgs } =
{ cfg := cfg_1, p := p_1, x := x_1, h := h_1, Δ := Δ_1, δ := δ_1, pHeadIdx := pHeadIdx_1,
pNumArgs := pNumArgs_1 }) =
(cfg = cfg_1 ∧ p = p_1 ∧ x = x_1 ∧ h = h_1 ∧ Δ = Δ_1 ∧ δ = δ_1 ∧ pHeadIdx = pHeadIdx_1 ∧ pNumArgs = pNumArgs_1)
theorem Mathlib.Tactic.DepRewrite.Config.mk.inj E1 #
∀ {transparency : Lean.Meta.TransparencyMode} {occs : Lean.Meta.Occurrences}
{castMode : Mathlib.Tactic.DepRewrite.CastMode} {castTransparency transparency_1 : Lean.Meta.TransparencyMode}
{occs_1 : Lean.Meta.Occurrences} {castMode_1 : Mathlib.Tactic.DepRewrite.CastMode}
{castTransparency_1 : Lean.Meta.TransparencyMode},
{ transparency := transparency, occs := occs, castMode := castMode, castTransparency := castTransparency } =
{ transparency := transparency_1, occs := occs_1, castMode := castMode_1,
castTransparency := castTransparency_1 } →
transparency = transparency_1 ∧ occs = occs_1 ∧ castMode = castMode_1 ∧ castTransparency = castTransparency_1
def Mathlib.Tactic.DepRewrite.Config.ctorIdx E1 #
Mathlib.Tactic.DepRewrite.Config → ℕ
abbrev Mathlib.Tactic.DepRewrite.CastMode.ctorElimType E1 #
{motive : Mathlib.Tactic.DepRewrite.CastMode → Sort u} → ℕ → Sort (max 1 u)
def Mathlib.Tactic.DepRewrite.Context.ctorIdx E1 #
Mathlib.Tactic.DepRewrite.Context → ℕ
def Mathlib.Tactic.DepRewrite.CastMode.ctorIdx E1 #
Mathlib.Tactic.DepRewrite.CastMode → ℕ
theorem Mathlib.Tactic.DepRewrite.Config.mk.injEq E0 #
∀ (transparency : Lean.Meta.TransparencyMode) (occs : Lean.Meta.Occurrences)
(castMode : Mathlib.Tactic.DepRewrite.CastMode) (castTransparency transparency_1 : Lean.Meta.TransparencyMode)
(occs_1 : Lean.Meta.Occurrences) (castMode_1 : Mathlib.Tactic.DepRewrite.CastMode)
(castTransparency_1 : Lean.Meta.TransparencyMode),
({ transparency := transparency, occs := occs, castMode := castMode, castTransparency := castTransparency } =
{ transparency := transparency_1, occs := occs_1, castMode := castMode_1,
castTransparency := castTransparency_1 }) =
(transparency = transparency_1 ∧ occs = occs_1 ∧ castMode = castMode_1 ∧ castTransparency = castTransparency_1)
theorem Mathlib.Tactic.DepRewrite.dcongrArg E1 #
∀ {α : Sort u} {a a' : α} {β : (a' : α) → a = a' → Sort v} (h : a = a') (f : (a' : α) → (h : a = a') → β a' h),
f a ⋯ = ⋯ ▸ f a' h
theorem Mathlib.Tactic.DepRewrite.hdcongrArg E1 #
∀ {α : Sort u} {a a' : α} {β : (a' : α) → a = a' → Sort v} (h : a = a') (f : (a' : α) → (h : a = a') → β a' h),
f a ⋯ ≍ f a' h
theorem Mathlib.Tactic.DepRewrite.heqL E1 #
∀ {α β : Sort u} {a : α} {b : β} (h : a ≍ b), a = cast ⋯ b
theorem Mathlib.Tactic.DepRewrite.heqR E1 #
∀ {α β : Sort u} {a : α} {b : β} (h : a ≍ b), cast ⋯ a = b
inductive Mathlib.Tactic.DepRewrite.CastMode E1 #
Type
See Config.castMode.
ctor Mathlib.Tactic.DepRewrite.CastMode.proofs E0 #
Mathlib.Tactic.DepRewrite.CastMode
Only insert casts on proofs.
In this mode, it is not permitted to cast subterms of proofs that are not themselves proofs.
ctor Mathlib.Tactic.DepRewrite.CastMode.all E0 #
Mathlib.Tactic.DepRewrite.CastMode
Insert casts whenever necessary.
instance Mathlib.Tactic.DepRewrite.instBEqCastMode E0 #
BEq Mathlib.Tactic.DepRewrite.CastMode
def Mathlib.Tactic.DepRewrite.instBEqCastMode.beq E1 #
Mathlib.Tactic.DepRewrite.CastMode → Mathlib.Tactic.DepRewrite.CastMode → Bool
instance Mathlib.Tactic.DepRewrite.instToStringCastMode E0 #
ToString Mathlib.Tactic.DepRewrite.CastMode
def Mathlib.Tactic.DepRewrite.CastMode.toNat E1 #
Mathlib.Tactic.DepRewrite.CastMode → ℕ
Embedding of CastMode into naturals.
instance Mathlib.Tactic.DepRewrite.instLECastMode E0 #
LE Mathlib.Tactic.DepRewrite.CastMode
instance Mathlib.Tactic.DepRewrite.instDecidableLECastMode E0 #
DecidableLE Mathlib.Tactic.DepRewrite.CastMode
structure Mathlib.Tactic.DepRewrite.Config E1 #
Type
Configures the behavior of the rewrite! and rw! tactics.
ctor Mathlib.Tactic.DepRewrite.Config.mk E0 #
Lean.Meta.TransparencyMode →
Lean.Meta.Occurrences →
Mathlib.Tactic.DepRewrite.CastMode → Lean.Meta.TransparencyMode → Mathlib.Tactic.DepRewrite.Config
abbrev Mathlib.Tactic.DepRewrite.Config.transparency E1 #
Mathlib.Tactic.DepRewrite.Config → Lean.Meta.TransparencyMode
Which transparency level to use when unifying the rewrite rule's LHS against subterms of the term being rewritten.
abbrev Mathlib.Tactic.DepRewrite.Config.occs E1 #
Mathlib.Tactic.DepRewrite.Config → Lean.Meta.Occurrences
Which occurrences to rewrite.
abbrev Mathlib.Tactic.DepRewrite.Config.castMode E1 #
Mathlib.Tactic.DepRewrite.Config → Mathlib.Tactic.DepRewrite.CastMode
The cast mode specifies when rewrite! is permitted to insert casts
in order to correct subterms that become type-incorrect
as a result of rewriting.
For example, given P : Nat → Prop, f : (n : Nat) → P n → Nat and h : P n₀,
rewriting f n₀ h by eq : n₀ = n₁ produces f n₁ h,
where h does not typecheck at P n₁.
The tactic will cast h to eq ▸ h : P n₁ iff .proofs ≤ castMode.
abbrev Mathlib.Tactic.DepRewrite.Config.castTransparency E1 #
Mathlib.Tactic.DepRewrite.Config → Lean.Meta.TransparencyMode
Which transparency level to use when cleaning up casts to decide if a cast is a refl-cast.
structure Mathlib.Tactic.DepRewrite.Context E1 #
Type
ReaderT context for M.
ctor Mathlib.Tactic.DepRewrite.Context.mk E0 #
Mathlib.Tactic.DepRewrite.Config →
Lean.Expr →
Lean.Expr →
Lean.Expr →
Array (Lean.FVarId × Lean.Expr) →
Std.HashSet Lean.FVarId → Lean.HeadIndex → ℕ → Mathlib.Tactic.DepRewrite.Context
abbrev Mathlib.Tactic.DepRewrite.Context.cfg E1 #
Mathlib.Tactic.DepRewrite.Context → Mathlib.Tactic.DepRewrite.Config
Configuration.
abbrev Mathlib.Tactic.DepRewrite.Context.p E1 #
Mathlib.Tactic.DepRewrite.Context → Lean.Expr
The pattern to generalize over.
abbrev Mathlib.Tactic.DepRewrite.Context.x E1 #
Mathlib.Tactic.DepRewrite.Context → Lean.Expr
The free variable to substitute for p.
abbrev Mathlib.Tactic.DepRewrite.Context.h E1 #
Mathlib.Tactic.DepRewrite.Context → Lean.Expr
A proof of p = x. Must be an fvar.
abbrev Mathlib.Tactic.DepRewrite.Context.Δ E1 #
Mathlib.Tactic.DepRewrite.Context → Array (Lean.FVarId × Lean.Expr)
The list of value-less binders (cdecls and nondependent ldecls)
that we have introduced.
Together with each binder, we store its type abstracted over x and h,
and with all occurrences of previous entries in Δ
casted along the abstracting equation.
E.g., if the local context is a : T, b : U,
we store (a, Ma) where Ma := fun (x' : α) (h' : x = x') => T[x'/x, h'/h]
and (b, fun (x' : α) (h' : x = x') => U[x'/x, h'/h, (Eq.rec (motive := Ma) a h)/a])
See the docstring on visitAndCast.
abbrev Mathlib.Tactic.DepRewrite.Context.δ E1 #
Mathlib.Tactic.DepRewrite.Context → Std.HashSet Lean.FVarId
The set of all dependent ldecls that we have introduced.
abbrev Mathlib.Tactic.DepRewrite.Context.pHeadIdx E1 #
Mathlib.Tactic.DepRewrite.Context → Lean.HeadIndex
Cached p.toHeadIndex.
abbrev Mathlib.Tactic.DepRewrite.Context.pNumArgs E1 #
Mathlib.Tactic.DepRewrite.Context → ℕ
Cached p.toNumArgs.
def Mathlib.Tactic.DepRewrite.canUseCache E1 #
ℕ → ℕ → ℕ → Lean.Meta.Occurrences → Bool
We use a cache entry iff the upcoming traversal would abstract exactly the same occurrences as the cached traversal.
abbrev Mathlib.Tactic.DepRewrite.M E1 #
Type → Type
Monad for computing dabstract.
The Nat state tracks which occurrence of the pattern we are about to see, 1-indexed
(so the initial value is 1).
The cache stores results of visit together with
- the
Natstate before the cached call; and - the difference in the state resulting from the call.
We store these because even if the cache hits,
we must update the state as if the call had been made.
Storing the difference suffices because the state increases monotonically.
See also canUseCache.
def Mathlib.Tactic.DepRewrite.checkCastAllowed E1 #
Lean.Expr → Lean.Expr → Mathlib.Tactic.DepRewrite.CastMode → Lean.MetaM Unit
Check that casting e : t is allowed in the current mode.
(We don't need to know what type e is cast to:
we only check the sort of t, and it cannot change.)
def Mathlib.Tactic.DepRewrite.zetaDelta E1 #
Lean.Expr → Std.HashSet Lean.FVarId → Lean.MetaM Lean.Expr
In e, inline the values of those ldecls that appear in fvars.
def Mathlib.Tactic.DepRewrite.castMData E1 #
Lean.MData
A piece of metadata associated with depRewrite.
def Mathlib.Tactic.DepRewrite.castBack? E1 #
Lean.Expr →
Lean.Expr →
Lean.Expr → Lean.Expr → Array (Lean.FVarId × Lean.Expr) → Std.HashSet Lean.FVarId → Lean.MetaM (Option Lean.Expr)
If e : te is a term whose type mentions x, h (the generalization variables)
or entries in Δ/δ,
return h.symm ▸ e : te[p/x, rfl/h, …].
Otherwise return none.
def Mathlib.Tactic.DepRewrite.castFwd E1 #
Lean.Expr →
Lean.Expr →
Lean.Expr → Lean.Expr → Lean.Expr → Array (Lean.FVarId × Lean.Expr) → Std.HashSet Lean.FVarId → Lean.MetaM Lean.Expr
Cast e : te[p/x, rfl/h, ...] to h ▸ e : te.
opaque Mathlib.Tactic.DepRewrite.visitAndCast E1 #
Lean.Expr → Option Lean.Expr → Mathlib.Tactic.DepRewrite.M Lean.Expr
Given e, return e' where e' has had
- the occurrences of
pinctx.cfg.occsreplaced byx; and - subterms cast as appropriate in order to make
e'type-correct.
If et? is not none, the output is guaranteed to have type (defeq to) et?.
We do not assume that e is well-typed.
We use this when processing binders:
to traverse ∀ (x : α), β,
we obtain α' ← visit α,
add x : α' to the local context
and continue traversing β.
Although x : α' ⊢ β may not hold,
the output β' should have x : α' ⊢ β' (otherwise we have a bug).
To achieve this, we maintain the invariant
that all entries in the local context that we have introduced
can be translated back to their original (pre-visit) types
using the motive computed by castBack?.motive.
(But we have not attempted to prove this.)
opaque Mathlib.Tactic.DepRewrite.visit E1 #
Lean.Expr → Option Lean.Expr → Mathlib.Tactic.DepRewrite.M Lean.Expr
Like visitAndCast, but does not insert casts at the top level.
The expected types of certain subterms are computed from et?.
opaque Mathlib.Tactic.DepRewrite.visitInner E1 #
Lean.Expr → Option Lean.Expr → Mathlib.Tactic.DepRewrite.M Lean.Expr
See visit.
def Mathlib.Tactic.DepRewrite.dabstract E1 #
Lean.Expr → Lean.Expr → Mathlib.Tactic.DepRewrite.Config → Lean.MetaM Lean.Expr
Analogue of kabstract with support for inserting casts.
def Lean.MVarId.depRewrite E1 #
Lean.MVarId →
Lean.Expr →
Lean.Expr → optParam Bool false → optParam Mathlib.Tactic.DepRewrite.Config { } → Lean.MetaM Lean.Meta.RewriteResult
Analogue of Lean.MVarId.rewrite with support for inserting casts.
def Mathlib.Tactic.DepRewrite.cleanupCasts E1 #
Lean.Expr → Lean.MetaM Lean.Expr
Cleanup casts introduced by rewrite! in e.
The result is expected to be defeq to the original expression.
def Mathlib.Tactic.DepRewrite.depRewriteSeq E1 #
Lean.ParserDescr
rewrite! is like rewrite,
but can also insert casts to adjust types that depend on the LHS of a rewrite.
It is available as an ordinary tactic and a conv tactic.
The sort of casts that are inserted is controlled by the castMode configuration option.
By default, only proof terms are casted;
by proof irrelevance, this adds no observable complexity.
With rewrite! +letAbs (castMode := .all), casts are inserted whenever necessary.
This means that the 'motive is not type correct' error never occurs,
at the expense of creating potentially complicated terms.
def Mathlib.Tactic.DepRewrite.depRwSeq E1 #
Lean.ParserDescr
rw! is like rewrite!, but also cleans up introduced refl-casts after every substitution.
It is available as an ordinary tactic and a conv tactic.
def Mathlib.Tactic.DepRewrite.depRewriteTarget E1 #
Lean.Syntax → Bool → optParam Mathlib.Tactic.DepRewrite.Config { } → Lean.Elab.Tactic.TacticM Unit
Apply rewrite! to the goal.
def Mathlib.Tactic.DepRewrite.depRwTarget E1 #
Lean.Syntax → Bool → optParam Mathlib.Tactic.DepRewrite.Config { } → Lean.Elab.Tactic.TacticM Unit
Apply rw! to the goal.
def Mathlib.Tactic.DepRewrite.depRewriteLocalDecl E1 #
Lean.Syntax → Bool → Lean.FVarId → optParam Mathlib.Tactic.DepRewrite.Config { } → Lean.Elab.Tactic.TacticM Unit
Apply rewrite! to a local declaration.
def Mathlib.Tactic.DepRewrite.depRwLocalDecl E1 #
Lean.Syntax → Bool → Lean.FVarId → optParam Mathlib.Tactic.DepRewrite.Config { } → Lean.Elab.Tactic.TacticM Unit
Apply rw! to a local declaration.
def Mathlib.Tactic.DepRewrite.elabDepRewriteConfig E1 #
Lean.Syntax →
optParam Mathlib.Tactic.DepRewrite.Config { } →
optParam Bool true → Lean.Elab.Tactic.TacticM Mathlib.Tactic.DepRewrite.Config
Elaborate DepRewrite.Config.
def Mathlib.Tactic.DepRewrite.evalDepRewriteSeq E1 #
Lean.Elab.Tactic.Tactic
rewrite! is like rewrite,
but can also insert casts to adjust types that depend on the LHS of a rewrite.
It is available as an ordinary tactic and a conv tactic.
The sort of casts that are inserted is controlled by the castMode configuration option.
By default, only proof terms are casted;
by proof irrelevance, this adds no observable complexity.
With rewrite! +letAbs (castMode := .all), casts are inserted whenever necessary.
This means that the 'motive is not type correct' error never occurs,
at the expense of creating potentially complicated terms.
def Mathlib.Tactic.DepRewrite.evalDepRwSeq E1 #
Lean.Elab.Tactic.Tactic
rw! is like rewrite!, but also cleans up introduced refl-casts after every substitution.
It is available as an ordinary tactic and a conv tactic.
def Mathlib.Tactic.DepRewrite.Conv.depRewrite E1 #
Lean.ParserDescr
rewrite! is like rewrite,
but can also insert casts to adjust types that depend on the LHS of a rewrite.
It is available as an ordinary tactic and a conv tactic.
The sort of casts that are inserted is controlled by the castMode configuration option.
By default, only proof terms are casted;
by proof irrelevance, this adds no observable complexity.
With rewrite! +letAbs (castMode := .all), casts are inserted whenever necessary.
This means that the 'motive is not type correct' error never occurs,
at the expense of creating potentially complicated terms.
def Mathlib.Tactic.DepRewrite.Conv.depRw E1 #
Lean.ParserDescr
rw! is like rewrite!, but also cleans up introduced refl-casts after every substitution.
It is available as an ordinary tactic and a conv tactic.
def Mathlib.Tactic.DepRewrite.Conv.depRewriteTarget E1 #
Lean.Syntax → Bool → optParam Mathlib.Tactic.DepRewrite.Config { } → Lean.Elab.Tactic.TacticM Unit
Apply rewrite! to the goal.
def Mathlib.Tactic.DepRewrite.Conv.depRwTarget E1 #
Lean.Syntax → Bool → optParam Mathlib.Tactic.DepRewrite.Config { } → Lean.Elab.Tactic.TacticM Unit
Apply rw! to the goal.
def Mathlib.Tactic.DepRewrite.Conv.evalDepRewriteSeq E1 #
Lean.Elab.Tactic.Tactic
rewrite! is like rewrite,
but can also insert casts to adjust types that depend on the LHS of a rewrite.
It is available as an ordinary tactic and a conv tactic.
The sort of casts that are inserted is controlled by the castMode configuration option.
By default, only proof terms are casted;
by proof irrelevance, this adds no observable complexity.
With rewrite! +letAbs (castMode := .all), casts are inserted whenever necessary.
This means that the 'motive is not type correct' error never occurs,
at the expense of creating potentially complicated terms.
def Mathlib.Tactic.DepRewrite.Conv.evalDepRwSeq E1 #
Lean.Elab.Tactic.Tactic
rw! is like rewrite!, but also cleans up introduced refl-casts after every substitution.
It is available as an ordinary tactic and a conv tactic.