Tom de Jong, 18-24 December 2020 Formalizing a paper proof sketch from 12 November 2020. Refactored 24 January 2022. We construct the free join-semilattice on a set X as the Kuratowski finite subsets of X. \begin{code} {-# OPTIONS --safe --without-K #-} open import UF.PropTrunc module OrderedTypes.FreeJoinSemiLattice (pt : propositional-truncations-exist) where open import Fin.ArithmeticViaEquivalence open import Fin.Kuratowski pt open import Fin.Type open import MLTT.Spartan open import Notation.UnderlyingType open import OrderedTypes.JoinSemiLattices open import UF.Base open import UF.Equiv open import UF.FunExt open import UF.Hedberg open import UF.ImageAndSurjection pt open import UF.Lower-FunExt open import UF.Powerset open import UF.Powerset-Fin pt open import UF.Sets open import UF.Subsingletons open import UF.Subsingletons-FunExt open PropositionalTruncation pt hiding (_β¨_) open binary-unions-of-subsets pt \end{code} The proof that the Kuratowski finite subsets of X denoted by π X and ordered by subset inclusion is a join-semilattice (with joins given by unions) is given in UF.Powerset-Fin.lagda. So we proceed directly to showing that π X is the *free* join-semilattice on a set X. Concretely, if L is a join-semilattice and f : X β L is any function, then there is a *unique* mediating map fβ : π X β L such that: (i) fβ is a join-semilattice homomorphism, i.e. - fβ preserves the least element; - fβ preserves binary joins. (ii) the diagram f X ---------> L \ ^ \ / Ξ· \ / β! fβ \ / v / π X commutes. The map Ξ· : X β π X is given by mapping x to the singleton subset β΄ x β΅. The idea in defining fβ is to map a Kuratowski finite subset A to the finite join β¨βΏ (f β π-to-carrier β¨ A β© β e) in L, where e is some eumeration (i.e. surjection) e : Fin n β π β¨ A β©. However, since Kuratowski finite subsets come with an *unspecified* such enumeration, we must show that the choice of enumeration is irrelevant, i.e. any two enumerations give rise to the same finite join. We then use a theorem by Kraus et al. [1] (see wconstant-map-to-set-factors-through-truncation-of-domain) to construct the desired mapping. [1] Theorem 5.4 in "Notions of Anonymous Existence in Martin-LΓΆf Type Theory" by Nicolai Kraus, MartΓn EscardΓ³, Thierry Coquand and Thorsten Altenkirch. In Logical Methods in Computer Science, volume 13, issue 1. 2017. \begin{code} module _ (π : JoinSemiLattice π₯ π£) where open JoinSemiLattice π module _ {X : π€ Μ } (X-is-set : is-set X) (f : X β L) where open singleton-subsets X-is-set open singleton-Kuratowski-finite-subsets X-is-set Ξ· : X β π X Ξ· x = β΄ x β΅[π] \end{code} We start by defining the mapping for a specified enumeration and we show that the choice of enumeration is irrelevant, i.e. fβ A is weakly constant. \begin{code} fβ : (A : π X) β (Ξ£ n κ β , Ξ£ e κ (Fin n β π A) , is-surjection e) β L fβ A (_ , e , _) = β¨βΏ (f β π-to-carrier A β e) fβ-is-wconstant : (A : π X) β wconstant (fβ A) fβ-is-wconstant A (n , e , Ο) (n' , e' , Ο') = β-is-antisymmetric _ _ u v where f' : π A β L f' = f β π-to-carrier A u : β¨βΏ (f' β e) β β¨βΏ (f' β e') u = β¨βΏ-is-lowerbound-of-upperbounds (f' β e) (β¨βΏ (f' β e')) Ο where Ο : (k : Fin n) β (f' β e) k β β¨βΏ (f' β e') Ο k = β₯β₯-rec (β-is-prop-valued _ _) Ο (Ο' (e k)) where Ο : (Ξ£ k' κ Fin n' , e' k' οΌ e k) β (f' β e) k β β¨βΏ (f' β e') Ο (k' , p) = (f' β e) k ββ¨ οΌ-to-β (ap f' p) β© (f' β e') k' ββ¨ β¨βΏ-is-upperbound (f' β e') k' β© β¨βΏ (f' β e') ββ v : β¨βΏ (f' β e') β β¨βΏ (f' β e) v = β¨βΏ-is-lowerbound-of-upperbounds (f' β e') (β¨βΏ (f' β e)) Ο where Ο : (k' : Fin n') β (f' β e') k' β β¨βΏ (f' β e) Ο k' = β₯β₯-rec (β-is-prop-valued _ _) Ο (Ο (e' k')) where Ο : (Ξ£ k κ Fin n , e k οΌ e' k') β (f' β e') k' β β¨βΏ (f' β e) Ο (k , p) = (f' β e') k' ββ¨ οΌ-to-β (ap f' p) β© (f' β e) k ββ¨ β¨βΏ-is-upperbound (f' β e) k β© β¨βΏ (f' β e) ββ \end{code} We now use the theorem by Kraus et al. to construct the map fβ from fβ. \begin{code} fβ : π X β L fβ (A , ΞΊ) = prβ (wconstant-map-to-set-factors-through-truncation-of-domain L-is-set (fβ A) (fβ-is-wconstant A)) ΞΊ fβ-in-terms-of-fβ : (A : π X) {n : β} {e : (Fin n β π A)} (Ο : is-surjection e) (ΞΊ : is-Kuratowski-finite-subset A) β fβ (A , ΞΊ) οΌ fβ A (n , e , Ο) fβ-in-terms-of-fβ A {n} {e} Ο ΞΊ = fβ (A , ΞΊ) οΌβ¨ I β© fβ (A , β£ n , e , Ο β£) οΌβ¨ II β© fβ A (n , e , Ο) β where I = ap (Ξ» - β fβ (A , -)) (β₯β₯-is-prop ΞΊ β£ n , e , Ο β£) II = (prβ (wconstant-map-to-set-factors-through-truncation-of-domain L-is-set (fβ A) (fβ-is-wconstant A)) (n , e , Ο)) β»ΒΉ \end{code} Recall that we must show that (i) fβ is a join-semilattice homomorphism, i.e. - fβ preserves the least element; - fβ preserves binary joins. (ii) the diagram f X ---------> L \ ^ \ / Ξ· \ / β! fβ \ / v / π X commutes. We show (ii) and then (i) now. \begin{code} fβ-after-Ξ·-is-f : fβ β Ξ· βΌ f fβ-after-Ξ·-is-f x = fβ (Ξ· x) οΌβ¨ I β© fβ β΄ x β΅ (1 , e , Ο) οΌβ¨ II β© f x β where e : Fin 1 β π β΄ x β΅ e π = x , refl Ο : is-surjection e Ο (x , refl) = β£ π , refl β£ I = fβ-in-terms-of-fβ β΄ x β΅ Ο β¨ Ξ· x β©β II = β-is-antisymmetric _ _ (β¨-is-lowerbound-of-upperbounds _ _ _ (β₯-is-least (f x)) (β-is-reflexive (f x))) (β¨-is-upperboundβ _ _) fβ-preserves-β₯ : fβ β [π] οΌ β₯ fβ-preserves-β₯ = β-is-antisymmetric _ _ u v where u : fβ β [π] β β₯ u = fβ β [π] ββ¨ uβ β© β¨βΏ (f β π-to-carrier β β e) ββ¨ uβ β© β₯ ββ where e : Fin 0 β π {π€} {X} β e = π-elim Ο : is-surjection e Ο (x , x-in-emptyset) = π-elim x-in-emptyset uβ = οΌ-to-β (fβ-in-terms-of-fβ β Ο β -is-Kuratowski-finite-subset) uβ = β-is-reflexive β₯ v : β₯ β fβ β [π] v = β₯-is-least (fβ β [π]) fβ-is-monotone : (A B : π X) β ((x : X) β x β β¨ A β© β x β β¨ B β©) β fβ A β fβ B fβ-is-monotone πΈ@(A , ΞΊβ) πΉ@(B , ΞΊβ) s = β₯β₯-recβ (β-is-prop-valued (fβ πΈ) (fβ πΉ)) Ξ³ ΞΊβ ΞΊβ where Ξ³ : (Ξ£ n κ β , Fin n β π A) β (Ξ£ m κ β , Fin m β π B) β fβ (A , ΞΊβ) β fβ (B , ΞΊβ) Ξ³ (n , e , e-surj) (n' , e' , e'-surj) = fβ πΈ ββ¨ uβ β© β¨βΏ (f β π-to-carrier A β e) ββ¨ uβ β© β¨βΏ (f β π-to-carrier B β e') ββ¨ uβ β© fβ πΉ ββ where uβ = οΌ-to-β (fβ-in-terms-of-fβ A e-surj ΞΊβ) uβ = οΌ-to-β (fβ-in-terms-of-fβ B e'-surj ΞΊβ) uβ = β¨βΏ-is-lowerbound-of-upperbounds (f β π-to-carrier A β e) (β¨βΏ (f β π-to-carrier B β e')) Ξ³β where Ξ³β : (k : Fin n) β (f β π-to-carrier A β e) k β β¨βΏ (f β π-to-carrier B β e') Ξ³β k = β₯β₯-rec (β-is-prop-valued _ _) Ξ³β t where x : X x = π-to-carrier A (e k) a : x β A a = π-to-membership A (e k) b : x β B b = s x a t : β k' κ Fin n' , e' k' οΌ (x , b) t = e'-surj (x , b) Ξ³β : (Ξ£ k' κ Fin n' , e' k' οΌ (x , b)) β (f β prβ β e) k β β¨βΏ (f β prβ β e') Ξ³β (k' , p) = (f β π-to-carrier A) (e k) ββ¨ vβ β© (f β π-to-carrier B) (e' k') ββ¨ vβ β© β¨βΏ (f β π-to-carrier B β e') ββ where vβ = οΌ-to-β (ap f q) where q : π-to-carrier A (e k) οΌ π-to-carrier B (e' k') q = ap prβ (p β»ΒΉ) vβ = β¨βΏ-is-upperbound (f β π-to-carrier B β e') k' fβ-preserves-β¨ : (A B : π X) β fβ (A βͺ[π] B) οΌ fβ A β¨ fβ B fβ-preserves-β¨ A B = β-is-antisymmetric _ _ u v where v : (fβ A β¨ fβ B) β fβ (A βͺ[π] B) v = β¨-is-lowerbound-of-upperbounds _ _ _ (fβ-is-monotone A (A βͺ[π] B) (βͺ[π]-is-upperboundβ A B)) (fβ-is-monotone B (A βͺ[π] B) (βͺ[π]-is-upperboundβ A B)) u : fβ (A βͺ[π] B) β (fβ A β¨ fβ B) u = β₯β₯-rec (β-is-prop-valued (fβ (A βͺ[π] B)) (fβ A β¨ fβ B)) Ξ³β (β¨ A β©β) where Ξ³β : (Ξ£ n κ β , Ξ£ e κ (Fin n β π β¨ A β©) , is-surjection e) β fβ (A βͺ[π] B) β (fβ A β¨ fβ B) Ξ³β (n , e , Ο) = β₯β₯-rec (β-is-prop-valued _ _) Ξ³β (β¨ B β©β) where Ξ³β : (Ξ£ n' κ β , Ξ£ e' κ (Fin n' β π β¨ B β©) , is-surjection e') β fβ (A βͺ[π] B) β (fβ A β¨ fβ B) Ξ³β (n' , e' , Ο') = fβ (A βͺ[π] B) ββ¨ lβ β© β¨βΏ (f' β [e,e']) ββ¨ lβ β© fβ A β¨ fβ B ββ where f' : π (β¨ A β© βͺ β¨ B β©) β L f' = f β π-to-carrier (β¨ A β© βͺ β¨ B β©) [e,e'] : Fin (n +' n') β π (β¨ A β© βͺ β¨ B β©) [e,e'] = (βͺ-enum β¨ A β© β¨ B β© e e') Ο : is-surjection [e,e'] Ο = βͺ-enum-is-surjection β¨ A β© β¨ B β© e e' Ο Ο' lβ = οΌ-to-β p where p : fβ (A βͺ[π] B) οΌ fβ (β¨ A β© βͺ β¨ B β©) (n +' n' , [e,e'] , Ο) p = fβ-in-terms-of-fβ (β¨ A β© βͺ β¨ B β©) Ο β¨ A βͺ[π] B β©β lβ = β¨βΏ-is-lowerbound-of-upperbounds (f' β [e,e']) (fβ A β¨ fβ B) Ο where Ο : (k : Fin (n +' n')) β (f' β [e,e']) k β (fβ A β¨ fβ B) Ο k = (f' β [e,e']) k ββ¨ β-is-reflexive _ β© (f' β βͺ-enum' β¨ A β© β¨ B β© e e') c ββ¨ Ο c β© (fβ A β¨ fβ B) ββ where c : Fin n + Fin n' c = β Fin+homo n n' β k Ο : (c : Fin n + Fin n') β (f' β βͺ-enum' β¨ A β© β¨ B β© e e') c β (fβ A β¨ fβ B) Ο (inl k) = (f' β βͺ-enum' β¨ A β© β¨ B β© e e') (inl k) ββ¨ uβ β© (f β π-to-carrier β¨ A β© β e) k ββ¨ uβ β© β¨βΏ (f β π-to-carrier β¨ A β© β e) ββ¨ uβ β© fβ β¨ A β© (n , e , Ο) ββ¨ uβ β© fβ A ββ¨ uβ β© fβ A β¨ fβ B ββ where uβ = β-is-reflexive ((f β π-to-carrier β¨ A β© β e) k) uβ = β¨βΏ-is-upperbound (f β π-to-carrier β¨ A β© β e) k uβ = β-is-reflexive (β¨βΏ (f β π-to-carrier β¨ A β© β e)) uβ = οΌ-to-β (fβ-in-terms-of-fβ β¨ A β© Ο β¨ A β©β) uβ = β¨-is-upperboundβ (fβ A) (fβ B) Ο (inr k) = (f' β βͺ-enum' β¨ A β© β¨ B β© e e') (inr k) ββ¨ uβ' β© (f β π-to-carrier β¨ B β© β e') k ββ¨ uβ' β© β¨βΏ (f β π-to-carrier β¨ B β© β e') ββ¨ uβ' β© fβ β¨ B β© (n' , e' , Ο') ββ¨ uβ' β© fβ B ββ¨ uβ ' β© fβ A β¨ fβ B ββ where uβ' = β-is-reflexive ((f β π-to-carrier β¨ B β© β e') k) uβ' = β¨βΏ-is-upperbound (f β π-to-carrier β¨ B β© β e') k uβ' = β-is-reflexive (β¨βΏ (f β π-to-carrier β¨ B β© β e')) uβ' = οΌ-to-β (fβ-in-terms-of-fβ β¨ B β© Ο' β¨ B β©β) uβ ' = β¨-is-upperboundβ (fβ A) (fβ B) \end{code} Finally we prove that fβ is the unique map with the above properties (i) & (ii). We do so by using the induction principle for Kuratowski finite subsets, which is proved in UF.Powerset-Fin.lagda. \begin{code} module _ (pe : propext π€) (fe : funext π€ (π€ βΊ)) where fβ-is-unique : (h : π X β L) β h β [π] οΌ β₯ β ((A B : π X) β h (A βͺ[π] B) οΌ h A β¨ h B) β (h β Ξ· βΌ f) β h βΌ fβ fβ-is-unique h pβ pβ pβ = Kuratowski-finite-subset-induction pe fe X X-is-set (Ξ» A β h A οΌ fβ A) (Ξ» _ β L-is-set) qβ qβ qβ where qβ : h β [π] οΌ fβ β [π] qβ = h β [π] οΌβ¨ pβ β© β₯ οΌβ¨ fβ-preserves-β₯ β»ΒΉ β© fβ β [π] β qβ : (x : X) β h (Ξ· x) οΌ fβ (Ξ· x) qβ x = h (Ξ· x) οΌβ¨ pβ x β© f x οΌβ¨ (fβ-after-Ξ·-is-f x) β»ΒΉ β© fβ (Ξ· x) β qβ : (A B : π X) β h A οΌ fβ A β h B οΌ fβ B β h (A βͺ[π] B) οΌ fβ (A βͺ[π] B) qβ A B rβ rβ = h (A βͺ[π] B) οΌβ¨ pβ A B β© h A β¨ h B οΌβ¨ apβ _β¨_ rβ rβ β© fβ A β¨ fβ B οΌβ¨ (fβ-preserves-β¨ A B) β»ΒΉ β© fβ (A βͺ[π] B) β \end{code} 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). \begin{code} module _ (pe : propext π€) (fe : funext (π€ βΊ) (π€ βΊ β π₯)) where homotopy-uniqueness-of-fβ : β! h κ (π X β L) , (h β [π] οΌ β₯) Γ ((A B : π X) β h (A βͺ[π] B) οΌ h A β¨ h B) Γ h β Ξ· βΌ f homotopy-uniqueness-of-fβ = (fβ , fβ-preserves-β₯ , fβ-preserves-β¨ , fβ-after-Ξ·-is-f) , Ξ³ where Ξ³ : (t : (Ξ£ h κ (π X β L) , (h β [π] οΌ β₯) Γ ((A B : π X) β h (A βͺ[π] B) οΌ h A β¨ h B) Γ h β Ξ· βΌ f)) β (fβ , fβ-preserves-β₯ , fβ-preserves-β¨ , fβ-after-Ξ·-is-f) οΌ t Ξ³ (h , pβ , pβ , pβ) = to-subtype-οΌ Ο (dfunext (lower-funext (π€ βΊ) (π€ βΊ) fe) (Ξ» A β (fβ-is-unique pe (lower-funext (π€ βΊ) π₯ fe) h pβ pβ pβ A) β»ΒΉ)) where Ο : (k : π X β L) β is-prop ((k β [π] οΌ β₯) Γ ((A B : π X) β k (A βͺ[π] B) οΌ (k A β¨ k B)) Γ k β Ξ· βΌ f) Ο k = Γ-is-prop L-is-set (Γ-is-prop (Ξ -is-prop fe (Ξ» _ β Ξ -is-prop (lower-funext (π€ βΊ) (π€ βΊ) fe) (Ξ» _ β L-is-set))) (Ξ -is-prop (lower-funext (π€ βΊ) (π€ βΊ) fe) (Ξ» _ β L-is-set))) \end{code} Added 17th March 2021 by Martin Escardo. Alternative definition of π: \begin{code} open import UF.Embeddings π' : π€ Μ β π€ βΊ Μ π' {π€} X = Ξ£ A κ π€ Μ , (A βͺ X) Γ is-Kuratowski-finite A \end{code} TODO. Show that π' X is equivalent to π X (using UF.Classifiers). Tom de Jong, 27 August 2021. We implement this TODO. \begin{code} open import UF.Univalence module _ {π€ : Universe} (ua : is-univalent π€) (fe : funext π€ (π€ βΊ)) where open import UF.Classifiers open import UF.EquivalenceExamples π-is-equivalent-to-π' : (X : π€ Μ ) β π X β π' X π-is-equivalent-to-π' X = Ξ³ where Ο : Subtype X β π X Ο = Ξ©-is-subtype-classifier ua fe X ΞΊ : π€ Μ β π€ Μ ΞΊ = is-Kuratowski-finite Ξ³ = π X ββ¨ β-refl _ β© (Ξ£ A κ π X , ΞΊ (π A)) ββ¨ I β© (Ξ£ S κ Subtype X , ΞΊ (π (β Ο β S))) ββ¨ Ξ£-assoc β© (Ξ£ A κ π€ Μ , Ξ£ e κ (A βͺ X) , ΞΊ (π (β Ο β (A , e)))) ββ¨ II β© (Ξ£ A κ π€ Μ , Ξ£ e κ (A βͺ X) , ΞΊ A) ββ¨ β-refl _ β© (Ξ£ A κ π€ Μ , (A βͺ X) Γ ΞΊ A) ββ¨ β-refl _ β© π' X β where I = β-sym (Ξ£-change-of-variable (Ξ» A β is-Kuratowski-finite-subset A) β Ο β (ββ-is-equiv Ο)) II = Ξ£-cong (Ξ» A β Ξ£-cong (Ξ» e β Ο A e)) where Ο : (A : π€ Μ ) (e : A βͺ X) β ΞΊ (π (β Ο β (A , e))) β ΞΊ A Ο A e = idtoeq (ΞΊ A') (ΞΊ A) (ap ΞΊ (eqtoid ua A' A lemma)) where A' : π€ Μ A' = π (β Ο β (A , e)) lemma = A' ββ¨ β-refl _ β© (Ξ£ x κ X , Ξ£ a κ A , etofun e a οΌ x) ββ¨ Ο β© A β where Ο = total-fiber-is-domain (etofun e) \end{code} TODO. In Chapter 9 of Johnstone's "Topos Theory" it is shown that X is Kuratowski finite if and only if π X is Kuratowski finite. A proof sketch in HoTT/UF is as follows. (1) π X is Kuratowski finite implies X is Kuratowski finite Suppose that we have a surjection e : Fin N β π X. By finite choice, we have for each 0 β€ i < N, a natural number nα΅’ with a surjection fα΅’ : Fin nα΅’ β π eα΅’. Now consider f : (Ξ£ i κ I , Fin nα΅’) β X (i , k) β¦ prβ (fα΅’ k) This is a surjection, because for x : X, there exists 0 β€ i < N with eα΅’ = [ x ] and hence, f (i , 0) = fα΅’ 0 = x. Finally, we observe that (Ξ£ i κ I , Fin nα΅’) β Fin (sum_{0 β€ i < N} nα΅’). (2) X is Kuratowski finite implies π X is Kuratowski finite Suppose that we have surjection e : Fin n β X. We construct a surjection f : Fin 2βΏ β π X f (bβ , ... , bβ) := finite join of eα΅’ for each bit bα΅’ that equals 1. To see that this is indeed a surjection, we use the induction principle of π X: - the empty set is mapped to by the sequence of n 0-bits. - for a singleton { x }, the element x is hit by eα΅’ for some 0 β€ i < n, so that { x } = f (bβ , ... , bβ) with bα΅’ = 1 and all other bβ±Ό = 0. - given subsets A,B : π X that are in the image of f, we obtain sequences π and π' such that f π = A and f π' = B so that the union A βͺ B is obtained as f (π β¨ π') where β¨ denotes pointwise disjunction. NB: It should be useful to use the formalized fact that Fin 2βΏ β Fin n β π.