FreeSupLattice
Tom de Jong, 8 & 15 January 2021 We construct the free π₯-sup-lattice on a set X : π₯ as the (π₯-)powerset of X.{-# OPTIONS --safe --without-K #-} open import MLTT.Spartan open import UF.FunExt open import UF.Lower-FunExt open import UF.Powerset open import UF.PropTrunc open import UF.Sets open import UF.Subsingletons open import UF.Subsingletons-FunExt module OrderedTypes.FreeSupLattice (pt : propositional-truncations-exist) where open PropositionalTruncation ptWe define sup-lattices using a record. We also introduce convenient helpers and syntax for reasoning about the order β.record SupLattice (π₯ π€ π£ : Universe) : π€Ο where constructor lattice field L : π€ Μ L-is-set : is-set L _β_ : L β L β π£ Μ β-is-prop-valued : (x y : L) β is-prop (x β y) β-is-reflexive : (x : L) β x β x β-is-transitive : (x y z : L) β x β y β y β z β x β z β-is-antisymmetric : (x y : L) β x β y β y β x β x οΌ y β : {I : π₯ Μ } β (I β L) β L β-is-upperbound : {I : π₯ Μ } (Ξ± : I β L) (i : I) β Ξ± i β β Ξ± β-is-lowerbound-of-upperbounds : {I : π₯ Μ } (Ξ± : I β L) (x : L) β ((i : I) β Ξ± i β x) β β Ξ± β x transitivity' : (x : L) {y z : L} β x β y β y β z β x β z transitivity' x {y} {z} = β-is-transitive x y z syntax transitivity' x u v = x ββ¨ u β© v infixr 0 transitivity' reflexivity' : (x : L) β x β x reflexivity' x = β-is-reflexive x syntax reflexivity' x = x ββ infix 1 reflexivity' οΌ-to-β : {x y : L} β x οΌ y β x β y οΌ-to-β {x} {x} refl = reflexivity' x β-transport : {I : π₯ Μ } (Ξ± Ξ² : I β L) β Ξ± βΌ Ξ² β β Ξ± οΌ β Ξ² β-transport {I} Ξ± Ξ² H = β-is-antisymmetric (β Ξ±) (β Ξ²) u v where u : β Ξ± β β Ξ² u = β-is-lowerbound-of-upperbounds Ξ± (β Ξ²) Ξ³ where Ξ³ : (i : I) β Ξ± i β β Ξ² Ξ³ i = Ξ± i ββ¨ οΌ-to-β (H i) β© Ξ² i ββ¨ β-is-upperbound Ξ² i β© β Ξ² ββ v : β Ξ² β β Ξ± v = β-is-lowerbound-of-upperbounds Ξ² (β Ξ±) Ξ³ where Ξ³ : (i : I) β Ξ² i β β Ξ± Ξ³ i = Ξ² i ββ¨ οΌ-to-β (H i β»ΒΉ) β© Ξ± i ββ¨ β-is-upperbound Ξ± i β© β Ξ± ββThe powerset of X is an example of a sup-lattice and every subset can be written as a union of singletons (this will come in useful later).module _ (pe : propext π₯) (fe : funext π₯ (π₯ βΊ)) (X : π₯ Μ ) (X-is-set : is-set X) where open unions-of-small-families pt π₯ π₯ X π-lattice : SupLattice π₯ (π₯ βΊ) π₯ SupLattice.L π-lattice = π X SupLattice.L-is-set π-lattice = powersets-are-sets fe pe SupLattice._β_ π-lattice = _β_ SupLattice.β-is-prop-valued π-lattice = β-is-prop (lower-funext π₯ (π₯ βΊ) fe) SupLattice.β-is-reflexive π-lattice = β-refl SupLattice.β-is-transitive π-lattice = β-trans SupLattice.β-is-antisymmetric π-lattice = (Ξ» A B β subset-extensionality pe fe) SupLattice.β π-lattice = β SupLattice.β-is-upperbound π-lattice = β-is-upperbound SupLattice.β-is-lowerbound-of-upperbounds π-lattice = β-is-lowerbound-of-upperbounds open singleton-subsets X-is-set express-subset-as-union-of-singletons : (A : π X) β A οΌ β (β΄_β΅ β (π-to-carrier A)) express-subset-as-union-of-singletons A = subset-extensionality pe fe u v where u : A β β (β΄_β΅ β (π-to-carrier A)) u x a = β£ (x , a) , refl β£ v : β (β΄_β΅ β (π-to-carrier A)) β A v x = β₯β₯-rec (β-is-prop A x) Ξ³ where Ξ³ : (Ξ£ i κ π A , x β (β΄_β΅ β π-to-carrier A) i) β x β A Ξ³ ((x , a) , refl) = aFinally we will show that π X is the free π₯-sup-lattice on a set X : π₯. Concretely, if L is a π₯-sup-lattice and f : X β L is any function, then there is a *unique* mediating map fβ : π X β L such that: (i) fβ is a sup-lattice homomorphism, i.e. - fβ preserves joins (of families indexed by types in π₯) (ii) the diagram f X ---------> L \ ^ \ / Ξ· \ / β! fβ \ / v / π X commutes. (The map Ξ· : X β π X is of course given by x β¦ β΄ x β΅.)module _ (π : SupLattice π₯ π€ π£) where open SupLattice π module _ (X : π₯ Μ ) (X-is-set : is-set X) (f : X β L) where open singleton-subsets X-is-set open unions-of-small-families pt π₯ π₯ X fΜ : (A : π X) β π A β L fΜ A = f β (π-to-carrier A) fβ : π X β L fβ A = β {π A} (fΜ A) Ξ· : X β π X Ξ· = β΄_β΅ fβ-after-Ξ·-is-f : fβ β Ξ· βΌ f fβ-after-Ξ·-is-f x = β-is-antisymmetric ((fβ β Ξ·) x) (f x) u v where u : (fβ β Ξ·) x β f x u = β-is-lowerbound-of-upperbounds (fΜ (Ξ· x)) (f x) Ξ³ where Ξ³ : (i : π (Ξ· x)) β (fΜ (Ξ· x)) i β f x Ξ³ (x , refl) = β-is-reflexive (f x) v : f x β (fβ β Ξ·) x v = β-is-upperbound (Ξ» (x , _) β f x) (x , refl) fβ-is-monotone : (A B : π X) β A β B β fβ A β fβ B fβ-is-monotone A B s = β-is-lowerbound-of-upperbounds (fΜ A) (fβ B) Ξ³ where Ξ³ : (i : Ξ£ x κ X , x β A) β fΜ A i β β (fΜ B) Ξ³ (x , a) = β-is-upperbound (fΜ B) (x , s x a) fβ-preserves-joins : (I : π₯ Μ ) (Ξ± : I β π X) β fβ (β Ξ±) οΌ β (fβ β Ξ±) fβ-preserves-joins I Ξ± = β-is-antisymmetric (fβ (β Ξ±)) (β (fβ β Ξ±)) u v where u : β (fΜ (β Ξ±)) β β (Ξ» (i : I) β β (fΜ (Ξ± i))) u = β-is-lowerbound-of-upperbounds (fΜ (β Ξ±)) (β (Ξ» (i : I) β β (fΜ (Ξ± i)))) Ξ³ where Ξ³ : (p : (Ξ£ x κ X , x β β Ξ±)) β fΜ (β Ξ±) p β β (Ξ» (i : I) β β (fΜ (Ξ± i))) Ξ³ (x , a) = β₯β₯-rec (β-is-prop-valued _ _) Ο a where Ο : (Ξ£ i κ I , x β Ξ± i) β f x β β (Ξ» (i : I) β β (fΜ (Ξ± i))) Ο (i , a') = f x ββ¨ uβ β© β (fΜ (Ξ± i)) ββ¨ uβ β© β (Ξ» (i : I) β β (fΜ (Ξ± i))) ββ where uβ = β-is-upperbound (fΜ (Ξ± i)) (x , a') uβ = β-is-upperbound (Ξ» i' β β (fΜ (Ξ± i'))) i v : β (Ξ» (i : I) β β (fΜ (Ξ± i))) β β (fΜ (β Ξ±)) v = β-is-lowerbound-of-upperbounds (Ξ» i β β (fΜ (Ξ± i))) (β (fΜ (β Ξ±))) Ξ³ where Ξ³ : (i : I) β β (fΜ (Ξ± i)) β β (fΜ (β Ξ±)) Ξ³ i = β-is-lowerbound-of-upperbounds (fΜ (Ξ± i)) (β (fΜ (β Ξ±))) Ο where Ο : (p : Ξ£ x κ X , x β Ξ± i) β fΜ (Ξ± i) p β β (fΜ (β Ξ±)) Ο (x , a) = β-is-upperbound (fΜ (β Ξ±)) (x , β£ i , a β£)Finally we prove that fβ is the unique map with the above properties (i) & (ii).module _ (pe : propext π₯) (fe : funext π₯ (π₯ βΊ)) where fβ-is-unique : (h : π X β L) β ((I : π₯ Μ ) (Ξ± : I β π X) β h (β Ξ±) οΌ β (h β Ξ±)) β (h β Ξ· βΌ f) β h βΌ fβ fβ-is-unique h pβ pβ A = h A οΌβ¨ ap h (express-subset-as-union-of-singletons pe fe X X-is-set A) β© h (β (Ξ· β prβ)) οΌβ¨ pβ (π A) (Ξ· β prβ) β© β (h β Ξ· β prβ) οΌβ¨ β-transport (h β Ξ· β prβ) (f β prβ) (Ξ» p β pβ (prβ p)) β© β (f β prβ) οΌβ¨reflβ© fβ A βAssuming some more function extensionality axioms, we can prove "homotopy uniqueness", i.e. the tuple consisting of fβ together with the proofs of (i) and (ii) is unique. This follows easily from the above, because (i) and (ii) are subsingletons (as L is a set).module _ (pe : propext π₯) (fe : funext (π₯ βΊ) (π₯ βΊ β π€)) where homotopy-uniqueness-of-fβ : β! h κ (π X β L) , (((I : π₯ Μ ) (Ξ± : I β π X) β h (β Ξ±) οΌ β (h β Ξ±))) Γ (h β Ξ· βΌ f) homotopy-uniqueness-of-fβ = (fβ , fβ-preserves-joins , fβ-after-Ξ·-is-f) , Ξ³ where Ξ³ : (t : (Ξ£ h κ (π X β L) , (((I : π₯ Μ ) (Ξ± : I β π X) β h (β Ξ±) οΌ β (h β Ξ±))) Γ (h β Ξ· βΌ f))) β (fβ , fβ-preserves-joins , fβ-after-Ξ·-is-f) οΌ t Ξ³ (h , pβ , pβ) = to-subtype-οΌ Ο (dfunext (lower-funext (π₯ βΊ) (π₯ βΊ) fe) (Ξ» A β (fβ-is-unique pe (lower-funext (π₯ βΊ) π€ fe) h pβ pβ A) β»ΒΉ)) where Ο : (k : π X β L) β is-prop (((I : π₯ Μ ) (Ξ± : I β π X) β k (β Ξ±) οΌ β (k β Ξ±)) Γ k β Ξ· βΌ f) Ο k = Γ-is-prop (Ξ -is-prop fe (Ξ» _ β Ξ -is-prop (lower-funext (π₯ βΊ) (π₯ βΊ) fe) (Ξ» _ β L-is-set))) (Ξ -is-prop (lower-funext (π₯ βΊ) (π₯ βΊ) fe) (Ξ» _ β L-is-set))