Lattices.Product¶
Finite products of lattices¶
This is the Lattices.Product module of the agda-lattices library.
This module constructs the product of lattices and records the properties of products that the library uses, as follows.
- The binary direct product
π³β ΓΛ‘ π³βof latticesπ³βandπ³βoverSig-Lattice: the lattice on the product setoid whose meet and join act componentwise (LatticeProduct). The construction mirrors the group case of agda-algebras (Classical.Structures.Group.Product) but is assembled through the setoid-level buildersetoidEqsToLatticeof Classical.Structures.Lattice.Basic, whose interpretation clauses reduce definitionally; consequently each of the eight lattice equations for the product is literally the pair of the component equations, and no term-induction lemma is needed. The induced meet order of Classical.Properties.Lattice is the componentwise order, definitionally, and the three accessorsβ€β-fst,β€β-sndandβ€β-pairname the two projections and the pairing. - The one-element lattice
πΛ‘, the empty product. - The binary product is finite when its factors are
(
ΓΛ‘-finite: the enumeration is the standard library's bijection betweenFin (m * n)andFin m Γ Fin n), semidistributive when its factors are (ΓΛ‘-semidistributive: the laws are universal Horn sentences, read componentwise), and its two projections are homomorphisms (fst-hom,snd-hom). - The product
Ξ m πof a family of lattices indexed byFin m, as nested binary products, with the same three properties, the projectionsprojas homomorphisms, tuples (tuple) from families of coordinates, and the order read coordinatewise (Ξ -β€).
The binary product came from agda-algebras, where it was the module
Classical.Structures.Lattice.Product, with its history. Following
agda-algebras' discipline for an eventual
Cubical port, the underlying equivalence of the product is isolated in
AΓB, the pointwise pair of the component equivalences, so that
it can be mechanically substituted on the port.
The product construction¶
LatticeProduct π³β π³β packages the whole development for a fixed
pair of lattices; opening it provides the product setoid, the componentwise
operations with their congruences and equations, the product lattice, and the
characterization of its order.
module LatticeProduct (π³β : Lattice Ξ± Ο) (π³β : Lattice Ξ² Ο) where private π¨ = projβ π³β π© = projβ π³β open Setoid π»[ π¨ ] using () renaming ( _β_ to _ββ_ ; refl to reflβ ; sym to symβ ; trans to transβ ) open Setoid π»[ π© ] using () renaming ( _β_ to _ββ_ ; refl to reflβ ; sym to symβ ; trans to transβ ) open Lattice-Op π³β using () renaming ( _β§_ to _β§β_ ; _β¨_ to _β¨β_ ; β§-cong to β§β-cong ; β¨-cong to β¨β-cong ; β§-assoc-law to β§β-assoc ; β§-comm-law to β§β-comm ; β§-idem-law to β§β-idem ; β¨-assoc-law to β¨β-assoc ; β¨-comm-law to β¨β-comm ; β¨-idem-law to β¨β-idem ; absorbΛ‘-law to absorbΛ‘β ; absorbΚ³-law to absorbΚ³β ) open Lattice-Op π³β using () renaming ( _β§_ to _β§β_ ; _β¨_ to _β¨β_ ; β§-cong to β§β-cong ; β¨-cong to β¨β-cong ; β§-assoc-law to β§β-assoc ; β§-comm-law to β§β-comm ; β§-idem-law to β§β-idem ; β¨-assoc-law to β¨β-assoc ; β¨-comm-law to β¨β-comm ; β¨-idem-law to β¨β-idem ; absorbΛ‘-law to absorbΛ‘β ; absorbΚ³-law to absorbΚ³β )
The carrier of the product is the pair type, and its equivalence is the pointwise pair of the component equivalences, the isolated-equality locus for the Cubical port.
AΓB : Setoid (Ξ± β Ξ²) (Ο β Ο) AΓB = record { Carrier = π[ π¨ ] Γ π[ π© ] ; _β_ = Ξ» p q β (projβ p ββ projβ q) Γ (projβ p ββ projβ q) ; isEquivalence = record { refl = reflβ , reflβ ; sym = Ξ» e β symβ (projβ e) , symβ (projβ e) ; trans = Ξ» (dβ , dβ) (eβ , eβ) β transβ dβ eβ , transβ dβ eβ } } open Setoid AΓB using () renaming ( _β_ to _ββ_ )
Meet and join act componentwise. The operations project rather than pattern-match their arguments, so they reduce on any pair expression, matched or not.
_β§β_ : π[ π¨ ] Γ π[ π© ] β π[ π¨ ] Γ π[ π© ] β π[ π¨ ] Γ π[ π© ] p β§β q = (projβ p β§β projβ q) , (projβ p β§β projβ q) _β¨β_ : π[ π¨ ] Γ π[ π© ] β π[ π¨ ] Γ π[ π© ] β π[ π¨ ] Γ π[ π© ] p β¨β q = (projβ p β¨β projβ q) , (projβ p β¨β projβ q)
Congruence and the eight equations are all inherited componentwise: each proof is the pair of the component proofs, applied at the projections.
β§β-cong : β {p q u v} β p ββ q β u ββ v β (p β§β u) ββ (q β§β v) β§β-cong e f = β§β-cong (projβ e) (projβ f) , β§β-cong (projβ e) (projβ f) β¨β-cong : β {p q u v} β p ββ q β u ββ v β (p β¨β u) ββ (q β¨β v) β¨β-cong e f = β¨β-cong (projβ e) (projβ f) , β¨β-cong (projβ e) (projβ f) β§β-assoc : β {p q r} β ((p β§β q) β§β r) ββ (p β§β (q β§β r)) β§β-assoc = β§β-assoc , β§β-assoc β§β-comm : β {p q} β (p β§β q) ββ (q β§β p) β§β-comm = β§β-comm , β§β-comm β§β-idem : β {p} β (p β§β p) ββ p β§β-idem = β§β-idem , β§β-idem β¨β-assoc : β {p q r} β ((p β¨β q) β¨β r) ββ (p β¨β (q β¨β r)) β¨β-assoc = β¨β-assoc , β¨β-assoc β¨β-comm : β {p q} β (p β¨β q) ββ (q β¨β p) β¨β-comm = β¨β-comm , β¨β-comm β¨β-idem : β {p} β (p β¨β p) ββ p β¨β-idem = β¨β-idem , β¨β-idem absorbΛ‘β : β {p q} β (p β§β (p β¨β q)) ββ p absorbΛ‘β = absorbΛ‘β , absorbΛ‘β absorbΚ³β : β {p q} β ((p β§β q) β¨β p) ββ p absorbΚ³β = absorbΚ³β , absorbΚ³β
Assembling through the setoid-level builder yields the product lattice.
ΓΛ‘-Lattice : Lattice (Ξ± β Ξ²) (Ο β Ο) ΓΛ‘-Lattice = setoidEqsToLattice AΓB _β§β_ _β¨β_ β§β-cong β¨β-cong β§β-assoc β§β-comm β§β-idem β¨β-assoc β¨β-comm β¨β-idem absorbΛ‘β absorbΚ³β
The product order is the componentwise order¶
The meet order of ΓΛ‘-Lattice at (p , q) unfolds definitionally
to the pair of the component meet orders, because the builder's interpretation
applies its argument tuple and the product setoid's equality is the pointwise pair.
The three accessors below are therefore projections and pairing, but we name them:
they are the interface through which consumers read the product order without
unfolding the builder.
open Lattice-Order ΓΛ‘-Lattice using () renaming ( _β€_ to _β€β_ ) open Lattice-Order π³β using () renaming ( _β€_ to _β€β_ ) open Lattice-Order π³β using () renaming ( _β€_ to _β€β_ ) -- The product order projects to the first factor's order. β€β-fst : β {p q} β p β€β q β projβ p β€β projβ q β€β-fst = projβ -- The product order projects to the second factor's order. β€β-snd : β {p q} β p β€β q β projβ p β€β projβ q β€β-snd = projβ -- Componentwise order proofs pair into a product order proof. β€β-pair : β {p q} β projβ p β€β projβ q β projβ p β€β projβ q β p β€β q β€β-pair e f = e , f
The product operator¶
The standalone binary operator, for consumers that need only the lattice.
infixr 7 _ΓΛ‘_ _ΓΛ‘_ : Lattice Ξ± Ο β Lattice Ξ² Ο β Lattice (Ξ± β Ξ²) (Ο β Ο) π³β ΓΛ‘ π³β = LatticeProduct.ΓΛ‘-Lattice π³β π³β
The one-element lattice¶
-- The one-element lattice, finite and semidistributive. πΛ‘ : Lattice 0β 0β πΛ‘ = eqsToLattice β€ (Ξ» _ _ β tt) (Ξ» _ _ β tt) (Ξ» _ _ _ β refl) (Ξ» _ _ β refl) (Ξ» _ β refl) (Ξ» _ _ _ β refl) (Ξ» _ _ β refl) (Ξ» _ β refl) (Ξ» _ _ β refl) (Ξ» _ _ β refl) πΛ‘-finite : FiniteAlgebra (projβ πΛ‘) πΛ‘-finite = record { _β_ = Ξ» _ _ β yes refl ; card = 1 ; enum = Ξ» _ β tt ; enum-sur = Ξ» _ β zero , refl } πΛ‘-semidistributive : IsSemidistributive πΛ‘ πΛ‘-semidistributive = (Ξ» _ _ _ _ β refl) , (Ξ» _ _ _ _ β refl)
Properties of binary products¶
module Product (π³β : Lattice Ξ± Ο) (π³β : Lattice Ξ² Ο) where open LatticeProduct π³β π³β public using ( β€β-fst ; β€β-snd ; β€β-pair ) open Setoid π»[ projβ π³β ] using () renaming ( refl to reflβ ) open Setoid π»[ projβ π³β ] using () renaming ( refl to reflβ ) -- The projections are homomorphisms. fst-hom : hom (projβ (π³β ΓΛ‘ π³β)) (projβ π³β) fst-hom = mkhom (projβ (π³β ΓΛ‘ π³β)) (projβ π³β) (record { to = projβ ; cong = projβ }) compatible where compatible : compatible-map (projβ (π³β ΓΛ‘ π³β)) (projβ π³β) (record { to = projβ ; cong = projβ }) compatible {β§-Op} {a} = interp-cong (projβ π³β) β§-Op Ξ» { 0F β reflβ ; 1F β reflβ } compatible {β¨-Op} {a} = interp-cong (projβ π³β) β¨-Op Ξ» { 0F β reflβ ; 1F β reflβ } snd-hom : hom (projβ (π³β ΓΛ‘ π³β)) (projβ π³β) snd-hom = mkhom (projβ (π³β ΓΛ‘ π³β)) (projβ π³β) (record { to = projβ ; cong = projβ }) compatible where compatible : compatible-map (projβ (π³β ΓΛ‘ π³β)) (projβ π³β) (record { to = projβ ; cong = projβ }) compatible {β§-Op} {a} = interp-cong (projβ π³β) β§-Op Ξ» { 0F β reflβ ; 1F β reflβ } compatible {β¨-Op} {a} = interp-cong (projβ π³β) β¨-Op Ξ» { 0F β reflβ ; 1F β reflβ } -- A product of finite lattices is finite. ΓΛ‘-finite : FiniteAlgebra (projβ π³β) β FiniteAlgebra (projβ π³β) β FiniteAlgebra (projβ (π³β ΓΛ‘ π³β)) ΓΛ‘-finite Fβ Fβ = record { _β_ = Ξ» (xβ , xβ) (yβ , yβ) β (xβ ββ yβ) Γ-dec (xβ ββ yβ) ; card = cardβ * cardβ ; enum = enum ; enum-sur = sur } where open FiniteAlgebra Fβ renaming ( _β_ to _ββ_ ; card to cardβ ; enum to enumβ ; enum-sur to surβ ) open FiniteAlgebra Fβ renaming ( _β_ to _ββ_ ; card to cardβ ; enum to enumβ ; enum-sur to surβ ) open Setoid π»[ projβ (π³β ΓΛ‘ π³β) ] using ( _β_ ) enum : Fin (cardβ * cardβ) β π[ projβ (π³β ΓΛ‘ π³β) ] enum i = enumβ (projβ (remQuot {m = cardβ} cardβ i)) , enumβ (projβ (remQuot {m = cardβ} cardβ i)) sur : β p β Ξ£[ i β Fin (cardβ * cardβ) ] enum i β p sur (x , y) with surβ x | surβ y ... | j , eβ | k , eβ = combine j k , subst (Ξ» q β (enumβ (projβ q) , enumβ (projβ q)) β (x , y)) (sym (remQuot-combine {n = cardβ} {k = cardβ} j k)) (eβ , eβ) -- A product of semidistributive lattices is semidistributive. ΓΛ‘-semidistributive : IsSemidistributive π³β β IsSemidistributive π³β β IsSemidistributive (π³β ΓΛ‘ π³β) ΓΛ‘-semidistributive (jβ , mβ) (jβ , mβ) = (Ξ» a b c (eβ , eβ) β jβ _ _ _ eβ , jβ _ _ _ eβ) , (Ξ» a b c (eβ , eβ) β mβ _ _ _ eβ , mβ _ _ _ eβ)
Products over Fin m¶
-- The product of a family indexed by Fin m, and its properties. Ξ : (m : β) β (Fin m β Lattice 0β 0β) β Lattice 0β 0β Ξ zero π = πΛ‘ Ξ (suc m) π = π zero ΓΛ‘ Ξ m (π β suc) Ξ -finite : β m (π : Fin m β Lattice 0β 0β) β (β j β FiniteAlgebra (projβ (π j))) β FiniteAlgebra (projβ (Ξ m π)) Ξ -finite zero π F = πΛ‘-finite Ξ -finite (suc m) π F = Product.ΓΛ‘-finite (π zero) (Ξ m (π β suc)) (F zero) (Ξ -finite m (π β suc) (F β suc)) Ξ -semidistributive : β m (π : Fin m β Lattice 0β 0β) β (β j β IsSemidistributive (π j)) β IsSemidistributive (Ξ m π) Ξ -semidistributive zero π S = πΛ‘-semidistributive Ξ -semidistributive (suc m) π S = Product.ΓΛ‘-semidistributive (π zero) (Ξ m (π β suc)) (S zero) (Ξ -semidistributive m (π β suc) (S β suc)) -- The j-th projection, as a map. projMap : β m (π : Fin m β Lattice 0β 0β) (j : Fin m) β π[ projβ (Ξ m π) ] β π[ projβ (π j) ] projMap (suc m) π zero = projβ projMap (suc m) π (suc j) = projMap m (π β suc) j β projβ -- A tuple from a family of coordinates. tuple : β m (π : Fin m β Lattice 0β 0β) β (β j β π[ projβ (π j) ]) β π[ projβ (Ξ m π) ] tuple zero π f = tt tuple (suc m) π f = f zero , tuple m (π β suc) (f β suc) projMap-tuple : β m π (f : β j β π[ projβ (π j) ]) j β projMap m π j (tuple m π f) β‘ f j projMap-tuple (suc m) π f zero = refl projMap-tuple (suc m) π f (suc j) = projMap-tuple m (π β suc) (f β suc) j -- The projections are homomorphisms. proj : β m (π : Fin m β Lattice 0β 0β) (j : Fin m) β hom (projβ (Ξ m π)) (projβ (π j)) proj (suc m) π zero = Product.fst-hom (π zero) (Ξ m (π β suc)) proj (suc m) π (suc j) = mkhom (projβ (Ξ (suc m) π)) (projβ (π (suc j))) map compatible where inner = proj m (π β suc) j map : Func π»[ projβ (Ξ (suc m) π) ] π»[ projβ (π (suc j)) ] map = record { to = Ξ» x β projβ inner β¨$β© projβ x ; cong = Ξ» e β Func.cong (projβ inner) (projβ e) } open Setoid π»[ projβ (π (suc j)) ] using () renaming ( refl to βrefl ; trans to βtrans ) compatible : compatible-map (projβ (Ξ (suc m) π)) (projβ (π (suc j))) map compatible {β§-Op} {a} = βtrans (IsHom.compatible (projβ inner) {β§-Op} {pair (projβ (a 0F)) (projβ (a 1F))}) (interp-cong (projβ (π (suc j))) β§-Op Ξ» { 0F β βrefl ; 1F β βrefl }) compatible {β¨-Op} {a} = βtrans (IsHom.compatible (projβ inner) {β¨-Op} {pair (projβ (a 0F)) (projβ (a 1F))}) (interp-cong (projβ (π (suc j))) β¨-Op Ξ» { 0F β βrefl ; 1F β βrefl }) proj-map : β m π j x β projβ (proj m π j) β¨$β© x β‘ projMap m π j x proj-map (suc m) π zero x = refl proj-map (suc m) π (suc j) x = proj-map m (π β suc) j (projβ x) -- The order of the product, from the coordinates. Ξ -β€ : β m π x y β (β j β Lattice-Order._β€_ (π j) (projMap m π j x) (projMap m π j y)) β Lattice-Order._β€_ (Ξ m π) x y Ξ -β€ zero π x y h = refl Ξ -β€ (suc m) π x y h = h zero , Ξ -β€ m (π β suc) (projβ x) (projβ y) (h β suc)