1-- Bounded lattices: least and greatest elements, and complementary pairs2-- 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.Bounded8import LatticeLaws910predicate IsBoundedLattice (A r bot top : Set) :=11 IsLattice(A, r) ∧ Least(A, r, A, bot) ∧ Greatest(A, r, A, top)1213-- Two elements are complementary when they meet at the bottom and join14-- at the top.15predicate Complementary (A r bot top x y : Set) :=16 y ∈ A ∧ meet(A, r, x, y) = bot ∧ join(A, r, x, y) = top1718theorem IsBoundedLattice.lattice (A r bot top : Set)19requires h : IsBoundedLattice(A, r, bot, top)20shows IsLattice(A, r)21proof22simp [IsBoundedLattice]2324theorem IsBoundedLattice.least (A r bot top : Set)25requires h : IsBoundedLattice(A, r, bot, top)26shows Least(A, r, A, bot)27proof28simp [IsBoundedLattice]2930theorem IsBoundedLattice.greatest (A r bot top : Set)31requires h : IsBoundedLattice(A, r, bot, top)32shows Greatest(A, r, A, top)33proof34simp [IsBoundedLattice]3536theorem IsBoundedLattice.of_bounds (A r bot top : Set)37requires lattice : IsLattice(A, r)38requires least : Least(A, r, A, bot)39requires greatest : Greatest(A, r, A, top)40shows IsBoundedLattice(A, r, bot, top)41proof42refine⟨lattice, least, greatest⟩4344theorem IsBoundedLattice.bottom_member (A r bot top : Set)45requires h : IsBoundedLattice(A, r, bot, top)46shows bot ∈ A47proof48exact Least.member with (IsBoundedLattice.least with h)4950theorem IsBoundedLattice.top_member (A r bot top : Set)51requires h : IsBoundedLattice(A, r, bot, top)52shows top ∈ A53proof54exact Greatest.member with (IsBoundedLattice.greatest with h)5556theorem IsBoundedLattice.bottom_le (A r bot top x : Set)57requires h : IsBoundedLattice(A, r, bot, top)58requires hx : x ∈ A59shows relates(r, bot, x)60proof61exact Least.below with (IsBoundedLattice.least with h), hx6263theorem IsBoundedLattice.le_top (A r bot top x : Set)64requires h : IsBoundedLattice(A, r, bot, top)65requires hx : x ∈ A66shows relates(r, x, top)67proof68exact Greatest.above with (IsBoundedLattice.greatest with h), hx6970theorem IsBoundedLattice.nonempty (A r bot top : Set)71requires h : IsBoundedLattice(A, r, bot, top)72shows Nonempty(A)73proof74refine⟨bot, IsBoundedLattice.bottom_member with h⟩7576theorem IsBoundedLattice.bottom_unique (A r bot top c : Set)77requires h : IsBoundedLattice(A, r, bot, top)78requires hc : Least(A, r, A, c)79shows c = bot80proof81have order := IsLattice.order with (IsBoundedLattice.lattice with h)82exact Least.unique with order, hc, (IsBoundedLattice.least with h)8384theorem IsBoundedLattice.top_unique (A r bot top c : Set)85requires h : IsBoundedLattice(A, r, bot, top)86requires hc : Greatest(A, r, A, c)87shows c = top88proof89have order := IsLattice.order with (IsBoundedLattice.lattice with h)90exact Greatest.unique with order, hc, (IsBoundedLattice.greatest with h)9192theorem IsBoundedLattice.le_bottom_iff (A r bot top x : Set)93requires h : IsBoundedLattice(A, r, bot, top)94requires hx : x ∈ A95shows relates(r, x, bot) ↔ x = bot96proof97have lattice := IsBoundedLattice.lattice with h98have antisymmetric := IsLattice.antisymmetric with lattice99have reflexive := IsLattice.reflexive with lattice100have botA := IsBoundedLattice.bottom_member with h101constructor102 . intro below103have above := IsBoundedLattice.bottom_le with h, hx104exact antisymmetric with x, hx, bot, botA, below, above105 . intro equal106rw equal107exact reflexive with bot, botA108109theorem IsBoundedLattice.top_le_iff (A r bot top x : Set)110requires h : IsBoundedLattice(A, r, bot, top)111requires hx : x ∈ A112shows relates(r, top, x) ↔ x = top113proof114have lattice := IsBoundedLattice.lattice with h115have antisymmetric := IsLattice.antisymmetric with lattice116have reflexive := IsLattice.reflexive with lattice117have topA := IsBoundedLattice.top_member with h118constructor119 . intro above120have below := IsBoundedLattice.le_top with h, hx121exact antisymmetric with x, hx, top, topA, below, above122 . intro equal123rw equal124exact reflexive with top, topA125126-- The bottom and top as units and absorbing elements127128theorem join.bottom_right (A r bot top x : Set)129requires h : IsBoundedLattice(A, r, bot, top)130requires hx : x ∈ A131shows join(A, r, x, bot) = x132proof133have lattice := IsBoundedLattice.lattice with h134have botA := IsBoundedLattice.bottom_member with h135exact join.of_ge with lattice, hx, botA,136 (IsBoundedLattice.bottom_le with h, hx)137138theorem join.bottom_left (A r bot top x : Set)139requires h : IsBoundedLattice(A, r, bot, top)140requires hx : x ∈ A141shows join(A, r, bot, x) = x142proof143have lattice := IsBoundedLattice.lattice with h144have botA := IsBoundedLattice.bottom_member with h145exact join.of_le with lattice, botA, hx,146 (IsBoundedLattice.bottom_le with h, hx)147148theorem meet.bottom_right (A r bot top x : Set)149requires h : IsBoundedLattice(A, r, bot, top)150requires hx : x ∈ A151shows meet(A, r, x, bot) = bot152proof153have lattice := IsBoundedLattice.lattice with h154have botA := IsBoundedLattice.bottom_member with h155exact meet.of_ge with lattice, hx, botA,156 (IsBoundedLattice.bottom_le with h, hx)157158theorem meet.bottom_left (A r bot top x : Set)159requires h : IsBoundedLattice(A, r, bot, top)160requires hx : x ∈ A161shows meet(A, r, bot, x) = bot162proof163have lattice := IsBoundedLattice.lattice with h164have botA := IsBoundedLattice.bottom_member with h165exact meet.of_le with lattice, botA, hx,166 (IsBoundedLattice.bottom_le with h, hx)167168theorem join.top_right (A r bot top x : Set)169requires h : IsBoundedLattice(A, r, bot, top)170requires hx : x ∈ A171shows join(A, r, x, top) = top172proof173have lattice := IsBoundedLattice.lattice with h174have topA := IsBoundedLattice.top_member with h175exact join.of_le with lattice, hx, topA, (IsBoundedLattice.le_top with h, hx)176177theorem join.top_left (A r bot top x : Set)178requires h : IsBoundedLattice(A, r, bot, top)179requires hx : x ∈ A180shows join(A, r, top, x) = top181proof182have lattice := IsBoundedLattice.lattice with h183have topA := IsBoundedLattice.top_member with h184exact join.of_ge with lattice, topA, hx, (IsBoundedLattice.le_top with h, hx)185186theorem meet.top_right (A r bot top x : Set)187requires h : IsBoundedLattice(A, r, bot, top)188requires hx : x ∈ A189shows meet(A, r, x, top) = x190proof191have lattice := IsBoundedLattice.lattice with h192have topA := IsBoundedLattice.top_member with h193exact meet.of_le with lattice, hx, topA, (IsBoundedLattice.le_top with h, hx)194195theorem meet.top_left (A r bot top x : Set)196requires h : IsBoundedLattice(A, r, bot, top)197requires hx : x ∈ A198shows meet(A, r, top, x) = x199proof200have lattice := IsBoundedLattice.lattice with h201have topA := IsBoundedLattice.top_member with h202exact meet.of_ge with lattice, topA, hx, (IsBoundedLattice.le_top with h, hx)203204theorem join.eq_bottom_iff (A r bot top x y : Set)205requires h : IsBoundedLattice(A, r, bot, top)206requires hx : x ∈ A207requires hy : y ∈ A208shows join(A, r, x, y) = bot ↔ x = bot ∧ y = bot209proof210have lattice := IsBoundedLattice.lattice with h211constructor212 . intro equal213have xJ := join.upper_left with lattice, hx, hy214have yJ := join.upper_right with lattice, hx, hy215rw equal at xJ216rw equal at yJ217constructor218 . exact IsBoundedLattice.le_bottom_iff.forward with h, hx, xJ219 . exact IsBoundedLattice.le_bottom_iff.forward with h, hy, yJ220 . intro both221rw [both.left, both.right]222exact join.idempotent with lattice, (IsBoundedLattice.bottom_member with h)223224theorem meet.eq_top_iff (A r bot top x y : Set)225requires h : IsBoundedLattice(A, r, bot, top)226requires hx : x ∈ A227requires hy : y ∈ A228shows meet(A, r, x, y) = top ↔ x = top ∧ y = top229proof230have lattice := IsBoundedLattice.lattice with h231constructor232 . intro equal233have mX := meet.lower_left with lattice, hx, hy234have mY := meet.lower_right with lattice, hx, hy235rw equal at mX236rw equal at mY237constructor238 . exact IsBoundedLattice.top_le_iff.forward with h, hx, mX239 . exact IsBoundedLattice.top_le_iff.forward with h, hy, mY240 . intro both241rw [both.left, both.right]242exact meet.idempotent with lattice, (IsBoundedLattice.top_member with h)243244-- The bounds as suprema and infima245246theorem IsBoundedLattice.supremum_empty (A r bot top : Set)247requires h : IsBoundedLattice(A, r, bot, top)248shows Supremum(A, r, ∅, bot)249proof250exact Supremum.empty_iff.backward with (IsBoundedLattice.least with h)251252theorem IsBoundedLattice.infimum_empty (A r bot top : Set)253requires h : IsBoundedLattice(A, r, bot, top)254shows Infimum(A, r, ∅, top)255proof256exact Infimum.empty_iff.backward with (IsBoundedLattice.greatest with h)257258theorem IsBoundedLattice.supremum_whole (A r bot top : Set)259requires h : IsBoundedLattice(A, r, bot, top)260shows Supremum(A, r, A, top)261proof262exact Supremum.whole_iff.backward with (IsBoundedLattice.greatest with h)263264theorem IsBoundedLattice.infimum_whole (A r bot top : Set)265requires h : IsBoundedLattice(A, r, bot, top)266shows Infimum(A, r, A, bot)267proof268exact Infimum.whole_iff.backward with (IsBoundedLattice.least with h)269270theorem IsBoundedLattice.converse (A r bot top : Set)271requires h : IsBoundedLattice(A, r, bot, top)272shows IsBoundedLattice(A, converse(r, A, A), top, bot)273proof274have lattice := IsBoundedLattice.lattice with h275refine⟨IsLattice.converse with lattice,276 Greatest.converse with (IsBoundedLattice.greatest with h),277 Least.converse with (IsBoundedLattice.least with h)⟩278279-- Complementary pairs280281theorem Complementary.member (A r bot top x y : Set)282requires h : Complementary(A, r, bot, top, x, y)283shows y ∈ A284proof285simp [Complementary]286287theorem Complementary.meet (A r bot top x y : Set)288requires h : Complementary(A, r, bot, top, x, y)289shows meet(A, r, x, y) = bot290proof291rcases h with⟨member, meetEq, joinEq⟩292exact meetEq293294theorem Complementary.join (A r bot top x y : Set)295requires h : Complementary(A, r, bot, top, x, y)296shows join(A, r, x, y) = top297proof298rcases h with⟨member, meetEq, joinEq⟩299exact joinEq300301theorem Complementary.symmetric (A r bot top x y : Set)302requires bounded : IsBoundedLattice(A, r, bot, top)303requires hx : x ∈ A304requires h : Complementary(A, r, bot, top, x, y)305shows Complementary(A, r, bot, top, y, x)306proof307have lattice := IsBoundedLattice.lattice with bounded308have hy := Complementary.member with h309have meetSwap := meet.commutative with lattice, hy, hx310have joinSwap := join.commutative with lattice, hy, hx311refine⟨hx, ?_, ?_⟩312 . rw meetSwap313exact Complementary.meet with h314 . rw joinSwap315exact Complementary.join with h316317theorem Complementary.bottom_top (A r bot top : Set)318requires bounded : IsBoundedLattice(A, r, bot, top)319shows Complementary(A, r, bot, top, bot, top)320proof321have botA := IsBoundedLattice.bottom_member with bounded322have topA := IsBoundedLattice.top_member with bounded323refine⟨topA, (meet.bottom_left with bounded, topA),324 (join.top_right with bounded, botA)⟩325326theorem Complementary.top_bottom (A r bot top : Set)327requires bounded : IsBoundedLattice(A, r, bot, top)328shows Complementary(A, r, bot, top, top, bot)329proof330have botA := IsBoundedLattice.bottom_member with bounded331have topA := IsBoundedLattice.top_member with bounded332refine⟨botA, (meet.bottom_right with bounded, topA),333 (join.top_left with bounded, botA)⟩334335theorem Complementary.converse (A r bot top x y : Set)336requires bounded : IsBoundedLattice(A, r, bot, top)337requires hx : x ∈ A338requires h : Complementary(A, r, bot, top, x, y)339shows Complementary(A, converse(r, A, A), top, bot, x, y)340proof341have lattice := IsBoundedLattice.lattice with bounded342have hy := Complementary.member with h343have joinDual := join.converse with lattice, hx, hy344have meetDual := meet.converse with lattice, hx, hy345refine⟨hy, ?_, ?_⟩346 . rw meetDual347exact Complementary.join with h348 . rw joinDual349exact Complementary.meet with h350