Martin Escardo, 7th August 2020.
This file improves the file InitialBinarySystem.lagda, which gives the
background for this file.
Modified 2nd May 2025 to remove the requirement that the underlying
types of binary systems are sets, and also to removed some unused
hypotheses. But it is still the case that the initial binary system is
a set.
\begin{code}
{-# OPTIONS --safe --without-K #-}
module BinarySystems.InitialBinarySystem2 where
open import MLTT.Spartan
open import UF.DiscreteAndSeparated
open import UF.Sets
open import UF.Sets-Properties
open import UF.Subsingletons-Properties
data πΉ : π€β Μ where
center : πΉ
left : πΉ β πΉ
right : πΉ β πΉ
data π : π€β Μ where
L : π
R : π
Ξ· : πΉ β π
pattern C = Ξ· center
l : π β π
l L = L
l R = C
l (Ξ· x) = Ξ· (left x)
r : π β π
r L = C
r R = R
r (Ξ· x) = Ξ· (right x)
π-eq-l : L οΌ l L
π-eq-l = refl
π-eq-r : R οΌ r R
π-eq-r = refl
π-eq-lr : l R οΌ r L
π-eq-lr = refl
\end{code}
We now show that π is a set.
\begin{code}
left-lc : (x y : πΉ) β left x οΌ left y β x οΌ y
left-lc x x refl = refl
right-lc : (x y : πΉ) β right x οΌ right y β x οΌ y
right-lc x x refl = refl
πΉ-is-discrete : (x y : πΉ) β (x οΌ y) + (x β y)
πΉ-is-discrete center center = inl refl
πΉ-is-discrete center (left y) = inr (Ξ» ())
πΉ-is-discrete center (right y) = inr (Ξ» ())
πΉ-is-discrete (left x) center = inr (Ξ» ())
πΉ-is-discrete (left x) (left y) =
Cases (πΉ-is-discrete x y)
(Ξ» (p : x οΌ y) β inl (ap left p))
(Ξ» (Ξ½ : x β y) β inr (contrapositive (left-lc x y) Ξ½))
πΉ-is-discrete (left x) (right y) = inr (Ξ» ())
πΉ-is-discrete (right x) center = inr (Ξ» ())
πΉ-is-discrete (right x) (left y) = inr (Ξ» ())
πΉ-is-discrete (right x) (right y) =
Cases (πΉ-is-discrete x y)
(Ξ» (p : x οΌ y) β inl (ap right p))
(Ξ» (Ξ½ : x β y) β inr (contrapositive (right-lc x y) Ξ½))
Ξ·-lc : (x y : πΉ) β Ξ· x οΌ Ξ· y β x οΌ y
Ξ·-lc x x refl = refl
π-is-discrete : (x y : π) β (x οΌ y) + (x β y)
π-is-discrete L L = inl refl
π-is-discrete L R = inr (Ξ» ())
π-is-discrete L (Ξ· x) = inr (Ξ» ())
π-is-discrete R L = inr (Ξ» ())
π-is-discrete R R = inl refl
π-is-discrete R (Ξ· x) = inr (Ξ» ())
π-is-discrete (Ξ· x) L = inr (Ξ» ())
π-is-discrete (Ξ· x) R = inr (Ξ» ())
π-is-discrete (Ξ· x) (Ξ· y) = Cases (πΉ-is-discrete x y)
(Ξ» (p : x οΌ y) β inl (ap Ξ· p))
(Ξ» (Ξ½ : x β y) β inr (contrapositive (Ξ·-lc x y) Ξ½))
π-is-set : is-set π
π-is-set = discrete-types-are-sets π-is-discrete
\end{code}
It turns out that we don't need to know that π is a set. But it is
interesting to know that the initial binary system is a set, even
though we don't require the underlying types of binary systems to be
sets.
We now prove a general induction principle for π and a particular case
of interest.
\begin{code}
open import UF.Subsingletons hiding (center)
π-induction : (P : π β π€ Μ )
β (a : P L)
β (b : P R)
β (f : (x : π) β P x β P (l x))
β (g : (x : π) β P x β P (r x))
β (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 C = f R b
π-induction P a b f g (Ξ· (left x)) = f (Ξ· x) (π-induction P a b f g (Ξ· x))
π-induction P a b f g (Ξ· (right x)) = g (Ξ· x) (π-induction P a b f g (Ξ· x))
\end{code}
(*) Alternatively, here we can take g L a, but then the proofs below
change.
In MLTT, induction principles come with equations. In our case they
are the expected ones.
\begin{code}
π-inductive : (P : π β π€ Μ )
β P L
β P R
β ((x : π) β P x β P (l x))
β ((x : π) β P x β P (r x))
β π€ Μ
π-inductive P a b f g = (a οΌ f L a)
Γ (f R b οΌ g L a)
Γ (b οΌ g R b)
π-induction-L
: (P : π β π€ Μ )
(a : P L)
(b : P R)
(f : (x : π) β P x β P (l x))
(g : (x : π) β P x β P (r x))
(ΞΉ : π-inductive P a b f g)
β π-induction P a b f g L οΌ a
π-induction-L P a b f g _ = refl
π-induction-R
: (P : π β π€ Μ )
(a : P L)
(b : P R)
(f : (x : π) β P x β P (l x))
(g : (x : π) β P x β P (r x))
(ΞΉ : π-inductive P a b f g)
β π-induction P a b f g R οΌ b
π-induction-R P a b f g _ = refl
\end{code}
For the next equation for the induction principle, we need the
assumption a οΌ f L a:
\begin{code}
π-induction-l
: (P : π β π€ Μ )
(a : P L)
(b : P R)
(f : (x : π) β P x β P (l x))
(g : (x : π) β P x β P (r x))
β (ΞΉ : π-inductive P a b f g)
β (x : π) β π-induction P a b f g (l x) οΌ f x (π-induction P a b f g x)
π-induction-l P a b f g ΞΉ L = prβ ΞΉ
π-induction-l P a b f g ΞΉ R = refl
π-induction-l P a b f g ΞΉ (Ξ· x) = refl
\end{code}
And for the last equation for the induction principle, we need the two
equations f R b οΌ g L a and b οΌ g R b as assumptions:
\begin{code}
π-induction-r
: (P : π β π€ Μ )
(a : P L)
(b : P R)
(f : (x : π) β P x β P (l x))
(g : (x : π) β P x β P (r x))
β (ΞΉ : π-inductive P a b f g)
β (x : π) β π-induction P a b f g (r x) οΌ g x (π-induction P a b f g x)
π-induction-r P a b f g ΞΉ L = prβ (prβ ΞΉ)
π-induction-r P a b f g ΞΉ R = prβ (prβ ΞΉ)
π-induction-r P a b f g ΞΉ (Ξ· x) = refl
\end{code}
We now give π the structure of a 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) = (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 π€β
π = (π , (L , R , l , r) , (π-eq-l , π-eq-lr , π-eq-r))
open import UF.SIP
open sip
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}
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 π L οΌ a
i = refl
ii : π-rec π R οΌ b
ii = refl
iii : (x : π) β π-rec π (l x) οΌ f (π-rec π x)
iii = π-induction-l (Ξ» _ β A) a b (Ξ» _ β f) (Ξ» _ β g) ΞΉ
iv : (x : π) β π-rec π (r x) οΌ g (π-rec π x)
iv = π-induction-r (Ξ» _ β A) a b (Ξ» _ β f) (Ξ» _ β g) ΞΉ
\end{code}
Some boiler plate code to name the projections follows:
\begin{code}
β¨_β©-L : (π : BS π€) β β¨ π β©
β¨ (A , (a , b , f , g) , ΞΉ) β©-L = a
β¨_β©-R : (π : BS π€) β β¨ π β©
β¨ (A , (a , b , f , g) , ΞΉ) β©-R = b
β¨_β©-l : (π : BS π€) β β¨ π β© β β¨ π β©
β¨ (A , (a , b , f , g) , ΞΉ) β©-l = f
β¨_β©-r : (π : BS π€) β β¨ π β© β β¨ π β©
β¨ (A , (a , b , f , g) , ΞΉ) β©-r = g
is-hom-L : (π : BS π€) (π : BS π₯) (h : β¨ π β© β β¨ π β©)
β is-hom π π h β h (β¨ π β©-L) οΌ β¨ π β©-L
is-hom-L π π h (i , ii , iii , iv) = i
is-hom-R : (π : BS π€) (π : BS π₯) (h : β¨ π β© β β¨ π β©)
β is-hom π π h β h (β¨ π β©-R) οΌ β¨ π β©-R
is-hom-R π π h (i , ii , iii , iv) = ii
is-hom-l : (π : BS π€) (π : BS π₯) (h : β¨ π β© β β¨ π β©)
β is-hom π π h β h β β¨ π β©-l βΌ β¨ π β©-l β h
is-hom-l π π h (i , ii , iii , iv) = iii
is-hom-r : (π : BS π€) (π : BS π₯) (h : β¨ π β© β β¨ π β©)
β is-hom π π h β h β β¨ π β©-r βΌ β¨ π β©-r β 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) Ξ± Ξ² Ο Ξ³
where
Ξ± = h L οΌβ¨ is-hom-L π π h u β©
β¨ π β©-L οΌβ¨ (is-hom-L π π k v)β»ΒΉ β©
k L β
Ξ² = h R οΌβ¨ is-hom-R π π h u β©
β¨ π β©-R οΌβ¨ (is-hom-R π π k v)β»ΒΉ β©
k R β
Ο : (x : π) β h x οΌ k x β h (l x) οΌ k (l x)
Ο x p = h (l x) οΌβ¨ is-hom-l π π h u x β©
β¨ π β©-l (h x) οΌβ¨ ap β¨ π β©-l p β©
β¨ π β©-l (k x) οΌβ¨ (is-hom-l π π k v x)β»ΒΉ β©
k (l x) β
Ξ³ : (x : π) β h x οΌ k x β h (r x) οΌ k (r x)
Ξ³ x p = h (r x) οΌβ¨ is-hom-r π π h u x β©
β¨ π β©-r (h x) οΌβ¨ ap β¨ π β©-r p β©
β¨ π β©-r (k x) οΌβ¨ (is-hom-r π π k v x)β»ΒΉ β©
k (r 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}
TODO. Now that we have removed the sethood requirement for the
underlying type of a binary system we need to prove unique existence
as contractibility (as done for nno's in the MGS'2019 lecture notes).
Primitive (or parametric) recursion, which has the above as a special
case:
\begin{code}
π-primrec : {A : π€ Μ } (a b : A) (f g : π β A β A) β π β A
π-primrec {π€} {A} a b f = π-induction (Ξ» _ β A) a b f
primitive-recursive : {A : π€ Μ } β A β A β (π β A β A) β (π β A β A) β (π β A) β π€ Μ
primitive-recursive a b f g h =
(h L οΌ a)
Γ (h R οΌ b)
Γ ((x : π) β h (l x) οΌ f x (h x))
Γ ((x : π) β h (r x) οΌ g x (h x))
π-pinductive : {A : π€ Μ } β A β A β (π β A β A) β (π β A β A) β π€ Μ
π-pinductive {π€} {A} a b f g = π-inductive (Ξ» _ β A) a b f g
π-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 ΞΉ =
refl ,
refl ,
π-induction-l (Ξ» _ β A) a b f g ΞΉ ,
π-induction-r (Ξ» _ β 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
Ξ± = h L οΌβ¨ hL β©
a οΌβ¨ kL β»ΒΉ β©
k L β
Ξ² = h R οΌβ¨ hR β©
b οΌβ¨ kR β»ΒΉ β©
k R β
Ο : (x : π) β h x οΌ k x β h (l x) οΌ k (l x)
Ο x p = h (l x) οΌβ¨ hl x β©
f x (h x) οΌβ¨ ap (f x) p β©
f x (k x) οΌβ¨ (kl x)β»ΒΉ β©
k (l x) β
Ξ³ : (x : π) β h x οΌ k x β h (r x) οΌ k (r x)
Ξ³ x p = h (r x) οΌβ¨ hr x β©
g x (h x) οΌβ¨ ap (g x) p β©
g x (k x) οΌβ¨ (kr x)β»ΒΉ β©
k (r x) β
Ξ΄ : h βΌ k
Ξ΄ = π-induction (Ξ» x β h x οΌ k x) Ξ± Ξ² Ο Ξ³
π-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 (l x) οΌ f x (h x))
Γ ((x : π) β h (r 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 L a' β a' οΌ a)
Γ (β b' β b' οΌ g R 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 L οΌβ¨ refl β©
h (l L) οΌβ¨ hl L β©
f L (h L) β
hL = h L οΌβ¨ fixa (h L) hL' β©
a β
hR : h R οΌ b
hR = fixb (h R) (hr R)
π-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 L = a
h R = b
h (l x) = f x
h (r x) = g x
For this to be well defined we need the following endpoint agreement
conditions:
(1) a οΌ f L,
(2) f R οΌ g L,
(3) b οΌ g R.
If we take a = f L and b = g L, so that (1) and (3) hold, we are left
with condition (2) as the only assumption, and the condition on h
becomes
h L = f L,
h R = g R,
h (l x) = f x,
h (r x) = g x.
But also the first two equations follow from the second two, since
h L = h (l L) = f L,
h R = h (r R) = g r.
Hence it is enough to consider the endpoint agreement condition (2)
and work with the equations
h (l x) = f x,
h (r x) = g x.
Hence the function π-cases defined belowgives 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 = l and g = r.
The following constructions and facts are all particular cases of
those for π-primrec.
\begin{code}
π-caseable : (A : π€ Μ ) β (π β A) β (π β A) β π€ Μ
π-caseable A f g = (f R οΌ g L)
π-caseable-gives-pinductive
: (A : π€ Μ )
(f g : π β A)
β π-caseable A f g
β π-pinductive (f L) (g R) (Ξ» x _ β f x) (Ξ» x _ β g x)
π-caseable-gives-pinductive A f g p
= refl , p , refl
π-cases : {A : π€ Μ } (f g : π β A) β π-caseable A f g β π β A
π-cases f g ΞΉ = π-primrec (f L) (g R) (Ξ» x _ β f x) (Ξ» x _ β g x)
case-equations : {A : π€ Μ } β (π β A) β (π β A) β (π β A) β π€ Μ
case-equations f g h = (h β l βΌ f)
Γ (h β r βΌ g)
π-cases-redundant-equations
: {A : π€ Μ }
(f g : π β A)
β (p : π-caseable A f g)
β (π-cases f g p L οΌ f L)
Γ (π-cases f g p R οΌ g R)
Γ (π-cases f g p β l βΌ f)
Γ (π-cases f g p β r βΌ g)
π-cases-redundant-equations f g ΞΉ
= π-primrec-primitive-recursive
(f L) (g R)
(Ξ» 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 L) (g R)
(Ξ» 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 L) (g R)
(Ξ» x _ β f x) (Ξ» x _ β g x)
(π-caseable-gives-pinductive _ f g ΞΉ)
(u , v)
where
u : β a' β a' οΌ f L β a' οΌ f L
u a' p = p
v : β b' β b' οΌ g R β b' οΌ g R
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 L οΌ f L
π-cases-L f g p = refl
π-cases-R : {A : π€ Μ } (f g : π β A) (p : π-caseable A f g)
β π-cases f g p R οΌ g R
π-cases-R f g p = refl
π-cases-l : {A : π€ Μ } (f g : π β A) (p : π-caseable A f g)
β π-cases f g p β l βΌ f
π-cases-l f g p = prβ (π-cases-equations f g p)
π-cases-r : {A : π€ Μ } (f g : π β A) (p : π-caseable A f g)
β π-cases f g p β r βΌ g
π-cases-r f g p = prβ (π-cases-equations f g p)
\end{code}
Here are some examples:
\begin{code}
m : π β π
m = π-cases (l β r) (r β l) refl
m-L : m L οΌ l C
m-L = refl
m-R : m R οΌ r C
m-R = refl
m-l : (x : π) β m (l x) οΌ l (r x)
m-l = π-cases-l _ _ refl
m-r : (x : π) β m (r x) οΌ r (l x)
m-r = π-cases-r _ _ refl
l-by-cases : l βΌ π-cases (l β l) (m β l) refl
l-by-cases = π-cases-uniqueness _ _
refl l ((Ξ» x β refl) , Ξ» x β (m-l x)β»ΒΉ)
r-by-cases : r βΌ π-cases (m β r) (r β r) refl
r-by-cases = π-cases-uniqueness _ _
refl r ((Ξ» x β (m-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 π (l β f) (m β f)
is-π‘-function : (π β π) β π€β Μ
is-π‘-function f = π-caseable π (m β f) (r β f)
π : (f : π β π) β is-π-function f β (π β π)
π f = π-cases (l β f) (m β f)
π‘ : (f : π β π) β is-π‘-function f β (π β π)
π‘ f = π-cases (m β f) (r β f)
preservation-ππ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f)
β is-π-function (π f π΅)
preservation-ππ f π΅ π» =
l (π f π΅ R) οΌβ¨ refl β©
l (m (f R)) οΌβ¨ ap l π» β©
l (r (f L)) οΌβ¨ (m-l (f L))β»ΒΉ β©
m (l (f L)) οΌβ¨ refl β©
m (π f π΅ L) β
preservation-ππ‘ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f)
β is-π‘-function (π f π΅)
preservation-ππ‘ f π΅ π» =
m (π f π΅ R) οΌβ¨ refl β©
m (m (f R)) οΌβ¨ ap m π» β©
m (r (f L)) οΌβ¨ m-r (f L) β©
r (l (f L)) οΌβ¨ refl β©
r (π f π΅ L) β
preservation-π‘π : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f)
β is-π-function (π‘ f π»)
preservation-π‘π f π΅ π» =
l (π‘ f π» R) οΌβ¨ refl β©
l (r (f R)) οΌβ¨ (m-l (f R))β»ΒΉ β©
m (l (f R)) οΌβ¨ ap m π΅ β©
m (m (f L)) οΌβ¨ refl β©
m (π‘ f π» L) β
preservation-π‘π‘ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f)
β is-π‘-function (π‘ f π»)
preservation-π‘π‘ f π΅ π» =
m (π‘ f π» R) οΌβ¨ refl β©
m (r (f R)) οΌβ¨ π-cases-r (l β r) (r β l) refl (f R) β©
r (l (f R)) οΌβ¨ ap r π΅ β©
r (m (f L)) οΌβ¨ refl β©
r (π‘ f π» L) β
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.
(NB. We no longer need to know that F is a set, but we keep the
original proof.)
\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
πΏπππ‘ = l , refl , refl
π
ππβπ‘ = r , refl , refl
F-eq-l : πΏπππ‘ οΌ ππππ‘ πΏπππ‘
F-eq-l = to-subtype-οΌ being-ππ‘-function-is-prop Ξ³
where
Ξ΄ : l βΌ π l refl
Ξ΄ = l-by-cases
Ξ³ : l οΌ π l refl
Ξ³ = dfunext fe Ξ΄
F-eq-lr : ππππ‘ π
ππβπ‘ οΌ πππβπ‘ πΏπππ‘
F-eq-lr = to-subtype-οΌ being-ππ‘-function-is-prop v
where
i = Ξ» (x : π) β
π-cases (l β r) (m β r) refl (l x) οΌβ¨ π-cases-l _ _ refl x β©
l (r x) οΌβ¨ (m-l x)β»ΒΉ β©
m (l x) β
ii = Ξ» (x : π) β
π-cases (l β r) (m β r) refl (r x) οΌβ¨ π-cases-r _ _ refl x β©
m (r x) οΌβ¨ m-r x β©
r (l x) β
iii : π-cases (l β r) (m β r) refl
βΌ π-cases (m β l) (r β l) refl
iii = π-cases-uniqueness _ _ refl (π-cases _ _ refl) (i , ii)
iv : π r refl βΌ π‘ l refl
iv = iii
v : π r refl οΌ π‘ l refl
v = dfunext fe iv
F-eq-r : π
ππβπ‘ οΌ πππβπ‘ π
ππβπ‘
F-eq-r = to-subtype-οΌ being-ππ‘-function-is-prop Ξ³
where
Ξ΄ : r βΌ π‘ r refl
Ξ΄ = r-by-cases
Ξ³ : r οΌ π‘ r refl
Ξ³ = dfunext fe Ξ΄
π : BS π€β
π = (F , (πΏπππ‘ , π
ππβπ‘ , ππππ‘ , πππβπ‘) , (F-eq-l , F-eq-lr , F-eq-r))
mid : π β F
mid = π-rec π
_β_ : π β π β π
x β y = prβ (mid x) y
β-property : (x : π)
β (l (x β R) οΌ m (x β L))
Γ (m (x β R) οΌ r (x β L))
β-property x = prβ (mid x)
mid-is-hom : is-hom π π (π-rec π)
mid-is-hom = π-rec-is-hom π
mid-is-hom-L : mid L οΌ πΏπππ‘
mid-is-hom-L = refl
mid-is-hom-L' : (y : π) β L β y οΌ l y
mid-is-hom-L' y = refl
mid-is-hom-R : mid R οΌ π
ππβπ‘
mid-is-hom-R = refl
mid-is-hom-R' : (y : π) β R β y οΌ r y
mid-is-hom-R' y = refl
mid-is-hom-l : (x : π) β mid (l x) οΌ ππππ‘ (mid x)
mid-is-hom-l = is-hom-l π π mid mid-is-hom
mid-is-hom-l' : (x y : π)
β (l x β L οΌ l (x β L))
Γ (l x β R οΌ m (x β R))
Γ (l x β l y οΌ l (x β y))
Γ (l x β r y οΌ m (x β y))
mid-is-hom-l' x y = u , v , w , t
where
Ξ± = Ξ» y β l x β y οΌβ¨ refl β©
prβ (mid (l x)) y οΌβ¨ happly (ap prβ (mid-is-hom-l x)) y β©
prβ (ππππ‘ (mid x)) y οΌβ¨ refl β©
π-cases (l β (x β_)) (m β (x β_)) (prβ (β-property x)) y β
u = Ξ± L
v = Ξ± R
w = Ξ± (l y) β π-cases-l
(l β (x β_))
(m β (x β_))
(prβ (β-property x))
y
t = Ξ± (r y) β π-cases-r
(l β (x β_))
(m β (x β_))
(prβ (β-property x))
y
mid-is-hom-r : (x : π) β mid (r x) οΌ πππβπ‘ (mid x)
mid-is-hom-r = is-hom-r π π mid mid-is-hom
mid-is-hom-r' : (x y : π)
β (r x β L οΌ m (x β L))
Γ (r x β R οΌ r (x β R))
Γ (r x β l y οΌ m (x β y))
Γ (r x β r y οΌ r (x β y))
mid-is-hom-r' x y = u , v , w , t
where
Ξ± = Ξ» y β r x β y οΌβ¨ refl β©
prβ (mid (r x)) y οΌβ¨ happly (ap prβ (mid-is-hom-r x)) y β©
prβ (πππβπ‘ (mid x)) y οΌβ¨ refl β©
π-cases (m β (x β_)) (r β (x β_)) (prβ (β-property x)) y β
u = Ξ± L
v = Ξ± R
w = Ξ± (l y) β π-cases-l
(m β (x β_))
(r β (x β_))
(prβ (β-property x))
y
t = Ξ± (r y) β π-cases-r
(m β (x β_))
(r β (x β_))
(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:
( l (x β R) οΌ m (x β L) )
Γ ( m (x β R) οΌ r (x β L) )
Γ ( L β y οΌ l y )
Γ ( R β y οΌ r y )
Γ ( l x β L οΌ l (x β L) )
Γ ( l x β R οΌ m (x β R) )
Γ ( l x β l y οΌ l (x β y) )
Γ ( l x β r y οΌ m (x β y) )
Γ ( r x β R οΌ r (x β R) )
Γ ( r x β L οΌ m (x β L) )
Γ ( r x β l y οΌ m (x β y) )
Γ ( r x β r y οΌ r (x β y) )
The first two come from the binary system F and the remaining ones from the homomorphism condition and case analysis.
TODO. Next we want to show that
_β_ : π β π β π
makes the initial binary system into the free midpoint algebra over
two generators (taken to be L and R, 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 = l x,
R β x = r x.