1-- Bounded lattices bundled as ordered sets, with bot(P) and top(P)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.BoundedOrder8import Bounded9import Join1011-- A bounded lattice is a lattice with a least and a greatest element; the12-- elements are determined by the order and read back as bot(P) and top(P).13predicate BoundedLattice (P : Set) :=14 Lattice(P) ∧ (∃ b, Least(points(P), le(P), points(P), b)) ∧15 (∃ t, Greatest(points(P), le(P), points(P), t))1617notationinfixl68"⊔"=> call2(sup(P), _, _) viahypothesis BoundedLattice(P) for P.points18notationinfixl69"⊓"=> call2(inf(P), _, _) viahypothesis BoundedLattice(P) for P.points19notationinfix50"≤"=> Le(P, _, _) viahypothesis BoundedLattice(P) for P.points2021instance BoundedLattice.lattice_of (P : Set)22requires bounded : BoundedLattice(P)23shows Lattice(P)24proof25simp [BoundedLattice]2627theorem BoundedLattice.exists_least (P : Set)28requires bounded : BoundedLattice(P)29shows∃ b, Least(points(P), le(P), points(P), b)30proof31obtain⟨lattice, least, greatest⟩:= bounded32exact least3334theorem BoundedLattice.exists_greatest (P : Set)35requires bounded : BoundedLattice(P)36shows∃ t, Greatest(points(P), le(P), points(P), t)37proof38obtain⟨lattice, least, greatest⟩:= bounded39exact greatest4041defunique bot (P : Set) (b ∈ points(P)) := Least(points(P), le(P), points(P), b)42requires bounded : BoundedLattice(P)43proof44obtain⟨b, least⟩:= BoundedLattice.exists_least with bounded45witness b46refine⟨Least.member with least, least⟩47uniqueness48intros b bIn first c cIn second49have order := IsLattice.order with (Lattice.unbundled with (BoundedLattice.lattice_of with bounded))50exact Least.unique with order, first, second5152defunique top (P : Set) (t ∈ points(P)) := Greatest(points(P), le(P), points(P), t)53requires bounded : BoundedLattice(P)54proof55obtain⟨t, greatest⟩:= BoundedLattice.exists_greatest with bounded56witness t57refine⟨Greatest.member with greatest, greatest⟩58uniqueness59intros t tIn first u uIn second60have order := IsLattice.order with (Lattice.unbundled with (BoundedLattice.lattice_of with bounded))61exact Greatest.unique with order, first, second6263-- Bridges to the unbundled form IsBoundedLattice(A, r, bot, top).64instance BoundedLattice.unbundled (P : Set)65requires bounded : BoundedLattice(P)66shows IsBoundedLattice(points(P), le(P), bot(P), top(P))67proof68have lattice := Lattice.unbundled with (BoundedLattice.lattice_of with bounded)69have least := bot.selected with bounded70have greatest := top.selected with bounded71exact IsBoundedLattice.of_bounds with lattice, least.right, greatest.right7273theorem BoundedLattice.mk (A r b t : Set)74requires bounded : IsBoundedLattice(A, r, b, t)75shows BoundedLattice(Order.mk(A, r))76proof77have lattice := Lattice.mk with (IsBoundedLattice.lattice with bounded)78have least := IsBoundedLattice.least with bounded79have greatest := IsBoundedLattice.greatest with bounded80unfold BoundedLattice81refine⟨lattice, ?_, ?_⟩82 . witness b83rw [Order.mk.points, Order.mk.le]84exact least85 . witness t86rw [Order.mk.points, Order.mk.le]87exact greatest8889theorem bot.mk (A r b t : Set)90requires bounded : IsBoundedLattice(A, r, b, t)91shows bot(Order.mk(A, r)) = b92proof93have bundled := BoundedLattice.mk with bounded94have selected := bot.selected with bundled95have least := IsBoundedLattice.least with bounded96have order := IsLattice.order with (IsBoundedLattice.lattice with bounded)97rw [Order.mk.points, Order.mk.le] at selected98exact Least.unique with order, selected.right, least99100theorem top.mk (A r b t : Set)101requires bounded : IsBoundedLattice(A, r, b, t)102shows top(Order.mk(A, r)) = t103proof104have bundled := BoundedLattice.mk with bounded105have selected := top.selected with bundled106have greatest := IsBoundedLattice.greatest with bounded107have order := IsLattice.order with (IsBoundedLattice.lattice with bounded)108rw [Order.mk.points, Order.mk.le] at selected109exact Greatest.unique with order, selected.right, greatest110111-- Two elements are complementary when they meet at the bottom and join at112-- the top; under a hypothesis the conjuncts read a ⊓ b = bot(P) and113-- a ⊔ b = top(P).114predicate IsCompl (P a b : Set) :=115 b ∈ points(P) ∧ call2(inf(P), a, b) = bot(P) ∧ call2(sup(P), a, b) = top(P)116117-- The bounds are written ⊥ and ⊤ wherever a hypothesis in scope supplies118-- the bounded lattice; both lie in points(P).119notation constant "⊥"=> bot(P) viahypothesis BoundedLattice(P) for P.points120notation constant "⊤"=> top(P) viahypothesis BoundedLattice(P) for P.points121122section BoundedLatticeLaws123variable (P : Set)124hypothesis bounded : BoundedLattice(P)125126instance bot.member127shows bot(P) ∈ points(P)128proof129have selected := bot.selected with bounded130exact selected.left131132instance top.member133shows top(P) ∈ points(P)134proof135have selected := top.selected with bounded136exact selected.left137138theorem bot.isLeast139shows IsLeast(P, points(P), bot(P))140proof141unfold IsLeast142have selected := bot.selected with bounded143exact selected.right144145theorem top.isGreatest146shows IsGreatest(P, points(P), top(P))147proof148unfold IsGreatest149have selected := top.selected with bounded150exact selected.right151152theorem bot_le (a ∈ points(P))153shows⊥≤ a154proof155unfold Le156exact IsBoundedLattice.bottom_le with (BoundedLattice.unbundled with bounded),157*158159theorem le_top (a ∈ points(P))160shows a ≤ ⊤161proof162unfold Le163exact IsBoundedLattice.le_top with (BoundedLattice.unbundled with bounded), *164165theorem bot_unique (b : Set)166requires least : IsLeast(P, points(P), b)167shows b = bot(P)168proof169unfold IsLeast at least170exact IsBoundedLattice.bottom_unique with (BoundedLattice.unbundled with bounded), *171172theorem top_unique (t : Set)173requires greatest : IsGreatest(P, points(P), t)174shows t = top(P)175proof176unfold IsGreatest at greatest177exact IsBoundedLattice.top_unique with (BoundedLattice.unbundled with bounded), *178179theorem le_bot_iff (a ∈ points(P))180shows a ≤ bot(P) ↔ a = bot(P)181proof182have characterization := IsBoundedLattice.le_bottom_iff with (BoundedLattice.unbundled with bounded), *183constructor184 . intro h185exact characterization.forward with (Le.relates with h)186 . intro h187exact Le.of_relates with (characterization.backward with h)188189theorem top_le_iff (a ∈ points(P))190shows top(P) ≤ a ↔ a = top(P)191proof192have characterization := IsBoundedLattice.top_le_iff with (BoundedLattice.unbundled with bounded), *193constructor194 . intro h195exact characterization.forward with (Le.relates with h)196 . intro h197exact Le.of_relates with (characterization.backward with h)198199theorem sup_bot_eq (a ∈ points(P))200shows a ⊔ bot(P) = a201proof202rw sup.join203exact join.bottom_right with (BoundedLattice.unbundled with bounded), *204205theorem bot_sup_eq (a ∈ points(P))206shows bot(P) ⊔ a = a207proof208rw sup.join209exact join.bottom_left with (BoundedLattice.unbundled with bounded), *210211theorem inf_bot_eq (a ∈ points(P))212shows a ⊓ bot(P) = bot(P)213proof214rw inf.meet215exact meet.bottom_right with (BoundedLattice.unbundled with bounded), *216217theorem bot_inf_eq (a ∈ points(P))218shows bot(P) ⊓ a = bot(P)219proof220rw inf.meet221exact meet.bottom_left with (BoundedLattice.unbundled with bounded), *222223theorem sup_top_eq (a ∈ points(P))224shows a ⊔ top(P) = top(P)225proof226rw sup.join227exact join.top_right with (BoundedLattice.unbundled with bounded), *228229theorem top_sup_eq (a ∈ points(P))230shows top(P) ⊔ a = top(P)231proof232rw sup.join233exact join.top_left with (BoundedLattice.unbundled with bounded), *234235theorem inf_top_eq (a ∈ points(P))236shows a ⊓ top(P) = a237proof238rw inf.meet239exact meet.top_right with (BoundedLattice.unbundled with bounded), *240241theorem top_inf_eq (a ∈ points(P))242shows top(P) ⊓ a = a243proof244rw inf.meet245exact meet.top_left with (BoundedLattice.unbundled with bounded), *246247theorem sup_eq_bot_iff (a b ∈ points(P))248shows a ⊔ b = bot(P) ↔ (a = bot(P) ∧ b = bot(P))249proof250rw sup.join251exact join.eq_bottom_iff with (BoundedLattice.unbundled with bounded), *252253theorem inf_eq_top_iff (a b ∈ points(P))254shows a ⊓ b = top(P) ↔ (a = top(P) ∧ b = top(P))255proof256rw inf.meet257exact meet.eq_top_iff with (BoundedLattice.unbundled with bounded), *258259theorem bot.isLUB_empty260shows IsLUB(P, ∅, bot(P))261proof262unfold IsLUB263exact IsBoundedLattice.supremum_empty with (BoundedLattice.unbundled with bounded), *264265theorem top.isGLB_empty266shows IsGLB(P, ∅, top(P))267proof268unfold IsGLB269exact IsBoundedLattice.infimum_empty with (BoundedLattice.unbundled with bounded), *270271theorem BoundedLattice.nonempty_points272shows Nonempty(points(P))273proof274exact IsBoundedLattice.nonempty with (BoundedLattice.unbundled with bounded),275*276277theorem IsCompl.member (a b : Set)278requires compl : IsCompl(P, a, b)279shows b ∈ points(P)280proof281obtain⟨bIn, meetEq, joinEq⟩:= compl282exact bIn283284theorem IsCompl.inf_eq_bot (a b : Set)285requires compl : IsCompl(P, a, b)286shows a ⊓ b = bot(P)287proof288obtain⟨bIn, meetEq, joinEq⟩:= compl289exact meetEq290291theorem IsCompl.sup_eq_top (a b : Set)292requires compl : IsCompl(P, a, b)293shows a ⊔ b = top(P)294proof295obtain⟨bIn, meetEq, joinEq⟩:= compl296exact joinEq297298theorem IsCompl.unbundled (b : Set) (a ∈ points(P))299requires compl : IsCompl(P, a, b)300shows Complementary(points(P), le(P), bot(P), top(P), a, b)301proof302obtain⟨bIn, meetEq, joinEq⟩:= compl303have meetBridge := inf.meet at P, a, b with*304have joinBridge := sup.join at P, a, b with*305unfold Complementary306rw [← meetBridge, ← joinBridge]307exact⟨bIn, meetEq, joinEq⟩308309theorem IsCompl.of_complementary (b : Set) (a ∈ points(P))310requires compl : Complementary(points(P), le(P), bot(P), top(P), a, b)311shows IsCompl(P, a, b)312proof313obtain⟨bIn, meetEq, joinEq⟩:= compl314have meetBridge := inf.meet at P, a, b with*315have joinBridge := sup.join at P, a, b with*316unfold IsCompl317rw [meetBridge, joinBridge]318exact⟨bIn, meetEq, joinEq⟩319320theorem IsCompl.symm (b : Set) (a ∈ points(P))321requires compl : IsCompl(P, a, b)322shows IsCompl(P, b, a)323proof324obtain⟨bIn, meetEq, joinEq⟩:= compl325have meetComm : b ⊓ a = a ⊓ b := inf_comm with*326have supComm : b ⊔ a = a ⊔ b := sup_comm with*327unfold IsCompl328rw [meetComm, supComm]329constructor330 . assumption331 . exact⟨meetEq, joinEq⟩332333theorem IsCompl.bot_top334shows IsCompl(P, bot(P), top(P))335proof336have topIn : top(P) ∈ points(P) := top.member with*337have meetEq : bot(P) ⊓ top(P) = bot(P) := inf_top_eq with*338have joinEq : bot(P) ⊔ top(P) = top(P) := bot_sup_eq with*339exact⟨topIn, meetEq, joinEq⟩340341end BoundedLatticeLaws342343-- The bounded-lattice rewrite set.344tactic bounded_simp :=simp [sup_bot_eq, bot_sup_eq, inf_bot_eq, bot_inf_eq, sup_top_eq, top_sup_eq, inf_top_eq, top_inf_eq, bot_le, le_top]345