Martin Escardo, 30th September 2026. We show that ๐, the initial binary system of BinarySystems.Type, is initial in the strong sense that the type of homomorphisms from it to any binary system is a singleton. For this to be possible we have to consider coherent homomorphisms, defined below. \begin{code} {-# OPTIONS --safe --without-K #-} open import UF.FunExt module BinarySystems.Initiality (fe : Fun-Ext) where open import MLTT.Spartan open import UF.Base open import UF.Equiv open import UF.EquivalenceExamples open import UF.Retracts open import UF.SIP open sip open import UF.Subsingletons hiding (center) open import BinarySystems.Type \end{code} Because the type of binary systems doesn't require the underlying type to be a set, we would like to prove unique existence as the singleton property of a ฮฃ type, written โ! here, as done e.g. for natural number objects in MGS.Unique-Existence (and with a dependent version in Naturals.UniversalProperty). But the notion of homomorphism of BinarySystems.Type will not do for this, because it doesn't mention the binary system equations, and so the type ฮฃ h ๊ (๐ โ โจ ๐ โฉ) , is-hom ๐ ๐ h is not a singleton in general. Indeed, l L is L by definition, and therefore the third component of is-hom ๐ ๐ h, applied to L, is an identification h L ๏ผ f (h L). Once h L is identified with the point a using the first component, this becomes an element of the identity type a ๏ผ f a, which is the first axiom of ๐, and hence is data unless the underlying type of ๐ is a set. For the circle with the points a and b both chosen to be the base point, and the functions f and g both chosen to be the identity, for instance, the constant map at the base point has a whole loop space of homomorphism structures. What is missing is that a homomorphism between structures presented by equations should also say how it respects the equations. We add this as three squares, one for each axiom. The axiom a ๏ผ f a of ๐ and the axiom a' ๏ผ f' a' of ๐ give the two routes ap h ฮนโ โ hl a h a ------------------------> f' (h a) | | hL | | ap f' hL | | v v a' ------------------------> f' a' ฮนโ' and the axioms b ๏ผ g b and b' ๏ผ g' b' give the two routes ap h ฮนโ โ hr b h b ------------------------> g' (h b) | | hR | | ap g' hR | | v v b' ------------------------> g' b' ฮนโ' whereas the axioms f b ๏ผ g a and f' b' ๏ผ g' a', which relate the two descriptions of the midpoint, give the two routes hl b ap f' hR ฮนโ' h (f b) --------> f' (h b) --------> f' b' -----> g' a' | ^ ap h ฮนโ | | | | v | h (g a) --------> g' (h a) ------------------------- hr a ap g' hL We define the notion of coherent homomorphism by requiring that the two routes are identified in each of these three cases. It turns out that higher coherences are not needed for the initiality result. \begin{code} is-coherent-hom : (๐ : BS ๐ค) (๐ : BS ๐ฅ) โ (โจ ๐ โฉ โ โจ ๐ โฉ) โ ๐ค โ ๐ฅ ฬ is-coherent-hom ๐@(A , (a , b , f , g) , (ฮนโ , ฮนโ , ฮนโ)) ๐@(B , (a' , b' , f' , g') , (ฮนโ' , ฮนโ' , ฮนโ')) h = ฮฃ (hL , hR , hl , hr) ๊ is-hom ๐ ๐ h , (ap h ฮนโ โ hl a โ ap f' hL ๏ผ hL โ ฮนโ') ร (ap h ฮนโ โ hr a โ ap g' hL ๏ผ hl b โ ap f' hR โ ฮนโ') ร (ap h ฮนโ โ hr b โ ap g' hR ๏ผ hR โ ฮนโ') \end{code} For any binary system ๐, the homomorphism ๐-rec ๐ recursively defined in BinarySystems.Type is coherent, and, moreover, the three squares hold by reflexivity, because the axioms of ๐ do, and because the homomorphism equations of ๐-rec at L, R and l R are the axioms of ๐ and reflexivities respectively. \begin{code} ๐-rec-is-coherent-hom : (๐ : BS ๐ค) โ is-coherent-hom ๐ ๐ (๐-rec ๐) ๐-rec-is-coherent-hom ๐@(A , (a , b , f , g) , ฮน) = ๐-rec-is-hom ๐ , refl , refl , refl \end{code} The type ๐น defined in BinarySystems.Type has no axioms, and so it is initial for a point and two endomaps with no equations, which we prove following the strategy of โ-is-nno in the module MGS.Unique-Existence. \begin{code} module _ (A : ๐ค ฬ ) (c : A) (f g : A โ A) where ๐น-rec : ๐น โ A ๐น-rec center = c ๐น-rec (left x) = f (๐น-rec x) ๐น-rec (right x) = g (๐น-rec x) ๐น-recursive : (๐น โ A) โ ๐ค ฬ ๐น-recursive w = (w center ๏ผ c) ร (w โ left โผ f โ w) ร (w โ right โผ g โ w) ๐น-recursive-retract : (w : ๐น โ A) โ ๐น-recursive w โ (w โผ ๐น-rec) ๐น-recursive-retract w = ฯ , ฯ , ฯฯ where ฯ : (w โผ ๐น-rec) โ ๐น-recursive w ฯ H = H center , (ฮป x โ H (left x) โ (ap f (H x))โปยน) , (ฮป x โ H (right x) โ (ap g (H x))โปยน) ฯ : ๐น-recursive w โ w โผ ๐น-rec ฯ z@(p , K , ฮ) center = p ฯ z@(p , K , ฮ) (left x) = K x โ ap f (ฯ z x) ฯ z@(p , K , ฮ) (right x) = ฮ x โ ap g (ฯ z x) cancel : {x y z : A} (k : x ๏ผ y) (q : y ๏ผ z) โ (k โ q) โ q โปยน ๏ผ k cancel k q = (k โ q) โ q โปยน ๏ผโจ โassoc k q (q โปยน) โฉ k โ (q โ q โปยน) ๏ผโจ ap (k โ_) (trans-sym' q) โฉ k โ ฯฯ : (z : ๐น-recursive w) โ ฯ (ฯ z) ๏ผ z ฯฯ z@(p , K , ฮ) = to-ร-๏ผ refl (to-ร-๏ผ (dfunext fe ฮบ) (dfunext fe ฮบ')) where ฮบ : (x : ๐น) โ ฯ z (left x) โ (ap f (ฯ z x))โปยน ๏ผ K x ฮบ x = cancel (K x) (ap f (ฯ z x)) ฮบ' : (x : ๐น) โ ฯ z (right x) โ (ap g (ฯ z x))โปยน ๏ผ ฮ x ฮบ' x = cancel (ฮ x) (ap g (ฯ z x)) ๐น-is-initial : โ! w ๊ (๐น โ A) , ๐น-recursive w ๐น-is-initial = retract-of-singleton (ฮฃ-retract _ _ (ฮป w โ ๐น-recursive w โโจ ๐น-recursive-retract w โฉ โ-gives-โท (โ-funext fe w ๐น-rec))) (singleton-types'-are-singletons ๐น-rec) \end{code} Before proceeding we state and prove the following technical lemma, which doesn't refer to binary systems. \begin{code} private contraction-lemma : {X : ๐ฅ ฬ } {x y : X} (p : x ๏ผ y) (Y : ๐ฆ ฬ ) โ (ฮฃ q ๊ x ๏ผ y , (refl โ q ๏ผ p) ร Y) โ Y contraction-lemma {_} {_} {X} {x} {y} p Y = (ฮฃ q ๊ x ๏ผ y , (refl โ q ๏ผ p) ร Y) โโจ I โฉ (ฮฃ q ๊ x ๏ผ y , (q ๏ผ p) ร Y) โโจ left-Id-equiv p โฉ Y โ where I = ฮฃ-cong (ฮป q โ ร-cong (๏ผ-cong-l (refl โ q) p refl-left-neutral) (โ-refl Y)) \end{code} We now fix a binary system ๐ and analyse the type of coherent homomorphisms from ๐ to it. \begin{code} module _ (A : ๐ค ฬ ) (a b : A) (f g : A โ A) (ฮนโ : a ๏ผ f a) (ฮนโ : f b ๏ผ g a) (ฮนโ : b ๏ผ g b) where ๐ : BS ๐ค ๐ = A , (a , b , f , g) , (ฮนโ , ฮนโ , ฮนโ) ๐-coherence : (h : ๐ โ A) โ is-hom ๐ ๐ h โ ๐ค ฬ ๐-coherence h (hL , hR , hl , hr) = (refl โ hl L โ ap f hL ๏ผ hL โ ฮนโ) ร (refl โ hr L โ ap g hL ๏ผ hl R โ ap f hR โ ฮนโ) ร (refl โ hr R โ ap g hR ๏ผ hR โ ฮนโ) is-coherent-hom-from-๐-explicitly : (h : ๐ โ A) โ is-coherent-hom ๐ ๐ h ๏ผ (ฮฃ u ๊ is-hom ๐ ๐ h , ๐-coherence h u) is-coherent-hom-from-๐-explicitly h = refl glue : A ร A ร (๐น โ A) โ ๐ โ A glue (u , v , w) L = u glue (u , v , w) R = v glue (u , v , w) (ฮท x) = w x unglue : (๐ โ A) โ A ร A ร (๐น โ A) unglue h = h L , h R , h โ ฮท glue-unglue : glue โ unglue โผ id glue-unglue h = dfunext fe ฯ where ฯ : glue (unglue h) โผ h ฯ L = refl ฯ R = refl ฯ (ฮท x) = refl unglue-glue : unglue โ glue โผ id unglue-glue _ = refl glue-is-equiv : is-equiv glue glue-is-equiv = qinvs-are-equivs glue (unglue , unglue-glue , glue-unglue) \end{code} We now show that the homomorphism data on glue (u , v , w) is equivalent to the following data. \begin{code} glue-data : (u v : A) (w : ๐น โ A) โ ๐ค ฬ glue-data u v w = (u ๏ผ a) ร (v ๏ผ b) ร ((u ๏ผ f u) ร (w center ๏ผ f v) ร (w โ left โผ f โ w)) ร ((w center ๏ผ g u) ร (v ๏ผ g v) ร (w โ right โผ g โ w)) glue-data-to-glue-hom-data : (u v : A) (w : ๐น โ A) โ glue-data u v w โ is-hom ๐ ๐ (glue (u , v , w)) glue-data-to-glue-hom-data u v w (hL , hR , (hlL , hlR , hlฮท) , (hrL , hrR , hrฮท)) = hL , hR , hl , hr where h : ๐ โ A h = glue (u , v , w) hl : h โ l โผ f โ h hl L = hlL hl R = hlR hl (ฮท x) = hlฮท x hr : h โ r โผ g โ h hr L = hrL hr R = hrR hr (ฮท x) = hrฮท x glue-data-to-glue-hom-data-is-equiv : (u v : A) (w : ๐น โ A) โ is-equiv (glue-data-to-glue-hom-data u v w) glue-data-to-glue-hom-data-is-equiv u v w = qinvs-are-equivs (glue-data-to-glue-hom-data u v w) (ฮ , ฮฮ , ฮฮ) where ฮ = glue-data-to-glue-hom-data u v w ฮ : codomain ฮ โ domain ฮ ฮ (hL , hR , hl , hr) = hL , hR , (hl L , hl R , hl โ ฮท) , (hr L , hr R , hr โ ฮท) ฮฮ : ฮ โ ฮ โผ id ฮฮ s = refl ฮฮ : ฮ โ ฮ โผ id ฮฮ i@(hL , hR , hl , hr) = to-ร-๏ผ refl (to-ร-๏ผ refl (to-ร-๏ผ (dfunext fe ฯ) (dfunext fe ฯ))) where ฯ : prโ (prโ (prโ (ฮ (ฮ i)))) โผ hl ฯ L = refl ฯ R = refl ฯ (ฮท x) = refl ฯ : prโ (prโ (prโ (ฮ (ฮ i)))) โผ hr ฯ L = refl ฯ R = refl ฯ (ฮท x) = refl \end{code} We now reorder the data so that it becomes possible to contract away portions of it in the equivalence proved in coherent-homs-โ below. \begin{code} w-data : (u v : A) (hL : u ๏ผ a) (hR : v ๏ผ b) (w : ๐น โ A) โ ๐ค ฬ w-data u v hL hR w = ฮฃ hlR ๊ w center ๏ผ f v , ฮฃ hrL ๊ w center ๏ผ g u , (refl โ hrL โ ap g hL ๏ผ hlR โ ap f hR โ ฮนโ) ร (w โ left โผ f โ w) ร (w โ right โผ g โ w) v-data : (u : A) (hL : u ๏ผ a) (v : A) โ ๐ค ฬ v-data u hL v = ฮฃ hR ๊ v ๏ผ b , ฮฃ hrR ๊ v ๏ผ g v , (refl โ hrR โ ap g hR ๏ผ hR โ ฮนโ) ร (ฮฃ w ๊ (๐น โ A) , w-data u v hL hR w) reordered-fiber : (u v : A) (w : ๐น โ A) โ ๐ค ฬ reordered-fiber u v w = ฮฃ hL ๊ u ๏ผ a , ฮฃ hlL ๊ u ๏ผ f u , (refl โ hlL โ ap f hL ๏ผ hL โ ฮนโ) ร (ฮฃ hR ๊ v ๏ผ b , ฮฃ hrR ๊ v ๏ผ g v , (refl โ hrR โ ap g hR ๏ผ hR โ ฮนโ) ร w-data u v hL hR w) reordered-fiber-โ : (u v : A) (w : ๐น โ A) โ reordered-fiber u v w โ (ฮฃ s ๊ glue-data u v w , ๐-coherence (glue (u , v , w)) (glue-data-to-glue-hom-data u v w s)) reordered-fiber-โ u v w = qinveq ฮฆ (ฮจ , ฮจฮฆ , ฮฆฮจ) where ฮฆ : reordered-fiber u v w โ ฮฃ s ๊ glue-data u v w , ๐-coherence (glue (u , v , w)) (glue-data-to-glue-hom-data u v w s) ฮฆ (hL , hlL , sqโ , hR , hrR , sqโ , hlR , hrL , sqโ , hlฮท , hrฮท) = (hL , hR , (hlL , hlR , hlฮท) , (hrL , hrR , hrฮท)) , sqโ , sqโ , sqโ ฮจ : codomain ฮฆ โ domain ฮฆ ฮจ ((hL , hR , (hlL , hlR , hlฮท) , (hrL , hrR , hrฮท)) , sqโ , sqโ , sqโ) = hL , hlL , sqโ , hR , hrR , sqโ , hlR , hrL , sqโ , hlฮท , hrฮท ฮจฮฆ : ฮจ โ ฮฆ โผ id ฮจฮฆ t = refl ฮฆฮจ : ฮฆ โ ฮจ โผ id ฮฆฮจ t = refl reordered-total-space : ๐ค ฬ reordered-total-space = ฮฃ u ๊ A , ฮฃ hL ๊ u ๏ผ a , ฮฃ hlL ๊ u ๏ผ f u , (refl โ hlL โ ap f hL ๏ผ hL โ ฮนโ) ร (ฮฃ v ๊ A , v-data u hL v) reordered-โ : reordered-total-space โ (ฮฃ (u , v , w) ๊ A ร A ร (๐น โ A) , reordered-fiber u v w) reordered-โ = qinveq ฮฆ (ฮจ , ฮจฮฆ , ฮฆฮจ) where ฮฆ : reordered-total-space โ ฮฃ (u , v , w) ๊ A ร A ร (๐น โ A) , reordered-fiber u v w ฮฆ (u , hL , hlL , sqโ , v , hR , hrR , sqโ , w , d) = (u , v , w) , hL , hlL , sqโ , hR , hrR , sqโ , d ฮจ : codomain ฮฆ โ domain ฮฆ ฮจ ((u , v , w) , hL , hlL , sqโ , hR , hrR , sqโ , d) = u , hL , hlL , sqโ , v , hR , hrR , sqโ , w , d ฮจฮฆ : ฮจ โ ฮฆ โผ id ฮจฮฆ t = refl ฮฆฮจ : ฮฆ โ ฮจ โผ id ฮฆฮจ t = refl \end{code} We now apply this reordering to prove the following equivalence by contracting the data step by step. \begin{code} coherent-homs-โ : (ฮฃ h ๊ (๐ โ A) , is-coherent-hom ๐ ๐ h) โ (ฮฃ w ๊ (๐น โ A) , ๐น-recursive A (f b) f g w) coherent-homs-โ = (ฮฃ h ๊ (๐ โ A) , is-coherent-hom ๐ ๐ h) โโจ I โฉ (ฮฃ t ๊ A ร A ร (๐น โ A) , is-coherent-hom ๐ ๐ (glue t)) โโจ II โฉ (ฮฃ (u , v , w) ๊ A ร A ร (๐น โ A) , ฮฃ s ๊ glue-data u v w , ๐-coherence (glue (u , v , w)) (glue-data-to-glue-hom-data u v w s)) โโจ III โฉ (ฮฃ (u , v , w) ๊ A ร A ร (๐น โ A) , reordered-fiber u v w) โโจ IV โฉ reordered-total-space โโจ V โฉ (ฮฃ hlL ๊ a ๏ผ f a , (refl โ hlL โ ap f refl ๏ผ refl โ ฮนโ) ร (ฮฃ v ๊ A , v-data a refl v)) โโจ VI โฉ (ฮฃ v ๊ A , v-data a refl v) โโจ VII โฉ (ฮฃ hrR ๊ b ๏ผ g b , (refl โ hrR โ ap g refl ๏ผ refl โ ฮนโ) ร (ฮฃ w ๊ (๐น โ A) , w-data a b refl refl w)) โโจ VIII โฉ (ฮฃ w ๊ (๐น โ A) , w-data a b refl refl w) โโจ IX โฉ (ฮฃ w ๊ (๐น โ A) , ๐น-recursive A (f b) f g w) โ where I = โ-sym (ฮฃ-change-of-variable (ฮป h โ is-coherent-hom ๐ ๐ h) glue glue-is-equiv) II = ฮฃ-cong' _ _ (ฮป (u , v , w) โ โ-sym (ฮฃ-change-of-variable (๐-coherence (glue (u , v , w))) (glue-data-to-glue-hom-data u v w) (glue-data-to-glue-hom-data-is-equiv u v w))) III = ฮฃ-cong' _ _ (ฮป (u , v , w) โ โ-sym (reordered-fiber-โ u v w)) IV = โ-sym reordered-โ V = based-contraction (ฮป u hL โ ฮฃ hlL ๊ u ๏ผ f u , (refl โ hlL โ ap f hL ๏ผ hL โ ฮนโ) ร (ฮฃ v ๊ A , v-data u hL v)) VI = contraction-lemma (refl โ ฮนโ) (ฮฃ v ๊ A , v-data a refl v) VII = based-contraction (ฮป v hR โ ฮฃ hrR ๊ v ๏ผ g v , (refl โ hrR โ ap g hR ๏ผ hR โ ฮนโ) ร (ฮฃ w ๊ (๐น โ A) , w-data a v refl hR w)) VIII = contraction-lemma (refl โ ฮนโ) (ฮฃ w ๊ (๐น โ A) , w-data a b refl refl w) IX = ฮฃ-cong' _ _ (ฮป w โ ฮฃ-cong' _ _ (ฮป hlR โ contraction-lemma (hlR โ ฮนโ) ((w โ left โผ f โ w) ร (w โ right โผ g โ w)))) \end{code} So ๐ is the initial binary system, in the sense that the type of coherent homomorphisms from it to any binary system is a singleton. \begin{code} ๐-is-initial : (๐ : BS ๐ค) โ โ! h ๊ (๐ โ โจ ๐ โฉ) , is-coherent-hom ๐ ๐ h ๐-is-initial (A , (a , b , f , g) , (ฮนโ , ฮนโ , ฮนโ)) = equiv-to-singleton (coherent-homs-โ A a b f g ฮนโ ฮนโ ฮนโ) (๐น-is-initial A (f b) f g) \end{code}