open import 1Lab.Prelude open import Algebra.Semilattice open import Algebra.Semigroup open import Algebra.Lattice open import Algebra.Magma open import Cat.Diagram.Coproduct.Indexed open import Cat.Diagram.Product.Indexed open import Cat.Diagram.Colimit.Base open import Cat.Diagram.Limit.Base open import Cat.Thin.Limits open import Cat.Thin open import Data.Power open import Data.Sum module Data.Power.Lattice where
Lattice of Subobjectsπ
The power set of a type can be organised into a lattice, where the meets of two subsets are given by their intersection and the joins are given by their union . Furthermore, we prove that the ordering induced by this lattice is the same as the subset inclusion ordering.
First, we take a detour to define the structure of β
as a Poset ordered by subset inclusion. This packages up the reflexivity and transitivity of the subset relation. Antisymmetry for this relation is exactly the principle of extensionality for subsets.
ββ : β {β} β Type β β Poset _ _ ββ A = make-poset {A = β A} {R = _β_} (Ξ» _ x β x) (Ξ» xβy yβz a aβx β yβz a (xβy a aβx)) β-ext Ξ» {x} {y} β Ξ -is-hlevel 1 Ξ» x β fun-is-hlevel 1 (y x .is-tr)
Back on track, we equip intersection of subsets with the structure of a semilattice:
β©-semilattice : β {β} {X : Type β} β is-semilattice (_β©_ {X = X}) β©-semilattice = r where open is-semilattice open is-semigroup r : is-semilattice _ r .has-is-semigroup .has-is-magma .has-is-set = β-is-set r .has-is-semigroup .associative = β-ext (Ξ» { x (a , b , c) β (a , b) , c }) (Ξ» { x ((a , b) , c) β a , b , c }) r .commutative = β-ext (Ξ» { x (a , b) β b , a }) (Ξ» { x (a , b) β b , a }) r .idempotent = β-ext (Ξ» { x (y , _) β y }) (Ξ» { x y β y , y })
We then equip union of subsets with the structure of a semilattice. This direction of the proof is a lot more annoying because of the truncation in _βͺ_, but it is essentially shuffling sums around:
βͺ-semilattice : β {β} {X : Type β} β is-semilattice (_βͺ_ {X = X}) βͺ-semilattice = r where open is-semilattice open is-semigroup
To show that subset union is associative, we must βshuffleβ coproducts (x β X) β (x β Y β x β Z)
to (x β X β x β Y) β (x β Z)
, which would be simple enough to do with pattern matching. The complication arises because in reality weβre shuffling P β β₯ Q β R β₯
into β₯ P β Q β₯ β R
and vice-versa, so we must use β₯-β₯-elim to get at the underlying coproduct, even though all of P
, Q
, and R
are propositions.
r : is-semilattice _ r .has-is-semigroup .has-is-magma .has-is-set = β-is-set r .has-is-semigroup .associative = β-ext (Ξ» _ β β₯-β₯-elim (Ξ» _ β squash) Ξ» { (inl x) β inc (inl (inc (inl x))) ; (inr x) β β₯-β₯-elim (Ξ» _ β squash) (Ξ» { (inl y) β inc (inl (inc (inr y))) ; (inr y) β inc (inr y) }) x }) (Ξ» _ β β₯-β₯-elim (Ξ» _ β squash) Ξ» { (inl x) β β₯-β₯-elim (Ξ» _ β squash) (Ξ» { (inl y) β inc (inl y) ; (inr y) β inc (inr (inc (inl y))) }) x ; (inr x) β inc (inr (inc (inr x))) })
For commutativity, since we are changing β₯ (x β X) β (x β Y) β₯
to β₯ (x β Y) β (x β X) β₯
, β΅β₯-β₯-map`{.Agda} suffices - there is no need to reassociate truncations.
r .commutative = β-ext (Ξ» _ β β₯-β₯-map Ξ» { (inl x) β inr x ; (inr x) β inl x }) (Ξ» _ β β₯-β₯-map Ξ» { (inl x) β inr x ; (inr x) β inl x })
For idempotence, we must show that x β X β β₯ (x β X) β (x β X) β₯
. Since x β X
is a proposition, we can eliminate from a truncation to it, at which point either branch will do just fine. In the other direction, we inject it into the left summand for definiteness.
r .idempotent {x = X} = β-ext (Ξ» _ β β₯-β₯-elim (Ξ» _ β X _ .is-tr) (Ξ» { (inl x) β x ; (inr x) β x })) Ξ» _ x β inc (inl x)
We must now show that intersections absorb unions, and that unions absorb intersections.
β©-absorbs-βͺ : β {β} {A : Type β} {X Y : β A} β X β© (X βͺ Y) β‘ X β©-absorbs-βͺ = β-ext (Ξ» { _ (a , _) β a }) Ξ» _ x β x , inc (inl x) βͺ-absorbs-β© : β {β} {A : Type β} {X Y : β A} β X βͺ (X β© Y) β‘ X βͺ-absorbs-β© {X = X} {Y = Y} = β-ext (Ξ» _ β β₯-β₯-elim (Ξ» x β X _ .is-tr) (Ξ» { (inl xβX) β xβX ; (inr (xβX , xβY)) β xβX })) Ξ» _ xβX β inc (inl xβX)
This means that assemble into a lattice, which we call Power:
open Lattice-on open is-lattice Power : β {β} (X : Type β) β Lattice-on (β X) Power X ._Lβ§_ = _β©_ Power X ._Lβ¨_ = _βͺ_ Power X .has-is-lattice .has-meets = β©-semilattice Power X .has-is-lattice .has-joins = βͺ-semilattice Power X .has-is-lattice .β§-absorbs-β¨ {y = y} = β©-absorbs-βͺ {Y = y} Power X .has-is-lattice .β¨-absorbs-β§ {y = y} = βͺ-absorbs-β© {Y = y}
It remains to show that the covariant ordering induced by the Power lattice is the same as ββ. For this we show that .
subset-β© : β {β} {A : Type β} {X Y : β A} β (X β Y) β (X β‘ (X β© Y)) subset-β© {X = X} {Y = Y} = prop-ext (Ξ -is-hlevel 1 Ξ» x β fun-is-hlevel 1 (Y x .is-tr)) (β-is-set _ _) to from where
In the βifβ direction, suppose that . We show that intersects to by extensionality of power sets: If and then , so . Conversely, if , then , so we are done.
to : X β Y β X β‘ (X β© Y) to xβy = β-ext (Ξ» x xβX β xβX , xβy x xβX) (Ξ» x xβXβ©Y β xβXβ©Y .fst)
In the βonly ifβ direction, suppose that . If , then (by the assumed equality), so , hence , so we are done.
from : (X β‘ (X β© Y)) β X β Y from path x xβX = transport (ap β£_β£ (happly path x)) xβX .snd
Completenessπ
The lattice of powersets of a type is complete, since it admits arbitrary meets. The meet of a family is the subset represented by , i.e., the set of elements present in all the subsets in the family.
module _ {β} {X : Type β} where private module β = Poset (ββ X) open Indexed-product β-indexed-meet : β {I : Type β} (F : I β β X) β Indexed-product β.underlying F β-indexed-meet F = ip where ip : Indexed-product _ _ ip .Ξ F i = (β x β i β F x) , Ξ -is-hlevel 1 Ξ» x β F x i .is-tr ip .Ο i x f = f i ip .has-is-ip = indexed-meetβindexed-product {P = β.βProset} _ Ξ» f x b i β f i x b β-complete : is-complete β β β.underlying β-complete = has-indexed-productsβproset-is-complete {P = β.βProset} β-indexed-meet
It is also cocomplete, since it admits arbitrary indexed joins. These are given, assuming is like above, by the subset . Note the use of , rather than : we need a proposition.
open Indexed-coproduct β-indexed-join : β {I : Type β} (F : I β β X) β Indexed-coproduct β.underlying F β-indexed-join F = ic where ic : Indexed-coproduct _ _ ic .Ξ£F i = (β[ x β _ ] (i β F x)) , squash ic .ΞΉ i x f = inc (i , f) ic .has-is-ic = indexed-joinβindexed-coproduct {P = β.βProset} _ Ξ» {B = B} f x β β₯-β₯-elim (Ξ» _ β B x .is-tr) (Ξ» { (i , y) β f i x y }) β-cocomplete : is-cocomplete β β β.underlying β-cocomplete = has-indexed-coproductsβproset-is-cocomplete {P = β.βProset} β-indexed-join