open import 1Lab.Prelude

open import Algebra.Semilattice

open import Cat.Functor.Equivalence
open import Cat.Functor.Base
open import Cat.Prelude
open import Cat.Thin

module Algebra.Lattice where


Latticesπ

A lattice $(A, \land, \lor)$ is a pair of semilattices $(A, \land)$ and $(A, \lor)$ which βfit togetherβ with equations specifying that $\land$ and $\lor$ are duals, called absorption laws.

record is-lattice (_β§_ : A β A β A) (_β¨_ : A β A β A) : Type (level-of A) where
field
has-meets : is-semilattice _β§_
has-joins : is-semilattice _β¨_

We rename the fields of has-meets and has-joins so they refer to the operator in their name, and hide anything extra from the hierarchy.
  open is-semilattice has-meets public
renaming ( associative to β§-associative
; commutative to β§-commutative
; idempotent to β§-idempotent
)
hiding ( has-is-magma ; has-is-semigroup )

open is-semilattice has-joins public
renaming ( associative to β¨-associative
; commutative to β¨-commutative
; idempotent to β¨-idempotent
)
hiding ( underlying-set ; has-is-magma ; has-is-set ; magma-hlevel )

  field
β§-absorbs-β¨ : β {x y} β (x β§ (x β¨ y)) β‘ x
β¨-absorbs-β§ : β {x y} β (x β¨ (x β§ y)) β‘ x


A lattice structure equips a type $A$ with two binary operators, the meet $\land$ and join $\lor$, such that $(A, \land, \lor)$ is a lattice. Since being a semilattice includes being a set, this means that being a lattice is a property of $(A, \land, \lor)$:

private unquoteDecl eqv = declare-record-iso eqv (quote is-lattice)

instance
H-Level-is-lattice : β {M J : A β A β A} {n} β H-Level (is-lattice M J) (suc n)
H-Level-is-lattice = prop-instance Ξ» x β
let open is-lattice x in Isoβis-hlevel 1 eqv (hlevel 1) x

record Lattice-on (A : Type β) : Type β where
field
_Lβ§_ : A β A β A
_Lβ¨_ : A β A β A

infixr 40 _Lβ§_
infixr 30 _Lβ¨_

field
has-is-lattice : is-lattice _Lβ§_ _Lβ¨_

open is-lattice has-is-lattice public

Lattice-onβis-meet-semi : is-semilattice _Lβ§_
Lattice-onβis-meet-semi = has-meets

Lattice-onβis-join-semi : is-semilattice _Lβ¨_
Lattice-onβis-join-semi = has-joins

open Lattice-on using (Lattice-onβis-meet-semi ; Lattice-onβis-join-semi) public

Lattice : β β β Type (lsuc β)
Lattice β = Ξ£ _ (Lattice-on {β = β})


Since the absorption laws are property, not structure, a lattice homomorphism turns out to be a function which is homomorphic for both semilattice structures, i.e.Β one that independently preserves meets and joins.

record Latticeβ (A B : Lattice β) (f : A .fst β B .fst) : Type β where
private
module A = Lattice-on (A .snd)
module B = Lattice-on (B .snd)

field
pres-β§ : β x y β f (x A.Lβ§ y) β‘ f x B.Lβ§ f y
pres-β¨ : β x y β f (x A.Lβ¨ y) β‘ f x B.Lβ¨ f y

Latticeβ : (A B : Lattice β) (f : A .fst β B .fst) β Type β
Latticeβ A B = Latticeβ A B β fst


Order-theoreticallyπ

We already know that a given semilattice structure can induce one of two posets, depending on whether the semilattice operator is being considered as equipping the poset with meets or joins. Weβd then expect that a lattice, having two semi-lattices, would have four poset structures. However, there are only two, which we call the βcovariantβ and βcontravariantβ orderings.

Latticeβcovariant-on : Lattice-on A β Poset (level-of A) (level-of A)
Latticeβcovariant-on lat = Semilattice-onβMeet-on (Lattice-onβis-meet-semi lat)

Latticeβcontravariant-on : Lattice-on A β Poset (level-of A) (level-of A)
Latticeβcontravariant-on lat = Semilattice-onβJoin-on (Lattice-onβis-meet-semi lat)


Above, the βcovariant orderβ is obtaining by considering the $(A, \land)$ semilattice as inducing meets on the poset (hence the operator being called $\land$). It can also be obtained in a dual way, by considering that $(A, \lor)$ induces joins on the poset. By the absorption laws, these constructions give rise to the same poset; We start by defining a monotone map (that is, a Functor) between the two possibilities:

covariant-order-map
: (l : Lattice-on A)
β Monotone-map
(Semilattice-onβMeet-on (Lattice-onβis-meet-semi l))
(Semilattice-onβJoin-on (Lattice-onβis-join-semi l))
covariant-order-map {A = A} l = F where
open Lattice-on l
hiding (Lattice-onβis-join-semi ; Lattice-onβis-meet-semi)

F : Monotone-map (Semilattice-onβMeet-on (Lattice-onβis-meet-semi l))
(Semilattice-onβJoin-on (Lattice-onβis-join-semi l))
F .Fβ = id
F .Fβ {x} {y} p = q where abstract
q : y β‘ x Lβ¨ y
q =
y               β‘β¨ sym β¨-absorbs-β§ β©β‘
y Lβ¨ β y Lβ§ x β β‘β¨ ap! β§-commutative β©β‘
y Lβ¨ β x Lβ§ y β β‘Λβ¨ apΒ‘ p β©β‘Λ
y Lβ¨ x          β‘β¨ β¨-commutative β©β‘
x Lβ¨ y          β
F .F-id = has-is-set _ _ _ _
F .F-β _ _ = has-is-set _ _ _ _


We now show that this functor is an equivalence: It is fully faithful and split essentially surjective.

covariant-order-map-is-equivalence
: (l : Lattice-on A) β is-equivalence (covariant-order-map l)
covariant-order-map-is-equivalence l =
ff+split-esoβis-equivalence ff eso
where
open Lattice-on l hiding (Lattice-onβis-join-semi)
import
Cat.Reasoning
(Semilattice-onβJoin-on (Lattice-onβis-join-semi l) .Poset.underlying)
as D


A tiny calculation shows that this functor is fully faithful, and essential surjectivity is immediate:

    ff : is-fully-faithful (covariant-order-map l)
ff {x} {y} .is-eqv p .centre .fst =
x               β‘β¨ sym β§-absorbs-β¨ β©β‘
x Lβ§ β x Lβ¨ y β β‘Λβ¨ apΒ‘ p β©β‘Λ
x Lβ§ y          β
ff .is-eqv y .centre .snd = has-is-set _ _ _ _
ff .is-eqv y .paths x =
Ξ£-path (has-is-set _ _ _ _)
(is-propβis-set (has-is-set _ _) _ _ _ _)

eso : is-split-eso (covariant-order-map l)
eso y .fst = y
eso y .snd =
D.make-iso (sym β¨-idempotent) (sym β¨-idempotent)
(has-is-set _ _ _ _)
(has-is-set _ _ _ _)