Skip to content

Commit b6031b3

Browse files
CoolRmalBergschaf
authored andcommitted
feat: a lemma about the symmetric difference of unions (leanprover-community#38536)
Created with the help of Codex.
1 parent 5cc2e72 commit b6031b3

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

Mathlib/Data/Set/Lattice.lean

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,37 @@ theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i,
380380
theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by
381381
simp only [diff_eq, compl_iInter, inter_iUnion]
382382

383+
section SymmDiff
384+
385+
open scoped symmDiff
386+
387+
lemma iUnion_symmDiff_subset {s : Set α} [Nonempty ι] {f : ι → Set α} :
388+
(⋃ n, f n) ∆ s ⊆ ⋃ n, f n ∆ s :=
389+
iSup_symmDiff_le
390+
391+
lemma symmDiff_iUnion_subset {s : Set α} [Nonempty ι] {f : ι → Set α} :
392+
s ∆ (⋃ n, f n) ⊆ ⋃ n, s ∆ f n :=
393+
symmDiff_iSup_le
394+
395+
lemma iUnion_symmDiff_iUnion_subset {f g : ι → Set α} :
396+
(⋃ n, f n) ∆ ⋃ n, g n ⊆ ⋃ n, f n ∆ g n :=
397+
iSup_symmDiff_iSup_le
398+
399+
lemma sUnion_symmDiff_subset {s : Set α} {S : Set (Set α)} (hS : S.Nonempty) :
400+
(⋃₀ S) ∆ s ⊆ ⋃₀ ((· ∆ s) '' S) :=
401+
sSup_symmDiff_le hS
402+
403+
lemma symmDiff_sUnion_subset {s : Set α} {S : Set (Set α)} (hS : S.Nonempty) :
404+
s ∆ (⋃₀ S) ⊆ ⋃₀ ((s ∆ ·) '' S) :=
405+
symmDiff_sSup_le hS
406+
407+
lemma sUnion_symmDiff_sUnion_subset {S T : Set (Set α)} (hS : S.Nonempty)
408+
(hT : T.Nonempty) :
409+
(⋃₀ S) ∆ ⋃₀ T ⊆ ⋃₀ (image2 (· ∆ ·) S T) :=
410+
sSup_symmDiff_sSup_le hS hT
411+
412+
end SymmDiff
413+
383414
theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i :=
384415
le_iSup_inf_iSup s t
385416

Mathlib/Order/CompleteBooleanAlgebra.lean

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,20 +657,45 @@ theorem compl_sInf' : (sInf s)ᶜ = sSup (Compl.compl '' s) :=
657657
theorem compl_sSup' : (sSup s)ᶜ = sInf (Compl.compl '' s) :=
658658
compl_sSup.trans sInf_image.symm
659659

660-
open scoped symmDiff in
660+
section symmDiff
661+
662+
open scoped symmDiff
663+
661664
/-- The symmetric difference of two `iSup`s is at most the `iSup` of the symmetric differences. -/
662665
theorem iSup_symmDiff_iSup_le {g : ι → α} : (⨆ i, f i) ∆ (⨆ i, g i) ≤ ⨆ i, ((f i) ∆ (g i)) := by
663666
simp_rw [symmDiff_le_iff, ← iSup_sup_eq]
664667
exact ⟨iSup_mono fun i ↦ sup_comm (g i) _ ▸ le_symmDiff_sup_right ..,
665668
iSup_mono fun i ↦ sup_comm (f i) _ ▸ symmDiff_comm (f i) _ ▸ le_symmDiff_sup_right ..⟩
666669

667-
open scoped symmDiff in
670+
theorem iSup_symmDiff_le [Nonempty ι] {a : α} : (⨆ i, f i) ∆ a ≤ ⨆ i, f i ∆ a := by
671+
simpa [iSup_const] using iSup_symmDiff_iSup_le (g := fun _ : ι ↦ a)
672+
673+
theorem symmDiff_iSup_le [Nonempty ι] {a : α} : a ∆ (⨆ i, f i) ≤ ⨆ i, a ∆ f i := by
674+
simpa [symmDiff_comm] using iSup_symmDiff_le (a := a)
675+
676+
theorem sSup_symmDiff_le (hs : s.Nonempty) {a : α} : sSup s ∆ a ≤ sSup ((· ∆ a) '' s) := by
677+
rw [sSup_image', sSup_eq_iSup']
678+
have : Nonempty s := Set.nonempty_coe_sort.mpr hs
679+
exact iSup_symmDiff_le
680+
681+
theorem symmDiff_sSup_le (hs : s.Nonempty) {a : α} : a ∆ sSup s ≤ sSup ((a ∆ ·) '' s) := by
682+
simpa [symmDiff_comm] using sSup_symmDiff_le (a := a) hs
683+
684+
theorem sSup_symmDiff_sSup_le {s t : Set α} (hs : s.Nonempty) (ht : t.Nonempty) :
685+
sSup s ∆ sSup t ≤ sSup (image2 (· ∆ ·) s t) := by
686+
rw [sSup_image2]
687+
calc
688+
_ ≤ ⨆ a ∈ s, a ∆ sSup t := by simpa [sSup_image] using sSup_symmDiff_le hs
689+
_ ≤ _ := iSup_mono fun a ↦ iSup_mono fun _ ↦ by simpa [sSup_image] using symmDiff_sSup_le ht
690+
668691
/-- A `biSup` version of `iSup_symmDiff_iSup_le`. -/
669692
theorem biSup_symmDiff_biSup_le {p : ι → Prop} {f g : (i : ι) → p i → α} :
670693
(⨆ i, ⨆ (h : p i), f i h) ∆ (⨆ i, ⨆ (h : p i), g i h) ≤
671694
⨆ i, ⨆ (h : p i), ((f i h) ∆ (g i h)) :=
672695
le_trans iSup_symmDiff_iSup_le <| iSup_mono fun _ ↦ iSup_symmDiff_iSup_le
673696

697+
end symmDiff
698+
674699
end CompleteBooleanAlgebra
675700

676701
/--

0 commit comments

Comments
 (0)