Skip to content

Commit aaabaed

Browse files
committed
chore: fix more induction/recursor branch names (#25770)
These were found using the regex `\| h. =>` and `def.*rec.*\(h. :`. Co-authored-by: Parcly Taxel <reddeloostw@gmail.com> Co-authored-by: Jeremy Tan Jie Rui <reddeloostw@gmail.com>
1 parent e1a06ff commit aaabaed

File tree

11 files changed

+75
-72
lines changed

11 files changed

+75
-72
lines changed

Mathlib/Analysis/Convolution.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,10 @@ theorem contDiffOn_convolution_right_with_param_aux {G : Type uP} {E' : Type uP}
11851185
universe, which is why we make the assumption in the lemma that all the relevant spaces
11861186
come from the same universe). -/
11871187
induction n using ENat.nat_induction generalizing g E' F with
1188-
| h0 =>
1188+
| zero =>
11891189
rw [WithTop.coe_zero, contDiffOn_zero] at hg ⊢
11901190
exact continuousOn_convolution_right_with_param L hk hgs hf hg
1191-
| hsuc n ih =>
1191+
| succ n ih =>
11921192
simp only [Nat.succ_eq_add_one, Nat.cast_add, Nat.cast_one, WithTop.coe_add,
11931193
WithTop.coe_natCast, WithTop.coe_one] at hg ⊢
11941194
let f' : P → G → P × G →L[𝕜] F := fun p a =>
@@ -1215,7 +1215,7 @@ theorem contDiffOn_convolution_right_with_param_aux {G : Type uP} {E' : Type uP}
12151215
exact hgs p y hp hy
12161216
apply ih (L.precompR (P × G) :) B
12171217
convert hg.2.2
1218-
| htop ih =>
1218+
| top ih =>
12191219
rw [contDiffOn_infty] at hg ⊢
12201220
exact fun n ↦ ih n L hgs (hg n)
12211221

Mathlib/Data/ENat/Basic.lean

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,12 @@ lemma coe_lt_coe {n m : ℕ} : (n : ℕ∞) < (m : ℕ∞) ↔ n < m := by simp
301301
lemma coe_le_coe {n m : ℕ} : (n : ℕ∞) ≤ (m : ℕ∞) ↔ n ≤ m := by simp
302302

303303
@[elab_as_elim]
304-
theorem nat_induction {P : ℕ∞ → Prop} (a : ℕ∞) (h0 : P 0) (hsuc : ∀ n : ℕ, P n → P n.succ)
305-
(htop : (∀ n : ℕ, P n) → P ⊤) : P a := by
306-
have A : ∀ n : ℕ, P n := fun n => Nat.recOn n h0 hsuc
304+
theorem nat_induction {motive : ℕ∞ → Prop} (a : ℕ∞) (zero : motive 0)
305+
(succ : ∀ n : ℕ, motive n → motive n.succ)
306+
(top : (∀ n : ℕ, motive n) → motive ⊤) : motive a := by
307+
have A : ∀ n : ℕ, motive n := fun n => Nat.recOn n zero succ
307308
cases a
308-
· exact htop A
309+
· exact top A
309310
· exact A _
310311

311312
lemma add_one_pos : 0 < n + 1 :=

Mathlib/Data/Fin/Tuple/Basic.lean

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ theorem consCases_cons {P : (∀ i : Fin n.succ, α i) → Sort v} (h : ∀ x₀
186186

187187
/-- Recurse on a tuple by splitting into `Fin.elim0` and `Fin.cons`. -/
188188
@[elab_as_elim]
189-
def consInduction {α : Sort*} {P : ∀ {n : ℕ}, (Fin n → α) → Sort v} (h0 : P Fin.elim0)
190-
(h : ∀ {n} (x₀) (x : Fin n → α), P x → P (Fin.cons x₀ x)) : ∀ {n : ℕ} (x : Fin n → α), P x
191-
| 0, x => by convert h0
192-
| _ + 1, x => consCases (fun _ _ ↦ h _ _ <| consInduction h0 h _) x
189+
def consInduction {α : Sort*} {motive : ∀ {n : ℕ}, (Fin n → α) → Sort v} (elim0 : motive Fin.elim0)
190+
(cons : ∀ {n} (x₀) (x : Fin n → α), motive x → motive (Fin.cons x₀ x)) :
191+
∀ {n : ℕ} (x : Fin n → α), motive x
192+
| 0, x => by convert elim0
193+
| _ + 1, x => consCases (fun _ _ ↦ cons _ _ <| consInduction elim0 cons _) x
193194

194195
theorem cons_injective_of_injective {α} {x₀ : α} {x : Fin n → α} (hx₀ : x₀ ∉ Set.range x)
195196
(hx : Function.Injective x) : Function.Injective (cons x₀ x : Fin n.succ → α) := by

Mathlib/Data/Fin/Tuple/NatAntidiagonal.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ theorem antidiagonalTuple_zero_succ (n : ℕ) : antidiagonalTuple 0 (n + 1) = []
7474
theorem mem_antidiagonalTuple {n : ℕ} {k : ℕ} {x : Fin k → ℕ} :
7575
x ∈ antidiagonalTuple k n ↔ ∑ i, x i = n := by
7676
induction x using Fin.consInduction generalizing n with
77-
| h0 =>
77+
| elim0 =>
7878
cases n
7979
· decide
8080
· simp
81-
| h x₀ x ih =>
81+
| cons x₀ x ih =>
8282
simp_rw [Fin.sum_cons, antidiagonalTuple, List.mem_flatMap, List.mem_map,
8383
List.Nat.mem_antidiagonal, Fin.cons_inj, exists_eq_right_right, ih,
8484
@eq_comm _ _ (Prod.snd _), and_comm (a := Prod.snd _ = _),

Mathlib/Data/Seq/Computation.lean

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,17 @@ theorem think_empty : empty α = think (empty α) :=
159159
destruct_eq_think destruct_empty
160160

161161
/-- Recursion principle for computations, compare with `List.recOn`. -/
162-
def recOn {C : Computation α → Sort v} (s : Computation α) (h1 : ∀ a, C (pure a))
163-
(h2 : ∀ s, C (think s)) : C s :=
162+
@[elab_as_elim]
163+
def recOn {motive : Computation α → Sort v} (s : Computation α) (pure : ∀ a, motive (pure a))
164+
(think : ∀ s, motive (think s)) : motive s :=
164165
match H : destruct s with
165166
| Sum.inl v => by
166167
rw [destruct_eq_pure H]
167-
apply h1
168+
apply pure
168169
| Sum.inr v => match v with
169170
| ⟨a, s'⟩ => by
170171
rw [destruct_eq_think H]
171-
apply h2
172+
apply think
172173

173174
/-- Corecursor constructor for `corec` -/
174175
def Corec.f (f : β → α ⊕ β) : α ⊕ β → Option α × (α ⊕ β)
@@ -255,7 +256,7 @@ theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s
255256
suffices head s = head s' ∧ R (tail s) (tail s') from
256257
And.imp id (fun r => ⟨tail s, tail s', by cases s; rfl, by cases s'; rfl, r⟩) this
257258
have h := bisim r; revert r h
258-
apply recOn s _ _ <;> intro r' <;> apply recOn s' _ _ <;> intro a' r h
259+
refine recOn s ?_ ?_ <;> intro r' <;> refine recOn s' ?_ ?_ <;> intro a' r h
259260
· constructor <;> dsimp at h
260261
· rw [h]
261262
· rw [h] at r
@@ -502,9 +503,8 @@ theorem length_thinkN (s : Computation α) [_h : Terminates s] (n) :
502503
(results_thinkN n (results_of_terminates _)).length
503504

504505
theorem eq_thinkN {s : Computation α} {a n} (h : Results s a n) : s = thinkN (pure a) n := by
505-
revert s
506-
induction n with | zero => _ | succ n IH => _ <;>
507-
(intro s; apply recOn s (fun a' => _) fun s => _) <;> intro a h
506+
induction n generalizing s with | zero | succ n IH <;>
507+
induction s using recOn with | pure a' | think s
508508
· rw [← eq_of_pure_mem h.mem]
509509
rfl
510510
· obtain ⟨n, h⟩ := of_results_think h
@@ -582,7 +582,7 @@ theorem map_think (f : α → β) : ∀ s, map f (think s) = think (map f s)
582582

583583
@[simp]
584584
theorem destruct_map (f : α → β) (s) : destruct (map f s) = lmap f (rmap (map f) (destruct s)) := by
585-
apply s.recOn <;> intro <;> simp
585+
induction s using recOn <;> simp
586586

587587
@[simp]
588588
theorem map_id : ∀ s : Computation α, map id s = s
@@ -623,9 +623,9 @@ theorem bind_pure (f : α → β) (s) : bind s (pure ∘ f) = map f s := by
623623
match c₁, c₂, h with
624624
| _, c₂, Or.inl (Eq.refl _) => rcases destruct c₂ with b | cb <;> simp
625625
| _, _, Or.inr ⟨s, rfl, rfl⟩ =>
626-
apply recOn s <;> intro s
627-
· simp
628-
· simpa using Or.inr ⟨s, rfl, rfl⟩
626+
induction s using recOn with
627+
| pure s => simp
628+
| think s => simpa using Or.inr ⟨s, rfl, rfl⟩
629629
· exact Or.inr ⟨s, rfl, rfl⟩
630630

631631
@[simp]
@@ -642,11 +642,13 @@ theorem bind_assoc (s : Computation α) (f : α → Computation β) (g : β →
642642
match c₁, c₂, h with
643643
| _, c₂, Or.inl (Eq.refl _) => rcases destruct c₂ with b | cb <;> simp
644644
| _, _, Or.inr ⟨s, rfl, rfl⟩ =>
645-
apply recOn s <;> intro s
646-
· simp only [BisimO, ret_bind]; generalize f s = fs
647-
apply recOn fs <;> intro t <;> simp
648-
· rcases destruct (g t) with b | cb <;> simp
649-
· simpa [BisimO] using Or.inr ⟨s, rfl, rfl⟩
645+
induction s using recOn with
646+
| pure s =>
647+
simp only [BisimO, ret_bind]; generalize f s = fs
648+
induction fs using recOn with
649+
| pure t => rw [ret_bind]; rcases destruct (g t) with b | cb <;> simp
650+
| think => simp
651+
| think s => simpa [BisimO] using Or.inr ⟨s, rfl, rfl⟩
650652
· exact Or.inr ⟨s, rfl, rfl⟩
651653

652654
theorem results_bind {s : Computation α} {f : α → Computation β} {a b m n} (h1 : Results s a m)
@@ -687,14 +689,14 @@ theorem length_bind (s : Computation α) (f : α → Computation β) [_T1 : Term
687689

688690
theorem of_results_bind {s : Computation α} {f : α → Computation β} {b k} :
689691
Results (bind s f) b k → ∃ a m n, Results s a m ∧ Results (f a) b n ∧ k = n + m := by
690-
induction k generalizing s with | zero => _ | succ n IH => _
691-
<;> apply recOn s (fun a => _) fun s' => _ <;> intro e h
692+
induction k generalizing s with | zero | succ n IH <;>
693+
induction s using recOn with intro h | pure a | think s'
692694
· simp only [ret_bind] at h
693-
exact ⟨e, _, _, results_pure _, h, rfl⟩
695+
exact ⟨_, _, _, results_pure _, h, rfl⟩
694696
· have := congr_arg head (eq_thinkN h)
695697
contradiction
696698
· simp only [ret_bind] at h
697-
exact ⟨e, _, n + 1, results_pure _, h, rfl⟩
699+
exact ⟨_, _, n + 1, results_pure _, h, rfl⟩
698700
· simp only [think_bind, results_think_iff] at h
699701
let ⟨a, m, n', h1, h2, e'⟩ := IH h
700702
rw [e']
@@ -796,19 +798,17 @@ theorem orElse_think (c₁ c₂ : Computation α) : (think c₁ <|> think c₂)
796798
theorem empty_orElse (c) : (empty α <|> c) = c := by
797799
apply eq_of_bisim (fun c₁ c₂ => (empty α <|> c₂) = c₁) _ rfl
798800
intro s' s h; rw [← h]
799-
apply recOn s <;> intro s <;> rw [think_empty]
800-
· simp
801-
simp only [BisimO, orElse_think, destruct_think]
802-
rw [← think_empty]
801+
induction s using recOn with rw [think_empty]
802+
| pure s => simp
803+
| think s => simp only [BisimO, orElse_think, destruct_think]; rw [← think_empty]
803804

804805
@[simp]
805806
theorem orElse_empty (c : Computation α) : (c <|> empty α) = c := by
806807
apply eq_of_bisim (fun c₁ c₂ => (c₂ <|> empty α) = c₁) _ rfl
807808
intro s' s h; rw [← h]
808-
apply recOn s <;> intro s <;> rw [think_empty]
809-
· simp
810-
simp only [BisimO, orElse_think, destruct_think]
811-
rw [← think_empty]
809+
induction s using recOn with rw [think_empty]
810+
| pure s => simp
811+
| think s => simp only [BisimO, orElse_think, destruct_think]; rw [← think_empty]
812812

813813
/-- `c₁ ~ c₂` asserts that `c₁` and `c₂` either both terminate with the same result,
814814
or both loop forever. -/
@@ -1045,11 +1045,11 @@ variable {R : α → β → Prop} {C : Computation α → Computation β → Pro
10451045
@[simp]
10461046
theorem LiftRelAux.ret_left (R : α → β → Prop) (C : Computation α → Computation β → Prop) (a cb) :
10471047
LiftRelAux R C (Sum.inl a) (destruct cb) ↔ ∃ b, b ∈ cb ∧ R a b := by
1048-
apply cb.recOn (fun b => _) fun cb => _
1049-
· intro b
1048+
induction cb using recOn with
1049+
| pure b =>
10501050
exact
10511051
fun h => ⟨_, ret_mem _, h⟩, fun ⟨b', mb, h⟩ => by rw [mem_unique (ret_mem _) mb]; exact h⟩
1052-
· intro
1052+
| think cb =>
10531053
rw [destruct_think]
10541054
exact ⟨fun ⟨b, h, r⟩ => ⟨b, think_mem h, r⟩, fun ⟨b, h, r⟩ => ⟨b, of_think_mem h, r⟩⟩
10551055

@@ -1071,10 +1071,9 @@ theorem LiftRelRec.lem {R : α → β → Prop} (C : Computation α → Computat
10711071
· simp only [destruct_pure, LiftRelAux.ret_left] at h
10721072
simp [h]
10731073
· simp only [liftRel_think_left]
1074-
revert h
1075-
apply cb.recOn (fun b => _) fun cb' => _ <;> intro _ h
1076-
· simpa using h
1077-
· simpa [h] using IH _ h
1074+
induction cb using recOn with
1075+
| pure b => simpa using h
1076+
| think cb => simpa [h] using IH _ h
10781077

10791078
theorem liftRel_rec {R : α → β → Prop} (C : Computation α → Computation β → Prop)
10801079
(H : ∀ {ca cb}, C ca cb → LiftRelAux R C (destruct ca) (destruct cb)) (ca cb) (Hc : C ca cb) :

Mathlib/Data/Set/Card.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,16 @@ theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆
393393
obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
394394

395395
theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
396-
revert hk
397-
refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_
398-
· obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
396+
induction k using ENat.nat_induction with
397+
| zero => exact ⟨∅, empty_subset _, by simp⟩
398+
| succ n IH =>
399+
obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hk)
399400
simp only [Nat.cast_succ] at *
400401
have hne : t₀ ≠ s := by
401-
rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
402+
rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hk; simp at hk
402403
obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
403404
exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_notMem hx.2, ht₀]⟩
404-
simp only [top_le_iff, encard_eq_top_iff]
405-
exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
405+
| top => rw [top_le_iff] at hk; exact ⟨s, Subset.rfl, hk⟩
406406

407407
theorem exists_superset_subset_encard_eq {k : ℕ∞}
408408
(hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :

Mathlib/Data/WSeq/Basic.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ def destruct : WSeq α → Computation (Option (α × WSeq α)) :=
8686
| some (some a, s') => Sum.inl (some (a, s'))
8787

8888
/-- Recursion principle for weak sequences, compare with `List.recOn`. -/
89-
def recOn {C : WSeq α → Sort v} (s : WSeq α) (h1 : C nil) (h2 : ∀ x s, C (cons x s))
90-
(h3 : ∀ s, C (think s)) : C s :=
91-
Seq.recOn s h1 fun o => Option.recOn o h3 h2
89+
@[elab_as_elim]
90+
def recOn {motive : WSeq α → Sort v} (s : WSeq α) (nil : motive nil)
91+
(cons : ∀ x s, motive (cons x s)) (think : ∀ s, motive (think s)) : motive s :=
92+
Seq.recOn s nil fun o => Option.recOn o think cons
9293

9394
/-- membership for weak sequences -/
9495
protected def Mem (s : WSeq α) (a : α) :=

Mathlib/Logic/Function/Iterate.lean

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,15 @@ theorem comp_iterate_pred_of_pos {n : ℕ} (hn : 0 < n) : f ∘ f^[n.pred] = f^[
177177
rw [← iterate_succ', Nat.succ_pred_eq_of_pos hn]
178178

179179
/-- A recursor for the iterate of a function. -/
180-
def Iterate.rec (p : α → Sort*) {f : α → α} (h : ∀ a, p a → p (f a)) {a : α} (ha : p a) (n : ℕ) :
181-
p (f^[n] a) :=
180+
@[elab_as_elim]
181+
def Iterate.rec (motive : α → Sort*) {a : α} (arg : motive a)
182+
{f : α → α} (app : ∀ a, motive a → motive (f a)) (n : ℕ) : motive (f^[n] a) :=
182183
match n with
183-
| 0 => ha
184-
| m+1 => Iterate.rec p h (h _ ha) m
184+
| 0 => arg
185+
| m + 1 => Iterate.rec motive (app _ arg) app m
185186

186-
theorem Iterate.rec_zero (p : α → Sort*) {f : α → α} (h : ∀ a, p a → p (f a)) {a : α} (ha : p a) :
187-
Iterate.rec p h ha 0 = ha :=
187+
theorem Iterate.rec_zero (motive : α → Sort*) {f : α → α} (app : ∀ a, motive a → motive (f a))
188+
{a : α} (arg : motive a) : Iterate.rec motive arg app 0 = arg :=
188189
rfl
189190

190191
variable {f} {m n : ℕ} {a : α}

Mathlib/NumberTheory/ArithmeticFunction.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,10 @@ open UniqueFactorizationMonoid
10901090
@[simp]
10911091
theorem moebius_mul_coe_zeta : (μ * ζ : ArithmeticFunction ℤ) = 1 := by
10921092
ext n
1093-
refine recOnPosPrimePosCoprime ?_ ?_ ?_ ?_ n
1094-
· intro p n hp hn
1093+
induction n using recOnPosPrimePosCoprime with
1094+
| zero => rw [ZeroHom.map_zero, ZeroHom.map_zero]
1095+
| one => simp
1096+
| prime_pow p n hp hn =>
10951097
rw [coe_mul_zeta_apply, sum_divisors_prime_pow hp, sum_range_succ']
10961098
simp_rw [Nat.pow_zero, moebius_apply_one,
10971099
moebius_apply_prime_pow hp (Nat.succ_ne_zero _), Nat.succ_inj, sum_ite_eq', mem_range,
@@ -1100,9 +1102,7 @@ theorem moebius_mul_coe_zeta : (μ * ζ : ArithmeticFunction ℤ) = 1 := by
11001102
rw [Ne, pow_eq_one_iff]
11011103
· exact hp.ne_one
11021104
· exact hn.ne'
1103-
· rw [ZeroHom.map_zero, ZeroHom.map_zero]
1104-
· simp
1105-
· intro a b _ha _hb hab ha' hb'
1105+
| coprime a b _ha _hb hab ha' hb' =>
11061106
rw [IsMultiplicative.map_mul_of_coprime _ hab, ha', hb',
11071107
IsMultiplicative.map_mul_of_coprime isMultiplicative_one hab]
11081108
exact isMultiplicative_moebius.mul isMultiplicative_zeta.natCast

Mathlib/Order/SuccPred/Archimedean.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ theorem Succ.rec {P : α → Prop} {m : α} (h0 : P m) (h1 : ∀ n, m ≤ n →
6767
theorem Succ.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) {a b : α} (h : a ≤ b) :
6868
p a ↔ p b := by
6969
obtain ⟨n, rfl⟩ := h.exists_succ_iterate
70-
exact Iterate.rec (fun b => p a ↔ p b) (fun c hc => hc.trans (hsucc _)) Iff.rfl n
70+
exact Iterate.rec (fun b => p a ↔ p b) Iff.rfl (fun c hc => hc.trans (hsucc _)) n
7171

7272
lemma le_total_of_codirected {r v₁ v₂ : α} (h₁ : r ≤ v₁) (h₂ : r ≤ v₂) : v₁ ≤ v₂ ∨ v₂ ≤ v₁ := by
7373
obtain ⟨n, rfl⟩ := h₁.exists_succ_iterate

0 commit comments

Comments
 (0)