Skip to content

Commit 4f54a55

Browse files
committed
chore: better recursor names for (#25555)
Also modify `Int.le_induction` and `Int.le_induction_down` to be like `Nat.le_induction` – `induction n, hn using` syntax can now be used with the first two recursors. See [Zulip](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Naming.20of.20.60Int.60.20recursors/near/522863583).
1 parent 994033e commit 4f54a55

File tree

10 files changed

+77
-78
lines changed

10 files changed

+77
-78
lines changed

Mathlib/Algebra/Group/Basic.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,9 @@ lemma zpow_sub_one (a : G) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ :=
833833
@[to_additive add_zsmul]
834834
lemma zpow_add (a : G) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by
835835
induction n with
836-
| hz => simp
837-
| hp n ihn => simp only [← Int.add_assoc, zpow_add_one, ihn, mul_assoc]
838-
| hn n ihn => rw [zpow_sub_one, ← mul_assoc, ← ihn, ← zpow_sub_one, Int.add_sub_assoc]
836+
| zero => simp
837+
| succ n ihn => simp only [← Int.add_assoc, zpow_add_one, ihn, mul_assoc]
838+
| pred n ihn => rw [zpow_sub_one, ← mul_assoc, ← ihn, ← zpow_sub_one, Int.add_sub_assoc]
839839

840840
@[to_additive one_add_zsmul]
841841
lemma zpow_one_add (a : G) (n : ℤ) : a ^ (1 + n) = a * a ^ n := by rw [zpow_add, zpow_one]
@@ -888,11 +888,11 @@ addition by `g` and `-g` on the left. For additive subgroups generated by more t
888888
lemma zpow_induction_left {g : G} {P : G → Prop} (h_one : P (1 : G))
889889
(h_mul : ∀ a, P a → P (g * a)) (h_inv : ∀ a, P a → P (g⁻¹ * a)) (n : ℤ) : P (g ^ n) := by
890890
induction n with
891-
| hz => rwa [zpow_zero]
892-
| hp n ih =>
891+
| zero => rwa [zpow_zero]
892+
| succ n ih =>
893893
rw [Int.add_comm, zpow_add, zpow_one]
894894
exact h_mul _ ih
895-
| hn n ih =>
895+
| pred n ih =>
896896
rw [Int.sub_eq_add_neg, Int.add_comm, zpow_add, zpow_neg_one]
897897
exact h_inv _ ih
898898

@@ -905,11 +905,11 @@ see `AddSubgroup.closure_induction_right`."]
905905
lemma zpow_induction_right {g : G} {P : G → Prop} (h_one : P (1 : G))
906906
(h_mul : ∀ a, P a → P (a * g)) (h_inv : ∀ a, P a → P (a * g⁻¹)) (n : ℤ) : P (g ^ n) := by
907907
induction n with
908-
| hz => rwa [zpow_zero]
909-
| hp n ih =>
908+
| zero => rwa [zpow_zero]
909+
| succ n ih =>
910910
rw [zpow_add_one]
911911
exact h_mul _ ih
912-
| hn n ih =>
912+
| pred n ih =>
913913
rw [zpow_sub_one]
914914
exact h_inv _ ih
915915

Mathlib/Algebra/GroupWithZero/Basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ lemma zpow_sub_one₀ (ha : a ≠ 0) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ :=
420420

421421
lemma zpow_add₀ (ha : a ≠ 0) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by
422422
induction n with
423-
| hz => simp
424-
| hp n ihn => simp only [← Int.add_assoc, zpow_add_one₀ ha, ihn, mul_assoc]
425-
| hn n ihn => rw [zpow_sub_one₀ ha, ← mul_assoc, ← ihn, ← zpow_sub_one₀ ha, Int.add_sub_assoc]
423+
| zero => simp
424+
| succ n ihn => simp only [← Int.add_assoc, zpow_add_one₀ ha, ihn, mul_assoc]
425+
| pred n ihn => rw [zpow_sub_one₀ ha, ← mul_assoc, ← ihn, ← zpow_sub_one₀ ha, Int.add_sub_assoc]
426426

427427
lemma zpow_add' {m n : ℤ} (h : a ≠ 0 ∨ m + n ≠ 0 ∨ m = 0 ∧ n = 0) :
428428
a ^ (m + n) = a ^ m * a ^ n := by

Mathlib/Algebra/Module/LinearMap/Defs.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,9 @@ instance CompatibleSMul.intModule {S : Type*} [Semiring S] [Module S M] [Module
580580
CompatibleSMul M M₂ ℤ S :=
581581
fun fₗ c x ↦ by
582582
induction c with
583-
| hz => simp
584-
| hp n ih => simp [add_smul, ih]
585-
| hn n ih => simp [sub_smul, ih]⟩
583+
| zero => simp
584+
| succ n ih => simp [add_smul, ih]
585+
| pred n ih => simp [sub_smul, ih]⟩
586586

587587
instance CompatibleSMul.units {R S : Type*} [Monoid R] [MulAction R M] [MulAction R M₂]
588588
[Semiring S] [Module S M] [Module S M₂] [CompatibleSMul M M₂ R S] : CompatibleSMul M M₂ Rˣ S :=

Mathlib/Data/Int/Init.lean

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,51 +71,52 @@ the upwards induction step `p i → p (i + 1)` and the downwards induction step
7171
7272
It is used as the default induction principle for the `induction` tactic.
7373
-/
74-
@[elab_as_elim, induction_eliminator] protected lemma induction_on {p : ℤ → Prop} (i : ℤ)
75-
(hz : p 0) (hp : ∀ i : ℕ, p i → p (i + 1)) (hn : ∀ i : ℕ, p (-i) → p (-i - 1)) : p i := by
74+
@[elab_as_elim, induction_eliminator] protected lemma induction_on {motive : ℤ → Prop} (i : ℤ)
75+
(zero : motive 0) (succ : ∀ i : ℕ, motive i → motive (i + 1))
76+
(pred : ∀ i : ℕ, motive (-i) → motive (-i - 1)) : motive i := by
7677
cases i with
7778
| ofNat i =>
7879
induction i with
79-
| zero => exact hz
80-
| succ i ih => exact hp _ ih
80+
| zero => exact zero
81+
| succ i ih => exact succ _ ih
8182
| negSucc i =>
82-
suffices ∀ n : ℕ, p (-n) from this (i + 1)
83+
suffices ∀ n : ℕ, motive (-n) from this (i + 1)
8384
intro n; induction n with
84-
| zero => simp [hz]
85-
| succ n ih => simpa [natCast_succ, Int.neg_add, Int.sub_eq_add_neg] using hn _ ih
85+
| zero => simp [zero]
86+
| succ n ih => simpa [natCast_succ, Int.neg_add, Int.sub_eq_add_neg] using pred _ ih
8687

8788
section inductionOn'
8889

89-
variable {C : ℤ → Sort*} (z b : ℤ)
90-
(H0 : C b) (Hs : ∀ k, b ≤ k → C k → C (k + 1)) (Hp : ∀ k ≤ b, C k → C (k - 1))
90+
variable {motive : ℤ → Sort*} (z b : ℤ) (zero : motive b)
91+
(succ : ∀ k, b ≤ k → motive k → motive (k + 1)) (pred : ∀ k ≤ b, motive k → motive (k - 1))
9192

9293
/-- Inductively define a function on `ℤ` by defining it at `b`, for the `succ` of a number greater
9394
than `b`, and the `pred` of a number less than `b`. -/
94-
@[elab_as_elim] protected def inductionOn' : C z :=
95-
cast (congrArg C <| show b + (z - b) = z by rw [Int.add_comm, z.sub_add_cancel b]) <|
95+
@[elab_as_elim] protected def inductionOn' : motive z :=
96+
cast (congrArg motive <| show b + (z - b) = z by rw [Int.add_comm, z.sub_add_cancel b]) <|
9697
match z - b with
9798
| .ofNat n => pos n
9899
| .negSucc n => neg n
99100
where
100101
/-- The positive case of `Int.inductionOn'`. -/
101-
pos : ∀ n : ℕ, C (b + n)
102-
| 0 => cast (by simp) H0
102+
pos : ∀ n : ℕ, motive (b + n)
103+
| 0 => cast (by simp) zero
103104
| n+1 => cast (by rw [Int.add_assoc]; rfl) <|
104-
Hs _ (Int.le_add_of_nonneg_right (natCast_nonneg _)) (pos n)
105+
succ _ (Int.le_add_of_nonneg_right (natCast_nonneg _)) (pos n)
105106
/-- The negative case of `Int.inductionOn'`. -/
106-
neg : ∀ n : ℕ, C (b + -[n+1])
107-
| 0 => Hp _ Int.le_rfl H0
107+
neg : ∀ n : ℕ, motive (b + -[n+1])
108+
| 0 => pred _ Int.le_rfl zero
108109
| n+1 => by
109-
refine cast (by rw [Int.add_sub_assoc]; rfl) (Hp _ (Int.le_of_lt ?_) (neg n))
110+
refine cast (by rw [Int.add_sub_assoc]; rfl) (pred _ (Int.le_of_lt ?_) (neg n))
110111
omega
111112

112-
variable {z b H0 Hs Hp}
113+
variable {z b zero succ pred}
113114

114-
lemma inductionOn'_self : b.inductionOn' b H0 Hs Hp = H0 :=
115+
lemma inductionOn'_self : b.inductionOn' b zero succ pred = zero :=
115116
cast_eq_iff_heq.mpr <| .symm <| by rw [b.sub_self, ← cast_eq_iff_heq]; rfl
116117

117118
lemma inductionOn'_sub_one (hz : z ≤ b) :
118-
(z - 1).inductionOn' b H0 Hs Hp = Hp z hz (z.inductionOn' b H0 Hs Hp) := by
119+
(z - 1).inductionOn' b zero succ pred = pred z hz (z.inductionOn' b zero succ pred) := by
119120
apply cast_eq_iff_heq.mpr
120121
obtain ⟨n, hn⟩ := Int.eq_negSucc_of_lt_zero (show z - 1 - b < 0 by omega)
121122
rw [hn]
@@ -133,35 +134,38 @@ lemma inductionOn'_sub_one (hz : z ≤ b) :
133134
end inductionOn'
134135

