module Order.Semilattice where
Semilattices🔗
A semilattice1 is a partially ordered set where every finite family of elements has a meet2. But semilattices-in-general admit an algebraic presentation, as well as an order-theoretic presentation: a semilattice is a commutative idempotent monoid.
As a concrete example of a semilattice before we get started, consider the subsets of a fixed type (like ), under the operation of subset intersection. If we don’t know about the “subset” relation, can we derive it just from the behaviour of intersection?
Surprisingly, the answer is yes! is a subset of iff. the intersection of and is . Check this for yourself: The intersection of (e.g.) and is just again, so .
Generalising away from subsets and intersection, we can recover a partial ordering from any commutative monoid in which all elements are idempotent. That is precisely the definition of a semilattice:
record is-semilattice {ℓ} {A : Type ℓ} (⊤ : A) (_∧_ : A → A → A) : Type ℓ where
no-eta-equality
field
: is-monoid ⊤ _∧_
has-is-monoid : ∀ {x} → x ∧ x ≡ x
idempotent : ∀ {x y} → x ∧ y ≡ y ∧ x
commutative open is-monoid has-is-monoid public
record Semilattice-on {ℓ} (A : Type ℓ) : Type ℓ where
no-eta-equality
field
: A
top _∩_ : A → A → A
: is-semilattice top _∩_
has-is-semilattice open is-semilattice has-is-semilattice public
infixr 25 _∩_
Rather than going through the usual displayed structure dance, here we exhibit semilattices through an embedding into monoids: when is considered as a monoid, the information that it is a semilattice is a proposition. To be a bit more explicit, is a semilattice homomorphism when and .
: ∀ ℓ → Thin-structure {ℓ = ℓ} ℓ Semilattice-on
Semilattice-structure =
Semilattice-structure ℓ _ _ SLat↪Mon (Monoid-structure ℓ) where Full-substructure ℓ
One might wonder about the soundness of this definition if we want to think of semilattices as order-theoretic objects: is a semilattice homomorphism in the above sense necessarily monotone? A little calculation tells us that yes: we can expand to mean , which by preservation of meets means — which is certainly the casae if , i.e., .
: ∀ ℓ → Precategory (lsuc ℓ) ℓ
Semilattices = Structured-objects (Semilattice-structure ℓ)
Semilattices ℓ
: ∀ ℓ → Type (lsuc ℓ)
Semilattice = Precategory.Ob (Semilattices ℓ) Semilattice ℓ
As orders🔗
We’ve already commented that a semilattice structure gives rise to a partial order on the underlying set — and, in some sense, this order is canonical — by setting to mean . To justify their inclusion in the same namespace as thin categories, though, we have to make this formal, by exhibiting a functor from semilattices to posets.
: ∀ {ℓ} → Functor (Semilattices ℓ) (Posets ℓ ℓ)
Meet-semi-lattice .F₀ X = po where
Meet-semi-lattice open Poset
module X = Semilattice-on (X .snd)
: Poset _ _
po .Ob = ⌞ X ⌟
po ._≤_ x y = x ≡ x X.∩ y
po .≤-thin = hlevel 1
po .≤-refl = sym X.idempotent po
Proving that our now-familiar semilattice-induced order is a partial order reduces to a matter of algebra, which is presented without comment. Note that we do not need idempotence for transitivity or antisymmetry: it is only for reflexivity, where directly translates to .
.≤-trans {x} {y} {z} x=x∧y y=y∧z =
po
x ≡⟨ x=x∧y ⟩.∩ ⌜ y ⌝ ≡⟨ ap! y=y∧z ⟩
x X.∩ (y X.∩ z) ≡⟨ X.associative ⟩
x X.∩ y ⌝ X.∩ z ≡˘⟨ ap¡ x=x∧y ⟩
⌜ x X.∩ z ∎
x X.≤-antisym {x} {y} x=x∧y y=y∧x =
po
x ≡⟨ x=x∧y ⟩.∩ y ≡⟨ X.commutative ⟩
x X.∩ x ≡˘⟨ y=y∧x ⟩
y X y ∎
And, formalising our comments about monotonicity from before, any semilattice homomorphism is a monotone map under the induced ordering.
.F₁ f .hom = f .hom
Meet-semi-lattice .F₁ f .pres-≤ p = ap (f .hom) p ∙ f .preserves .Monoid-hom.pres-⋆ _ _
Meet-semi-lattice .F-id = trivial!
Meet-semi-lattice .F-∘ f g = trivial! Meet-semi-lattice
The interface🔗
This section is less about the mathematics per se, and more about how we formalise it. Semilattices (and lattices more generally) are an interesting structure, in that they are category-like in two different ways! In one direction, we have the the category structure by taking having a single Hom-set, and setting to be the composition operation — the delooping of the monoid. In the other direction, we have the poset structure, with the ordering induced by meets.
To effectively formalise mathematics to do with lattices, we need a convenient interface for both of these “categories”. We already have a fantastic module for working with morphisms in nontrivial categories: instantiating it with the delooping of the monoid means we get, for free, a bunch of combinators for handling big meet expressions.
module Semilattice {ℓ} (A : Semilattice ℓ) where
: Poset _ _
po = Meet-semi-lattice .F₀ A
po open Order.Reasoning po public
private module X = Semilattice-on (A .snd) renaming
( associative to ∩-assoc
; idl to ∩-idl
; idr to ∩-idr
; commutative to ∩-commutative
; idempotent to ∩-idempotent
)
open X using ( top ; _∩_ ; ∩-assoc ; ∩-idl ; ∩-idr ; ∩-commutative ; ∩-idempotent ; ⋂ )
public
open Cat.Reasoning (B (Semilattice-on.to-monoid (A .snd)))
hiding ( Ob ; Hom ; id ; _∘_ ; assoc ; idl ; idr ) public
As an example of reasoning about the lattice operator, let us prove that is indeed the meet of and in the induced ordering. It’s reduced to a bit of algebra:
: ∀ {x y} → is-meet po x y (x ∩ y)
∩-is-meet {x} {y} .is-meet.meet≤l =
∩-is-meet (sym ∩-idempotent) ⟩
x ∩ y ≡⟨ pushl (x ∩ y) ≡⟨ ∩-commutative ⟩
x ∩ (x ∩ y) ∩ x ∎
{x} {y} .is-meet.meet≤r =
∩-is-meet
x ∩ y ≡˘⟨ pullr ∩-idempotent ⟩(x ∩ y) ∩ y ∎
{x} {y} .is-meet.greatest lb lb=lb∧x lb=lb∧y =
∩-is-meet
lb ≡⟨ lb=lb∧y ⟩
lb ∩ y ≡⟨ pushl lb=lb∧x ⟩(x ∩ y) ∎ lb ∩