The areas / V34. The tactics of Mathlib
Mathlib.Tactic.Peel
16 declarations. Mathlib docs · Source
The peel tactic
peel h with h' idents* tries to apply forall_imp (or Exists.imp, or Filter.Eventually.mp,
Filter.Frequently.mp and Filter.Eventually.of_forall) with the argument h and uses idents*
to introduce variables with the supplied names, giving the "peeled" argument the name h'.
One can provide a numeric argument as in peel 4 h which will peel 4 quantifiers off
the expressions automatically name any variables not specifically named in the with clause.
In addition, the user may supply a term e via ... using e in order to close the goal
immediately. In particular, peel h using e is equivalent to peel h; exact e. The using syntax
may be paired with any of the other features of peel.
def Mathlib.Tactic.Peel.peel E1 #
Lean.ParserDescr
Peels matching quantifiers off of a given term and the goal and introduces the relevant variables.
peel epeels all quantifiers (at reducible transparency), usingthisfor the name of the peeled hypothesis.peel e with hispeel ebut names the peeled hypothesish. Ifhis_then usesthisfor the name of the peeled hypothesis.peel n epeelsnquantifiers (at default transparency).peel n e with x y z ... hpeelsnquantifiers, names the peeled hypothesish, and usesx,y,z, and so on to name the introduced variables; these names may be_. Ifhis_then usesthisfor the name of the peeled hypothesis. The length of the list of variables does not need to equaln.peel e with x₁ ... xₙ hispeel n e with x₁ ... xₙ h.
There are also variants that apply to an iff in the goal:
peel npeelsnquantifiers in an iff.peel with x₁ ... xₙpeelsnquantifiers in an iff and names them.
Given p q : ℕ → Prop, h : ∀ x, p x, and a goal ⊢ : ∀ x, q x, the tactic peel h with x h'
will introduce x : ℕ, h' : p x into the context and the new goal will be ⊢ q x. This works
with ∃, as well as ∀ᶠ and ∃ᶠ, and it can even be applied to a sequence of quantifiers. Note
that this is a logically weaker setup, so using this tactic is not always feasible.
For a more complex example, given a hypothesis and a goal:
h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
⊢ ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) ≤ ε
(which differ only in </≤), applying peel h with ε hε N n hn h_peel will yield a tactic state:
h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
ε : ℝ
hε : 0 < ε
N n : ℕ
hn : N ≤ n
h_peel : 1 / (n + 1 : ℝ) < ε
⊢ 1 / (n + 1 : ℝ) ≤ ε
and the goal can be closed with exact h_peel.le.
Note that in this example, h and the goal are logically equivalent statements, but peel
cannot be immediately applied to show that the goal implies h.
In addition, peel supports goals of the form (∀ x, p x) ↔ ∀ x, q x, or likewise for any
other quantifier. In this case, there is no hypothesis or term to supply, but otherwise the syntax
is the same. So for such goals, the syntax is peel 1 or peel with x, and after which the
resulting goal is p x ↔ q x. The congr! tactic can also be applied to goals of this form using
congr! 1 with x. While congr! applies congruence lemmas in general, peel can be relied upon
to only apply to outermost quantifiers.
Finally, the user may supply a term e via ... using e in order to close the goal
immediately. In particular, peel h using e is equivalent to peel h; exact e. The using syntax
may be paired with any of the other features of peel.
This tactic works by repeatedly applying lemmas such as forall_imp, Exists.imp,
Filter.Eventually.mp, Filter.Frequently.mp, and Filter.Eventually.of_forall.
theorem Mathlib.Tactic.Peel.and_imp_left_of_imp_imp E1 #
∀ {p q r : Prop}, (r → p → q) → r ∧ p → r ∧ q
theorem Mathlib.Tactic.Peel.eventually_imp E1 #
∀ {α : Type u_1} {p q : α → Prop} {f : Filter α}, (∀ (x : α), p x → q x) → (∀ᶠ (x : α) in f, p x) → ∀ᶠ (x : α) in f, q x
theorem Mathlib.Tactic.Peel.frequently_imp E1 #
∀ {α : Type u_1} {p q : α → Prop} {f : Filter α}, (∀ (x : α), p x → q x) → (∃ᶠ (x : α) in f, p x) → ∃ᶠ (x : α) in f, q x
theorem Mathlib.Tactic.Peel.eventually_congr E1 #
∀ {α : Type u_1} {p q : α → Prop} {f : Filter α},
(∀ (x : α), p x ↔ q x) → ((∀ᶠ (x : α) in f, p x) ↔ ∀ᶠ (x : α) in f, q x)
theorem Mathlib.Tactic.Peel.frequently_congr E1 #
∀ {α : Type u_1} {p q : α → Prop} {f : Filter α},
(∀ (x : α), p x ↔ q x) → ((∃ᶠ (x : α) in f, p x) ↔ ∃ᶠ (x : α) in f, q x)
def Mathlib.Tactic.Peel.quantifiers E1 #
List Lean.Name
The list of constants that are regarded as being quantifiers.
def Mathlib.Tactic.Peel.whnfQuantifier E1 #
Lean.Expr → Bool → Lean.MetaM Lean.Expr
If unfold is false then do whnfR, otherwise unfold everything that's not a quantifier,
according to the quantifiers list.
def Mathlib.Tactic.Peel.throwPeelError E1 #
{α : Type} → Lean.Expr → Lean.Expr → Lean.MetaM α
Throws an error saying ty and target could not be matched up.
def Mathlib.Tactic.Peel.mkFreshBinderName E1 #
Lean.Expr → Lean.MetaM Lean.Name
If f is a lambda then use its binding name to generate a new hygienic name,
and otherwise choose a new hygienic name.
def Mathlib.Tactic.Peel.applyPeelThm E1 #
Lean.Name →
Lean.MVarId → Lean.Expr → Lean.Expr → Lean.Expr → Lean.Name → Lean.Name → Lean.MetaM (Lean.FVarId × List Lean.MVarId)
Applies a "peel theorem" with two main arguments, where the first is the new goal
and the second can be filled in using e. Then it intros two variables with the
provided names.
If, for example, goal : ∃ y : α, q y and thm := Exists.imp, the metavariable returned has
type q x where x : α has been introduced into the context.
def Mathlib.Tactic.Peel.peelCore E1 #
Lean.MVarId → Lean.Expr → Option Lean.Name → Lean.Name → Bool → Lean.MetaM (Lean.FVarId × List Lean.MVarId)
This is the core to the peel tactic.
It tries to match e and goal as quantified statements (using ∀ and the quantifiers in
the quantifiers list), then applies "peel theorems" using applyPeelThm.
We treat ∧ as a quantifier for sake of dealing with quantified statements
like ∃ δ > (0 : ℝ), q δ, which is notation for ∃ δ, δ > (0 : ℝ) ∧ q δ.
def Mathlib.Tactic.Peel.peelArgs E1 #
Lean.Expr → ℕ → List Lean.Name → Option Lean.Name → optParam Bool true → Lean.Elab.Tactic.TacticM Unit
Given a list l of names, this peels num quantifiers off of the expression e and
the main goal and introduces variables with the provided names until the list of names is exhausted.
Note: the name n? (with default this) is used for the name of the expression e with
quantifiers peeled.
opaque Mathlib.Tactic.Peel.peelUnbounded E1 #
Lean.Expr → Option Lean.Name → optParam Bool false → Lean.Elab.Tactic.TacticM Bool
Similar to peelArgs but peels arbitrarily many quantifiers. Returns whether or not
any quantifiers were peeled.
def Mathlib.Tactic.Peel.peelIffAux E0 #
Lean.Elab.Tactic.TacticM Unit
Peel off a single quantifier from an ↔.
def Mathlib.Tactic.Peel.peelArgsIff E1 #
List Lean.Name → Lean.Elab.Tactic.TacticM Unit
Peel off quantifiers from an ↔ and assign the names given in l to the introduced
variables.