1-- Lattices bundled as ordered sets, with join and meet written ⊔ and ⊓2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: Grant Passmore67module Grace.Cumulus.Lattice.Join8import LatticeLaws9import Order1011-- A lattice as a property of a bundled order. The join and meet of two12-- elements are set functions sup(P) and inf(P) on points(P) × points(P),13-- applied as a ⊔ b and a ⊓ b wherever a hypothesis Lattice(P) is in scope.14predicate Lattice (P : Set) := IsLattice(points(P), le(P))1516instance Lattice.unbundled (P : Set)17requires lattice : Lattice(P)18shows IsLattice(points(P), le(P))19proof20simp [Lattice]2122theorem Lattice.mk (A r : Set)23requires lattice : IsLattice(A, r)24shows Lattice(Order.mk(A, r))25proof26unfold Lattice27rw [Order.mk.points, Order.mk.le]28exact lattice2930instance Lattice.partial_order (P : Set)31requires lattice : Lattice(P)32shows PartialOrder(P)33proof34unfold Order.PartialOrder35exact IsLattice.order with (Lattice.unbundled with lattice)3637def pairJoin (P p : Set) : Set:=38 join(points(P), le(P), firstOf(points(P), points(P), p), secondOf(points(P), points(P), p))39def pairMeet (P p : Set) : Set:=40 meet(points(P), le(P), firstOf(points(P), points(P), p), secondOf(points(P), points(P), p))4142theorem pairJoin.pair (P a b : Set)43requires aIn : a ∈ points(P)44requires bIn : b ∈ points(P)45shows pairJoin(P, (a, b)) = join(points(P), le(P), a, b)46proof47have pairIn : (a, b) ∈ points(P) × points(P) := product.pair with*48obtain⟨firstIn, y, yIn, shape⟩:= firstOf.selected with pairIn49obtain⟨secondIn, x, xIn, shape2⟩:= secondOf.selected with pairIn50have coordinates := orderedPair.injective with shape51have coordinates2 := orderedPair.injective with shape252unfold pairJoin53cc5455theorem pairMeet.pair (P a b : Set)56requires aIn : a ∈ points(P)57requires bIn : b ∈ points(P)58shows pairMeet(P, (a, b)) = meet(points(P), le(P), a, b)59proof60have pairIn : (a, b) ∈ points(P) × points(P) := product.pair with*61obtain⟨firstIn, y, yIn, shape⟩:= firstOf.selected with pairIn62obtain⟨secondIn, x, xIn, shape2⟩:= secondOf.selected with pairIn63have coordinates := orderedPair.injective with shape64have coordinates2 := orderedPair.injective with shape265unfold pairMeet66cc6768defgraph sup (P : Set) (p ∈ points(P) × points(P)) : points(P) := pairJoin(P, p)69requires lattice : Lattice(P)70proof71have unbundled := Lattice.unbundled with lattice72have first := firstOf.selected with member73have second := secondOf.selected with member74unfold pairJoin75exact join.member with unbundled, first.left, second.left7677defgraph inf (P : Set) (p ∈ points(P) × points(P)) : points(P) := pairMeet(P, p)78requires lattice : Lattice(P)79proof80have unbundled := Lattice.unbundled with lattice81have first := firstOf.selected with member82have second := secondOf.selected with member83unfold pairMeet84exact meet.member with unbundled, first.left, second.left8586notationinfixl68"⊔"=> call2(sup(P), _, _) viahypothesis Lattice(P) for P.points87notationinfixl69"⊓"=> call2(inf(P), _, _) viahypothesis Lattice(P) for P.points88notationinfix50"≤"=> Le(P, _, _) viahypothesis Lattice(P) for P.points8990section LatticeOperations91variable (P : Set)92hypothesis lattice : Lattice(P)9394-- The bundled operations are the unbundled join and meet.95theorem sup.join (a b ∈ points(P))96shows a ⊔ b = join(points(P), le(P), a, b)97proof98have pairIn : (a, b) ∈ points(P) × points(P) := product.pair with*99have value := sup.value at P, (a, b) with lattice, pairIn100have pair := pairJoin.pair at P, a, b with*101unfold call2102cc103104theorem inf.meet (a b ∈ points(P))105shows a ⊓ b = meet(points(P), le(P), a, b)106proof107have pairIn : (a, b) ∈ points(P) × points(P) := product.pair with*108have value := inf.value at P, (a, b) with lattice, pairIn109have pair := pairMeet.pair at P, a, b with*110unfold call2111cc112113instance sup.member (a b ∈ points(P))114shows a ⊔ b ∈ points(P)115proof116have pairIn : (a, b) ∈ points(P) × points(P) := product.pair with*117have function := sup.function with lattice118unfold call2119exact FunctionBetween.apply_closed with function, pairIn120121instance inf.member (a b ∈ points(P))122shows a ⊓ b ∈ points(P)123proof124have pairIn : (a, b) ∈ points(P) × points(P) := product.pair with*125have function := inf.function with lattice126unfold call2127exact FunctionBetween.apply_closed with function, pairIn128129-- The defining properties of join and meet.130theorem le_sup_left (a b ∈ points(P))131shows a ≤ a ⊔ b132proof133unfold Le134rw sup.join135exact join.upper_left with*136137theorem le_sup_right (a b ∈ points(P))138shows b ≤ a ⊔ b139proof140unfold Le141rw sup.join142exact join.upper_right with*143144theorem sup_le (a b c ∈ points(P))145requires hac : a ≤ c146requires hbc : b ≤ c147shows a ⊔ b ≤ c148proof149unfold Le150rw sup.join151exact join.least with*152153theorem inf_le_left (a b ∈ points(P))154shows a ⊓ b ≤ a155proof156unfold Le157rw inf.meet158exact meet.lower_left with*159160theorem inf_le_right (a b ∈ points(P))161shows a ⊓ b ≤ b162proof163unfold Le164rw inf.meet165exact meet.lower_right with*166167theorem le_inf (a b c ∈ points(P))168requires hab : a ≤ b169requires hac : a ≤ c170shows a ≤ b ⊓ c171proof172unfold Le173rw inf.meet174exact meet.greatest with*175176theorem sup.isLUB (a b ∈ points(P))177shows IsLUB(P, {a, b}, a ⊔ b)178proof179unfold IsLUB180rw sup.join181exact join.supremum with*182183theorem inf.isGLB (a b ∈ points(P))184shows IsGLB(P, {a, b}, a ⊓ b)185proof186unfold IsGLB187rw inf.meet188exact meet.infimum with*189190theorem sup.of_isLUB (s : Set) (a b ∈ points(P))191requires lub : IsLUB(P, {a, b}, s)192shows s = a ⊔ b193proof194unfold IsLUB at lub195rw sup.join196exact join.of_supremum with*197198theorem inf.of_isGLB (i : Set) (a b ∈ points(P))199requires glb : IsGLB(P, {a, b}, i)200shows i = a ⊓ b201proof202unfold IsGLB at glb203rw inf.meet204exact meet.of_infimum with*205206end LatticeOperations207208-- The equational laws of join and meet, and the order they determine.209section LatticeLaws210variable (P : Set)211hypothesis lattice : Lattice(P)212213theorem sup_comm (a b ∈ points(P))214shows a ⊔ b = b ⊔ a215proof216have first : a ⊔ b ≤ b ⊔ a := sup_le with (le_sup_right with*), (le_sup_left with*)217have second : b ⊔ a ≤ a ⊔ b := sup_le with (le_sup_right with*), (le_sup_left with*)218exact le_antisymm with*219220theorem inf_comm (a b ∈ points(P))221shows a ⊓ b = b ⊓ a222proof223have first : a ⊓ b ≤ b ⊓ a := le_inf with (inf_le_right with*), (inf_le_left with*)224have second : b ⊓ a ≤ a ⊓ b := le_inf with (inf_le_right with*), (inf_le_left with*)225exact le_antisymm with*226227theorem sup_idem (a ∈ points(P))228shows a ⊔ a = a229proof230rw sup.join231exact join.idempotent with*232233theorem inf_idem (a ∈ points(P))234shows a ⊓ a = a235proof236rw inf.meet237exact meet.idempotent with*238239theorem sup_eq_right (a b ∈ points(P))240requires hab : a ≤ b241shows a ⊔ b = b242proof243rw sup.join244exact join.of_le with*245246theorem sup_eq_left (a b ∈ points(P))247requires hba : b ≤ a248shows a ⊔ b = a249proof250rw sup.join251exact join.of_ge with*252253theorem inf_eq_left (a b ∈ points(P))254requires hab : a ≤ b255shows a ⊓ b = a256proof257rw inf.meet258exact meet.of_le with*259260theorem inf_eq_right (a b ∈ points(P))261requires hba : b ≤ a262shows a ⊓ b = b263proof264rw inf.meet265exact meet.of_ge with*266267theorem sup_eq_right_iff (a b ∈ points(P))268shows a ≤ b ↔ a ⊔ b = b269proof270constructor271 . intro hab272exact sup_eq_right with*273 . intro same274have upper : a ≤ a ⊔ b := le_sup_left with*275 rwa same at upper276277theorem inf_eq_left_iff (a b ∈ points(P))278shows a ≤ b ↔ a ⊓ b = a279proof280constructor281 . intro hab282exact inf_eq_left with*283 . intro same284have lower : a ⊓ b ≤ b := inf_le_right with*285 rwa same at lower286287theorem sup_assoc (a b c ∈ points(P))288shows (a ⊔ b) ⊔ c = a ⊔ (b ⊔ c)289proof290simp [sup.join]291exact join.associative with*292293theorem inf_assoc (a b c ∈ points(P))294shows (a ⊓ b) ⊓ c = a ⊓ (b ⊓ c)295proof296simp [inf.meet]297exact meet.associative with*298299theorem sup_left_comm (a b c ∈ points(P))300shows a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c)301proof302simp [sup.join]303exact join.left_commutative with*304305theorem inf_left_comm (a b c ∈ points(P))306shows a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c)307proof308simp [inf.meet]309exact meet.left_commutative with*310311theorem sup_absorb (a b ∈ points(P))312shows a ⊔ (a ⊓ b) = a313proof314simp [sup.join, inf.meet]315exact join.absorb with*316317theorem inf_absorb (a b ∈ points(P))318shows a ⊓ (a ⊔ b) = a319proof320simp [sup.join, inf.meet]321exact meet.absorb with*322323theorem sup_le_iff (a b c ∈ points(P))324shows a ⊔ b ≤ c ↔ (a ≤ c ∧ b ≤ c)325proof326constructor327 . intro h328haveleft : a ≤ a ⊔ b := le_sup_left with*329haveright : b ≤ a ⊔ b := le_sup_right with*330constructor331 . exact le_trans withleft, h332 . exact le_trans withright, h333 . intro both334obtain⟨hac, hbc⟩:= both335exact sup_le with*336337theorem le_inf_iff (a b c ∈ points(P))338shows a ≤ b ⊓ c ↔ (a ≤ b ∧ a ≤ c)339proof340constructor341 . intro h342haveleft : b ⊓ c ≤ b := inf_le_left with*343haveright : b ⊓ c ≤ c := inf_le_right with*344constructor345 . exact le_trans with h, left346 . exact le_trans with h, right347 . intro both348obtain⟨hab, hac⟩:= both349exact le_inf with*350351theorem sup_le_sup (a b c d ∈ points(P))352requires hac : a ≤ c353requires hbd : b ≤ d354shows a ⊔ b ≤ c ⊔ d355proof356unfold Le357rw [sup.join, sup.join]358exact join.monotone with*359360theorem inf_le_inf (a b c d ∈ points(P))361requires hac : a ≤ c362requires hbd : b ≤ d363shows a ⊓ b ≤ c ⊓ d364proof365unfold Le366rw [inf.meet, inf.meet]367exact meet.monotone with*368369theorem sup_le_sup_left (a b c ∈ points(P))370requires hbc : b ≤ c371shows a ⊔ b ≤ a ⊔ c372proof373unfold Le374rw [sup.join, sup.join]375exact join.monotone_right with*376377theorem sup_le_sup_right (a b c ∈ points(P))378requires hab : a ≤ b379shows a ⊔ c ≤ b ⊔ c380proof381unfold Le382rw [sup.join, sup.join]383exact join.monotone_left with*384385theorem inf_le_inf_left (a b c ∈ points(P))386requires hbc : b ≤ c387shows a ⊓ b ≤ a ⊓ c388proof389unfold Le390rw [inf.meet, inf.meet]391exact meet.monotone_right with*392393theorem inf_le_inf_right (a b c ∈ points(P))394requires hab : a ≤ b395shows a ⊓ c ≤ b ⊓ c396proof397unfold Le398rw [inf.meet, inf.meet]399exact meet.monotone_left with*400401theorem le_sup_of_le_left (a b c ∈ points(P))402requires hab : a ≤ b403shows a ≤ b ⊔ c404proof405exact le_trans with hab, (le_sup_left with*)406407theorem le_sup_of_le_right (a b c ∈ points(P))408requires hac : a ≤ c409shows a ≤ b ⊔ c410proof411exact le_trans with hac, (le_sup_right with*)412413theorem inf_le_of_left_le (a b c ∈ points(P))414requires hac : a ≤ c415shows a ⊓ b ≤ c416proof417exact le_trans with (inf_le_left with*), hac418419theorem inf_le_of_right_le (a b c ∈ points(P))420requires hbc : b ≤ c421shows a ⊓ b ≤ c422proof423exact le_trans with (inf_le_right with*), hbc424425theorem inf_le_sup (a b ∈ points(P))426shows a ⊓ b ≤ a ⊔ b427proof428unfold Le429rw [inf.meet, sup.join]430exact meet.le_join with*431432-- The distributive and modular inequalities, which hold in every lattice.433theorem sup_inf_le_inf_sup (a b c ∈ points(P))434shows (a ⊓ b) ⊔ (a ⊓ c) ≤ a ⊓ (b ⊔ c)435proof436unfold Le437rw [inf.meet, inf.meet, sup.join, sup.join, inf.meet]438exact meet.join_distributive_le with*439440theorem sup_inf_le_inf_sup_sup (a b c ∈ points(P))441shows a ⊔ (b ⊓ c) ≤ (a ⊔ b) ⊓ (a ⊔ c)442proof443unfold Le444rw [inf.meet, sup.join, sup.join, sup.join, inf.meet]445exact join.meet_distributive_ge with*446447theorem sup_inf_le_of_le (a b c ∈ points(P))448requires hba : b ≤ a449shows b ⊔ (a ⊓ c) ≤ a ⊓ (b ⊔ c)450proof451unfold Le452rw [inf.meet, sup.join, sup.join, inf.meet]453exact join.modular_le with*454455end LatticeLaws456457-- The lattice rewrite set: idempotency, absorption, associativity, and the458-- bounds of a join and a meet, each applied where the memberships of its459-- elements are in scope.460tactic lattice_simp :=simp [sup_idem, inf_idem, sup_absorb, inf_absorb, sup_assoc, inf_assoc, le_sup_left, le_sup_right, inf_le_left, inf_le_right, le_refl]461