135136
/-- Inductively define a function on `ℤ` by defining it on `ℕ` and extending it from `n` to `-n`. -/
136-
@[elab_as_elim] protected def negInduction {C : ℤ → Sort*} (nat : ∀ n : ℕ, C n)
137-
(neg : (∀ n : ℕ, C n) → ∀ n : ℕ, C (-n)) : ∀ n : ℤ, C n
137+
@[elab_as_elim] protected def negInduction {motive : ℤ → Sort*} (nat : ∀ n : ℕ, motive n)
138+
(neg : (∀ n : ℕ, motive n) → ∀ n : ℕ, motive (-n)) : ∀ n : ℤ, motive n
138139
| .ofNat n => nat n
139140
| .negSucc n => neg nat <| n + 1
140141

141142
/-- See `Int.inductionOn'` for an induction in both directions. -/
142-
protected lemma le_induction {P : ℤ → Prop} {m : ℤ} (h0 : P m)
143-
(h1 : ∀ n : ℤ, m ≤ n → P n → P (n + 1)) (n : ℤ) : m ≤ n → P n := by
144-
refine Int.inductionOn' n m ?_ ?_ ?_
143+
@[elab_as_elim]
144+
protected lemma le_induction {m : ℤ} {motive : ∀ n, m ≤ n → Prop} (base : motive m m.le_refl)
145+
(succ : ∀ n hmn, motive n hmn → motive (n + 1) (le_add_one hmn)) : ∀ n hmn, motive n hmn := by
146+
refine fun n ↦ Int.inductionOn' n m ?_ ?_ ?_
145147
· intro
146-
exact h0
148+
exact base
147149
· intro k hle hi _
148-
exact h1 k hle (hi hle)
150+
exact succ k hle (hi hle)
149151
· intro k hle _ hle'
150152
omega
151153

