1-- The equational laws of join and meet, and the order they determine2-- 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.LatticeLaws8import Lattice910-- Commutativity and idempotency1112theorem join.commutative (A r x y : Set)13requires lattice : IsLattice(A, r)14requires hx : x ∈ A15requires hy : y ∈ A16shows join(A, r, x, y) = join(A, r, y, x)17proof18have supremum := join.supremum with lattice, hx, hy19have swap := pair.commutative at x, y20rw swap at supremum21exact join.of_supremum with lattice, hy, hx, supremum2223theorem meet.commutative (A r x y : Set)24requires lattice : IsLattice(A, r)25requires hx : x ∈ A26requires hy : y ∈ A27shows meet(A, r, x, y) = meet(A, r, y, x)28proof29have infimum := meet.infimum with lattice, hx, hy30have swap := pair.commutative at x, y31rw swap at infimum32exact meet.of_infimum with lattice, hy, hx, infimum3334theorem join.idempotent (A r x : Set)35requires lattice : IsLattice(A, r)36requires hx : x ∈ A37shows join(A, r, x, x) = x38proof39have order := IsLattice.order with lattice40have supremum := Supremum.singleton with order, hx41have same := pair.self at x42rw← same at supremum43 symm44exact join.of_supremum with lattice, hx, hx, supremum4546theorem meet.idempotent (A r x : Set)47requires lattice : IsLattice(A, r)48requires hx : x ∈ A49shows meet(A, r, x, x) = x50proof51have order := IsLattice.order with lattice52have infimum := Infimum.singleton with order, hx53have same := pair.self at x54rw← same at infimum55 symm56exact meet.of_infimum with lattice, hx, hx, infimum5758-- The order is recovered from either operation.5960theorem join.of_le (A r x y : Set)61requires lattice : IsLattice(A, r)62requires hx : x ∈ A63requires hy : y ∈ A64requires hxy : relates(r, x, y)65shows join(A, r, x, y) = y66proof67have reflexive := IsLattice.reflexive with lattice68have supremum : Supremum(A, r, {x, y}, y)69apply Supremum.of_pair with hx, hy, hy, hxy, (reflexive with y, hy)70intros b hb xb yb71exact yb72 symm73exact join.of_supremum with lattice, hx, hy, supremum7475theorem join.of_ge (A r x y : Set)76requires lattice : IsLattice(A, r)77requires hx : x ∈ A78requires hy : y ∈ A79requires hyx : relates(r, y, x)80shows join(A, r, x, y) = x81proof82have swap := join.commutative with lattice, hx, hy83rw swap84exact join.of_le with lattice, hy, hx, hyx8586theorem meet.of_le (A r x y : Set)87requires lattice : IsLattice(A, r)88requires hx : x ∈ A89requires hy : y ∈ A90requires hxy : relates(r, x, y)91shows meet(A, r, x, y) = x92proof93have reflexive := IsLattice.reflexive with lattice94have infimum : Infimum(A, r, {x, y}, x)95apply Infimum.of_pair with hx, hy, hx, (reflexive with x, hx), hxy96intros b hb bx by_97exact bx98 symm99exact meet.of_infimum with lattice, hx, hy, infimum100101theorem meet.of_ge (A r x y : Set)102requires lattice : IsLattice(A, r)103requires hx : x ∈ A104requires hy : y ∈ A105requires hyx : relates(r, y, x)106shows meet(A, r, x, y) = y107proof108have swap := meet.commutative with lattice, hx, hy109rw swap110exact meet.of_le with lattice, hy, hx, hyx111112theorem join.eq_right_iff (A r x y : Set)113requires lattice : IsLattice(A, r)114requires hx : x ∈ A115requires hy : y ∈ A116shows relates(r, x, y) ↔ join(A, r, x, y) = y117proof118constructor119 . intro hxy120exact join.of_le with lattice, hx, hy, hxy121 . intro equal122have upper := join.upper_left with lattice, hx, hy123rw equal at upper124exact upper125126theorem join.eq_left_iff (A r x y : Set)127requires lattice : IsLattice(A, r)128requires hx : x ∈ A129requires hy : y ∈ A130shows relates(r, y, x) ↔ join(A, r, x, y) = x131proof132constructor133 . intro hyx134exact join.of_ge with lattice, hx, hy, hyx135 . intro equal136have upper := join.upper_right with lattice, hx, hy137rw equal at upper138exact upper139140theorem meet.eq_left_iff (A r x y : Set)141requires lattice : IsLattice(A, r)142requires hx : x ∈ A143requires hy : y ∈ A144shows relates(r, x, y) ↔ meet(A, r, x, y) = x145proof146constructor147 . intro hxy148exact meet.of_le with lattice, hx, hy, hxy149 . intro equal150have lower := meet.lower_right with lattice, hx, hy151rw equal at lower152exact lower153154theorem meet.eq_right_iff (A r x y : Set)155requires lattice : IsLattice(A, r)156requires hx : x ∈ A157requires hy : y ∈ A158shows relates(r, y, x) ↔ meet(A, r, x, y) = y159proof160constructor161 . intro hyx162exact meet.of_ge with lattice, hx, hy, hyx163 . intro equal164have lower := meet.lower_left with lattice, hx, hy165rw equal at lower166exact lower167168-- Absorption169170theorem join.absorb (A r x y : Set)171requires lattice : IsLattice(A, r)172requires hx : x ∈ A173requires hy : y ∈ A174shows join(A, r, x, meet(A, r, x, y)) = x175proof176have meetA := meet.member with lattice, hx, hy177have lower := meet.lower_left with lattice, hx, hy178exact join.of_ge with lattice, hx, meetA, lower179180theorem join.absorb_swap (A r x y : Set)181requires lattice : IsLattice(A, r)182requires hx : x ∈ A183requires hy : y ∈ A184shows join(A, r, x, meet(A, r, y, x)) = x185proof186have meetA := meet.member with lattice, hy, hx187have lower := meet.lower_right with lattice, hy, hx188exact join.of_ge with lattice, hx, meetA, lower189190theorem meet.absorb (A r x y : Set)191requires lattice : IsLattice(A, r)192requires hx : x ∈ A193requires hy : y ∈ A194shows meet(A, r, x, join(A, r, x, y)) = x195proof196have joinA := join.member with lattice, hx, hy197have upper := join.upper_left with lattice, hx, hy198exact meet.of_le with lattice, hx, joinA, upper199200theorem meet.absorb_swap (A r x y : Set)201requires lattice : IsLattice(A, r)202requires hx : x ∈ A203requires hy : y ∈ A204shows meet(A, r, x, join(A, r, y, x)) = x205proof206have joinA := join.member with lattice, hy, hx207have upper := join.upper_right with lattice, hy, hx208exact meet.of_le with lattice, hx, joinA, upper209210-- Bounds through join and meet211212theorem join.le_iff (A r x y b : Set)213requires lattice : IsLattice(A, r)214requires hx : x ∈ A215requires hy : y ∈ A216requires hb : b ∈ A217shows relates(r, join(A, r, x, y), b) ↔ relates(r, x, b) ∧ relates(r, y, b)218proof219have transitive := IsLattice.transitive with lattice220have joinA := join.member with lattice, hx, hy221constructor222 . intro below223have xJ := join.upper_left with lattice, hx, hy224have yJ := join.upper_right with lattice, hx, hy225constructor226 . exact transitive with x, hx, join(A, r, x, y), joinA, b, hb, xJ, below227 . exact transitive with y, hy, join(A, r, x, y), joinA, b, hb, yJ, below228 . intro both229exact join.least with lattice, hx, hy, hb, both.left, both.right230231theorem meet.ge_iff (A r x y b : Set)232requires lattice : IsLattice(A, r)233requires hx : x ∈ A234requires hy : y ∈ A235requires hb : b ∈ A236shows relates(r, b, meet(A, r, x, y)) ↔ relates(r, b, x) ∧ relates(r, b, y)237proof238have transitive := IsLattice.transitive with lattice239have meetA := meet.member with lattice, hx, hy240constructor241 . intro above242have mX := meet.lower_left with lattice, hx, hy243have mY := meet.lower_right with lattice, hx, hy244constructor245 . exact transitive with b, hb, meet(A, r, x, y), meetA, x, hx, above, mX246 . exact transitive with b, hb, meet(A, r, x, y), meetA, y, hy, above, mY247 . intro both248exact meet.greatest with lattice, hx, hy, hb, both.left, both.right249250theorem meet.le_join (A r x y : Set)251requires lattice : IsLattice(A, r)252requires hx : x ∈ A253requires hy : y ∈ A254shows relates(r, meet(A, r, x, y), join(A, r, x, y))255proof256have transitive := IsLattice.transitive with lattice257have meetA := meet.member with lattice, hx, hy258have joinA := join.member with lattice, hx, hy259have lower := meet.lower_left with lattice, hx, hy260have upper := join.upper_left with lattice, hx, hy261exact transitive with meet(A, r, x, y), meetA, x, hx, join(A, r, x, y),262 joinA, lower, upper263264-- Monotonicity265266theorem join.monotone (A r x y u v : Set)267requires lattice : IsLattice(A, r)268requires hx : x ∈ A269requires hy : y ∈ A270requires hu : u ∈ A271requires hv : v ∈ A272requires hxu : relates(r, x, u)273requires hyv : relates(r, y, v)274shows relates(r, join(A, r, x, y), join(A, r, u, v))275proof276have transitive := IsLattice.transitive with lattice277have joinA := join.member with lattice, hu, hv278have uJ := join.upper_left with lattice, hu, hv279have vJ := join.upper_right with lattice, hu, hv280have xJ := transitive with x, hx, u, hu, join(A, r, u, v), joinA, hxu, uJ281have yJ := transitive with y, hy, v, hv, join(A, r, u, v), joinA, hyv, vJ282exact join.least with lattice, hx, hy, joinA, xJ, yJ283284theorem join.monotone_left (A r x y u : Set)285requires lattice : IsLattice(A, r)286requires hx : x ∈ A287requires hy : y ∈ A288requires hu : u ∈ A289requires hxu : relates(r, x, u)290shows relates(r, join(A, r, x, y), join(A, r, u, y))291proof292have reflexive := IsLattice.reflexive with lattice293exact join.monotone with lattice, hx, hy, hu, hy, hxu, (reflexive with y, hy)294295theorem join.monotone_right (A r x y v : Set)296requires lattice : IsLattice(A, r)297requires hx : x ∈ A298requires hy : y ∈ A299requires hv : v ∈ A300requires hyv : relates(r, y, v)301shows relates(r, join(A, r, x, y), join(A, r, x, v))302proof303have reflexive := IsLattice.reflexive with lattice304exact join.monotone with lattice, hx, hy, hx, hv, (reflexive with x, hx), hyv305306theorem meet.monotone (A r x y u v : Set)307requires lattice : IsLattice(A, r)308requires hx : x ∈ A309requires hy : y ∈ A310requires hu : u ∈ A311requires hv : v ∈ A312requires hxu : relates(r, x, u)313requires hyv : relates(r, y, v)314shows relates(r, meet(A, r, x, y), meet(A, r, u, v))315proof316have transitive := IsLattice.transitive with lattice317have meetA := meet.member with lattice, hx, hy318have mX := meet.lower_left with lattice, hx, hy319have mY := meet.lower_right with lattice, hx, hy320have mU := transitive with meet(A, r, x, y), meetA, x, hx, u, hu, mX, hxu321have mV := transitive with meet(A, r, x, y), meetA, y, hy, v, hv, mY, hyv322exact meet.greatest with lattice, hu, hv, meetA, mU, mV323324theorem meet.monotone_left (A r x y u : Set)325requires lattice : IsLattice(A, r)326requires hx : x ∈ A327requires hy : y ∈ A328requires hu : u ∈ A329requires hxu : relates(r, x, u)330shows relates(r, meet(A, r, x, y), meet(A, r, u, y))331proof332have reflexive := IsLattice.reflexive with lattice333exact meet.monotone with lattice, hx, hy, hu, hy, hxu, (reflexive with y, hy)334335theorem meet.monotone_right (A r x y v : Set)336requires lattice : IsLattice(A, r)337requires hx : x ∈ A338requires hy : y ∈ A339requires hv : v ∈ A340requires hyv : relates(r, y, v)341shows relates(r, meet(A, r, x, y), meet(A, r, x, v))342proof343have reflexive := IsLattice.reflexive with lattice344exact meet.monotone with lattice, hx, hy, hx, hv, (reflexive with x, hx), hyv345346-- Associativity347348theorem join.associative (A r x y z : Set)349requires lattice : IsLattice(A, r)350requires hx : x ∈ A351requires hy : y ∈ A352requires hz : z ∈ A353shows join(A, r, join(A, r, x, y), z) = join(A, r, x, join(A, r, y, z))354proof355have transitive := IsLattice.transitive with lattice356have xyA := join.member with lattice, hx, hy357have yzA := join.member with lattice, hy, hz358have uA := join.member with lattice, xyA, hz359have xXY := join.upper_left with lattice, hx, hy360have yXY := join.upper_right with lattice, hx, hy361have yYZ := join.upper_left with lattice, hy, hz362have zYZ := join.upper_right with lattice, hy, hz363have xyU := join.upper_left with lattice, xyA, hz364have zU := join.upper_right with lattice, xyA, hz365have xU := transitive with x, hx, join(A, r, x, y), xyA, join(A, r, join(A,366 r, x, y), z), uA, xXY, xyU367have yU := transitive with y, hy, join(A, r, x, y), xyA, join(A, r, join(A,368 r, x, y), z), uA, yXY, xyU369have yzU := join.least with lattice, hy, hz, uA, yU, zU370have supremum : Supremum(A, r, {x, join(A, r, y, z)}, join(A, r, join(A, r,371 x, y), z))372apply Supremum.of_pair with hx, yzA, uA, xU, yzU373intros b hb xb yzb374have yb := transitive with y, hy, join(A, r, y, z), yzA, b, hb, yYZ, yzb375have zb := transitive with z, hz, join(A, r, y, z), yzA, b, hb, zYZ, yzb376have xyb := join.least with lattice, hx, hy, hb, xb, yb377exact join.least with lattice, xyA, hz, hb, xyb, zb378exact join.of_supremum with lattice, hx, yzA, supremum379380theorem meet.associative (A r x y z : Set)381requires lattice : IsLattice(A, r)382requires hx : x ∈ A383requires hy : y ∈ A384requires hz : z ∈ A385shows meet(A, r, meet(A, r, x, y), z) = meet(A, r, x, meet(A, r, y, z))386proof387have transitive := IsLattice.transitive with lattice388have xyA := meet.member with lattice, hx, hy389have yzA := meet.member with lattice, hy, hz390have uA := meet.member with lattice, xyA, hz391have xyX := meet.lower_left with lattice, hx, hy392have xyY := meet.lower_right with lattice, hx, hy393have yzY := meet.lower_left with lattice, hy, hz394have yzZ := meet.lower_right with lattice, hy, hz395have uXY := meet.lower_left with lattice, xyA, hz396have uZ := meet.lower_right with lattice, xyA, hz397have uX := transitive with meet(A, r, meet(A, r, x, y), z), uA, meet(A, r,398 x, y), xyA, x, hx, uXY, xyX399have uY := transitive with meet(A, r, meet(A, r, x, y), z), uA, meet(A, r,400 x, y), xyA, y, hy, uXY, xyY401have uYZ := meet.greatest with lattice, hy, hz, uA, uY, uZ402have infimum : Infimum(A, r, {x, meet(A, r, y, z)}, meet(A, r, meet(A, r, x,403 y), z))404apply Infimum.of_pair with hx, yzA, uA, uX, uYZ405intros b hb bx byz406have by_ := transitive with b, hb, meet(A, r, y, z), yzA, y, hy, byz, yzY407have bz := transitive with b, hb, meet(A, r, y, z), yzA, z, hz, byz, yzZ408have bxy := meet.greatest with lattice, hx, hy, hb, bx, by_409exact meet.greatest with lattice, xyA, hz, hb, bxy, bz410exact meet.of_infimum with lattice, hx, yzA, infimum411412theorem join.left_commutative (A r x y z : Set)413requires lattice : IsLattice(A, r)414requires hx : x ∈ A415requires hy : y ∈ A416requires hz : z ∈ A417shows join(A, r, x, join(A, r, y, z)) = join(A, r, y, join(A, r, x, z))418proof419have first := join.associative with lattice, hx, hy, hz420have swap := join.commutative with lattice, hx, hy421have second := join.associative with lattice, hy, hx, hz422rw← first423rw swap424exact second425426theorem meet.left_commutative (A r x y z : Set)427requires lattice : IsLattice(A, r)428requires hx : x ∈ A429requires hy : y ∈ A430requires hz : z ∈ A431shows meet(A, r, x, meet(A, r, y, z)) = meet(A, r, y, meet(A, r, x, z))432proof433have first := meet.associative with lattice, hx, hy, hz434have swap := meet.commutative with lattice, hx, hy435have second := meet.associative with lattice, hy, hx, hz436rw← first437rw swap438exact second439440-- The distributive and modular inequalities hold in every lattice.441442theorem meet.join_distributive_le (A r x y z : Set)443requires lattice : IsLattice(A, r)444requires hx : x ∈ A445requires hy : y ∈ A446requires hz : z ∈ A447shows relates(r, join(A, r, meet(A, r, x, y), meet(A, r, x, z)),448 meet(A, r, x, join(A, r, y, z)))449proof450have transitive := IsLattice.transitive with lattice451have xyA := meet.member with lattice, hx, hy452have xzA := meet.member with lattice, hx, hz453have yzA := join.member with lattice, hy, hz454have targetA := meet.member with lattice, hx, yzA455have yYZ := join.upper_left with lattice, hy, hz456have zYZ := join.upper_right with lattice, hy, hz457have xyX := meet.lower_left with lattice, hx, hy458have xyY := meet.lower_right with lattice, hx, hy459have xzX := meet.lower_left with lattice, hx, hz460have xzZ := meet.lower_right with lattice, hx, hz461have xyYZ := transitive with meet(A, r, x, y), xyA, y, hy, join(A, r, y, z),462 yzA, xyY, yYZ463have xzYZ := transitive with meet(A, r, x, z), xzA, z, hz, join(A, r, y, z),464 yzA, xzZ, zYZ465have xyT := meet.greatest with lattice, hx, yzA, xyA, xyX, xyYZ466have xzT := meet.greatest with lattice, hx, yzA, xzA, xzX, xzYZ467exact join.least with lattice, xyA, xzA, targetA, xyT, xzT468469theorem join.meet_distributive_ge (A r x y z : Set)470requires lattice : IsLattice(A, r)471requires hx : x ∈ A472requires hy : y ∈ A473requires hz : z ∈ A474shows relates(r, join(A, r, x, meet(A, r, y, z)),475 meet(A, r, join(A, r, x, y), join(A, r, x, z)))476proof477have transitive := IsLattice.transitive with lattice478have xyA := join.member with lattice, hx, hy479have xzA := join.member with lattice, hx, hz480have yzA := meet.member with lattice, hy, hz481have targetA := meet.member with lattice, xyA, xzA482have xXY := join.upper_left with lattice, hx, hy483have xXZ := join.upper_left with lattice, hx, hz484have yXY := join.upper_right with lattice, hx, hy485have zXZ := join.upper_right with lattice, hx, hz486have yzY := meet.lower_left with lattice, hy, hz487have yzZ := meet.lower_right with lattice, hy, hz488have xT := meet.greatest with lattice, xyA, xzA, hx, xXY, xXZ489have yzXY := transitive with meet(A, r, y, z), yzA, y, hy, join(A, r, x, y),490 xyA, yzY, yXY491have yzXZ := transitive with meet(A, r, y, z), yzA, z, hz, join(A, r, x, z),492 xzA, yzZ, zXZ493have yzT := meet.greatest with lattice, xyA, xzA, yzA, yzXY, yzXZ494exact join.least with lattice, hx, yzA, targetA, xT, yzT495496theorem join.modular_le (A r x y z : Set)497requires lattice : IsLattice(A, r)498requires hx : x ∈ A499requires hy : y ∈ A500requires hz : z ∈ A501requires hyx : relates(r, y, x)502shows503 relates(r, join(A, r, y, meet(A, r, x, z)), meet(A, r, x, join(A, r, y, z)))504proof505have transitive := IsLattice.transitive with lattice506have xzA := meet.member with lattice, hx, hz507have yzA := join.member with lattice, hy, hz508have targetA := meet.member with lattice, hx, yzA509have yYZ := join.upper_left with lattice, hy, hz510have zYZ := join.upper_right with lattice, hy, hz511have xzX := meet.lower_left with lattice, hx, hz512have xzZ := meet.lower_right with lattice, hx, hz513have yT := meet.greatest with lattice, hx, yzA, hy, hyx, yYZ514have xzYZ := transitive with meet(A, r, x, z), xzA, z, hz, join(A, r, y, z),515 yzA, xzZ, zYZ516have xzT := meet.greatest with lattice, hx, yzA, xzA, xzX, xzYZ517exact join.least with lattice, hy, xzA, targetA, yT, xzT518