Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit e744033

Browse files
committed
feat(data/finset/basic, lattice): Simple lemmas (#9723)
This proves lemmas about `finset.sup`/`finset.inf` and `finset.singleton`.
1 parent bf34d9b commit e744033

File tree

3 files changed

+108
-6
lines changed

3 files changed

+108
-6
lines changed

src/data/finset/basic.lean

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,11 @@ theorem not_mem_singleton {a b : α} : a ∉ ({b} : finset α) ↔ a ≠ b := no
402402

403403
theorem mem_singleton_self (a : α) : a ∈ ({a} : finset α) := or.inl rfl
404404

405+
lemma singleton_injective : injective (singleton : α → finset α) :=
406+
λ a b h, mem_singleton.1 (h ▸ mem_singleton_self _)
407+
405408
theorem singleton_inj {a b : α} : ({a} : finset α) = {b} ↔ a = b :=
406-
⟨λ h, mem_singleton.1 (h ▸ mem_singleton_self _), congr_arg _⟩
409+
singleton_injective.eq_iff
407410

408411
@[simp] theorem singleton_nonempty (a : α) : ({a} : finset α).nonempty := ⟨a, mem_singleton_self a⟩
409412

@@ -644,6 +647,21 @@ theorem induction_on' {α : Type*} {p : finset α → Prop} [decidable_eq α]
644647
@finset.induction_on α (λ T, T ⊆ S → p T) _ S (λ _, h₁) (λ a s has hqs hs,
645648
let ⟨hS, sS⟩ := finset.insert_subset.1 hs in h₂ hS sS has (hqs sS)) (finset.subset.refl S)
646649

650+
/-- To prove a proposition about a nonempty `s : finset α`, it suffices to show it holds for all
651+
singletons and that if it holds for `t : finset α`, then it also holds for the `finset` obtained by
652+
inserting an element in `t`. -/
653+
@[elab_as_eliminator]
654+
lemma nonempty.cons_induction {α : Type*} {s : finset α} (hs : s.nonempty) {p : finset α → Prop}
655+
(h₀ : ∀ a, p {a}) (h₁ : ∀ ⦃a⦄ s (h : a ∉ s), p s → p (finset.cons a s h)) :
656+
p s :=
657+
begin
658+
induction s using finset.cons_induction with a t ha h,
659+
{ exact (not_nonempty_empty hs).elim, },
660+
obtain rfl | ht := t.eq_empty_or_nonempty,
661+
{ exact h₀ a },
662+
{ exact h₁ t ha (h ht) }
663+
end
664+
647665
/-- Inserting an element to a finite set is equivalent to the option type. -/
648666
def subtype_insert_equiv_option {t : finset α} {x : α} (h : x ∉ t) :
649667
{i // i ∈ insert x t} ≃ option {i // i ∈ t} :=
@@ -2170,6 +2188,8 @@ card_eq_zero.trans val_eq_zero
21702188
theorem card_pos {s : finset α} : 0 < card s ↔ s.nonempty :=
21712189
pos_iff_ne_zero.trans $ (not_congr card_eq_zero).trans nonempty_iff_ne_empty.symm
21722190

2191+
alias finset.card_pos ↔ _ finset.nonempty.card_pos
2192+
21732193
theorem card_ne_zero_of_mem {s : finset α} {a : α} (h : a ∈ s) : card s ≠ 0 :=
21742194
(not_congr card_eq_zero).2 (ne_empty_of_mem h)
21752195

@@ -2794,6 +2814,13 @@ by rw [disjoint.comm, disjoint_left]
27942814
theorem disjoint_iff_ne {s t : finset α} : disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b :=
27952815
by simp only [disjoint_left, imp_not_comm, forall_eq']
27962816

2817+
lemma not_disjoint_iff {s t : finset α} :
2818+
¬disjoint s t ↔ ∃ a, a ∈ s ∧ a ∈ t :=
2819+
not_forall.trans $ exists_congr $ λ a, begin
2820+
rw [finset.inf_eq_inter, finset.mem_inter],
2821+
exact not_not,
2822+
end
2823+
27972824
theorem disjoint_of_subset_left {s t u : finset α} (h : s ⊆ u) (d : disjoint u t) : disjoint s t :=
27982825
disjoint_left.2 (λ x m₁, (disjoint_left.1 d) (h m₁))
27992826

src/data/finset/lattice.lean

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ variables [semilattice_sup_bot α]
2525
/-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/
2626
def sup (s : finset β) (f : β → α) : α := s.fold (⊔) ⊥ f
2727

28-
variables {s s₁ s₂ : finset β} {f : β → α}
28+
variables {s s₁ s₂ : finset β} {f g : β → α}
2929

3030
lemma sup_def : s.sup f = (s.1.map f).sup := rfl
3131

@@ -38,7 +38,7 @@ fold_cons h
3838
@[simp] lemma sup_insert [decidable_eq β] {b : β} : (insert b s : finset β).sup f = f b ⊔ s.sup f :=
3939
fold_insert_idem
4040

41-
lemma sup_image [decidable_eq β] (s : finset γ) (f : γ → β) (g : β → α):
41+
lemma sup_image [decidable_eq β] (s : finset γ) (f : γ → β) (g : β → α) :
4242
(s.image f).sup g = s.sup (g ∘ f) :=
4343
fold_image_idem
4444

@@ -53,6 +53,14 @@ lemma sup_union [decidable_eq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.
5353
finset.induction_on s₁ (by rw [empty_union, sup_empty, bot_sup_eq]) $ λ a s has ih,
5454
by rw [insert_union, sup_insert, sup_insert, ih, sup_assoc]
5555

56+
lemma sup_sup : s.sup (f ⊔ g) = s.sup f ⊔ s.sup g :=
57+
begin
58+
refine finset.cons_induction_on s _ (λ b t _ h, _),
59+
{ rw [sup_empty, sup_empty, sup_empty, bot_sup_eq] },
60+
{ rw [sup_cons, sup_cons, sup_cons, h],
61+
exact sup_sup_sup_comm _ _ _ _ }
62+
end
63+
5664
theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a∈s₂, f a = g a) : s₁.sup f = s₂.sup g :=
5765
by subst hs; exact finset.fold_congr hfg
5866

@@ -98,6 +106,26 @@ sup_le $ assume b hb, le_sup (h hb)
98106
(λ h, ⟨c, or.inl rfl, h⟩) (λ h, let ⟨b, hb, hlt⟩ := ih h in ⟨b, or.inr hb, hlt⟩)),
99107
(λ ⟨b, hb, hlt⟩, lt_of_lt_of_le hlt (le_sup hb))⟩
100108

109+
@[simp] lemma sup_attach (s : finset β) (f : β → α) : s.attach.sup (λ x, f x) = s.sup f :=
110+
(s.attach.sup_map (function.embedding.subtype _) f).symm.trans $ congr_arg _ attach_map_val
111+
112+
@[simp] lemma sup_erase_bot [decidable_eq α] (s : finset α) : (s.erase ⊥).sup id = s.sup id :=
113+
begin
114+
refine (sup_mono (s.erase_subset _)).antisymm (finset.sup_le_iff.2 $ λ a ha, _),
115+
obtain rfl | ha' := eq_or_ne a ⊥,
116+
{ exact bot_le },
117+
{ exact le_sup (mem_erase.2 ⟨ha', ha⟩) }
118+
end
119+
120+
lemma sup_sdiff_right {α β : Type*} [generalized_boolean_algebra α] (s : finset β) (f : β → α)
121+
(a : α) :
122+
s.sup (λ b, f b \ a) = s.sup f \ a :=
123+
begin
124+
refine finset.cons_induction_on s _ (λ b t _ h, _),
125+
{ rw [sup_empty, sup_empty, bot_sdiff] },
126+
{ rw [sup_cons, sup_cons, h, sup_sdiff] }
127+
end
128+
101129
lemma comp_sup_eq_sup_comp [semilattice_sup_bot γ] {s : finset β}
102130
{f : β → α} (g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) :
103131
g (s.sup f) = s.sup (g ∘ f) :=
@@ -137,7 +165,7 @@ begin
137165
end
138166

139167
lemma sup_le_of_le_directed {α : Type*} [semilattice_sup_bot α] (s : set α)
140-
(hs : s.nonempty) (hdir : directed_on (≤) s) (t : finset α):
168+
(hs : s.nonempty) (hdir : directed_on (≤) s) (t : finset α) :
141169
(∀ x ∈ t, ∃ y ∈ s, x ≤ y) → ∃ x, x ∈ s ∧ t.sup id ≤ x :=
142170
begin
143171
classical,
@@ -188,7 +216,7 @@ variables [semilattice_inf_top α]
188216
/-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/
189217
def inf (s : finset β) (f : β → α) : α := s.fold (⊓) ⊤ f
190218

191-
variables {s s₁ s₂ : finset β} {f : β → α}
219+
variables {s s₁ s₂ : finset β} {f g : β → α}
192220

193221
lemma inf_def : s.inf f = (s.1.map f).inf := rfl
194222

@@ -201,7 +229,7 @@ fold_empty
201229
@[simp] lemma inf_insert [decidable_eq β] {b : β} : (insert b s : finset β).inf f = f b ⊓ s.inf f :=
202230
fold_insert_idem
203231

204-
lemma inf_image [decidable_eq β] (s : finset γ) (f : γ → β) (g : β → α):
232+
lemma inf_image [decidable_eq β] (s : finset γ) (f : γ → β) (g : β → α) :
205233
(s.image f).inf g = s.inf (g ∘ f) :=
206234
fold_image_idem
207235

@@ -215,6 +243,9 @@ inf_singleton
215243
lemma inf_union [decidable_eq β] : (s₁ ∪ s₂).inf f = s₁.inf f ⊓ s₂.inf f :=
216244
@sup_union (order_dual α) _ _ _ _ _ _
217245

246+
lemma inf_inf : s.inf (f ⊓ g) = s.inf f ⊓ s.inf g :=
247+
@sup_sup (order_dual α) _ _ _ _ _
248+
218249
theorem inf_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a∈s₂, f a = g a) : s₁.inf f = s₂.inf g :=
219250
by subst hs; exact finset.fold_congr hfg
220251

@@ -249,6 +280,38 @@ le_inf $ assume b hb, inf_le (h hb)
249280
@[simp] lemma inf_lt_iff [is_total α (≤)] {a : α} : s.inf f < a ↔ (∃ b ∈ s, f b < a) :=
250281
@lt_sup_iff (order_dual α) _ _ _ _ _ _
251282

283+
lemma inf_attach (s : finset β) (f : β → α) : s.attach.inf (λ x, f x) = s.inf f :=
284+
@sup_attach (order_dual α) _ _ _ _
285+
286+
@[simp] lemma inf_erase_top [decidable_eq α] (s : finset α) : (s.erase ⊤).inf id = s.inf id :=
287+
@sup_erase_bot (order_dual α) _ _ _
288+
289+
lemma sup_sdiff_left {α β : Type*} [boolean_algebra α] (s : finset β) (f : β → α) (a : α) :
290+
s.sup (λ b, a \ f b) = a \ s.inf f :=
291+
begin
292+
refine finset.cons_induction_on s _ (λ b t _ h, _),
293+
{ rw [sup_empty, inf_empty, sdiff_top] },
294+
{ rw [sup_cons, inf_cons, h, sdiff_inf] }
295+
end
296+
297+
lemma inf_sdiff_left {α β : Type*} [boolean_algebra α] {s : finset β} (hs : s.nonempty) (f : β → α)
298+
(a : α) :
299+
s.inf (λ b, a \ f b) = a \ s.sup f :=
300+
begin
301+
refine hs.cons_induction (λ b, _) (λ b t _ h, _),
302+
{ rw [sup_singleton, inf_singleton] },
303+
{ rw [sup_cons, inf_cons, h, sdiff_sup] }
304+
end
305+
306+
lemma inf_sdiff_right {α β : Type*} [boolean_algebra α] {s : finset β} (hs : s.nonempty) (f : β → α)
307+
(a : α) :
308+
s.inf (λ b, f b \ a) = s.inf f \ a :=
309+
begin
310+
refine hs.cons_induction (λ b, _) (λ b t _ h, _),
311+
{ rw [inf_singleton, inf_singleton] },
312+
{ rw [inf_cons, inf_cons, h, inf_sdiff] }
313+
end
314+
252315
lemma comp_inf_eq_inf_comp [semilattice_inf_top γ] {s : finset β}
253316
{f : β → α} (g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) (top : g ⊤ = ⊤) :
254317
g (s.inf f) = s.inf (g ∘ f) :=
@@ -892,6 +955,12 @@ lemma sup_eq_bUnion {α β} [decidable_eq β] (s : finset α) (t : α → finset
892955
s.sup t = s.bUnion t :=
893956
by { ext, rw [mem_sup, mem_bUnion], }
894957

958+
@[simp] lemma sup_singleton' [decidable_eq α] (s : finset α) : s.sup singleton = s :=
959+
begin
960+
refine (finset.sup_le $ λ a, _).antisymm (λ a ha, mem_sup.2 ⟨a, ha, mem_singleton_self a⟩),
961+
exact singleton_subset_iff.2,
962+
end
963+
895964
end finset
896965

897966
section lattice

src/order/lattice.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a]
234234
lemma sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b :=
235235
by rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
236236

237+
lemma sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) :=
238+
by rw [sup_assoc, sup_left_comm b, ←sup_assoc]
239+
237240
lemma forall_le_or_exists_lt_sup (a : α) : (∀b, b ≤ a) ∨ (∃b, a < b) :=
238241
suffices (∃b, ¬b ≤ a) → (∃b, a < b),
239242
by rwa [or_iff_not_imp_left, not_forall],
@@ -389,6 +392,9 @@ lemma inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) :=
389392
lemma inf_right_comm (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ b :=
390393
@sup_right_comm (order_dual α) _ a b c
391394

395+
lemma inf_inf_inf_comm (a b c d : α) : a ⊓ b ⊓ (c ⊓ d) = a ⊓ c ⊓ (b ⊓ d) :=
396+
@sup_sup_sup_comm (order_dual α) _ _ _ _ _
397+
392398
lemma forall_le_or_exists_lt_inf (a : α) : (∀b, a ≤ b) ∨ (∃b, b < a) :=
393399
@forall_le_or_exists_lt_sup (order_dual α) _ a
394400

0 commit comments

Comments
 (0)