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

Commit ad7ef86

Browse files
committed
refactor(set_theory/cardinal): split up mk_Union_le_mk_sigma, add mk_Union_eq_mk_sigma; add equiv congruence for subtype
1 parent 8a1de24 commit ad7ef86

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

src/data/equiv/basic.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ def pi_equiv_subtype_sigma (ι : Type*) (π : ι → Type*) :
507507
assume ⟨f, hf⟩, subtype.eq $ funext $ assume i, sigma.eq (hf i).symm $
508508
eq_of_heq $ rec_heq_of_heq _ $ rec_heq_of_heq _ $ heq.refl _⟩
509509

510+
def subtype_congr {α : Type*} {p q : α → Prop} (h : p = q) : subtype p ≃ subtype q :=
511+
⟨subtype.map id $ by rw [h]; exact assume h, id, subtype.map id $ by rw [h]; exact assume h, id,
512+
assume ⟨a, h⟩, rfl, assume ⟨a, h⟩, rfl,⟩
513+
514+
def set_congr {α : Type*} {s t : set α} (h : s = t) : s ≃ t :=
515+
subtype_congr h
516+
510517
end
511518

512519
section

src/data/set/lattice.lean

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -664,24 +664,34 @@ end disjoint
664664
theorem set.disjoint_diff {a b : set α} : disjoint a (b \ a) :=
665665
disjoint_iff.2 (inter_diff_self _ _)
666666

667-
section
668-
open set
669-
set_option eqn_compiler.zeta true
667+
namespace set
668+
variables (t : α → set β)
670669

671-
noncomputable def set.bUnion_eq_sigma_of_disjoint {α β} {s : set α} {t : α → set β}
672-
(h : pairwise_on s (disjoint on t)) : (⋃i∈s, t i) ≃ (Σi:s, t i.val) :=
673-
let f : (Σi:s, t i.val) → (⋃i∈s, t i) := λ⟨⟨a, ha⟩, ⟨b, hb⟩⟩, ⟨b, mem_bUnion ha hb⟩ in
674-
have injective f,
675-
from assume ⟨⟨a₁, ha₁⟩, ⟨b₁, hb₁⟩⟩ ⟨⟨a₂, ha₂⟩, ⟨b₂, hb₂⟩⟩ eq,
670+
def sigma_to_Union (x : Σi, t i) : (⋃i, t i) := ⟨x.2, mem_Union.2 ⟨x.1, x.2.2⟩⟩
671+
672+
lemma surjective_sigma_to_Union : surjective (sigma_to_Union t)
673+
| ⟨b, hb⟩ := have ∃a, b ∈ t a, by simpa using hb, let ⟨a, hb⟩ := this in ⟨⟨a, ⟨b, hb⟩⟩, rfl⟩
674+
675+
lemma injective_sigma_to_Union (h : ∀i j, i ≠ j → disjoint (t i) (t j)) :
676+
injective (sigma_to_Union t)
677+
| ⟨a₁, ⟨b₁, h₁⟩⟩ ⟨a₂, ⟨b₂, h₂⟩⟩ eq :=
676678
have b_eq : b₁ = b₂, from congr_arg subtype.val eq,
677679
have a_eq : a₁ = a₂, from classical.by_contradiction $ assume ne,
678-
have b₁ ∈ t a₁ ∩ t a₂, from ⟨hb₁, b_eq.symm ▸ hb₂⟩,
679-
h _ ha₁ _ ha₂ ne this,
680-
sigma.eq (subtype.eq a_eq) (subtype.eq $ by subst b_eq; subst a_eq),
681-
have surjective f,
682-
from assume ⟨b, hb⟩,
683-
have ∃a∈s, b ∈ t a, by simpa using hb,
684-
let ⟨a, ha, hb⟩ := this in ⟨⟨⟨a, ha⟩, ⟨b, hb⟩⟩, rfl⟩,
685-
(equiv.of_bijective ⟨‹injective f›, ‹surjective f›⟩).symm
680+
have b₁ ∈ t a₁ ∩ t a₂, from ⟨h₁, b_eq.symm ▸ h₂⟩,
681+
h _ _ ne this,
682+
sigma.eq a_eq $ subtype.eq $ by subst b_eq; subst a_eq
686683

