Martin Escardo, 4th August 2020. (Going back to 1993 or earlier.) A construction of the initial binary system in Spartan MLTT, without HITs or quotients, or extensionality axioms. A binary system is a set A with distinguished points a b : A and functions f g : A β A such that (1) a = f a, (2) b = g b, (3) f b = g a. The initial binary system is the closed interval of dyadic rationals (see below for a picture). We construct it as a quotient of the following type πΉ, with L,R,l,r corresponding to a,b,f,g, without assuming that our type theory has quotients - it just happens to have the quotient we want. \begin{code} {-# OPTIONS --safe --without-K #-} module BinarySystems.InitialBinarySystem where open import MLTT.Spartan open import UF.Sets-Properties open import UF.Subsingletons-Properties data πΉ : π€β Μ where L R : πΉ l r : πΉ β πΉ \end{code} We want to perform the identifications (1) L = l L, (2) R = r R, (3) l R = C = r L, so that l and r become congruences. We call C (for "center") the equal points of (3). Here is a pictorial illustration of what we have in mind: Left endpoint center right endpoint L C R [------------------+------------------] (the dyadic closed interval) | [ image of l | image of r ] v common point of the images Geometrically, the functions l and r are supposed to be affine transformations that scale and translate the interval to two smaller copies with a common overlapping point. To perform the identifications, we could quotient or use a HIT (higher inductive type). We instead take a retract, defined by the fixed points of an idempotent normalization function. We take the biased choice l R for C before we perform the identification (3). This will be the canonical, or normal-form representative of the common point of the images. More generally, a binary system is a type A with distinguished points a b : A and functions f g : A β A such that (1) a = f a, (2) b = g b, (3) f b = g a. What we want to do is to quotient the type πΉ, so that the quotient map is retraction, to get the initial binary system. \begin{code} C : πΉ C = l R is-normal : πΉ β π€β Μ is-normal L = π is-normal R = π is-normal (l L) = π is-normal (l R) = π is-normal (l (l x)) = is-normal (l x) is-normal (l (r x)) = is-normal (r x) is-normal (r L) = π is-normal (r R) = π is-normal (r (l x)) = is-normal (l x) is-normal (r (r x)) = is-normal (r x) \end{code} The following can be proved directly, but it also follows from the result proved below that we have an idempotent normalization function with the normal elements as its fixed points, and from the fact that πΉ has decidable equality (not proved here). \begin{code} normality-is-decidable : (x : πΉ) β is-normal x + Β¬ is-normal x normality-is-decidable L = inl β normality-is-decidable R = inl β normality-is-decidable (l L) = inr id normality-is-decidable (l R) = inl β normality-is-decidable (l (l x)) = normality-is-decidable (l x) normality-is-decidable (l (r x)) = normality-is-decidable (r x) normality-is-decidable (r L) = inr id normality-is-decidable (r R) = inr id normality-is-decidable (r (l x)) = normality-is-decidable (l x) normality-is-decidable (r (r x)) = normality-is-decidable (r x) \end{code} We don't use the fact that normality is decidable anywhere in this file, but, because the proof is so easy, we couldn't resist including it. To define the normalization function, we define versions π and π£ of l and r that preserve normality. \begin{code} π : πΉ β πΉ π L = L π R = C π (l x) = l (l x) π (r x) = l (r x) π£ : πΉ β πΉ π£ L = C π£ R = R π£ (l x) = r (l x) π£ (r L) = r C π£ (r R) = R π£ (r (l x)) = r (r (l x)) π£ (r (r x)) = r (r (r x)) \end{code} The fact that the construction of π£ is not the symmetric version of that of π (and that it is longer) corresponds to the fact that we made a biased choice for the normal form of the center C, favouring l. The preservation proofs are by case analysis without induction: \begin{code} π-preserves-normality : (x : πΉ) β is-normal x β is-normal (π x) π-preserves-normality L i = β π-preserves-normality R i = β π-preserves-normality (l x) i = i π-preserves-normality (r x) i = i π£-preserves-normality : (x : πΉ) β is-normal x β is-normal (π£ x) π£-preserves-normality L β = β π£-preserves-normality R β = β π£-preserves-normality (l R) β = β π£-preserves-normality (l (l x)) i = i π£-preserves-normality (l (r x)) i = i π£-preserves-normality (r (l x)) i = i π£-preserves-normality (r (r x)) i = i \end{code} The normalization function replaces l and r by their "semantic" versions π and π£: \begin{code} normalize : πΉ β πΉ normalize L = L normalize R = R normalize (l x) = π (normalize x) normalize (r x) = π£ (normalize x) \end{code} By construction, the result of normalization is normal, with a direct proof by induction: \begin{code} normalize-is-normal : (x : πΉ) β is-normal (normalize x) normalize-is-normal L = β normalize-is-normal R = β normalize-is-normal (l x) = π-preserves-normality (normalize x) (normalize-is-normal x) normalize-is-normal (r x) = π£-preserves-normality (normalize x) (normalize-is-normal x) \end{code} We now prove that normal points are fixed points of the normalization function. We need a simple lemma for that purpose, proved by case analysis. \begin{code} π£r-equation : (x : πΉ) β is-normal (r x) β π£ (r x) οΌ r (r x) π£r-equation L i = π-elim i π£r-equation R i = π-elim i π£r-equation (l x) i = refl π£r-equation (r x) i = refl \end{code} To prove that normal points are fixed points of the normalization function, we need to simultaneously prove two lemmas by induction: \begin{code} nfp-lemma-l : (x : πΉ) β is-normal (l x) β π (normalize x) οΌ l x nfp-lemma-r : (x : πΉ) β is-normal (r x) β π£ (normalize x) οΌ r x nfp-lemma-l L i = π-elim i nfp-lemma-l R β = refl nfp-lemma-l (l x) i = ap π (nfp-lemma-l x i) nfp-lemma-l (r x) i = ap π (nfp-lemma-r x i) nfp-lemma-r L i = π-elim i nfp-lemma-r R i = π-elim i nfp-lemma-r (l x) i = ap π£ (nfp-lemma-l x i) nfp-lemma-r (r x) i = π£ (π£ (normalize x)) οΌβ¨ ap π£ (nfp-lemma-r x i) β© π£ (r x) οΌβ¨ π£r-equation x i β© r (r x) β \end{code} Now the proof of the desired result is by cases (without induction), using the above two lemmas. \begin{code} normals-are-fixed-points : (x : πΉ) β is-normal x β normalize x οΌ x normals-are-fixed-points L β = refl normals-are-fixed-points R β = refl normals-are-fixed-points (l x) i = nfp-lemma-l x i normals-are-fixed-points (r x) i = nfp-lemma-r x i \end{code} We have the following two corollaries: \begin{code} fixed-points-are-normal : (x : πΉ) β normalize x οΌ x β is-normal x fixed-points-are-normal x p = transport is-normal p (normalize-is-normal x) normalization-idemp : (x : πΉ) β normalize (normalize x) οΌ normalize x normalization-idemp x = normals-are-fixed-points (normalize x) (normalize-is-normal x) \end{code} We now show that πΉis a set in the sense of univalent mathematics and that it has decidable equality. There are short proofs of some of the following lemmas in Agda. But we are restricting ourselves to a fragment of Agda corresponding to a spartan Martin-LΓΆf type theory. In particular, in MLTT, it is not possible to prove that L β R without using a universe, but Agda just gives this as a fact. We want to show that the equality of πΉis truth valued, as opposed to arbitrary-type valued, where a truth value, or proposition, is a type with at most one element. For that purpose, we first define our own truth valued equality, where Ξ©β is the type of truth values in the first universe π€β. \begin{code} open import UF.Hedberg open import UF.Sets open import UF.SubtypeClassifier open import UF.Subsingletons hiding (center) Ο : πΉ β πΉ β Ξ©β Ο L L = β€ Ο L R = β₯ Ο L (l y) = β₯ Ο L (r y) = β₯ Ο R L = β₯ Ο R R = β€ Ο R (l y) = β₯ Ο R (r y) = β₯ Ο (l x) L = β₯ Ο (l x) R = β₯ Ο (l x) (l y) = Ο x y Ο (l x) (r y) = β₯ Ο (r x) L = β₯ Ο (r x) R = β₯ Ο (r x) (l y) = β₯ Ο (r x) (r y) = Ο x y _οΌ[πΉ]_ : πΉ β πΉ β π€β Μ x οΌ[πΉ] y = Ο x y holds οΌ[πΉ]-is-prop-valued : (x y : πΉ) β is-prop (x οΌ[πΉ] y) οΌ[πΉ]-is-prop-valued x y = holds-is-prop (Ο x y) refl[πΉ] : (x : πΉ) β x οΌ[πΉ] x refl[πΉ] L = β refl[πΉ] R = β refl[πΉ] (l x) = refl[πΉ] x refl[πΉ] (r x) = refl[πΉ] x \end{code} The induction principle for our notion of equality: \begin{code} JπΉ : (x : πΉ) (A : (y : πΉ) β x οΌ[πΉ] y β π₯ Μ ) β A x (refl[πΉ] x) β (y : πΉ) (r : x οΌ[πΉ] y) β A y r JπΉ L A b L β = b JπΉ L A b R p = π-elim p JπΉ L A b (l y) p = π-elim p JπΉ L A b (r y) p = π-elim p JπΉ R A b L p = π-elim p JπΉ R A b R β = b JπΉ R A b (l y) p = π-elim p JπΉ R A b (r y) p = π-elim p JπΉ (l x) A b L p = π-elim p JπΉ (l x) A b R p = π-elim p JπΉ (l x) A b (l y) p = JπΉ x (A β l) b y p JπΉ (l x) A b (r y) p = π-elim p JπΉ (r x) A b L p = π-elim p JπΉ (r x) A b R p = π-elim p JπΉ (r x) A b (l y) p = π-elim p JπΉ (r x) A b (r y) p = JπΉ x (A β r) b y p \end{code} From this we get back and forth conversions between our notion of equality and the one of MLTT, where Jbased is the "based" induction principle for MLTT equality. \begin{code} from-οΌ[πΉ] : (x y : πΉ) β x οΌ[πΉ] y β x οΌ y from-οΌ[πΉ] x = JπΉ x (Ξ» y p β x οΌ y) refl to-οΌ[πΉ] : (x y : πΉ) β x οΌ y β x οΌ[πΉ] y to-οΌ[πΉ] x = Jbased x (Ξ» y p β x οΌ[πΉ] y) (refl[πΉ] x) \end{code} To show that πΉis a set, it is enough to prove that the type x οΌ y has a constant endomap. We construct it as the composition of our forth and back conversions. It is constant because our notion of equality is truth valued (any two elements of our equality type are equal). \begin{code} πΉ-is-set : is-set πΉ πΉ-is-set = Id-collapsibles-are-sets (f , ΞΊ) where f : {x y : πΉ} β x οΌ y β x οΌ y f {x} {y} p = from-οΌ[πΉ] x y (to-οΌ[πΉ] x y p) ΞΊ : {x y : πΉ} (p q : x οΌ y) β f p οΌ f q ΞΊ {x} {y} p q = u where t : to-οΌ[πΉ] x y p οΌ to-οΌ[πΉ] x y q t = οΌ[πΉ]-is-prop-valued x y (to-οΌ[πΉ] x y p) (to-οΌ[πΉ] x y q) u : from-οΌ[πΉ] x y (to-οΌ[πΉ] x y p) οΌ from-οΌ[πΉ] x y (to-οΌ[πΉ] x y q) u = ap (from-οΌ[πΉ] x y) t \end{code} Another way to show that a type is a set is to show that it has decidable equality, as is well known, which is the original version of Hedberg's Theorem. \begin{code} οΌ[πΉ]-is-decidable : (x y : πΉ) β (x οΌ[πΉ] y) + Β¬ (x οΌ[πΉ] y) οΌ[πΉ]-is-decidable L L = inl β οΌ[πΉ]-is-decidable L R = inr id οΌ[πΉ]-is-decidable L (l y) = inr id οΌ[πΉ]-is-decidable L (r y) = inr id οΌ[πΉ]-is-decidable R L = inr id οΌ[πΉ]-is-decidable R R = inl β οΌ[πΉ]-is-decidable R (l y) = inr id οΌ[πΉ]-is-decidable R (r y) = inr id οΌ[πΉ]-is-decidable (l x) L = inr id οΌ[πΉ]-is-decidable (l x) R = inr id οΌ[πΉ]-is-decidable (l x) (l y) = οΌ[πΉ]-is-decidable x y οΌ[πΉ]-is-decidable (l x) (r y) = inr id οΌ[πΉ]-is-decidable (r x) L = inr id οΌ[πΉ]-is-decidable (r x) R = inr id οΌ[πΉ]-is-decidable (r x) (l y) = inr id οΌ[πΉ]-is-decidable (r x) (r y) = οΌ[πΉ]-is-decidable x y πΉ-has-decidable-equality : (x y : πΉ) β (x οΌ y) + Β¬ (x οΌ y) πΉ-has-decidable-equality x y = Ξ΄ (οΌ[πΉ]-is-decidable x y) where Ξ΄ : (x οΌ[πΉ] y) + Β¬ (x οΌ[πΉ] y) β (x οΌ y) + Β¬ (x οΌ y) Ξ΄ (inl p) = inl (from-οΌ[πΉ] x y p) Ξ΄ (inr Ξ½) = inr (contrapositive (to-οΌ[πΉ] x y) Ξ½) \end{code} So we get an alternative proof that normality is decidable: an element x of πΉ is normal if and only if normalize x οΌ x. But we actually don't need the normalization procedure to construct the initial binary system, whose underlying type will be called π. However, we will use some of the above machinery. \begin{code} π : π€β Μ π = Ξ£ x κ πΉ , is-normal x being-normal-is-prop : (x : πΉ) β is-prop (is-normal x) being-normal-is-prop L = π-is-prop being-normal-is-prop R = π-is-prop being-normal-is-prop (l L) = π-is-prop being-normal-is-prop (l R) = π-is-prop being-normal-is-prop (l (l x)) = being-normal-is-prop (l x) being-normal-is-prop (l (r x)) = being-normal-is-prop (r x) being-normal-is-prop (r L) = π-is-prop being-normal-is-prop (r R) = π-is-prop being-normal-is-prop (r (l x)) = being-normal-is-prop (l x) being-normal-is-prop (r (r x)) = being-normal-is-prop (r x) π-is-set : is-set π π-is-set = subsets-of-sets-are-sets πΉ is-normal πΉ-is-set (Ξ» {x} β being-normal-is-prop x) Left Center Right : π Left = L , β Center = C , β Right = R , β left right : π β π left (x , i) = π x , π-preserves-normality x i right (x , i) = π£ x , π£-preserves-normality x i π-eq-lR-C : left Right οΌ Center π-eq-lR-C = refl π-eq-rL-C : right Left οΌ Center π-eq-rL-C = refl π-eq-l : Left οΌ left Left π-eq-l = refl π-eq-r : Right οΌ right Right π-eq-r = refl π-eq-lr : left Right οΌ right Left π-eq-lr = refl π-eq-lm : left Right οΌ Center π-eq-lm = refl π-eq-rm : right Left οΌ Center π-eq-rm = refl \end{code} We now use the above to show that π is the initial binary system. \begin{code} binary-system-structure : π€ Μ β π€ Μ binary-system-structure A = A Γ A Γ (A β A) Γ (A β A) binary-system-axioms : (A : π€ Μ ) β binary-system-structure A β π€ Μ binary-system-axioms A (a , b , f , g) = is-set A Γ (a οΌ f a) Γ (f b οΌ g a) Γ (b οΌ g b) BS : (π€ : Universe) β π€ βΊ Μ BS π€ = Ξ£ A κ π€ Μ , Ξ£ s κ binary-system-structure A , binary-system-axioms A s π : BS π€β π = (π , (Left , Right , left , right) , (π-is-set , π-eq-l , π-eq-lr , π-eq-r)) open import UF.SIP open sip \end{code} The notion of homomorphism of binary systems is the expected one: \begin{code} is-hom : (π : BS π€) (π' : BS π₯) β (β¨ π β© β β¨ π' β©) β π€ β π₯ Μ is-hom (A , (a , b , f , g) , _) (A' , (a' , b' , f' , g') , _) h = (h a οΌ a') Γ (h b οΌ b') Γ (h β f βΌ f' β h) Γ (h β g βΌ g' β h) \end{code} In order to show that π is the initial binary system, we first prove (the expected) induction principle for its underlying type π (with a perhaps unexpected proof): \begin{code} π-inductive : (P : π β π€ Μ ) β P Left β P Right β ((x : π) β P x β P (left x)) β ((x : π) β P x β P (right x)) β π€ Μ π-inductive P a b f g = ((x : π) β is-set (P x)) Γ (a οΌ f Left a) Γ (f Right b οΌ g Left a) Γ (b οΌ g Right b) π-induction : (P : π β π€ Μ ) β (a : P Left) β (b : P Right) β (f : (x : π) β P x β P (left x)) β (g : (x : π) β P x β P (right x)) β π-inductive P a b f g β (x : π) β P x π-induction P a b f g ΞΉ (L , β) = a π-induction P a b f g ΞΉ (R , β) = b π-induction P a b f g ΞΉ (l R , i) = f (R , β) b π-induction P a b f g ΞΉ (l (l x) , i) = f (l x , i) (π-induction P a b f g ΞΉ (l x , i)) π-induction P a b f g ΞΉ (l (r x) , i) = f (r x , i) (π-induction P a b f g ΞΉ (r x , i)) π-induction P a b f g ΞΉ (r (l R) , i) = g (l R , β) (f (R , β) b) π-induction P a b f g ΞΉ (r (l (l x)) , i) = g (l (l x) , i) (π-induction P a b f g ΞΉ (l (l x) , i)) π-induction P a b f g ΞΉ (r (l (r x)) , i) = g (l (r x) , i) (π-induction P a b f g ΞΉ (l (r x) , i)) π-induction P a b f g ΞΉ (r (r (l x)) , i) = g (r (l x) , i) (π-induction P a b f g ΞΉ (r (l x) , i)) π-induction P a b f g ΞΉ (r (r (r x)) , i) = g (r (r x) , i) (π-induction P a b f g ΞΉ (r (r x) , i)) \end{code} In MLTT, induction principles come with equations. In our case they are the expected ones. \begin{code} π-induction-eq-Left : (P : π β π€ Μ ) (a : P Left) (b : P Right) (f : (x : π) β P x β P (left x)) (g : (x : π) β P x β P (right x)) (ΞΉ : π-inductive P a b f g) β π-induction P a b f g ΞΉ Left οΌ a π-induction-eq-Left P a b f g _ = refl π-induction-eq-Right : (P : π β π€ Μ ) (a : P Left) (b : P Right) (f : (x : π) β P x β P (left x)) (g : (x : π) β P x β P (right x)) (ΞΉ : π-inductive P a b f g) β π-induction P a b f g ΞΉ Right οΌ b π-induction-eq-Right P a b f g _ = refl \end{code} For the next equation for the induction principle, we need the assumption a οΌ f Left a: \begin{code} π-induction-eq-left : (P : π β π€ Μ ) (a : P Left) (b : P Right) (f : (x : π) β P x β P (left x)) (g : (x : π) β P x β P (right x)) β (ΞΉ : π-inductive P a b f g) β (x : π) β π-induction P a b f g ΞΉ (left x) οΌ f x (π-induction P a b f g ΞΉ x) π-induction-eq-left P a b f g ΞΉ (L , β) = prβ (prβ ΞΉ) π-induction-eq-left P a b f g ΞΉ (R , β) = refl π-induction-eq-left P a b f g ΞΉ (l x , i) = refl π-induction-eq-left P a b f g ΞΉ (r x , i) = refl \end{code} And for the last equation for the induction principle, we need the two equations f Right b οΌ g Left a and b οΌ g Right b as assumptions: \begin{code} π-induction-eq-right : (P : π β π€ Μ ) (a : P Left) (b : P Right) (f : (x : π) β P x β P (left x)) (g : (x : π) β P x β P (right x)) β (ΞΉ : π-inductive P a b f g) β (x : π) β π-induction P a b f g ΞΉ (right x) οΌ g x (π-induction P a b f g ΞΉ x) π-induction-eq-right P a b f g ΞΉ (L , β) = prβ (prβ (prβ ΞΉ)) π-induction-eq-right P a b f g ΞΉ (R , β) = prβ (prβ (prβ ΞΉ)) π-induction-eq-right P a b f g ΞΉ (l R , i) = refl π-induction-eq-right P a b f g ΞΉ (l (l x) , i) = refl π-induction-eq-right P a b f g ΞΉ (l (r x) , i) = refl π-induction-eq-right P a b f g ΞΉ (r (l x) , i) = refl π-induction-eq-right P a b f g ΞΉ (r (r x) , i) = refl \end{code} From now on we don't rely on the particular construction of π. We only use the induction principle and its equations. As usual, the recursion principle is a particular case of the induction principle: \begin{code} π-rec : (π : BS π€) β (π β β¨ π β©) π-rec (A , (a , b , f , g) , (ΞΉβ , ΞΉ')) = π-induction (Ξ» _ β A) a b (Ξ» _ β f) (Ξ» _ β g) ((Ξ» _ β ΞΉβ) , ΞΉ') \end{code} And so are its equations, which amount to the fact that π-rec constructs a homomorphism: \begin{code} π-rec-is-hom : (π : BS π€) β is-hom π π (π-rec π) π-rec-is-hom (A , (a , b , f , g) , ΞΉ) = i , ii , iii , iv where π = (A , (a , b , f , g) , ΞΉ) i : π-rec π Left οΌ a i = π-induction-eq-Left (Ξ» _ β A) a b (Ξ» _ β f) (Ξ» _ β g) ((Ξ» _ β prβ ΞΉ) , prβ ΞΉ) ii : π-rec π Right οΌ b ii = π-induction-eq-Right (Ξ» _ β A) a b (Ξ» _ β f) (Ξ» _ β g) ((Ξ» _ β prβ ΞΉ) , prβ ΞΉ) iii : (x : π) β π-rec π (left x) οΌ f (π-rec π x) iii = π-induction-eq-left (Ξ» _ β A) a b (Ξ» _ β f) (Ξ» _ β g) ((Ξ» _ β prβ ΞΉ) , prβ ΞΉ) iv : (x : π) β π-rec π (right x) οΌ g (π-rec π x) iv = π-induction-eq-right (Ξ» _ β A) a b (Ξ» _ β f) (Ξ» _ β g) ((Ξ» _ β prβ ΞΉ) , prβ ΞΉ) \end{code} Some boiler plate code to name the projections follows: \begin{code} β¨_β©-Left : (π : BS π€) β β¨ π β© β¨ (A , (a , b , f , g) , ΞΉ) β©-Left = a β¨_β©-Right : (π : BS π€) β β¨ π β© β¨ (A , (a , b , f , g) , ΞΉ) β©-Right = b β¨_β©-left : (π : BS π€) β β¨ π β© β β¨ π β© β¨ (A , (a , b , f , g) , ΞΉ) β©-left = f β¨_β©-right : (π : BS π€) β β¨ π β© β β¨ π β© β¨ (A , (a , b , f , g) , ΞΉ) β©-right = g β¨_β©-is-set : (π : BS π€) β is-set β¨ π β© β¨ (A , (a , b , f , g) , ΞΉ) β©-is-set = prβ ΞΉ is-hom-L : (π : BS π€) (π : BS π₯) (h : β¨ π β© β β¨ π β©) β is-hom π π h β h (β¨ π β©-Left) οΌ β¨ π β©-Left is-hom-L π π h (i , ii , iii , iv) = i is-hom-R : (π : BS π€) (π : BS π₯) (h : β¨ π β© β β¨ π β©) β is-hom π π h β h (β¨ π β©-Right) οΌ β¨ π β©-Right is-hom-R π π h (i , ii , iii , iv) = ii is-hom-l : (π : BS π€) (π : BS π₯) (h : β¨ π β© β β¨ π β©) β is-hom π π h β h β β¨ π β©-left βΌ β¨ π β©-left β h is-hom-l π π h (i , ii , iii , iv) = iii is-hom-r : (π : BS π€) (π : BS π₯) (h : β¨ π β© β β¨ π β©) β is-hom π π h β h β β¨ π β©-right βΌ β¨ π β©-right β h is-hom-r π π h (i , ii , iii , iv) = iv \end{code} This is the end of the boiler plate code. To conclude that π is the initial binary system, it remains to prove that there is at most one homomorphism from it to any other binary system. \begin{code} π-at-most-one-hom : (π : BS π€) (h k : π β β¨ π β©) β is-hom π π h β is-hom π π k β h βΌ k π-at-most-one-hom π h k u v = π-induction (Ξ» x β h x οΌ k x) Ξ± Ξ² Ο Ξ³ ((Ξ» x β props-are-sets β¨ π β©-is-set) , β¨ π β©-is-set Ξ± (Ο Left Ξ±) , β¨ π β©-is-set (Ο Right Ξ²) (Ξ³ Left Ξ±) , β¨ π β©-is-set Ξ² (Ξ³ Right Ξ²)) where Ξ± = h Left οΌβ¨ is-hom-L π π h u β© β¨ π β©-Left οΌβ¨ (is-hom-L π π k v)β»ΒΉ β© k Left β Ξ² = h Right οΌβ¨ is-hom-R π π h u β© β¨ π β©-Right οΌβ¨ (is-hom-R π π k v)β»ΒΉ β© k Right β Ο : (x : π) β h x οΌ k x β h (left x) οΌ k (left x) Ο x p = h (left x) οΌβ¨ is-hom-l π π h u x β© β¨ π β©-left (h x) οΌβ¨ ap β¨ π β©-left p β© β¨ π β©-left (k x) οΌβ¨ (is-hom-l π π k v x)β»ΒΉ β© k (left x) β Ξ³ : (x : π) β h x οΌ k x β h (right x) οΌ k (right x) Ξ³ x p = h (right x) οΌβ¨ is-hom-r π π h u x β© β¨ π β©-right (h x) οΌβ¨ ap β¨ π β©-right p β© β¨ π β©-right (k x) οΌβ¨ (is-hom-r π π k v x)β»ΒΉ β© k (right x) β π-rec-unique : (π : BS π€) (h : π β β¨ π β©) β is-hom π π h β h βΌ π-rec π π-rec-unique π h u = π-at-most-one-hom π h (π-rec π) u (π-rec-is-hom π) \end{code} Primitive (or parametric) recursion, which has the above as a special case: \begin{code} π-pinductive : {A : π€ Μ } β A β A β (π β A β A) β (π β A β A) β π€ Μ π-pinductive {π€} {A} a b f g = π-inductive (Ξ» _ β A) a b f g π-primrec : {A : π€ Μ } (a b : A) (f g : π β A β A) β π-pinductive a b f g β π β A π-primrec {π€} {A} a b f g = π-induction (Ξ» _ β A) a b f g primitive-recursive : {A : π€ Μ } β A β A β (π β A β A) β (π β A β A) β (π β A) β π€ Μ primitive-recursive a b f g h = (h Left οΌ a) Γ (h Right οΌ b) Γ ((x : π) β h (left x) οΌ f x (h x)) Γ ((x : π) β h (right x) οΌ g x (h x)) π-primrec-primitive-recursive : {A : π€ Μ } (a b : A) (f g : π β A β A) β (ΞΉ : π-pinductive a b f g) β primitive-recursive a b f g (π-primrec a b f g ΞΉ) π-primrec-primitive-recursive {π€} {A} a b f g ΞΉ = π-induction-eq-Left (Ξ» _ β A) a b f g ΞΉ , π-induction-eq-Right (Ξ» _ β A) a b f g ΞΉ , π-induction-eq-left (Ξ» _ β A) a b f g ΞΉ , π-induction-eq-right (Ξ» _ β A) a b f g ΞΉ π-at-most-one-primrec : {A : π€ Μ } (a b : A) (f g : π β A β A) β π-pinductive a b f g β (h k : π β A) β primitive-recursive a b f g h β primitive-recursive a b f g k β h βΌ k π-at-most-one-primrec {π€} {A} a b f g (ΞΉβ , ΞΉ') h k (hL , hR , hl , hr) (kL , kR , kl , kr) = Ξ΄ where arbitrary-element-of-π = Left A-is-set : is-set A A-is-set = ΞΉβ arbitrary-element-of-π Ξ± = h Left οΌβ¨ hL β© a οΌβ¨ kL β»ΒΉ β© k Left β Ξ² = h Right οΌβ¨ hR β© b οΌβ¨ kR β»ΒΉ β© k Right β Ο : (x : π) β h x οΌ k x β h (left x) οΌ k (left x) Ο x p = h (left x) οΌβ¨ hl x β© f x (h x) οΌβ¨ ap (f x) p β© f x (k x) οΌβ¨ (kl x)β»ΒΉ β© k (left x) β Ξ³ : (x : π) β h x οΌ k x β h (right x) οΌ k (right x) Ξ³ x p = h (right x) οΌβ¨ hr x β© g x (h x) οΌβ¨ ap (g x) p β© g x (k x) οΌβ¨ (kr x)β»ΒΉ β© k (right x) β set-condition : (x : π) β is-set (h x οΌ k x) set-condition x = props-are-sets A-is-set eql : Ξ± οΌ Ο Left Ξ± eql = A-is-set Ξ± (Ο Left Ξ±) eqlr : Ο Right Ξ² οΌ Ξ³ Left Ξ± eqlr = A-is-set (Ο Right Ξ²) (Ξ³ Left Ξ±) eqr : Ξ² οΌ Ξ³ Right Ξ² eqr = A-is-set Ξ² (Ξ³ Right Ξ²) Ξ΄ : h βΌ k Ξ΄ = π-induction (Ξ» x β h x οΌ k x) Ξ± Ξ² Ο Ξ³ (set-condition , eql , eqlr , eqr) π-primrec-uniqueness : {A : π€ Μ } (a b : A) (f g : π β A β A) β (ΞΉ : π-pinductive a b f g) β (h : π β A) β primitive-recursive a b f g h β h βΌ π-primrec a b f g ΞΉ π-primrec-uniqueness a b f g ΞΉ h hph = π-at-most-one-primrec a b f g ΞΉ h (π-primrec a b f g ΞΉ) hph (π-primrec-primitive-recursive a b f g ΞΉ) \end{code} Under some special conditions that often hold in practice, we can remove the "base" case in the uniqueness theorem. \begin{code} is-wprimrec : {A : π€ Μ } β (π β A β A) β (π β A β A) β (π β A) β π€ Μ is-wprimrec f g h = ((x : π) β h (left x) οΌ f x (h x)) Γ ((x : π) β h (right x) οΌ g x (h x)) primrec-is-wprimrec : {A : π€ Μ } (a b : A) (f g : π β A β A) (h : π β A) β primitive-recursive a b f g h β is-wprimrec f g h primrec-is-wprimrec a b f g h (hL , hR , hl , hr) = (hl , hr) fixed-point-conditions : {A : π€ Μ } β A β A β (π β A β A) β (π β A β A) β π€ Μ fixed-point-conditions a b f g = (β a' β a' οΌ f Left a' β a' οΌ a) Γ (β b' β b' οΌ g Right b' β b' οΌ b) wprimrec-primitive-recursive : {A : π€ Μ } (a b : A) (f g : π β A β A) (h : π β A) β fixed-point-conditions a b f g β is-wprimrec f g h β primitive-recursive a b f g h wprimrec-primitive-recursive a b f g h (fixa , fixb) (hl , hr) = (hL , hR , hl , hr) where hL' = h Left οΌβ¨ refl β© h (left Left) οΌβ¨ hl Left β© f Left (h Left) β hL = h Left οΌβ¨ fixa (h Left) hL' β© a β hR : h Right οΌ b hR = fixb (h Right) (hr Right) π-at-most-one-wprimrec : {A : π€ Μ } (a b : A) (f g : π β A β A) β (ΞΉ : π-pinductive a b f g) β fixed-point-conditions a b f g β (h k : π β A) β is-wprimrec f g h β is-wprimrec f g k β h βΌ k π-at-most-one-wprimrec a b f g ΞΉ fixc h k (hl , hr) (kl , kr) = π-at-most-one-primrec a b f g ΞΉ h k (wprimrec-primitive-recursive a b f g h fixc (hl , hr)) (wprimrec-primitive-recursive a b f g k fixc (kl , kr)) π-wprimrec-uniqueness : {A : π€ Μ } (a b : A) (f g : π β A β A) β (ΞΉ : π-pinductive a b f g) β fixed-point-conditions a b f g β (h : π β A) β is-wprimrec f g h β h βΌ π-primrec a b f g ΞΉ π-wprimrec-uniqueness a b f g ΞΉ fixc h hph = π-at-most-one-wprimrec a b f g ΞΉ fixc h (π-primrec a b f g ΞΉ) hph (primrec-is-wprimrec a b f g ( π-primrec a b f g ΞΉ) (π-primrec-primitive-recursive a b f g ΞΉ)) \end{code} Definition by cases of functions π β A is a particular case of parametric recursion. Given a b : A and f g : π β A, we want to define h : π β A by cases as follows: h Left οΌ a h Right οΌ b h (left x) = f x h (right x) = g x For this to be well defined we need the following endpoint agreement conditions: (1) a οΌ f Left, (2) f Right οΌ g Left, (3) b οΌ g Right. If we take a = f Left and b = g Left, so that (1) and (2) hold, we are left with condition (3) as the only assumption, and the condition on h becomes h Left οΌ f Left, h Right οΌ g Right, h (left x) = f x, h (right x) = g x. But also the first two equations follow from the second two, since h Left = h (left Left) = f Left, h Right = h (right Right) = g right. Hence it is enough to consider the endpoint agreement condition (3) and work with the equations h (left x) = f x, h (right x) = g x. Hence π-cases gives the mediating map of a pushout diagram that glues two copies of the dyadic interval, identifying the end of one with the beginning of the other, so that π is equivalent to the pushout π +β π: π β π +β π when f = left and g = right. The function π-cases defined below produces the mediating map of the pushout: The following constructions and facts are all particular cases of those for π-primrec. \begin{code} π-caseable : (A : π€ Μ ) β (π β A) β (π β A) β π€ Μ π-caseable A f g = is-set A Γ (f Right οΌ g Left) π-caseable-gives-pinductive : (A : π€ Μ ) (f g : π β A) β π-caseable A f g β π-pinductive (f Left) (g Right) (Ξ» x _ β f x) (Ξ» x _ β g x) π-caseable-gives-pinductive A f g (A-is-set , p) = (Ξ» _ β A-is-set) , refl , p , refl π-cases : {A : π€ Μ } (f g : π β A) β π-caseable A f g β π β A π-cases f g ΞΉ = π-primrec (f Left) (g Right) (Ξ» x _ β f x) (Ξ» x _ β g x) (π-caseable-gives-pinductive _ f g ΞΉ) case-equations : {A : π€ Μ } β (π β A) β (π β A) β (π β A) β π€ Μ case-equations f g h = (h β left βΌ f) Γ (h β right βΌ g) π-cases-redundant-equations : {A : π€ Μ } (f g : π β A) β (p : π-caseable A f g) β (π-cases f g p Left οΌ f Left) Γ (π-cases f g p Right οΌ g Right) Γ (π-cases f g p β left βΌ f) Γ (π-cases f g p β right βΌ g) π-cases-redundant-equations f g ΞΉ = π-primrec-primitive-recursive (f Left) (g Right) (Ξ» x _ β f x) (Ξ» x _ β g x) (π-caseable-gives-pinductive _ f g ΞΉ) π-cases-equations : {A : π€ Μ } (f g : π β A) β (p : π-caseable A f g) β case-equations f g (π-cases f g p) π-cases-equations f g p = primrec-is-wprimrec (f Left) (g Right) (Ξ» x _ β f x) (Ξ» x _ β g x) (π-cases f g p) (π-cases-redundant-equations f g p) π-at-most-one-cases : {A : π€ Μ } (f g : π β A) β π-caseable A f g β (h k : π β A) β case-equations f g h β case-equations f g k β h βΌ k π-at-most-one-cases f g ΞΉ = π-at-most-one-wprimrec (f Left) (g Right) (Ξ» x _ β f x) (Ξ» x _ β g x) (π-caseable-gives-pinductive _ f g ΞΉ) (u , v) where u : β a' β a' οΌ f Left β a' οΌ f Left u a' p = p v : β b' β b' οΌ g Right β b' οΌ g Right v a' p = p π-cases-uniqueness : {A : π€ Μ } (f g : π β A) β (p : π-caseable A f g) β (h : π β A) β case-equations f g h β h βΌ π-cases f g p π-cases-uniqueness f g p h he = π-at-most-one-cases f g p h (π-cases f g p) he (π-cases-equations f g p) π-cases-L : {A : π€ Μ } (f g : π β A) (p : π-caseable A f g) β π-cases f g p Left οΌ f Left π-cases-L f g p = prβ (π-cases-redundant-equations f g p) π-cases-R : {A : π€ Μ } (f g : π β A) (p : π-caseable A f g) β π-cases f g p Right οΌ g Right π-cases-R f g p = prβ (prβ (π-cases-redundant-equations f g p)) π-cases-l : {A : π€ Μ } (f g : π β A) (p : π-caseable A f g) β π-cases f g p β left βΌ f π-cases-l f g p = prβ (prβ (prβ ((π-cases-redundant-equations f g p)))) π-cases-r : {A : π€ Μ } (f g : π β A) (p : π-caseable A f g) β π-cases f g p β right βΌ g π-cases-r f g p = prβ (prβ (prβ ((π-cases-redundant-equations f g p)))) \end{code} We now specialize to A = π for notational convenience: \begin{code} ππ-caseable : (f g : π β π) β π€β Μ ππ-caseable f g = f Right οΌ g Left ππ-cases : (f g : π β π) β ππ-caseable f g β (π β π) ππ-cases f g p = π-cases f g (π-is-set , p) \end{code} Here are some examples: \begin{code} center : π β π center = ππ-cases (left β right) (right β left) refl center-l : (x : π) β center (left x) οΌ left (right x) center-l = π-cases-l _ _ (π-is-set , refl) center-r : (x : π) β center (right x) οΌ right (left x) center-r = π-cases-r _ _ (π-is-set , refl) left-by-cases : left βΌ ππ-cases (left β left) (center β left) refl left-by-cases = π-cases-uniqueness _ _ (π-is-set , refl) left ((Ξ» x β refl) , Ξ» x β (center-l x)β»ΒΉ) right-by-cases : right βΌ ππ-cases (center β right) (right β right) refl right-by-cases = π-cases-uniqueness _ _ (π-is-set , refl) right ((Ξ» x β (center-r x)β»ΒΉ) , (Ξ» x β refl)) \end{code} We now define the midpoint operation _β_ : π β (π β π) by initiality. We will work with a subset of the function type π β π and make it into a binary system. \begin{code} is-π-function : (π β π) β π€β Μ is-π-function f = ππ-caseable (left β f) (center β f) is-π‘-function : (π β π) β π€β Μ is-π‘-function f = ππ-caseable (center β f) (right β f) π : (f : π β π) β is-π-function f β (π β π) π f = ππ-cases (left β f) (center β f) π‘ : (f : π β π) β is-π‘-function f β (π β π) π‘ f = ππ-cases (center β f) (right β f) preservation-ππ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f) β is-π-function (π f π΅) preservation-ππ f π΅ π» = left (π f π΅ Right) οΌβ¨ ap left (π-cases-R (left β f) (center β f) (π-is-set , π΅)) β© left (center (f Right)) οΌβ¨ ap left π» β© left (right (f Left)) οΌβ¨ (center-l (f Left))β»ΒΉ β© center (left (f Left)) οΌβ¨ (ap center (π-cases-L (left β f) (center β f) (π-is-set , π΅)))β»ΒΉ β© center (π f π΅ Left) β preservation-ππ‘ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f) β is-π‘-function (π f π΅) preservation-ππ‘ f π΅ π» = center (π f π΅ Right) οΌβ¨ ap center (π-cases-R (left β f) (center β f) (π-is-set , π΅)) β© center (center (f Right)) οΌβ¨ ap center π» β© center (right (f Left)) οΌβ¨ center-r (f Left) β© right (left (f Left)) οΌβ¨ ap right ((π-cases-L (left β f) (center β f) (π-is-set , π΅))β»ΒΉ) β© right (π f π΅ Left) β preservation-π‘π : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f) β is-π-function (π‘ f π») preservation-π‘π f π΅ π» = left (π‘ f π» Right) οΌβ¨ ap left (π-cases-R (center β f) (right β f) (π-is-set , π»)) β© left (right (f Right)) οΌβ¨ (center-l (f Right))β»ΒΉ β© center (left (f Right)) οΌβ¨ ap center π΅ β© center (center (f Left)) οΌβ¨ ap center ((π-cases-L (center β f) (right β f) (π-is-set , π»))β»ΒΉ) β© center (π‘ f π» Left) β preservation-π‘π‘ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f) β is-π‘-function (π‘ f π») preservation-π‘π‘ f π΅ π» = center (π‘ f π» Right) οΌβ¨ ap center (π-cases-R (center β f) (right β f) (π-is-set , π»)) β© center (right (f Right)) οΌβ¨ π-cases-r (left β right) (right β left) (π-is-set , refl) (f Right) β© right (left (f Right)) οΌβ¨ ap right π΅ β© right (center (f Left)) οΌβ¨ ap right ((π-cases-L (center β f) (right β f) (π-is-set , π»))β»ΒΉ) β© right (π‘ f π» Left) β is-ππ‘-function : (π β π) β π€β Μ is-ππ‘-function f = is-π-function f Γ is-π‘-function f being-ππ‘-function-is-prop : (f : π β π) β is-prop (is-ππ‘-function f) being-ππ‘-function-is-prop f = Γ-is-prop π-is-set π-is-set \end{code} The desired subset of the function type π β π is this: \begin{code} F : π€β Μ F = Ξ£ f κ (π β π) , is-ππ‘-function f \end{code} We now need to assume function extensionality. \begin{code} open import UF.Base open import UF.FunExt module _ (fe : Fun-Ext) where F-is-set : is-set F F-is-set = subsets-of-sets-are-sets (π β π) is-ππ‘-function (Ξ -is-set fe (Ξ» _ β π-is-set)) (Ξ» {f} β being-ππ‘-function-is-prop f) ππππ‘ πππβπ‘ : F β F ππππ‘ (f , (π΅ , π»)) = π f π΅ , preservation-ππ f π΅ π» , preservation-ππ‘ f π΅ π» πππβπ‘ (f , (π΅ , π»)) = π‘ f π» , preservation-π‘π f π΅ π» , preservation-π‘π‘ f π΅ π» πΏπππ‘ π ππβπ‘ : F πΏπππ‘ = left , refl , refl π ππβπ‘ = right , refl , refl F-eq-l : πΏπππ‘ οΌ ππππ‘ πΏπππ‘ F-eq-l = to-subtype-οΌ being-ππ‘-function-is-prop Ξ³ where Ξ΄ : left βΌ π left refl Ξ΄ = left-by-cases Ξ³ : left οΌ π left refl Ξ³ = dfunext fe Ξ΄ F-eq-lr : ππππ‘ π ππβπ‘ οΌ πππβπ‘ πΏπππ‘ F-eq-lr = to-subtype-οΌ being-ππ‘-function-is-prop v where i = Ξ» (x : π) β ππ-cases (left β right) (center β right) refl (left x) οΌβ¨ π-cases-l _ _ (π-is-set , refl) x β© left (right x) οΌβ¨ (center-l x)β»ΒΉ β© center (left x) β ii = Ξ» (x : π) β ππ-cases (left β right) (center β right) refl (right x) οΌβ¨ π-cases-r _ _ (π-is-set , refl) x β© center (right x) οΌβ¨ center-r x β© right (left x) β iii : ππ-cases (left β right) (center β right) refl βΌ ππ-cases (center β left) (right β left) refl iii = π-cases-uniqueness _ _ (π-is-set , refl) (ππ-cases _ _ refl) (i , ii) iv : π right refl βΌ π‘ left refl iv = iii v : π right refl οΌ π‘ left refl v = dfunext fe iv F-eq-r : π ππβπ‘ οΌ πππβπ‘ π ππβπ‘ F-eq-r = to-subtype-οΌ being-ππ‘-function-is-prop Ξ³ where Ξ΄ : right βΌ π‘ right refl Ξ΄ = right-by-cases Ξ³ : right οΌ π‘ right refl Ξ³ = dfunext fe Ξ΄ π : BS π€β π = (F , (πΏπππ‘ , π ππβπ‘ , ππππ‘ , πππβπ‘) , (F-is-set , F-eq-l , F-eq-lr , F-eq-r)) mid : π β F mid = π-rec π _β_ : π β π β π x β y = prβ (mid x) y β-property : (x : π) β (left (x β Right) οΌ center (x β Left)) Γ (center (x β Right) οΌ right (x β Left)) β-property x = prβ (mid x) mid-is-hom : is-hom π π (π-rec π) mid-is-hom = π-rec-is-hom π mid-is-hom-L : mid Left οΌ πΏπππ‘ mid-is-hom-L = is-hom-L π π mid mid-is-hom mid-is-hom-L' : (y : π) β Left β y οΌ left y mid-is-hom-L' y = ap (Ξ» - β prβ - y) mid-is-hom-L mid-is-hom-R : mid Right οΌ π ππβπ‘ mid-is-hom-R = is-hom-R π π mid mid-is-hom mid-is-hom-R' : (y : π) β Right β y οΌ right y mid-is-hom-R' y = ap (Ξ» - β prβ - y) mid-is-hom-R mid-is-hom-l : (x : π) β mid (left x) οΌ ππππ‘ (mid x) mid-is-hom-l = is-hom-l π π mid mid-is-hom mid-is-hom-l' : (x y : π) β (left x β Left οΌ left (x β Left)) Γ (left x β Right οΌ center (x β Right)) Γ (left x β left y οΌ left (x β y)) Γ (left x β right y οΌ center (x β y)) mid-is-hom-l' x y = u , v , w , t where Ξ± = Ξ» y β left x β y οΌβ¨ refl β© prβ (mid (left x)) y οΌβ¨ happly (ap prβ (mid-is-hom-l x)) y β© prβ (ππππ‘ (mid x)) y οΌβ¨ refl β© ππ-cases (left β (x β_)) (center β (x β_)) (prβ (β-property x)) y β u = Ξ± Left β π-cases-L (left β (x β_)) (center β (x β_)) (π-is-set , prβ (β-property x)) v = Ξ± Right β π-cases-R (left β (x β_)) (center β (x β_)) (π-is-set , prβ (β-property x)) w = Ξ± (left y) β π-cases-l (left β (x β_)) (center β (x β_)) (π-is-set , prβ (β-property x)) y t = Ξ± (right y) β π-cases-r (left β (x β_)) (center β (x β_)) (π-is-set , prβ (β-property x)) y mid-is-hom-r : (x : π) β mid (right x) οΌ πππβπ‘ (mid x) mid-is-hom-r = is-hom-r π π mid mid-is-hom mid-is-hom-r' : (x y : π) β (right x β Right οΌ right (x β Right)) Γ (right x β Left οΌ center (x β Left)) Γ (right x β left y οΌ center (x β y)) Γ (right x β right y οΌ right (x β y)) mid-is-hom-r' x y = u , v , w , t where Ξ± = Ξ» y β right x β y οΌβ¨ refl β© prβ (mid (right x)) y οΌβ¨ happly (ap prβ (mid-is-hom-r x)) y β© prβ (πππβπ‘ (mid x)) y οΌβ¨ refl β© ππ-cases (center β (x β_)) (right β (x β_)) (prβ (β-property x)) y β u = Ξ± Right β π-cases-R (center β (x β_)) (right β (x β_)) (π-is-set , prβ (β-property x)) v = Ξ± Left β π-cases-L (center β (x β_)) (right β (x β_)) (π-is-set , prβ (β-property x)) w = Ξ± (left y) β π-cases-l (center β (x β_)) (right β (x β_)) (π-is-set , prβ (β-property x)) y t = Ξ± (right y) β π-cases-r (center β (x β_)) (right β (x β_)) (π-is-set , prβ (β-property x)) y \end{code} So, the set of defining equations is the following, where it can be seen that there is some redundancy: ( left (x β Right) οΌ center (x β Left) ) Γ ( center (x β Right) οΌ right (x β Left) ) Γ ( Left β y οΌ left y ) Γ ( Right β y οΌ right y ) Γ ( left x β Left οΌ left (x β Left) ) Γ ( left x β Right οΌ center (x β Right) ) Γ ( left x β left y οΌ left (x β y) ) Γ ( left x β right y οΌ center (x β y) ) Γ ( right x β Right οΌ right (x β Right) ) Γ ( right x β Left οΌ center (x β Left) ) Γ ( right x β left y οΌ center (x β y) ) Γ ( right x β right y οΌ right (x β y) ) The first two come from the binary system F and the remaining ones from the homomorphism condition and cases analysis. Next we want to show that _β_ : π β π β π makes the initial binary system into the free midpoint algebra over two generators (taken to be Left and Right, as expected), where the midpoint axioms are (idempotency) x β x οΌ x, (commutativity) x β y οΌ y β x, (transposition) (u β v) β (x β y) οΌ (u β x) β (v β y). In fact, in the initial binary system, there is a unique midpoint operation _β_ such that L β x = left x, R β x = right x. To be continued.