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

Commit c2f896f

Browse files
committed
feat(data/set): add some lemmas (#4263)
Some lemmas about sets, mostly involving disjointness I also sneaked in the lemma `(λ x : α, y) = const α y` which is useful to rewrite with.
1 parent 1892724 commit c2f896f

File tree

3 files changed

+57
-25
lines changed

3 files changed

+57
-25
lines changed

src/data/set/basic.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,8 +1886,11 @@ by { split_ifs; simp [h] }
18861886
theorem image_swap_eq_preimage_swap : image (@prod.swap α β) = preimage prod.swap :=
18871887
image_eq_preimage_of_inverse prod.swap_left_inverse prod.swap_right_inverse
18881888

1889+
theorem preimage_swap_prod {s : set α} {t : set β} : prod.swap ⁻¹' t.prod s = s.prod t :=
1890+
by { ext ⟨x, y⟩, simp [and_comm] }
1891+
18891892
theorem image_swap_prod : prod.swap '' t.prod s = s.prod t :=
1890-
by { ext ⟨x, y⟩, simp [image_swap_eq_preimage_swap, and_comm] }
1893+
by rw [image_swap_eq_preimage_swap, preimage_swap_prod]
18911894

18921895
theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} :
18931896
(image m₁ s).prod (image m₂ t) = image (λp:α×β, (m₁ p.1, m₂ p.2)) (s.prod t) :=

src/data/set/lattice.lean

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,73 +1005,100 @@ end set
10051005

10061006
/- disjoint sets -/
10071007

1008+
section disjoint
1009+
1010+
variables {s t u : set α}
1011+
1012+
namespace disjoint
1013+
1014+
/-! We define some lemmas in the `disjoint` namespace to be able to use projection notation. -/
1015+
1016+
theorem union_left (hs : disjoint s u) (ht : disjoint t u) : disjoint (s ∪ t) u :=
1017+
hs.sup_left ht
1018+
1019+
theorem union_right (ht : disjoint s t) (hu : disjoint s u) : disjoint s (t ∪ u) :=
1020+
ht.sup_right hu
1021+
1022+
lemma preimage {α β} (f : α → β) {s t : set β} (h : disjoint s t) : disjoint (f ⁻¹' s) (f ⁻¹' t) :=
1023+
λ x hx, h hx
1024+
1025+
end disjoint
1026+
10081027
namespace set
10091028

1010-
protected theorem disjoint_iff {s t : set α} : disjoint s t ↔ s ∩ t ⊆ ∅ := iff.rfl
1029+
protected theorem disjoint_iff : disjoint s t ↔ s ∩ t ⊆ ∅ := iff.rfl
10111030

1012-
theorem disjoint_iff_inter_eq_empty {s t : set α} : disjoint s t ↔ s ∩ t = ∅ :=
1031+
theorem disjoint_iff_inter_eq_empty : disjoint s t ↔ s ∩ t = ∅ :=
10131032
disjoint_iff
10141033

1015-
lemma not_disjoint_iff {s t : set α} : ¬disjoint s t ↔ ∃x, x ∈ s ∧ x ∈ t :=
1034+
lemma not_disjoint_iff : ¬disjoint s t ↔ ∃x, x ∈ s ∧ x ∈ t :=
10161035
not_forall.trans $ exists_congr $ λ x, not_not
10171036

1018-
lemma disjoint_left {s t : set α} : disjoint s t ↔ ∀ {a}, a ∈ s → a ∉ t :=
1037+
lemma disjoint_left : disjoint s t ↔ ∀ {a}, a ∈ s → a ∉ t :=
10191038
show (∀ x, ¬(x ∈ s ∩ t)) ↔ _, from ⟨λ h a, not_and.1 $ h a, λ h a, not_and.2 $ h a⟩
10201039

1021-
theorem disjoint_right {s t : set α} : disjoint s t ↔ ∀ {a}, a ∈ t → a ∉ s :=
1040+
theorem disjoint_right : disjoint s t ↔ ∀ {a}, a ∈ t → a ∉ s :=
10221041
by rw [disjoint.comm, disjoint_left]
10231042

1024-
theorem disjoint_of_subset_left {s t u : set α} (h : s ⊆ u) (d : disjoint u t) : disjoint s t :=
1043+
theorem disjoint_of_subset_left (h : s ⊆ u) (d : disjoint u t) : disjoint s t :=
10251044
d.mono_left h
10261045

1027-
theorem disjoint_of_subset_right {s t u : set α} (h : t ⊆ u) (d : disjoint s u) : disjoint s t :=
1046+
theorem disjoint_of_subset_right (h : t ⊆ u) (d : disjoint s u) : disjoint s t :=
10281047
d.mono_right h
10291048

10301049
theorem disjoint_of_subset {s t u v : set α} (h1 : s ⊆ u) (h2 : t ⊆ v) (d : disjoint u v) :
10311050
disjoint s t :=
10321051
d.mono h1 h2
10331052

1034-
@[simp] theorem disjoint_union_left {s t u : set α} :
1053+
@[simp] theorem disjoint_union_left :
10351054
disjoint (s ∪ t) u ↔ disjoint s u ∧ disjoint t u :=
10361055
disjoint_sup_left
10371056