152154
/-- See `Int.inductionOn'` for an induction in both directions. -/
153-
protected theorem le_induction_down {P : ℤ → Prop} {m : ℤ} (h0 : P m)
154-
(h1 : ∀ n : ℤ, n ≤ m → P n → P (n - 1)) (n : ℤ) : n ≤ m → P n :=
155-
Int.inductionOn' n m (fun _ ↦ h0) (fun k hle _ hle' ↦ by omega)
156-
fun k hle hi _ ↦ h1 k hle (hi hle)
155+
@[elab_as_elim]
156+
protected lemma le_induction_down {m : ℤ} {motive : ∀ n, n ≤ m → Prop} (base : motive m m.le_refl)
157+
(pred : ∀ n hmn, motive n hmn → motive (n - 1) (by omega)) : ∀ n hmn, motive n hmn := fun n ↦
158+
Int.inductionOn' n m (fun _ ↦ base) (fun k hle _ hle' ↦ by omega)
159+
fun k hle hi _ ↦ pred k hle (hi hle)
157160

158161
section strongRec
159162

160-
variable {P : ℤ → Sort*} (lt : ∀ n < m, P n) (ge : ∀ n ≥ m, (∀ k < n, P k) → P n)
163+
variable {motive : ℤ → Sort*} (lt : ∀ n < m, motive n)
164+
(ge : ∀ n ≥ m, (∀ k < n, motive k) → motive n)
161165