687-
end
684+
lemma bijective_sigma_to_Union (h : ∀i j, i ≠ j → disjoint (t i) (t j)) :
685+
bijective (sigma_to_Union t) :=
686+
⟨injective_sigma_to_Union t h, surjective_sigma_to_Union t⟩
687+
688+
noncomputable def Union_eq_sigma_of_disjoint {t : α → set β}
689+
(h : ∀i j, i ≠ j → disjoint (t i) (t j)) : (⋃i, t i) ≃ (Σi, t i) :=
690+
(equiv.of_bijective $ bijective_sigma_to_Union t h).symm
691+
692+
noncomputable def bUnion_eq_sigma_of_disjoint {s : set α} {t : α → set β}
693+
(h : pairwise_on s (disjoint on t)) : (⋃i∈s, t i) ≃ (Σi:s, t i.val) :=
694+
equiv.trans (equiv.set_congr (bUnion_eq_Union _ _)) $ Union_eq_sigma_of_disjoint $
695+
assume ⟨i, hi⟩ ⟨j, hj⟩ ne, h _ hi _ hj $ assume eq, ne $ subtype.eq eq
696+
697+
end set

src/set_theory/cardinal.lean

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -699,16 +699,18 @@ mk_le_of_surjective surjective_onto_image
699699
theorem mk_range_le {α β : Type u} {f : α → β} {s : set α} : mk (range f) ≤ mk α :=
700700
mk_le_of_surjective surjective_onto_range
701701

702-
theorem mk_eq_of_injective {α β : Type u} {f : α → β} {s : set α} (hf : injective f) : mk (f '' s) = mk s :=
702+
theorem mk_eq_of_injective {α β : Type u} {f : α → β} {s : set α} (hf : injective f) :
703+
mk (f '' s) = mk s :=
703704
quotient.sound ⟨(equiv.set.image f s hf).symm⟩
704705

705706
theorem mk_Union_le_sum_mk {α ι : Type u} {f : ι → set α} : mk (⋃ i, f i) ≤ sum (λ i, mk (f i)) :=
706-
calc mk (⋃ i, f i)
707-
≤ mk (Σ i, f i) :
708-
let f : (Σ i, f i) → (⋃ i, f i) := λ ⟨i, x, hx⟩, ⟨x, mem_Union.2 ⟨i, hx⟩⟩ in
709-
have surjective f := λ ⟨x, hx⟩, let ⟨i, hi⟩ := mem_Union.1 hx in ⟨⟨i, x, hi⟩, rfl⟩,
710-
mk_le_of_surjective this
711-
... = sum (λ i, mk (f i)) : (sum_mk _).symm
707+
calc mk (⋃ i, f i) ≤ mk (Σ i, f i) : mk_le_of_surjective (set.surjective_sigma_to_Union f)
708+
... = sum (λ i, mk (f i)) : (sum_mk _).symm
709+
710+
theorem mk_Union_eq_sum_mk {α ι : Type u} {f : ι → set α} (h : ∀i j, i ≠ j → disjoint (f i) (f j)) :
711+
mk (⋃ i, f i) = sum (λ i, mk (f i)) :=
712+
calc mk (⋃ i, f i) = mk (Σi, f i) : quot.sound ⟨set.Union_eq_sigma_of_disjoint h⟩
713+
... = sum (λi, mk (f i)) : (sum_mk _).symm
712714

713715
@[simp] lemma finset_card {α : Type u} {s : finset α} : ↑(finset.card s) = mk (↑s : set α) :=
714716
by rw [fintype_card, nat_cast_inj, fintype.card_coe]

0 commit comments

Comments
 (0)