1-- Suprema and infima of subsets of an ordered set, and order duality2-- 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.Bounds8import Set.Order910-- A supremum is a least upper bound; an infimum is a greatest lower bound.11predicate Supremum (A r S s : Set) :=12 UpperBound(A, r, S, s) ∧ (∀ b ∈ A, UpperBound(A, r, S, b) → relates(r, s, b))13predicate Infimum (A r S i : Set) :=14 LowerBound(A, r, S, i) ∧ (∀ b ∈ A, LowerBound(A, r, S, b) → relates(r, b, i))1516-- Projections of the bound predicates1718theorem UpperBound.member (A r S a : Set)19requires h : UpperBound(A, r, S, a)20shows a ∈ A21proof22simp [UpperBound]2324theorem UpperBound.subset (A r S a : Set)25requires h : UpperBound(A, r, S, a)26shows S ⊆ A27proof28simp [UpperBound]2930theorem UpperBound.above (A r S a x : Set)31requires h : UpperBound(A, r, S, a)32requires hx : x ∈ S33shows relates(r, x, a)34proof35rcases h with⟨member, bounded, above⟩36exact above with x, hx3738theorem LowerBound.member (A r S a : Set)39requires h : LowerBound(A, r, S, a)40shows a ∈ A41proof42simp [LowerBound]4344theorem LowerBound.subset (A r S a : Set)45requires h : LowerBound(A, r, S, a)46shows S ⊆ A47proof48simp [LowerBound]4950theorem LowerBound.below (A r S a x : Set)51requires h : LowerBound(A, r, S, a)52requires hx : x ∈ S53shows relates(r, a, x)54proof55rcases h with⟨member, bounded, below⟩56exact below with x, hx5758theorem Least.member (A r S a : Set)59requires h : Least(A, r, S, a)60shows a ∈ S61proof62simp [Least]6364theorem Least.lower (A r S a : Set)65requires h : Least(A, r, S, a)66shows LowerBound(A, r, S, a)67proof68simp [Least]6970theorem Least.below (A r S a x : Set)71requires h : Least(A, r, S, a)72requires hx : x ∈ S73shows relates(r, a, x)74proof75have lower := Least.lower with h76exact LowerBound.below with lower, hx7778theorem Greatest.member (A r S a : Set)79requires h : Greatest(A, r, S, a)80shows a ∈ S81proof82simp [Greatest]8384theorem Greatest.upper (A r S a : Set)85requires h : Greatest(A, r, S, a)86shows UpperBound(A, r, S, a)87proof88simp [Greatest]8990theorem Greatest.above (A r S a x : Set)91requires h : Greatest(A, r, S, a)92requires hx : x ∈ S93shows relates(r, x, a)94proof95have upper := Greatest.upper with h96exact UpperBound.above with upper, hx9798-- Bounds of the empty set, of subsets, and of pairs99100theorem UpperBound.empty (A r a : Set)101requires ha : a ∈ A102shows UpperBound(A, r, ∅, a)103proof104refine⟨ha, empty.subset at A, ?_⟩105intros x hx106exfalso107exactset.empty with hx108109theorem LowerBound.empty (A r a : Set)110requires ha : a ∈ A111shows LowerBound(A, r, ∅, a)112proof113refine⟨ha, empty.subset at A, ?_⟩114intros x hx115exfalso116exactset.empty with hx117118theorem UpperBound.antitone (A r S T a : Set)119requires hST : S ⊆ T120requires h : UpperBound(A, r, T, a)121shows UpperBound(A, r, S, a)122proof123rcases h with⟨member, bounded, above⟩124refine⟨member, (Subset.transitive with hST, bounded), ?_⟩125intros x hx126exact above with x, (hST with x, hx)127128theorem LowerBound.antitone (A r S T a : Set)129requires hST : S ⊆ T130requires h : LowerBound(A, r, T, a)131shows LowerBound(A, r, S, a)132proof133rcases h with⟨member, bounded, below⟩134refine⟨member, (Subset.transitive with hST, bounded), ?_⟩135intros x hx136exact below with x, (hST with x, hx)137138theorem UpperBound.raise (A r S a b : Set)139requires order : IsPartialOrder(A, r)140requires h : UpperBound(A, r, S, a)141requires hb : b ∈ A142requires hab : relates(r, a, b)143shows UpperBound(A, r, S, b)144proof145have transitive := IsPartialOrder.transitive with order146rcases h with⟨member, bounded, above⟩147refine⟨hb, bounded, ?_⟩148intros x hx149have xA := bounded with x, hx150exact transitive with x, xA, a, member, b, hb, (above with x, hx), hab151152theorem LowerBound.lower (A r S a b : Set)153requires order : IsPartialOrder(A, r)154requires h : LowerBound(A, r, S, a)155requires hb : b ∈ A156requires hba : relates(r, b, a)157shows LowerBound(A, r, S, b)158proof159have transitive := IsPartialOrder.transitive with order160rcases h with⟨member, bounded, below⟩161refine⟨hb, bounded, ?_⟩162intros x hx163have xA := bounded with x, hx164exact transitive with b, hb, a, member, x, xA, hba, (below with x, hx)165166theorem UpperBound.singleton (A r x : Set)167requires order : IsPartialOrder(A, r)168requires hx : x ∈ A169shows UpperBound(A, r, {x}, x)170proof171have reflexive := IsPartialOrder.reflexive with order172have bounded : {x} ⊆ A bysimp173refine⟨hx, bounded, ?_⟩174intros y hy175have equal := singleton.membership.forward with hy176rw equal177exact reflexive with x, hx178179theorem LowerBound.singleton (A r x : Set)180requires order : IsPartialOrder(A, r)181requires hx : x ∈ A182shows LowerBound(A, r, {x}, x)183proof184have reflexive := IsPartialOrder.reflexive with order185have bounded : {x} ⊆ A bysimp186refine⟨hx, bounded, ?_⟩187intros y hy188have equal := singleton.membership.forward with hy189rw equal190exact reflexive with x, hx191192theorem UpperBound.pair (A r x y a : Set)193requires hx : x ∈ A194requires hy : y ∈ A195requires ha : a ∈ A196requires hxa : relates(r, x, a)197requires hya : relates(r, y, a)198shows UpperBound(A, r, {x, y}, a)199proof200have bounded : {x, y} ⊆ A bysimp201refine⟨ha, bounded, ?_⟩202intros z hz203havecases:= pair.membership.forward with hz204casescaseswith zx | zy205 . rw zx206exact hxa207 . rw zy208exact hya209210theorem LowerBound.pair (A r x y a : Set)211requires hx : x ∈ A212requires hy : y ∈ A213requires ha : a ∈ A214requires hax : relates(r, a, x)215requires hay : relates(r, a, y)216shows LowerBound(A, r, {x, y}, a)217proof218have bounded : {x, y} ⊆ A bysimp219refine⟨ha, bounded, ?_⟩220intros z hz221havecases:= pair.membership.forward with hz222casescaseswith zx | zy223 . rw zx224exact hax225 . rw zy226exact hay227228theorem UpperBound.pair_left (A r x y a : Set)229requires h : UpperBound(A, r, {x, y}, a)230shows relates(r, x, a)231proof232exact UpperBound.above with h, (pair.left at x, y)233234theorem UpperBound.pair_right (A r x y a : Set)235requires h : UpperBound(A, r, {x, y}, a)236shows relates(r, y, a)237proof238exact UpperBound.above with h, (pair.right at x, y)239240theorem LowerBound.pair_left (A r x y a : Set)241requires h : LowerBound(A, r, {x, y}, a)242shows relates(r, a, x)243proof244exact LowerBound.below with h, (pair.left at x, y)245246theorem LowerBound.pair_right (A r x y a : Set)247requires h : LowerBound(A, r, {x, y}, a)248shows relates(r, a, y)249proof250exact LowerBound.below with h, (pair.right at x, y)251252-- Projections of suprema and infima253254theorem Supremum.upper (A r S s : Set)255requires h : Supremum(A, r, S, s)256shows UpperBound(A, r, S, s)257proof258simp [Supremum]259260theorem Supremum.least (A r S s b : Set)261requires h : Supremum(A, r, S, s)262requires hb : b ∈ A263requires bound : UpperBound(A, r, S, b)264shows relates(r, s, b)265proof266rcases h with⟨upper, least⟩267exact least with b, hb, bound268269theorem Supremum.member (A r S s : Set)270requires h : Supremum(A, r, S, s)271shows s ∈ A272proof273exact UpperBound.member with (Supremum.upper with h)274275theorem Supremum.subset (A r S s : Set)276requires h : Supremum(A, r, S, s)277shows S ⊆ A278proof279exact UpperBound.subset with (Supremum.upper with h)280281theorem Supremum.above (A r S s x : Set)282requires h : Supremum(A, r, S, s)283requires hx : x ∈ S284shows relates(r, x, s)285proof286exact UpperBound.above with (Supremum.upper with h), hx287288theorem Infimum.lower (A r S i : Set)289requires h : Infimum(A, r, S, i)290shows LowerBound(A, r, S, i)291proof292simp [Infimum]293294theorem Infimum.greatest (A r S i b : Set)295requires h : Infimum(A, r, S, i)296requires hb : b ∈ A297requires bound : LowerBound(A, r, S, b)298shows relates(r, b, i)299proof300rcases h with⟨lower, greatest⟩301exact greatest with b, hb, bound302303theorem Infimum.member (A r S i : Set)304requires h : Infimum(A, r, S, i)305shows i ∈ A306proof307exact LowerBound.member with (Infimum.lower with h)308309theorem Infimum.subset (A r S i : Set)310requires h : Infimum(A, r, S, i)311shows S ⊆ A312proof313exact LowerBound.subset with (Infimum.lower with h)314315theorem Infimum.below (A r S i x : Set)316requires h : Infimum(A, r, S, i)317requires hx : x ∈ S318shows relates(r, i, x)319proof320exact LowerBound.below with (Infimum.lower with h), hx321322-- Uniqueness323324theorem Supremum.unique (A r S s t : Set)325requires order : IsPartialOrder(A, r)326requires hs : Supremum(A, r, S, s)327requires ht : Supremum(A, r, S, t)328shows s = t329proof330have antisymmetric := IsPartialOrder.antisymmetric with order331have sA := Supremum.member with hs332have tA := Supremum.member with ht333have st := Supremum.least with hs, tA, (Supremum.upper with ht)334have ts := Supremum.least with ht, sA, (Supremum.upper with hs)335exact antisymmetric with s, sA, t, tA, st, ts336337theorem Infimum.unique (A r S i j : Set)338requires order : IsPartialOrder(A, r)339requires hi : Infimum(A, r, S, i)340requires hj : Infimum(A, r, S, j)341shows i = j342proof343have antisymmetric := IsPartialOrder.antisymmetric with order344have iA := Infimum.member with hi345have jA := Infimum.member with hj346have ji := Infimum.greatest with hi, jA, (Infimum.lower with hj)347have ij := Infimum.greatest with hj, iA, (Infimum.lower with hi)348exact antisymmetric with i, iA, j, jA, ij, ji349350-- Greatest elements are suprema, and a supremum that belongs to the set351-- is its greatest element.352353theorem Greatest.supremum (A r S g : Set)354requires h : Greatest(A, r, S, g)355shows Supremum(A, r, S, g)356proof357rcases h with⟨member, upper⟩358constructor359 . exact upper360 . intros b hb bound361exact UpperBound.above with bound, member362363theorem Least.infimum (A r S l : Set)364requires h : Least(A, r, S, l)365shows Infimum(A, r, S, l)366proof367rcases h with⟨member, lower⟩368constructor369 . exact lower370 . intros b hb bound371exact LowerBound.below with bound, member372373theorem Supremum.greatest_of_member (A r S s : Set)374requires h : Supremum(A, r, S, s)375requires hs : s ∈ S376shows Greatest(A, r, S, s)377proof378refine⟨hs, Supremum.upper with h⟩379380theorem Infimum.least_of_member (A r S i : Set)381requires h : Infimum(A, r, S, i)382requires hi : i ∈ S383shows Least(A, r, S, i)384proof385refine⟨hi, Infimum.lower with h⟩386387-- The empty set and the whole points388389theorem Supremum.empty_iff (A r s : Set)390shows Supremum(A, r, ∅, s) ↔ Least(A, r, A, s)391proof392constructor393 . intro h394have sA := Supremum.member with h395constructor396 . exact sA397 . refine⟨sA, Subset.reflexive at A, ?_⟩398intros x hx399exact Supremum.least with h, hx, (UpperBound.empty at A, r, x with hx)400 . intro h401rcases h with⟨sA, _, _, below⟩402constructor403 . exact UpperBound.empty with sA404 . intros b hb bound405exact below with b, hb406407theorem Infimum.empty_iff (A r i : Set)408shows Infimum(A, r, ∅, i) ↔ Greatest(A, r, A, i)409proof410constructor411 . intro h412have iA := Infimum.member with h413constructor414 . exact iA415 . refine⟨iA, Subset.reflexive at A, ?_⟩416intros x hx417exact Infimum.greatest with h, hx, (LowerBound.empty at A, r, x with hx)418 . intro h419rcases h with⟨iA, _, _, above⟩420constructor421 . exact LowerBound.empty with iA422 . intros b hb bound423exact above with b, hb424425theorem Supremum.whole_iff (A r s : Set)426shows Supremum(A, r, A, s) ↔ Greatest(A, r, A, s)427proof428constructor429 . intro h430exact Supremum.greatest_of_member with h, (Supremum.member with h)431 . intro h432exact Greatest.supremum with h433434theorem Infimum.whole_iff (A r i : Set)435shows Infimum(A, r, A, i) ↔ Least(A, r, A, i)436proof437constructor438 . intro h439exact Infimum.least_of_member with h, (Infimum.member with h)440 . intro h441exact Least.infimum with h442443-- Singletons and pairs444445theorem Supremum.singleton (A r x : Set)446requires order : IsPartialOrder(A, r)447requires hx : x ∈ A448shows Supremum(A, r, {x}, x)449proof450constructor451 . exact UpperBound.singleton with order, hx452 . intros b hb bound453exact UpperBound.above with bound, (singleton.self at x)454455theorem Infimum.singleton (A r x : Set)456requires order : IsPartialOrder(A, r)457requires hx : x ∈ A458shows Infimum(A, r, {x}, x)459proof460constructor461 . exact LowerBound.singleton with order, hx462 . intros b hb bound463exact LowerBound.below with bound, (singleton.self at x)464465theorem Supremum.of_pair (A r x y s : Set)466requires hx : x ∈ A467requires hy : y ∈ A468requires hs : s ∈ A469requires hxs : relates(r, x, s)470requires hys : relates(r, y, s)471requires least :472∀ b ∈ A, relates(r, x, b) → relates(r, y, b) → relates(r, s, b)473shows Supremum(A, r, {x, y}, s)474proof475constructor476 . exact UpperBound.pair with hx, hy, hs, hxs, hys477 . intros b hb bound478have xb := UpperBound.pair_left with bound479have yb := UpperBound.pair_right with bound480exact least with b, hb, xb, yb481482theorem Infimum.of_pair (A r x y i : Set)483requires hx : x ∈ A484requires hy : y ∈ A485requires hi : i ∈ A486requires hix : relates(r, i, x)487requires hiy : relates(r, i, y)488requires greatest :489∀ b ∈ A, relates(r, b, x) → relates(r, b, y) → relates(r, b, i)490shows Infimum(A, r, {x, y}, i)491proof492constructor493 . exact LowerBound.pair with hx, hy, hi, hix, hiy494 . intros b hb bound495have bx := LowerBound.pair_left with bound496have byBound := LowerBound.pair_right with bound497exact greatest with b, hb, bx, byBound498499theorem Supremum.pair_left (A r x y s : Set)500requires h : Supremum(A, r, {x, y}, s)501shows relates(r, x, s)502proof503exact UpperBound.pair_left with (Supremum.upper with h)504505theorem Supremum.pair_right (A r x y s : Set)506requires h : Supremum(A, r, {x, y}, s)507shows relates(r, y, s)508proof509exact UpperBound.pair_right with (Supremum.upper with h)510511theorem Supremum.pair_least (A r x y s b : Set)512requires h : Supremum(A, r, {x, y}, s)513requires hb : b ∈ A514requires hxb : relates(r, x, b)515requires hyb : relates(r, y, b)516shows relates(r, s, b)517proof518have bounded := Supremum.subset with h519have xA := bounded with x, (pair.left at x, y)520have yA := bounded with y, (pair.right at x, y)521have bound := UpperBound.pair with xA, yA, hb, hxb, hyb522exact Supremum.least with h, hb, bound523524theorem Infimum.pair_left (A r x y i : Set)525requires h : Infimum(A, r, {x, y}, i)526shows relates(r, i, x)527proof528exact LowerBound.pair_left with (Infimum.lower with h)529530theorem Infimum.pair_right (A r x y i : Set)531requires h : Infimum(A, r, {x, y}, i)532shows relates(r, i, y)533proof534exact LowerBound.pair_right with (Infimum.lower with h)535536theorem Infimum.pair_greatest (A r x y i b : Set)537requires h : Infimum(A, r, {x, y}, i)538requires hb : b ∈ A539requires hbx : relates(r, b, x)540requires hby : relates(r, b, y)541shows relates(r, b, i)542proof543have bounded := Infimum.subset with h544have xA := bounded with x, (pair.left at x, y)545have yA := bounded with y, (pair.right at x, y)546have bound := LowerBound.pair with xA, yA, hb, hbx, hby547exact Infimum.greatest with h, hb, bound548549-- Monotonicity in the set550551theorem Supremum.monotone (A r S T s t : Set)552requires hST : S ⊆ T553requires hs : Supremum(A, r, S, s)554requires ht : Supremum(A, r, T, t)555shows relates(r, s, t)556proof557have tA := Supremum.member with ht558have bound := UpperBound.antitone with hST, (Supremum.upper with ht)559exact Supremum.least with hs, tA, bound560561theorem Infimum.antitone (A r S T i j : Set)562requires hST : S ⊆ T563requires hi : Infimum(A, r, S, i)564requires hj : Infimum(A, r, T, j)565shows relates(r, j, i)566proof567have jA := Infimum.member with hj568have bound := LowerBound.antitone with hST, (Infimum.lower with hj)569exact Infimum.greatest with hi, jA, bound570571-- Duality: the converse of an order exchanges the two notions.572573theorem IsPartialOrder.converse (A r : Set)574requires order : IsPartialOrder(A, r)575shows IsPartialOrder(A, converse(r, A, A))576proof577have reflexive := IsPartialOrder.reflexive with order578have transitive := IsPartialOrder.transitive with order579have antisymmetric := IsPartialOrder.antisymmetric with order580constructor581 . constructor582 . exact converse.relation at r, A, A583 . constructor584 . intros x hx585exact converse.relates with hx, hx, (reflexive with x, hx)586 . intros x hx y hy z hz xy yz587have yx := converse.reflects with xy588have zy := converse.reflects with yz589have zx := transitive with z, hz, y, hy, x, hx, zy, yx590exact converse.relates with hz, hx, zx591 . intros x hx y hy xy yx592have yxR := converse.reflects with xy593have xyR := converse.reflects with yx594exact antisymmetric with x, hx, y, hy, xyR, yxR595596theorem UpperBound.converse (A r S a : Set)597requires h : UpperBound(A, r, S, a)598shows LowerBound(A, converse(r, A, A), S, a)599proof600rcases h with⟨member, bounded, above⟩601refine⟨member, bounded, ?_⟩602intros x hx603have xA := bounded with x, hx604exact converse.relates with xA, member, (above with x, hx)605606theorem LowerBound.converse (A r S a : Set)607requires h : LowerBound(A, r, S, a)608shows UpperBound(A, converse(r, A, A), S, a)609proof610rcases h with⟨member, bounded, below⟩611refine⟨member, bounded, ?_⟩612intros x hx613have xA := bounded with x, hx614exact converse.relates with member, xA, (below with x, hx)615616theorem UpperBound.of_converse (A r S a : Set)617requires h : UpperBound(A, converse(r, A, A), S, a)618shows LowerBound(A, r, S, a)619proof620rcases h with⟨member, bounded, above⟩621refine⟨member, bounded, ?_⟩622intros x hx623exact converse.reflects with (above with x, hx)624625theorem LowerBound.of_converse (A r S a : Set)626requires h : LowerBound(A, converse(r, A, A), S, a)627shows UpperBound(A, r, S, a)628proof629rcases h with⟨member, bounded, below⟩630refine⟨member, bounded, ?_⟩631intros x hx632exact converse.reflects with (below with x, hx)633634theorem Supremum.converse (A r S s : Set)635requires h : Supremum(A, r, S, s)636shows Infimum(A, converse(r, A, A), S, s)637proof638have sA := Supremum.member with h639constructor640 . exact UpperBound.converse with (Supremum.upper with h)641 . intros b hb bound642have upper := LowerBound.of_converse with bound643have sb := Supremum.least with h, hb, upper644exact converse.relates with sA, hb, sb645646theorem Infimum.converse (A r S i : Set)647requires h : Infimum(A, r, S, i)648shows Supremum(A, converse(r, A, A), S, i)649proof650have iA := Infimum.member with h651constructor652 . exact LowerBound.converse with (Infimum.lower with h)653 . intros b hb bound654have lower := UpperBound.of_converse with bound655have bi := Infimum.greatest with h, hb, lower656exact converse.relates with hb, iA, bi657658theorem Supremum.of_converse (A r S s : Set)659requires h : Supremum(A, converse(r, A, A), S, s)660shows Infimum(A, r, S, s)661proof662have sA := Supremum.member with h663constructor664 . exact UpperBound.of_converse with (Supremum.upper with h)665 . intros b hb bound666have upper := LowerBound.converse with bound667have sb := Supremum.least with h, hb, upper668exact converse.reflects with sb669670theorem Infimum.of_converse (A r S i : Set)671requires h : Infimum(A, converse(r, A, A), S, i)672shows Supremum(A, r, S, i)673proof674have iA := Infimum.member with h675constructor676 . exact LowerBound.of_converse with (Infimum.lower with h)677 . intros b hb bound678have lower := UpperBound.converse with bound679have bi := Infimum.greatest with h, hb, lower680exact converse.reflects with bi681682theorem Least.converse (A r S a : Set)683requires h : Least(A, r, S, a)684shows Greatest(A, converse(r, A, A), S, a)685proof686rcases h with⟨member, lower⟩687refine⟨member, LowerBound.converse with lower⟩688689theorem Greatest.converse (A r S a : Set)690requires h : Greatest(A, r, S, a)691shows Least(A, converse(r, A, A), S, a)692proof693rcases h with⟨member, upper⟩694refine⟨member, UpperBound.converse with upper⟩695