162166
/-- A strong recursor for `Int` that specifies explicit values for integers below a threshold,
163167
and is analogous to `Nat.strongRec` for integers on or above the threshold. -/
164-
@[elab_as_elim] protected def strongRec (n : ℤ) : P n := by
168+
@[elab_as_elim] protected def strongRec (n : ℤ) : motive n := by
165169
refine if hnm : n < m then lt n hnm else ge n (by omega) (n.inductionOn' m lt ?_ ?_)
166170
· intro _n _ ih l _
167171
exact if hlm : l < m then lt l hlm else ge l (by omega) fun k _ ↦ ih k (by omega)

Mathlib/GroupTheory/CoprodI.lean

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,12 +1031,9 @@ theorem _root_.FreeGroup.injective_lift_of_ping_pong : Function.Injective (FreeG
10311031
smul_set_mono ((hXYdisj j i).union_left <| hYdisj hij.symm).subset_compl_right
10321032
_ ⊆ X i := by
10331033
clear hnne0 hlt
1034-
refine Int.le_induction (P := fun n => a i ^ n • (Y i)ᶜ ⊆ X i) ?_ ?_ n h1n
1035-
· dsimp
1036-
rw [zpow_one]
1037-
exact hX i
1038-
· dsimp
1039-
intro n _hle hi
1034+
induction n, h1n using Int.le_induction with
1035+
| base => rw [zpow_one]; exact hX i
1036+
| succ n _hle hi =>
10401037
calc
10411038
a i ^ (n + 1) • (Y i)ᶜ = (a i ^ n * a i) • (Y i)ᶜ := by rw [zpow_add, zpow_one]
10421039
_ = a i ^ n • a i • (Y i)ᶜ := MulAction.mul_smul _ _ _
@@ -1051,12 +1048,10 @@ theorem _root_.FreeGroup.injective_lift_of_ping_pong : Function.Injective (FreeG
10511048
a i ^ n • X' j ⊆ a i ^ n • (X i)ᶜ :=
10521049
smul_set_mono ((hXdisj hij.symm).union_left (hXYdisj i j).symm).subset_compl_right
10531050
_ ⊆ Y i := by
1054-
refine Int.le_induction_down (P := fun n => a i ^ n • (X i)ᶜ ⊆ Y i) ?_ ?_ _ h1n
1055-
· dsimp
1056-
rw [zpow_neg, zpow_one]
1057-
exact hY i
1058-
· dsimp
1059-
intro n _ hi
1051+
clear hnne0 hgt
1052+
induction n, h1n using Int.le_induction_down with
1053+
| base => rw [zpow_neg, zpow_one]; exact hY i
1054+
| pred n hle hi =>
10601055
calc
10611056
a i ^ (n - 1) • (X i)ᶜ = (a i ^ n * (a i)⁻¹) • (X i)ᶜ := by rw [zpow_sub, zpow_one]
10621057
_ = a i ^ n • (a i)⁻¹ • (X i)ᶜ := MulAction.mul_smul _ _ _

Mathlib/LinearAlgebra/Matrix/FixedDetMatrices.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ private lemma prop_red_T_pow (hS : ∀ B, C B → C (S • B)) (hT : ∀ B, C B
224224
∀ B (n : ℤ), C (T^n • B) ↔ C B := by
225225
intro B n
226226
induction n with
227-
| hz => simp only [zpow_zero, one_smul, imp_self]
228-
| hp n hn =>
227+
| zero => simp only [zpow_zero, one_smul, imp_self]
228+
| succ n hn =>
229229
simpa only [add_comm (n:ℤ), zpow_add _ 1, ← smul_eq_mul, zpow_one, smul_assoc, prop_red_T hS hT]
230-
| hn m hm =>
230+
| pred m hm =>
231231
rwa [sub_eq_neg_add, zpow_add, zpow_neg_one, ← prop_red_T hS hT, mul_smul, smul_inv_smul]
232232

233233
@[elab_as_elim]

Mathlib/LinearAlgebra/Matrix/SpecialLinearGroup.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,12 @@ theorem coe_T_inv : ↑(T⁻¹) = !![1, -1; 0, 1] := by simp [coe_inv, coe_T, ad
468468

469469
theorem coe_T_zpow (n : ℤ) : (T ^ n).1 = !![1, n; 0, 1] := by
470470
induction n with
471-
| hz => rw [zpow_zero, coe_one, Matrix.one_fin_two]
472-
| hp n h =>
471+
| zero => rw [zpow_zero, coe_one, Matrix.one_fin_two]
472+
| succ n h =>
473473
simp_rw [zpow_add, zpow_one, coe_mul, h, coe_T, Matrix.mul_fin_two]
474474
congrm !![_, ?_; _, _]
475475
rw [mul_one, mul_one, add_comm]
476-
| hn n h =>
476+
| pred n h =>
477477
simp_rw [zpow_sub, zpow_one, coe_mul, h, coe_T_inv, Matrix.mul_fin_two]
478478
congrm !![?_, ?_; _, _] <;> ring
479479

Mathlib/LinearAlgebra/Matrix/ZPow.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ theorem _root_.IsUnit.det_zpow {A : M} (h : IsUnit A.det) (n : ℤ) : IsUnit (A
109109

110110
theorem isUnit_det_zpow_iff {A : M} {z : ℤ} : IsUnit (A ^ z).det ↔ IsUnit A.det ∨ z = 0 := by
111111
induction z with
112-
| hz => simp
113-
| hp z =>
112+
| zero => simp
113+
| succ z =>
114114
rw [← Int.natCast_succ, zpow_natCast, det_pow, isUnit_pow_succ_iff, ← Int.ofNat_zero,
115115
Int.ofNat_inj]
116116
simp
117-
| hn z =>
117+
| pred z =>
118118
rw [← neg_add', ← Int.natCast_succ, zpow_neg_natCast, isUnit_nonsing_inv_det_iff, det_pow,
119119
isUnit_pow_succ_iff, neg_eq_zero, ← Int.ofNat_zero, Int.ofNat_inj]
120120
simp
@@ -148,9 +148,9 @@ theorem zpow_sub_one {A : M} (h : IsUnit A.det) (n : ℤ) : A ^ (n - 1) = A ^ n
148148

149149
theorem zpow_add {A : M} (ha : IsUnit A.det) (m n : ℤ) : A ^ (m + n) = A ^ m * A ^ n := by
150150
induction n with
151-
| hz => simp
152-
| hp n ihn => simp only [← add_assoc, zpow_add_one ha, ihn, mul_assoc]
153-
| hn n ihn => rw [zpow_sub_one ha, ← mul_assoc, ← ihn, ← zpow_sub_one ha, add_sub_assoc]
151+
| zero => simp
152+
| succ n ihn => simp only [← add_assoc, zpow_add_one ha, ihn, mul_assoc]
153+
| pred n ihn => rw [zpow_sub_one ha, ← mul_assoc, ← ihn, ← zpow_sub_one ha, add_sub_assoc]
154154

155155
theorem zpow_add_of_nonpos {A : M} {m n : ℤ} (hm : m ≤ 0) (hn : n ≤ 0) :
156156
A ^ (m + n) = A ^ m * A ^ n := by

Mathlib/LinearAlgebra/Reflection.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ lemma reflection_mul_reflection_zpow_apply_self (m : ℤ)
279279
(S R (k - 2)).eval t = (f y * g x - 2) * (S R (k - 1)).eval t - (S R k).eval t := by
280280
simp [S_sub_two, ht]
281281
induction m with
282-
| hz => simp
283-
| hp m ih =>
282+
| zero => simp
283+
| succ m ih =>
284284
-- Apply the inductive hypothesis.
285285
rw [add_comm (m : ℤ) 1, zpow_one_add, LinearEquiv.mul_apply, LinearEquiv.mul_apply, ih]
286286
-- Expand out all the reflections and use `hf`, `hg`.
@@ -289,7 +289,7 @@ lemma reflection_mul_reflection_zpow_apply_self (m : ℤ)
289289
match_scalars
290290
· linear_combination (norm := ring_nf) -S_eval_t_sub_two (m + 1)
291291
· ring_nf
292-
| hn m ih =>
292+
| pred m ih =>
293293
-- Apply the inductive hypothesis.
294294
rw [sub_eq_add_neg (-m : ℤ) 1, add_comm (-m : ℤ) (-1), zpow_add, zpow_neg_one, mul_inv_rev,
295295
reflection_inv, reflection_inv, LinearEquiv.mul_apply, LinearEquiv.mul_apply, ih]

Mathlib/RingTheory/Polynomial/Chebyshev.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,11 @@ theorem S_comp_two_mul_X (n : ℤ) : (S R n).comp (2 * X) = U R n := by
498498

499499
theorem S_sq_add_S_sq (n : ℤ) : S R n ^ 2 + S R (n + 1) ^ 2 - X * S R n * S R (n + 1) = 1 := by
500500
induction n with
501-
| hz => simp; ring
502-
| hp n ih =>
501+
| zero => simp; ring
502+
| succ n ih =>
503503
have h₁ := S_add_two R n
504504
linear_combination (norm := ring_nf) (S R (2 + n) - S R n) * h₁ + ih
505-
| hn n ih =>
505+
| pred n ih =>
506506
have h₁ := S_sub_one R (-n)
507507
linear_combination (norm := ring_nf) (S R (-1 - n) - S R (1 - n)) * h₁ + ih
508508

0 commit comments

Comments
 (0)