Backward compatible implementation of lean 3 cases tactic #
This tactic is similar to the cases tactic in Lean 4 core, but the syntax for giving
names is different:
example (h : p ∨ q) : q ∨ p := by
cases h with
| inl hp => exact Or.inr hp
| inr hq => exact Or.inl hq
example (h : p ∨ q) : q ∨ p := by
cases' h with hp hq
· exact Or.inr hp
· exact Or.inl hq
example (h : p ∨ q) : q ∨ p := by
rcases h with hp | hq
· exact Or.inr hp
· exact Or.inl hq
Prefer cases or rcases when possible, because these tactics promote structured proofs.
Equations
Instances For
induction' x applies induction on the variable x of the inductive type t to the main goal,
producing one goal for each constructor of t, in which x is replaced by that constructor
applied to newly introduced variables. induction' adds an inductive hypothesis for
each recursive argument to the constructor. This is a backwards-compatible variant of the
induction tactic in Lean 4 core.
Prefer induction when possible, because it promotes structured proofs.
induction' x with n1 n2 ...names the introduced hypotheses: arguments to constructors and inductive hypotheses. This is the main difference withinductionin core Lean.induction' e, whereeis an expression instead of a variable, generalizesein the goal, and then performs induction on the resulting variable.induction' h : e, whereeis an expression instead of a variable, generalizesein the goal, and then performs induction on the resulting variable, adding to each goal the hypothesish : e = _where_is the constructor instance.induction' x using rusesras the principle of induction. Herershould be a term whose result type is of the formC t1 t2 ..., whereCis a bound variable andt1,t2, ... (if present) are bound variables.induction' x generalizing z1 z2 ...generalizes over the local variablesz1,z2, ... in the inductive hypothesis.
Example:
open Nat
example (n : ℕ) : 0 < factorial n := by
induction' n with n ih
· rw [factorial_zero]
simp
· rw [factorial_succ]
apply mul_pos (succ_pos n) ih
-- Though the following equivalent spellings should be preferred
example (n : ℕ) : 0 < factorial n := by
induction n
case zero =>
rw [factorial_zero]
simp
case succ n ih =>
rw [factorial_succ]
apply mul_pos (succ_pos n) ih
Equations
Instances For
cases' x, where the variable x has inductive type t, splits the main goal,
producing one goal for each constructor of t, in which x is replaced by that constructor
applied to newly introduced variables. This is a backwards-compatible variant of the
cases tactic in Lean 4 core.
Prefer cases, rcases, or obtain when possible, because these tactics promote
structured proofs.
cases' x with n1 n2 ...names the arguments to the constructors. This is the main difference withcasesin core Lean.cases' e, whereeis an expression instead of a variable, generalizesein the goal, and then performs induction on the resulting variable.cases' h : e, whereeis an expression instead of a variable, generalizesein the goal, and then splits by cases on the resulting variable, adding to each goal the hypothesish : e = _where_is the constructor instance.cases' x using rusesras the case matching rule. Herershould be a term whose result type is of the formC t1 t2 ..., whereCis a bound variable andt1,t2, ... (if present) are bound variables.
Example:
example (h : p ∨ q) : q ∨ p := by
cases' h with hp hq
· exact Or.inr hp
· exact Or.inl hq
-- Though the following equivalent spellings should be preferred
example (h : p ∨ q) : q ∨ p := by
cases h with
| inl hp => exact Or.inr hp
| inr hq => exact Or.inl hq
example (h : p ∨ q) : q ∨ p := by
rcases h with hp | hq
· exact Or.inr hp
· exact Or.inl hq