1038-
theorem disjoint.union_left {s t u : set α} (hs : disjoint s u) (ht : disjoint t u) :
1039-
disjoint (s ∪ t) u :=
1040-
hs.sup_left ht
1041-
1042-
@[simp] theorem disjoint_union_right {s t u : set α} :
1057+
@[simp] theorem disjoint_union_right :
10431058
disjoint s (t ∪ u) ↔ disjoint s t ∧ disjoint s u :=
10441059
disjoint_sup_right
10451060

1046-
theorem disjoint.union_right {s t u : set α} (ht : disjoint s t) (hu : disjoint s u) :
1047-
disjoint s (t ∪ u) :=
1048-
ht.sup_right hu
1049-
10501061
theorem disjoint_diff {a b : set α} : disjoint a (b \ a) :=
10511062
disjoint_iff.2 (inter_diff_self _ _)
10521063

10531064
theorem disjoint_compl_left (s : set α) : disjoint sᶜ s := assume a ⟨h₁, h₂⟩, h₁ h₂
10541065

10551066
theorem disjoint_compl_right (s : set α) : disjoint s sᶜ := assume a ⟨h₁, h₂⟩, h₂ h₁
10561067

1057-
theorem disjoint_singleton_left {a : α} {s : set α} : disjoint {a} s ↔ a ∉ s :=
1068+
@[simp] lemma univ_disjoint {s : set α}: disjoint univ s ↔ s = ∅ :=
1069+
by simp [set.disjoint_iff_inter_eq_empty]
1070+
1071+
@[simp] lemma disjoint_univ {s : set α} : disjoint s univ ↔ s = ∅ :=
1072+
by simp [set.disjoint_iff_inter_eq_empty]
1073+
1074+
@[simp] theorem disjoint_singleton_left {a : α} {s : set α} : disjoint {a} s ↔ a ∉ s :=
10581075
by simp [set.disjoint_iff, subset_def]; exact iff.rfl
10591076

1060-
theorem disjoint_singleton_right {a : α} {s : set α} : disjoint s {a} ↔ a ∉ s :=
1077+
@[simp] theorem disjoint_singleton_right {a : α} {s : set α} : disjoint s {a} ↔ a ∉ s :=
10611078
by rw [disjoint.comm]; exact disjoint_singleton_left
10621079

10631080
theorem disjoint_image_image {f : β → α} {g : γ → α} {s : set β} {t : set γ}
10641081
(h : ∀b∈s, ∀c∈t, f b ≠ g c) : disjoint (f '' s) (g '' t) :=
10651082
by rintros a ⟨⟨b, hb, eq⟩, ⟨c, hc, rfl⟩⟩; exact h b hb c hc eq
10661083

1067-
lemma disjoint.preimage {α β} (f : α → β) {s t : set β} (h : disjoint s t) :
1068-
disjoint (f ⁻¹' s) (f ⁻¹' t) :=
1069-
λ x hx, h hx
1070-
10711084
theorem pairwise_on_disjoint_fiber (f : α → β) (s : set β) :
10721085
pairwise_on s (disjoint on (λ y, f ⁻¹' {y})) :=
10731086
λ y₁ _ y₂ _ hy x ⟨hx₁, hx₂⟩, hy (eq.trans (eq.symm hx₁) hx₂)
10741087

1088+
lemma preimage_eq_empty {f : α → β} {s : set β} (h : disjoint s (range f)) :
1089+
f ⁻¹' s = ∅ :=
1090+
by simpa using h.preimage f
1091+
1092+
lemma preimage_eq_empty_iff {f : α → β} {s : set β} : disjoint s (range f) ↔ f ⁻¹' s = ∅ :=
1093+
⟨preimage_eq_empty,
1094+
λ h, by { simp [eq_empty_iff_forall_not_mem, set.disjoint_iff_inter_eq_empty] at h ⊢, finish }⟩
1095+
1096+
end set
1097+
1098+
end disjoint
1099+
1100+
namespace set
1101+
10751102
/-- A collection of sets is `pairwise_disjoint`, if any two different sets in this collection
10761103
are disjoint. -/
10771104
def pairwise_disjoint (s : set (set α)) : Prop :=
@@ -1088,7 +1115,7 @@ begin
10881115
intro h, apply hxy, apply congr_arg f, exact subtype.eq h
10891116
end
10901117

1091-
/- warning: classical -/
1118+
/- classical -/
10921119
lemma pairwise_disjoint.elim {s : set (set α)} (h : pairwise_disjoint s) {x y : set α}
10931120
(hx : x ∈ s) (hy : y ∈ s) (z : α) (hzx : z ∈ x) (hzy : z ∈ y) : x = y :=
10941121
not_not.1 $ λ h', h x hx y hy h' ⟨hzx, hzy⟩

src/logic/function/basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ variables {α β γ : Sort*} {f : α → β}
2626
lemma comp_apply {α : Sort u} {β : Sort v} {φ : Sort w} (f : β → φ) (g : α → β) (a : α) :
2727
(f ∘ g) a = f (g a) := rfl
2828

29+
lemma const_def {y : β} : (λ x : α, y) = const α y := rfl
30+
2931
@[simp] lemma const_apply {y : β} {x : α} : const α y x = y := rfl
3032

3133
@[simp] lemma const_comp {f : α → β} {c : γ} : const β c ∘ f = const α c := rfl

0 commit comments

Comments
 (0)