1-- Families of sets: intersections of families, complements within a2-- carrier, and the De Morgan laws between them3-- Part of Cumulus, the Grace17 mathematics library.4-- Copyright (c) 2026 Grant Passmore.5-- Released under the Apache License 2.0. See LICENSE in the repository root.6-- Authors: Grant Passmore78module Grace.Cumulus.Set.Family9import Powerset1011-- The intersection of a family is carved out of its union, so it is a set12-- for every family and the empty family's intersection is empty.13def familyIntersection (S : Set) : Set:= { x ∈⋃(S) |∀ A ∈ S, x ∈ A }14notationprefix90"⋂"=> familyIntersection1516-- The complement of A within a carrier E.17def complement (E A : Set) : Set:= E ∖ A1819-- The family of complements of the members of S within E.20def complements (E S : Set) : Set:= { E ∖ A | A ∈ S }2122theorem familyIntersection.membership_of_nonempty (x S : Set)23requires nonempty : Nonempty(S)24shows x ∈ ⋂(S) ↔∀ A ∈ S, x ∈ A25proof26constructor27 . intro h28simp [familyIntersection] at h29exact h.right30 . intro h31obtain⟨B, hB⟩:= nonempty32simp [familyIntersection]33constructor34 . exact union.contains with hB, (h with B, hB)35 . exact h3637theorem familyIntersection.subset_of_member (A S : Set)38requires h : A ∈ S39shows ⋂(S) ⊆ A40proof41intros x hx42simp [familyIntersection] at hx43exact hx.right with A, h4445theorem familyIntersection.subset_union (S : Set)46shows ⋂(S) ⊆⋃(S)47proof48intros x hx49simp [familyIntersection] at hx50exact hx.left5152theorem familyIntersection.empty53shows ⋂(∅) =∅54proof55apply Subset.empty_iff.forward56have included := familyIntersection.subset_union at∅57 rwa union.empty at included5859theorem familyIntersection.greatest (Z S : Set)60requires nonempty : Nonempty(S)61requires h : ∀ A ∈ S, Z ⊆ A62shows Z ⊆ ⋂(S)63proof64intros x hx65apply familyIntersection.membership_of_nonempty.backward with nonempty66intros A hA67exact h with A, hA, x, hx6869theorem familyIntersection.antitone (S T : Set)70requires nonempty : Nonempty(S)71requires h : S ⊆ T72shows ⋂(T) ⊆ ⋂(S)73proof74apply familyIntersection.greatest with nonempty75intros A hA76exact familyIntersection.subset_of_member with (h with A, hA)7778theorem familyIntersection.singleton (A : Set)79shows ⋂({A}) = A80proof81apply Subset.antisymmetric82 . exact familyIntersection.subset_of_member with (singleton.self at A)83 . apply familyIntersection.greatest with (Nonempty.singleton at A)84intros B hB85simp [singleton.membership] at hB86rw hB87exact Subset.reflexive8889theorem familyIntersection.pair (A B : Set)90shows ⋂({A, B}) = A ∩ B91proof92apply Subset.antisymmetric93 . apply Subset.intersection_iff.backward94constructor95 . exact familyIntersection.subset_of_member with (pair.left at A, B)96 . exact familyIntersection.subset_of_member with (pair.right at A, B)97 . have nonempty : Nonempty({A, B}) :=⟨A, (pair.left at A, B)⟩98apply familyIntersection.greatest with nonempty99intros C hC100simpat hC101cases hC with hA | hB102 . rw hA103exact intersection.subset_left104 . rw hB105exact intersection.subset_right106107theorem familyIntersection.union2 (S T : Set)108requires nonemptyS : Nonempty(S)109requires nonemptyT : Nonempty(T)110shows ⋂(S ∪ T) = ⋂(S) ∩ ⋂(T)111proof112apply Subset.antisymmetric113 . apply Subset.intersection_iff.backward114constructor115 . exact familyIntersection.antitone with nonemptyS, (union2.subset_left at S, T)116 . exact familyIntersection.antitone with nonemptyT, (union2.subset_right at S, T)117 . obtain⟨B, hB⟩:= nonemptyS118have nonempty : Nonempty(S ∪ T) :=⟨B, (union2.subset_left at S, T with B, hB)⟩119apply familyIntersection.greatest with nonempty120intros A hA121simp [union2.membership] at hA122cases hA with hS | hT123 . exact Subset.transitive with (intersection.subset_left at ⋂(S), ⋂(T)), (familyIntersection.subset_of_member with hS)124 . exact Subset.transitive with (intersection.subset_right at ⋂(S), ⋂(T)), (familyIntersection.subset_of_member with hT)125126-- Complements within a carrier127128theorem complement.membership (x E A : Set)129shows x ∈ complement(E, A) ↔ x ∈ E ∧¬(x ∈ A)130proof131simp [complement, difference.membership]132133theorem complement.subset (E A : Set)134shows complement(E, A) ⊆ E135proof136simp [complement]137138theorem complement.union2 (E A : Set)139requires h : A ⊆ E140shows A ∪ complement(E, A) = E141proof142simp [complement]143ext y144simp145146theorem complement.intersection (E A : Set)147shows A ∩ complement(E, A) =∅148proof149ext y150simp [complement]151152theorem complement.complement (E A : Set)153requires h : A ⊆ E154shows complement(E, complement(E, A)) = A155proof156simp [complement]157ext y158simp159160theorem complement.empty (E : Set)161shows complement(E, ∅) = E162proof163simp [complement]164exact difference.empty165166theorem complement.self (E : Set)167shows complement(E, E) =∅168proof169simp [complement]170exact difference.self171172theorem complement.antitone (E A B : Set)173requires h : A ⊆ B174shows complement(E, B) ⊆ complement(E, A)175proof176intros x hx177simp [complement.membership] at hx178simp [complement.membership]179180theorem complement.subset_iff (E A B : Set)181requires hA : A ⊆ E182requires hB : B ⊆ E183shows A ⊆ B ↔ complement(E, B) ⊆ complement(E, A)184proof185constructor186 . intro h187exact complement.antitone with h188 . intros h x hx189by_contra absent190have inE : x ∈ E := hA with x, hx191have member : x ∈ complement(E, B) bysimp [complement.membership, inE, absent]192have inComplement : x ∈ complement(E, A) := h with x, member193simp [complement.membership] at inComplement194195theorem complement.injective (E A B : Set)196requires hA : A ⊆ E197requires hB : B ⊆ E198requires h : complement(E, A) = complement(E, B)199shows A = B200proof201have double := complement.complement with hA202rw [← double, h]203exact complement.complement with hB204205theorem complement.union2_distrib (E A B : Set)206shows complement(E, A ∪ B) = complement(E, A) ∩ complement(E, B)207proof208simp [complement]209exact difference.union2210211theorem complement.intersection_distrib (E A B : Set)212shows complement(E, A ∩ B) = complement(E, A) ∪ complement(E, B)213proof214simp [complement]215exact difference.intersection216217theorem complement.disjoint_iff (E A B : Set)218requires hA : A ⊆ E219shows Disjoint(A, B) ↔ A ⊆ complement(E, B)220proof221constructor222 . intro h223have absent := Disjoint.iff.forward with h224intros x hx225simp [complement.membership]226 . intro h227apply Disjoint.iff.backward228intros x hx229have member : x ∈ complement(E, B) := h with x, hx230simp [complement.membership] at member231exact member.right232233-- De Morgan laws for families234235theorem complements.union (E S : Set)236requires nonempty : Nonempty(S)237shows complement(E, ⋃(S)) = ⋂(complements(E, S))238proof239obtain⟨C, hC⟩:= nonempty240have nonemptyComplements : Nonempty(complements(E, S))241witness E ∖ C242apply complements.membership.backward243witness C244constructor245 . exact hC246 . rfl247ext x248constructor249 . intro hx250simp [complement.membership] at hx251apply familyIntersection.membership_of_nonempty.backward with nonemptyComplements252intros B hB253obtain⟨A, hA, shape⟩:= complements.membership.forward with hB254rw← shape255simp [difference.membership]256constructor257 . exact hx.left258 . intro inA259exact hx.right with (union.contains with hA, inA)260 . intro hx261have everywhere := familyIntersection.membership_of_nonempty.forward with nonemptyComplements, hx262have inFirst : x ∈ E ∖ C263apply everywhere264apply complements.membership.backward265witness C266constructor267 . exact hC268 . rfl269simp [difference.membership] at inFirst270simp [complement.membership]271constructor272 . exact inFirst.left273 . intro inUnion274simp [set.union] at inUnion275obtain⟨A, hA, inA⟩:= inUnion276have inComplement : x ∈ E ∖ A277apply everywhere278apply complements.membership.backward279witness A280constructor281 . exact hA282 . rfl283simp [difference.membership] at inComplement284285theorem complements.intersection (E S : Set)286requires nonempty : Nonempty(S)287shows complement(E, ⋂(S)) =⋃(complements(E, S))288proof289ext x290constructor291 . intro hx292simp [complement.membership] at hx293have notEverywhere : ¬(∀ A ∈ S, x ∈ A)294intro everywhere295exact hx.right with (familyIntersection.membership_of_nonempty.backward with nonempty, everywhere)296by_contra absent297apply notEverywhere298intros A hA299by_contra outside300apply absent301have inComplement : x ∈ E ∖ A bysimp [difference.membership, hx.left, outside]302have member : E ∖ A ∈ complements(E, S)303apply complements.membership.backward304witness A305constructor306 . exact hA307 . rfl308exact union.contains with member, inComplement309 . intro hx310simp [set.union] at hx311obtain⟨B, hB, inB⟩:= hx312obtain⟨A, hA, shape⟩:= complements.membership.forward with hB313rw← shape at inB314simp [difference.membership] at inB315simp [complement.membership]316constructor317 . exact inB.left318 . intro inIntersection319have inA : x ∈ A := familyIntersection.subset_of_member with hA, x, inIntersection320exact inB.right with inA321