Skip to content

Commit ac1e75f

Browse files
committed
refactor: hypothesis naming in custom recursors (#1658)
I have renamed hypotheses in `WithBot.recBotCoe`, `WithTop.recTopCoe` and `Finset.cons_induction` on the basis that rather than ```lean cases f₁ using WithBot.recBotCoe with | h₁ => … | h₂ f₁ => … ``` we would prefer to be able to write ```lean cases f₁ using WithBot.recBotCoe with | bot => … | coe f₁ => … ``` and rather than ```lean induction s using cons_induction with | h₁ => … | @h₂ c s hc ih => … ``` we would prefer ```lean induction s using cons_induction with | empty => … | @COns c t hc ih => … ```` I also tidied up some of inf' stuff in Finset.Lattice by using named arguments to specify the dual type instead of `@`s and `_ _ _`.
1 parent d38f441 commit ac1e75f

File tree

4 files changed

+70
-78
lines changed

4 files changed

+70
-78
lines changed

Mathlib/Data/Finset/Basic.lean

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,17 +1184,19 @@ theorem ssubset_insert (h : a ∉ s) : s ⊂ insert a s :=
11841184
ssubset_iff.mpr ⟨a, h, Subset.rfl⟩
11851185
#align finset.ssubset_insert Finset.ssubset_insert
11861186

1187+
#check Finset.mk
1188+
11871189
@[elab_as_elim]
1188-
theorem cons_induction {α : Type _} {p : Finset α → Prop} (h₁ : p ∅)
1189-
(h₂ : ∀ ⦃a : α⦄ {s : Finset α} (h : a ∉ s), p s → p (cons a s h)) : ∀ s, p s
1190-
| ⟨s, nd⟩ =>
1191-
Multiset.induction_on s (fun _ => h₁)
1192-
(fun a s IH nd => by
1193-
cases' nodup_cons.1 nd with m nd'
1194-
rw [← (eq_of_veq _ : cons a (Finset.mk s _) m = ⟨a ::ₘ s, nd⟩)]
1195-
· exact h₂ m (IH nd')
1196-
· rw [cons_val])
1197-
nd
1190+
theorem cons_induction {α : Type _} {p : Finset α → Prop} (empty : p ∅)
1191+
(cons : ∀ ⦃a : α⦄ {s : Finset α} (h : a ∉ s), p s → p (cons a s h)) : ∀ s, p s
1192+
| ⟨s, nd⟩ => by
1193+
induction s using Multiset.induction with
1194+
| empty => exact empty
1195+
| @cons a s IH =>
1196+
cases' nodup_cons.1 nd with m nd'
1197+
rw [← (eq_of_veq _ : Finset.cons a ⟨s, _⟩ m = ⟨a ::ₘ s, nd⟩)]
1198+
· exact cons m (IH nd')
1199+
· rw [cons_val]
11981200
#align finset.cons_induction Finset.cons_induction
11991201

12001202
@[elab_as_elim]
@@ -1204,9 +1206,9 @@ theorem cons_induction_on {α : Type _} {p : Finset α → Prop} (s : Finset α)
12041206
#align finset.cons_induction_on Finset.cons_induction_on
12051207

12061208
@[elab_as_elim]
1207-
protected theorem induction {α : Type _} {p : Finset α → Prop} [DecidableEq α] (h₁ : p ∅)
1208-
(h₂ : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s :=
1209-
cons_induction h₁ fun a s ha => (s.cons_eq_insert a ha).symm ▸ h₂ ha
1209+
protected theorem induction {α : Type _} {p : Finset α → Prop} [DecidableEq α] (empty : p ∅)
1210+
(insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s :=
1211+
cons_induction empty fun a s ha => (s.cons_eq_insert a ha).symm ▸ insert ha
12101212
#align finset.induction Finset.induction
12111213

12121214
/-- To prove a proposition about an arbitrary `Finset α`,

Mathlib/Data/Finset/Lattice.lean

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -568,35 +568,27 @@ theorem comp_sup_eq_sup_comp_of_is_total [SemilatticeSup β] [OrderBot β] (g :
568568
@[simp]
569569
protected theorem le_sup_iff (ha : ⊥ < a) : a ≤ s.sup f ↔ ∃ b ∈ s, a ≤ f b := by
570570
apply Iff.intro
571-
· intro h'
572-
induction s using Finset.cons_induction with
573-
| h₁ => exact False.elim (not_le_of_lt ha h')
574-
| @h₂ c s hc ih =>
575-
rw [sup_cons, _root_.le_sup_iff] at h'
576-
cases h' with
577-
| inl h => exact ⟨c, mem_cons.2 (Or.inl rfl), h⟩
578-
| inr h =>
579-
rcases ih h with ⟨b, hb, hle⟩
580-
exact ⟨b, mem_cons.2 (Or.inr hb), hle⟩
581-
· rintro ⟨b, hb, hle⟩
582-
exact le_trans hle (le_sup hb)
571+
· induction s using cons_induction with
572+
| empty => exact (absurd · (not_le_of_lt ha))
573+
| @cons c t hc ih =>
574+
rw [sup_cons, le_sup_iff]
575+
exact fun
576+
| Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩
577+
| Or.inr h => let ⟨b, hb, hle⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hle⟩
578+
· exact fun ⟨b, hb, hle⟩ => le_trans hle (le_sup hb)
583579
#align finset.le_sup_iff Finset.le_sup_iff
584580

585581
@[simp]
586582
protected theorem lt_sup_iff : a < s.sup f ↔ ∃ b ∈ s, a < f b := by
587583
apply Iff.intro
588-
· intro h'
589-
induction s using Finset.cons_induction with
590-
| h₁ => exact False.elim (not_lt_bot h')
591-
| @h₂ c s hc ih =>
592-
rw [sup_cons, _root_.lt_sup_iff] at h'
593-
cases h' with
594-
| inl h => exact ⟨c, mem_cons.2 (Or.inl rfl), h⟩
595-
| inr h =>
596-
rcases ih h with ⟨b, hb, hlt⟩
597-
exact ⟨b, mem_cons.2 (Or.inr hb), hlt⟩
598-
· rintro ⟨b, hb, hlt⟩
599-
exact lt_of_lt_of_le hlt (le_sup hb)
584+
· induction s using cons_induction with
585+
| empty => exact (absurd · not_lt_bot)
586+
| @cons c t hc ih =>
587+
rw [sup_cons, lt_sup_iff]
588+
exact fun
589+
| Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩
590+
| Or.inr h => let ⟨b, hb, hlt⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hlt⟩
591+
· exact fun ⟨b, hb, hlt⟩ => lt_of_lt_of_le hlt (le_sup hb)
600592
#align finset.lt_sup_iff Finset.lt_sup_iff
601593

602594
@[simp]
@@ -738,27 +730,27 @@ theorem comp_sup'_eq_sup'_comp [SemilatticeSup γ] {s : Finset β} (H : s.Nonemp
738730
rw [coe_sup']
739731
refine' comp_sup_eq_sup_comp g' _ rfl
740732
intro f₁ f₂
741-
induction f₁ using WithBot.recBotCoe with
742-
| h₁ =>
733+
cases f₁ using WithBot.recBotCoe with
734+
| bot =>
743735
rw [bot_sup_eq]
744736
exact bot_sup_eq.symm
745-
| h₂ f₁ =>
746-
induction f₂ using WithBot.recBotCoe with
747-
| h₁ => rfl
748-
| h₂ f₂ => exact congr_arg _ (g_sup f₁ f₂)
737+
| coe f₁ =>
738+
cases f₂ using WithBot.recBotCoe with
739+
| bot => rfl
740+
| coe f₂ => exact congr_arg _ (g_sup f₁ f₂)
749741
#align finset.comp_sup'_eq_sup'_comp Finset.comp_sup'_eq_sup'_comp
750742

751743
theorem sup'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂))
752744
(hs : ∀ b ∈ s, p (f b)) : p (s.sup' H f) := by
753745
show @WithBot.recBotCoe α (fun _ => Prop) True p ↑(s.sup' H f)
754746
rw [coe_sup']
755747
refine' sup_induction trivial _ hs
756-
rintro (_ | a₁) h1 a₂ h2
748+
rintro (_ | a₁) h₁ a₂ h₂
757749
· rw [WithBot.none_eq_bot, bot_sup_eq]
758-
exact h2
759-
induction a₂ using WithBot.recBotCoe with
760-
| h₁ => exact h1
761-
| h₂ a₂ => exact hp a₁ h1 a₂ h2
750+
exact h₂
751+
· cases a₂ using WithBot.recBotCoe with
752+
| bot => exact h₁
753+
| coe a₂ => exact hp a₁ h₁ a₂ h₂
762754
#align finset.sup'_induction Finset.sup'_induction
763755

764756
theorem sup'_mem (s : Set α) (w : ∀ (x) (_ : x ∈ s) (y) (_ : y ∈ s), x ⊔ y ∈ s) {ι : Type _}
@@ -824,37 +816,37 @@ theorem inf'_singleton {b : β} {h : ({b} : Finset β).Nonempty} : ({b} : Finset
824816
#align finset.inf'_singleton Finset.inf'_singleton
825817

826818
theorem le_inf' {a : α} (hs : ∀ b ∈ s, a ≤ f b) : a ≤ s.inf' H f :=
827-
@sup'_le αᵒᵈ _ _ _ H f _ hs
819+
sup'_le (α := αᵒᵈ) H f hs
828820
#align finset.le_inf' Finset.le_inf'
829821

830822
theorem inf'_le {b : β} (h : b ∈ s) : s.inf' ⟨b, h⟩ f ≤ f b :=
831-
@le_sup' αᵒᵈ _ _ _ f _ h
823+
le_sup' (α := αᵒᵈ) f h
832824
#align finset.inf'_le Finset.inf'_le
833825

834826
@[simp]
835827
theorem inf'_const (a : α) : (s.inf' H fun _ => a) = a :=
836-
@sup'_const αᵒᵈ _ _ _ H _
828+
sup'_const (α := αᵒᵈ) H a
837829
#align finset.inf'_const Finset.inf'_const
838830

839831
@[simp]
840832
theorem le_inf'_iff {a : α} : a ≤ s.inf' H f ↔ ∀ b ∈ s, a ≤ f b :=
841-
@sup'_le_iff αᵒᵈ _ _ _ H f _
833+
sup'_le_iff (α := αᵒᵈ) H f
842834
#align finset.le_inf'_iff Finset.le_inf'_iff
843835

844836
theorem inf'_bunionᵢ [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β}
845837
(Ht : ∀ b, (t b).Nonempty) :
846838
(s.bunionᵢ t).inf' (Hs.bunionᵢ fun b _ => Ht b) f = s.inf' Hs (fun b => (t b).inf' (Ht b) f) :=
847-
@sup'_bunionᵢ αᵒᵈ _ _ _ _ _ _ Hs _ Ht
839+
sup'_bunionᵢ (α := αᵒᵈ) _ Hs Ht
848840
#align finset.inf'_bUnion Finset.inf'_bunionᵢ
849841

850842
theorem comp_inf'_eq_inf'_comp [SemilatticeInf γ] {s : Finset β} (H : s.Nonempty) {f : β → α}
851843
(g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) : g (s.inf' H f) = s.inf' H (g ∘ f) :=
852-
@comp_sup'_eq_sup'_comp αᵒᵈ _ γᵒᵈ _ _ _ H f g g_inf
844+
comp_sup'_eq_sup'_comp (α := αᵒᵈ) (γ := γᵒᵈ) H g g_inf
853845
#align finset.comp_inf'_eq_inf'_comp Finset.comp_inf'_eq_inf'_comp
854846

855847
theorem inf'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂))
856848
(hs : ∀ b ∈ s, p (f b)) : p (s.inf' H f) :=
857-
@sup'_induction αᵒᵈ _ _ _ H f _ hp hs
849+
sup'_induction (α := αᵒᵈ) H f hp hs
858850
#align finset.inf'_induction Finset.inf'_induction
859851

860852
theorem inf'_mem (s : Set α) (w : ∀ (x) (_ : x ∈ s) (y) (_ : y ∈ s), x ⊓ y ∈ s) {ι : Type _}
@@ -865,13 +857,13 @@ theorem inf'_mem (s : Set α) (w : ∀ (x) (_ : x ∈ s) (y) (_ : y ∈ s), x
865857
@[congr]
866858
theorem inf'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) :
867859
s.inf' H f = t.inf' (h₁ ▸ H) g :=
868-
@sup'_congr αᵒᵈ _ _ _ H _ _ _ h₁ h₂
860+
sup'_congr (α := αᵒᵈ) H h₁ h₂
869861
#align finset.inf'_congr Finset.inf'_congr
870862

871863
@[simp]
872864
theorem inf'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty)
873865
(hs' : s.Nonempty := Finset.map_nonempty.mp hs) : (s.map f).inf' hs g = s.inf' hs' (g ∘ f) :=
874-
@sup'_map αᵒᵈ _ _ _ _ _ _ hs hs'
866+
sup'_map (α := αᵒᵈ) _ hs hs'
875867
#align finset.inf'_map Finset.inf'_map
876868

877869
end Inf'
@@ -900,17 +892,17 @@ section Inf
900892
variable [SemilatticeInf α] [OrderTop α]
901893

902894
theorem inf'_eq_inf {s : Finset β} (H : s.Nonempty) (f : β → α) : s.inf' H f = s.inf f :=
903-
@sup'_eq_sup αᵒᵈ _ _ _ _ H f
895+
sup'_eq_sup (α := αᵒᵈ) H f
904896
#align finset.inf'_eq_inf Finset.inf'_eq_inf
905897

906898
theorem inf_closed_of_inf_closed {s : Set α} (t : Finset α) (htne : t.Nonempty) (h_subset : ↑t ⊆ s)
907899
(h : ∀ (a) (_ : a ∈ s) (b) (_ : b ∈ s), a ⊓ b ∈ s) : t.inf id ∈ s :=
908-
@sup_closed_of_sup_closed αᵒᵈ _ _ _ t htne h_subset h
900+
sup_closed_of_sup_closed (α := αᵒᵈ) t htne h_subset h
909901
#align finset.inf_closed_of_inf_closed Finset.inf_closed_of_inf_closed
910902

911903
theorem coe_inf_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) :
912904
(↑(s.inf f) : WithTop α) = s.inf ((↑) ∘ f) :=
913-
@coe_sup_of_nonempty αᵒᵈ _ _ _ _ h f
905+
coe_sup_of_nonempty (α := αᵒᵈ) h f
914906
#align finset.coe_inf_of_nonempty Finset.coe_inf_of_nonempty
915907

916908
end Inf
@@ -926,7 +918,7 @@ protected theorem sup_apply {C : β → Type _} [∀ b : β, SemilatticeSup (C b
926918
protected theorem inf_apply {C : β → Type _} [∀ b : β, SemilatticeInf (C b)]
927919
[∀ b : β, OrderTop (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) :
928920
s.inf f b = s.inf fun a => f a b :=
929-
@Finset.sup_apply _ _ (fun b => (C b)ᵒᵈ) _ _ s f b
921+
Finset.sup_apply (C := fun b => (C b)ᵒᵈ) s f b
930922
#align finset.inf_apply Finset.inf_apply
931923

932924
@[simp]
@@ -940,7 +932,7 @@ protected theorem sup'_apply {C : β → Type _} [∀ b : β, SemilatticeSup (C
940932
protected theorem inf'_apply {C : β → Type _} [∀ b : β, SemilatticeInf (C b)]
941933
{s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) :
942934
s.inf' H f b = s.inf' H fun a => f a b :=
943-
@Finset.sup'_apply _ _ (fun b => (C b)ᵒᵈ) _ _ H f b
935+
Finset.sup'_apply (C := fun b => (C b)ᵒᵈ) H f b
944936
#align finset.inf'_apply Finset.inf'_apply
945937

946938
@[simp]
@@ -991,17 +983,17 @@ theorem sup'_lt_iff : s.sup' H f < a ↔ ∀ i ∈ s, f i < a := by
991983

992984
@[simp]
993985
theorem inf'_le_iff : s.inf' H f ≤ a ↔ ∃ i ∈ s, f i ≤ a :=
994-
@le_sup'_iff αᵒᵈ _ _ _ H f _
986+
le_sup'_iff (α := αᵒᵈ) H
995987
#align finset.inf'_le_iff Finset.inf'_le_iff
996988

997989
@[simp]
998990
theorem inf'_lt_iff : s.inf' H f < a ↔ ∃ i ∈ s, f i < a :=
999-
@lt_sup'_iff αᵒᵈ _ _ _ H f _
991+
lt_sup'_iff (α := αᵒᵈ) H
1000992
#align finset.inf'_lt_iff Finset.inf'_lt_iff
1001993

1002994
@[simp]
1003995
theorem lt_inf'_iff : a < s.inf' H f ↔ ∀ i ∈ s, a < f i :=
1004-
@sup'_lt_iff αᵒᵈ _ _ _ H f _
996+
sup'_lt_iff (α := αᵒᵈ) H
1005997
#align finset.lt_inf'_iff Finset.lt_inf'_iff
1006998

1007999
theorem exists_mem_eq_sup' (f : ι → α) : ∃ i, i ∈ s ∧ s.sup' H f = f i := by
@@ -1015,7 +1007,7 @@ theorem exists_mem_eq_sup' (f : ι → α) : ∃ i, i ∈ s ∧ s.sup' H f = f i
10151007
#align finset.exists_mem_eq_sup' Finset.exists_mem_eq_sup'
10161008

10171009
theorem exists_mem_eq_inf' (f : ι → α) : ∃ i, i ∈ s ∧ s.inf' H f = f i :=
1018-
@exists_mem_eq_sup' αᵒᵈ _ _ _ H f
1010+
exists_mem_eq_sup' (α := αᵒᵈ) H f
10191011
#align finset.exists_mem_eq_inf' Finset.exists_mem_eq_inf'
10201012

10211013
theorem exists_mem_eq_sup [OrderBot α] (s : Finset ι) (h : s.Nonempty) (f : ι → α) :
@@ -1025,7 +1017,7 @@ theorem exists_mem_eq_sup [OrderBot α] (s : Finset ι) (h : s.Nonempty) (f : ι
10251017

10261018
theorem exists_mem_eq_inf [OrderTop α] (s : Finset ι) (h : s.Nonempty) (f : ι → α) :
10271019
∃ i, i ∈ s ∧ s.inf f = f i :=
1028-
@exists_mem_eq_sup αᵒᵈ _ _ _ _ h f
1020+
exists_mem_eq_sup (α := αᵒᵈ) s h f
10291021
#align finset.exists_mem_eq_inf Finset.exists_mem_eq_inf
10301022

10311023
end LinearOrder

Mathlib/Data/Multiset/Basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ theorem cons_inj_right (a : α) : ∀ {s t : Multiset α}, a ::ₘ s = a ::ₘ t
152152
#align multiset.cons_inj_right Multiset.cons_inj_right
153153

154154
@[recursor 5]
155-
protected theorem induction {p : Multiset α → Prop} (h₁ : p 0)
156-
(h₂ : ∀ ⦃a : α⦄ {s : Multiset α}, p s → p (a ::ₘ s)) : ∀ s, p s := by
157-
rintro ⟨l⟩; induction' l with _ _ ih <;> [exact h₁, exact h₂ ih]
155+
protected theorem induction {p : Multiset α → Prop} (empty : p 0)
156+
(cons : ∀ ⦃a : α⦄ {s : Multiset α}, p s → p (a ::ₘ s)) : ∀ s, p s := by
157+
rintro ⟨l⟩; induction' l with _ _ ih <;> [exact empty, exact cons ih]
158158
#align multiset.induction Multiset.induction
159159

160160
@[elab_as_elim]

Mathlib/Order/WithBot.lean

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ theorem coe_ne_bot : (a : WithBot α) ≠ ⊥ :=
9595

9696
/-- Recursor for `WithBot` using the preferred forms `⊥` and `↑a`. -/
9797
@[elab_as_elim]
98-
def recBotCoe {C : WithBot α → Sort _} (h₁ : C ⊥) (h₂ : ∀ a : α, C a) :
99-
∀ n : WithBot α, C n
100-
| none => h₁
101-
| Option.some a => h₂ a
102-
98+
def recBotCoe {C : WithBot α → Sort _} (bot : C ⊥) (coe : ∀ a : α, C a) : ∀ n : WithBot α, C n
99+
| none => bot
100+
| Option.some a => coe a
103101
#align with_bot.rec_bot_coe WithBot.recBotCoe
104102

105103
@[simp]
@@ -612,9 +610,9 @@ theorem coe_ne_top : (a : WithTop α) ≠ ⊤ :=
612610

613611
/-- Recursor for `WithTop` using the preferred forms `⊤` and `↑a`. -/
614612
@[elab_as_elim]
615-
def recTopCoe {C : WithTop α → Sort _} (h₁ : C ⊤) (h₂ : ∀ a : α, C a) : ∀ n : WithTop α, C n
616-
| none => h₁
617-
| Option.some a => h₂ a
613+
def recTopCoe {C : WithTop α → Sort _} (top : C ⊤) (coe : ∀ a : α, C a) : ∀ n : WithTop α, C n
614+
| none => top
615+
| Option.some a => coe a
618616
#align with_top.rec_top_coe WithTop.recTopCoe
619617

620618
@[simp]

0 commit comments

Comments
 (0)