Skip to content

Commit 1f7c79f

Browse files
Jun2Mapnelson1pre-commit-ci-lite[bot]
committed
feat(Order/Partition): add Rel, relation induced by partition on Set (leanprover-community#36991)
**Main changes:** * **Set partition API**: Adds a `Set` section with various useful lemmas for working with partitions of sets. * **Induced relation**: Defines `Partition.Rel`, a transitive and symmetric binary relation (partial equivalence relation) induced by a partition of a set. Co-authored-by: Peter Nelson <apn.uni@gmail.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent eb4f246 commit 1f7c79f

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Mathlib/Order/Partition/Basic.lean

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ of `Q`.
2727
* `Partition s`: For `[CompleteLattice α]` and `s : α`, a `Partition s` is an independent
2828
collection of nontrivial elements whose supremum is `s`.
2929
* `Partition.removeBot`: A constructor for `Partition s` that removes `⊥` from a set of parts.
30+
* `Partition.Rel`: The partial equivalence relation induced by a partition of a set.
3031
3132
## TODO
3233
@@ -214,4 +215,102 @@ lemma parts_top_subset : ((⊤ : Partition s) : Set α) ⊆ {s} := by
214215

215216
end Order
216217

218+
variable {S : Set (Set α)} {u s t : Set α} {a b c : α} {P Q : Partition u}
219+
220+
section Set
221+
222+
@[simp] protected lemma sUnion_eq (P : Partition s) : ⋃₀ P = s := P.sSup_eq
223+
224+
lemma nonempty_of_mem (ht : t ∈ P) : t.Nonempty := notMem_singleton_empty.1 <| P.ne_bot_of_mem ht
225+
226+
lemma empty_notMem : ∅ ∉ P := P.bot_notMem
227+
228+
lemma subset_of_mem (ht : t ∈ P) : t ⊆ u := P.le_of_mem ht
229+
230+
lemma mem_iff_exists : x ∈ u ↔ ∃ t ∈ P, x ∈ t := by
231+
refine ⟨fun hx ↦ ?_, fun ⟨t, htP, hxt⟩ ↦ subset_of_mem htP hxt⟩
232+
rwa [← P.sUnion_eq, mem_sUnion] at hx
233+
234+
lemma eq_of_mem_inter (ht : t ∈ P) (hs : s ∈ P) (hx : x ∈ t ∩ s) : t = s :=
235+
PairwiseDisjoint.elim P.pairwiseDisjoint ht hs fun
236+
(hdj : Disjoint t s) ↦ by simp [hdj.inter_eq] at hx
237+
238+
lemma eq_of_mem_of_mem (ht : t ∈ P) (hus : s ∈ P) (hxt : x ∈ t) (hxs : x ∈ s) : t = s :=
239+
eq_of_mem_inter ht hus ⟨hxt, hxs⟩
240+
241+
lemma mem_iff_unique : x ∈ u ↔ ∃! t, t ∈ P ∧ x ∈ t := by
242+
refine ⟨fun hx ↦ ?_, fun ⟨_, ⟨htP, hxt⟩, _⟩ ↦ subset_of_mem htP hxt⟩
243+
rw [← P.sUnion_eq, mem_sUnion] at hx
244+
obtain ⟨t, ht, hxt⟩ := hx
245+
exact ⟨t, ⟨ht, hxt⟩, fun s ⟨hsP, hxs⟩ ↦ P.eq_of_mem_of_mem hsP ht hxs hxt⟩
246+
247+
lemma subset_sUnion_and_mem_iff_mem (hSP : S ⊆ P) : t ⊆ ⋃₀ S ∧ t ∈ P ↔ t ∈ S := by
248+
refine ⟨fun ⟨htsu, htP⟩ ↦ ?_, fun htS ↦ ⟨subset_sUnion_of_mem htS, hSP htS⟩⟩
249+
obtain ⟨x, hxt⟩ := nonempty_of_mem htP
250+
obtain ⟨s, hsS, hxs⟩ := htsu hxt
251+
obtain rfl := eq_of_mem_of_mem htP (hSP hsS) hxt hxs
252+
exact hsS
253+
254+
lemma subset_sUnion_iff_mem (ht : t ∈ P) (hSP : S ⊆ P.parts) : t ⊆ ⋃₀ S ↔ t ∈ S := by
255+
rw [← subset_sUnion_and_mem_iff_mem hSP]
256+
simp [ht]
257+
258+
end Set
259+
260+
/-! ### Induced relation -/
261+
262+
section Rel
263+
264+
/-- Every partition of `s : Set α` induces a transitive, symmetric binary relation on `α`
265+
whose equivalence classes are the parts of `P`. The relation is irreflexive outside `s`. -/
266+
def Rel (P : Partition s) (a b : α) : Prop :=
267+
∃ t ∈ P, a ∈ t ∧ b ∈ t
268+
269+
lemma rel_le_iff_le : P.Rel ≤ Q.Rel ↔ P ≤ Q := by
270+
refine ⟨fun h S hS ↦ ?_, fun h a b ⟨t, ht, ha, hb⟩ ↦ ?_⟩
271+
· obtain ⟨x, hxS⟩ := nonempty_of_mem hS
272+
obtain ⟨T, hT, hxT, -⟩ := h x x ⟨S, hS, hxS, hxS⟩
273+
refine ⟨T, hT, fun a haS ↦ ?_⟩
274+
obtain ⟨T', hT', haT', hxT'⟩ := h a x ⟨S, hS, haS, hxS⟩
275+
obtain rfl := eq_of_mem_of_mem hT hT' hxT hxT'
276+
exact haT'
277+
obtain ⟨t', ht', htt'⟩ := h ht
278+
use t', ht', htt' ha, htt' hb
279+
280+
lemma Rel.exists (h : P.Rel x y) : ∃ t ∈ P, x ∈ t ∧ y ∈ t := h
281+
282+
lemma Rel.forall (h : P.Rel x y) (ht : t ∈ P) : x ∈ t ↔ y ∈ t := by
283+
obtain ⟨t, ht', hx, hy⟩ := h
284+
exact ⟨fun h ↦ by rwa [P.eq_of_mem_of_mem ht ht' h hx],
285+
fun h ↦ by rwa [P.eq_of_mem_of_mem ht ht' h hy]⟩
286+
287+
@[simp]
288+
lemma rel_rfl_iff : P.Rel x x ↔ x ∈ u := by
289+
refine ⟨fun hx ↦ ?_, fun hx ↦ ?_⟩
290+
· obtain ⟨t, ht, hxP, -⟩ := hx
291+
exact subset_of_mem ht hxP
292+
obtain ⟨t, ⟨ht, hxt⟩, -⟩ := P.mem_iff_unique.mp hx
293+
exact ⟨t, ht, hxt, hxt⟩
294+
295+
instance (P : Partition u) : Std.Symm P.Rel where
296+
symm _ _ := fun ⟨t, ht, ha, hb⟩ ↦ ⟨t, ht, hb, ha⟩
297+
298+
instance (P : Partition u) : IsTrans α P.Rel where
299+
trans _ _ _ := fun ⟨t, ht, ha, hb⟩ ⟨t', ht', hb', hc⟩ ↦
300+
⟨t, ht, ha, by rwa [eq_of_mem_of_mem ht ht' hb hb']⟩
301+
302+
lemma Rel.symm (h : P.Rel x y) : P.Rel y x := symm_of P.Rel h
303+
304+
lemma rel_comm : P.Rel x y ↔ P.Rel y x := ⟨Rel.symm, Rel.symm⟩
305+
306+
lemma Rel.trans (hxy : P.Rel x y) (hyz : P.Rel y z) : P.Rel x z := trans_of P.Rel hxy hyz
307+
308+
lemma Rel.left_mem (h : P.Rel x y) : x ∈ u := by
309+
obtain ⟨t, htP, hxt, -⟩ := h
310+
exact subset_of_mem htP hxt
311+
312+
lemma Rel.right_mem (h : P.Rel x y) : y ∈ u := h.symm.left_mem
313+
314+
end Rel
315+
217316
end Partition

0 commit comments

Comments
 (0)