1-- Complete lattices bundled as ordered sets, with sSup(P) and sInf(P), and2-- the powerset lattice3-- 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.Lattice.CompleteLattice9import Complete10import BoundedOrder1112-- A complete lattice is a property of the bundled order; the supremum and13-- infimum of a subset are the set functions sSup(P) and sInf(P) on the14-- powerset of the points, applied as sSup(P)(S).15predicate CompleteLattice (P : Set) := IsCompleteLattice(points(P), le(P))1617notationinfixl68"⊔"=> call2(sup(P), _, _) viahypothesis CompleteLattice(P) for P.points18notationinfixl69"⊓"=> call2(inf(P), _, _) viahypothesis CompleteLattice(P) for P.points19notationinfix50"≤"=> Le(P, _, _) viahypothesis CompleteLattice(P) for P.points2021instance CompleteLattice.unbundled (P : Set)22requires complete : CompleteLattice(P)23shows IsCompleteLattice(points(P), le(P))24proof25simp [CompleteLattice]2627theorem CompleteLattice.mk (A r : Set)28requires complete : IsCompleteLattice(A, r)29shows CompleteLattice(Order.mk(A, r))30proof31unfold CompleteLattice32rw [Order.mk.points, Order.mk.le]33exact complete3435theorem CompleteLattice.lattice_of (P : Set)36requires complete : CompleteLattice(P)37shows Lattice(P)38proof39unfold Join.Lattice40exact IsCompleteLattice.lattice with (CompleteLattice.unbundled with complete)4142instance CompleteLattice.bounded_of (P : Set)43requires complete : CompleteLattice(P)44shows BoundedLattice(P)45proof46have unbundled := CompleteLattice.unbundled with complete47have bounded := IsCompleteLattice.bounded with unbundled48have lattice : Lattice(P) := CompleteLattice.lattice_of with complete49refine⟨lattice, ?_, ?_⟩50 . witness supremum(points(P), le(P), ∅)51exact IsBoundedLattice.least with bounded52 . witness supremum(points(P), le(P), points(P))53exact IsBoundedLattice.greatest with bounded5455theorem CompleteLattice.subset_of_member (P S : Set)56requires member : S ∈𝒫(points(P))57shows S ⊆ points(P)58proof59exact powerset.membership_iff.forward with member6061defgraph sSup (P : Set) (S ∈𝒫(points(P))) : points(P) := supremum(points(P), le(P), S)62requires complete : CompleteLattice(P)63proof64have subset := CompleteLattice.subset_of_member with member65exact supremum.member with (CompleteLattice.unbundled with complete), subset6667defgraph sInf (P : Set) (S ∈𝒫(points(P))) : points(P) := infimum(points(P), le(P), S)68requires complete : CompleteLattice(P)69proof70have subset := CompleteLattice.subset_of_member with member71exact infimum.member with (CompleteLattice.unbundled with complete), subset7273-- The supremum and infimum of a subset S of the points are written ⨆ S74-- and ⨅ S, and the bounds ⊥ and ⊤, wherever a hypothesis in scope supplies75-- the complete lattice; each value lies in points(P).76notationprefix90"⨆"=>apply(sSup(P), _) viahypothesis CompleteLattice(P) for P.points77notationprefix90"⨅"=>apply(sInf(P), _) viahypothesis CompleteLattice(P) for P.points78notation constant "⊥"=> bot(P) viahypothesis CompleteLattice(P) for P.points79notation constant "⊤"=> top(P) viahypothesis CompleteLattice(P) for P.points8081section CompleteLatticeLaws82variable (P : Set)83hypothesis complete : CompleteLattice(P)8485-- The bundled operations are the unbundled supremum and infimum.86theorem sSup.supremum (S : Set)87requires hS : S ⊆ points(P)88shows sSup(P)(S) = supremum(points(P), le(P), S)89proof90have member : S ∈𝒫(points(P)) := powerset.membership_iff.backward with hS91exact sSup.value with complete, member9293theorem sInf.infimum (S : Set)94requires hS : S ⊆ points(P)95shows sInf(P)(S) = infimum(points(P), le(P), S)96proof97have member : S ∈𝒫(points(P)) := powerset.membership_iff.backward with hS98exact sInf.value with complete, member99100instance sSup.member (S : Set)101requires hS : S ⊆ points(P)102shows sSup(P)(S) ∈ points(P)103proof104rw sSup.supremum105exact supremum.member with*106107instance sInf.member (S : Set)108requires hS : S ⊆ points(P)109shows sInf(P)(S) ∈ points(P)110proof111rw sInf.infimum112exact infimum.member with*113114theorem sSup.isLUB (S : Set)115requires hS : S ⊆ points(P)116shows IsLUB(P, S, sSup(P)(S))117proof118unfold IsLUB119rw sSup.supremum120exact supremum.supremum with*121122theorem sInf.isGLB (S : Set)123requires hS : S ⊆ points(P)124shows IsGLB(P, S, sInf(P)(S))125proof126unfold IsGLB127rw sInf.infimum128exact infimum.infimum with*129130theorem le_sSup (S a : Set)131requires hS : S ⊆ points(P)132requires aIn : a ∈ S133shows a ≤ ⨆ S134proof135unfold Le136rw sSup.supremum137exact supremum.above with*138139theorem sSup_le (S : Set) (b ∈ points(P))140requires hS : S ⊆ points(P)141requires bound : ∀ x ∈ S, x ≤ b142shows sSup(P)(S) ≤ b143proof144unfold Le145rw sSup.supremum146have bIn : b ∈ points(P) byassumption147have above : ∀ x ∈ S, relates(le(P), x, b)148intros x xIn149exact Le.relates with (bound with x, xIn)150have upper : UpperBound(points(P), le(P), S, b) :=⟨bIn, hS, above⟩151exact supremum.least with*152153theorem sInf_le (S a : Set)154requires hS : S ⊆ points(P)155requires aIn : a ∈ S156shows ⨅ S ≤ a157proof158unfold Le159rw sInf.infimum160exact infimum.below with*161162theorem le_sInf (S : Set) (b ∈ points(P))163requires hS : S ⊆ points(P)164requires bound : ∀ x ∈ S, b ≤ x165shows b ≤ sInf(P)(S)166proof167unfold Le168rw sInf.infimum169have bIn : b ∈ points(P) byassumption170have below : ∀ x ∈ S, relates(le(P), b, x)171intros x xIn172exact Le.relates with (bound with x, xIn)173have lower : LowerBound(points(P), le(P), S, b) :=⟨bIn, hS, below⟩174exact infimum.greatest with*175176theorem sSup_le_iff (S : Set) (b ∈ points(P))177requires hS : S ⊆ points(P)178shows sSup(P)(S) ≤ b ↔∀ x ∈ S, x ≤ b179proof180constructor181 . intros h x xIn182have xIn2 : x ∈ points(P) := hS with x, xIn183have above : x ≤ sSup(P)(S) := le_sSup with*184exact le_trans with above, h185 . intro bound186exact sSup_le with*187188theorem le_sInf_iff (S : Set) (b ∈ points(P))189requires hS : S ⊆ points(P)190shows b ≤ sInf(P)(S) ↔∀ x ∈ S, b ≤ x191proof192constructor193 . intros h x xIn194have xIn2 : x ∈ points(P) := hS with x, xIn195have below : sInf(P)(S) ≤ x := sInf_le with*196exact le_trans with h, below197 . intro bound198exact le_sInf with*199200theorem sSup.of_isLUB (S s : Set)201requires hS : S ⊆ points(P)202requires lub : IsLUB(P, S, s)203shows s = sSup(P)(S)204proof205unfold IsLUB at lub206rw sSup.supremum207exact supremum.of_supremum with*208209theorem sInf.of_isGLB (S i : Set)210requires hS : S ⊆ points(P)211requires glb : IsGLB(P, S, i)212shows i = sInf(P)(S)213proof214unfold IsGLB at glb215rw sInf.infimum216exact infimum.of_infimum with*217218theorem sSup_le_sSup (S T : Set)219requires hST : S ⊆ T220requires hT : T ⊆ points(P)221shows sSup(P)(S) ≤ sSup(P)(T)222proof223unfold Le224have hS : S ⊆ points(P) := Subset.transitive with hST, hT225rw [sSup.supremum, sSup.supremum]226exact supremum.monotone with*227228theorem sInf_le_sInf (S T : Set)229requires hST : S ⊆ T230requires hT : T ⊆ points(P)231shows sInf(P)(T) ≤ sInf(P)(S)232proof233unfold Le234have hS : S ⊆ points(P) := Subset.transitive with hST, hT235rw [sInf.infimum, sInf.infimum]236exact infimum.antitone with*237238theorem sSup_pair (a b ∈ points(P))239shows sSup(P)({a, b}) = a ⊔ b240proof241have hS : {a, b} ⊆ points(P) bysimp242rw [sSup.supremum, sup.join]243exact supremum.pair with*244245theorem sInf_pair (a b ∈ points(P))246shows sInf(P)({a, b}) = a ⊓ b247proof248have hS : {a, b} ⊆ points(P) bysimp249rw [sInf.infimum, inf.meet]250exact infimum.pair with*251252theorem sSup_singleton (a ∈ points(P))253shows sSup(P)({a}) = a254proof255have hS : {a} ⊆ points(P) bysimp256rw sSup.supremum257exact supremum.singleton with*258259theorem sInf_singleton (a ∈ points(P))260shows sInf(P)({a}) = a261proof262have hS : {a} ⊆ points(P) bysimp263rw sInf.infimum264exact infimum.singleton with*265266theorem sSup_empty267shows sSup(P)(∅) = bot(P)268proof269have hS : ∅⊆ points(P) := empty.subset at points(P)270have least : IsLeast(P, points(P), sSup(P)(∅))271unfold IsLeast272rw sSup.supremum273exact supremum.empty with*274exact bot_unique with*275276theorem sInf_empty277shows sInf(P)(∅) = top(P)278proof279have hS : ∅⊆ points(P) := empty.subset at points(P)280have greatest : IsGreatest(P, points(P), sInf(P)(∅))281unfold IsGreatest282rw sInf.infimum283exact infimum.empty with*284exact top_unique with*285286theorem sSup_univ287shows sSup(P)(points(P)) = top(P)288proof289have hS : points(P) ⊆ points(P) := Subset.reflexive at points(P)290have greatest : IsGreatest(P, points(P), sSup(P)(points(P)))291unfold IsGreatest292rw sSup.supremum293exact supremum.whole with*294exact top_unique with*295296theorem sInf_univ297shows sInf(P)(points(P)) = bot(P)298proof299have hS : points(P) ⊆ points(P) := Subset.reflexive at points(P)300have least : IsLeast(P, points(P), sInf(P)(points(P)))301unfold IsLeast302rw sInf.infimum303exact infimum.whole with*304exact bot_unique with*305306theorem sSup_union (S T : Set)307requires hS : S ⊆ points(P)308requires hT : T ⊆ points(P)309shows sSup(P)(S ∪ T) = sSup(P)(S) ⊔ sSup(P)(T)310proof311have hST : S ∪ T ⊆ points(P) := union2.subset with*312rw [sup.join, sSup.supremum, sSup.supremum, sSup.supremum]313exact supremum.union2 with*314315theorem sInf_union (S T : Set)316requires hS : S ⊆ points(P)317requires hT : T ⊆ points(P)318shows sInf(P)(S ∪ T) = sInf(P)(S) ⊓ sInf(P)(T)319proof320have hST : S ∪ T ⊆ points(P) := union2.subset with*321rw [inf.meet, sInf.infimum, sInf.infimum, sInf.infimum]322exact infimum.union2 with*323324end CompleteLatticeLaws325326-- The powerset of a set under inclusion is a complete lattice: join is327-- union, meet is intersection, and the supremum of a family is its union.328def powersetLattice (X : Set) : Set:= Order.mk(𝒫(X), powersetOrder(X))329330theorem powersetLattice.points (X : Set)331shows points(powersetLattice(X)) =𝒫(X)332proof333simp [powersetLattice, Order.mk.points]334335theorem powersetLattice.le (X : Set)336shows le(powersetLattice(X)) = powersetOrder(X)337proof338simp [powersetLattice, Order.mk.le]339340instance powersetLattice.complete (X : Set)341shows CompleteLattice(powersetLattice(X))342proof343unfold powersetLattice344exact CompleteLattice.mk with (IsCompleteLattice.powerset at X)345346section PowersetLattice347variable (X : Set)348hypothesis complete : CompleteLattice(powersetLattice(X))349350theorem powersetLattice.member (B : Set)351requires hB : B ∈𝒫(X)352shows B ∈ points(powersetLattice(X))353proof354rw powersetLattice.points355exact hB356357theorem powersetLattice.le_iff (B C ∈𝒫(X))358shows B ≤ C ↔ B ⊆ C359proof360have characterization := powersetOrder.relates at X, B, C with*361rw← powersetLattice.le at characterization362constructor363 . intro h364exact characterization.forward with (Le.relates with h)365 . intro h366exact Le.of_relates with (characterization.backward with h)367368theorem powersetLattice.sup (B C ∈𝒫(X))369shows B ⊔ C = B ∪ C370proof371have BIn : B ∈ points(powersetLattice(X)) := powersetLattice.member at X, B with*372have CIn : C ∈ points(powersetLattice(X)) := powersetLattice.member at X, C with*373rw [sup.join, powersetLattice.points, powersetLattice.le]374exact powersetOrder.join with*375376theorem powersetLattice.inf (B C ∈𝒫(X))377shows B ⊓ C = B ∩ C378proof379have BIn : B ∈ points(powersetLattice(X)) := powersetLattice.member at X, B with*380have CIn : C ∈ points(powersetLattice(X)) := powersetLattice.member at X, C with*381rw [inf.meet, powersetLattice.points, powersetLattice.le]382exact powersetOrder.meet with*383384theorem powersetLattice.sSup (S : Set)385requires hS : S ⊆𝒫(X)386shows sSup(powersetLattice(X))(S) =⋃(S)387proof388have subset : S ⊆ points(powersetLattice(X))389rw powersetLattice.points390exact hS391rw [sSup.supremum, powersetLattice.points, powersetLattice.le]392exact powersetOrder.supremum_value with*393394theorem powersetLattice.sInf (S : Set)395requires hS : S ⊆𝒫(X)396shows sInf(powersetLattice(X))(S) = relativeIntersection(X, S)397proof398have subset : S ⊆ points(powersetLattice(X))399rw powersetLattice.points400exact hS401rw [sInf.infimum, powersetLattice.points, powersetLattice.le]402exact powersetOrder.infimum_value with*403404theorem powersetLattice.bot405shows bot(powersetLattice(X)) =∅406proof407unfold powersetLattice408exact bot.mk with (powersetOrder.bounded at X)409410theorem powersetLattice.top411shows top(powersetLattice(X)) = X412proof413unfold powersetLattice414exact top.mk with (powersetOrder.bounded at X)415416end PowersetLattice417