Martin Escardo, 7th August 2020.
This file improves the file InitialBinarySystem.lagda, which gives the
background for this file.
\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 : π
Ξ· : πΉ β π
C : π
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
open import UF.Subsingletons hiding (center)
π-inductive : (P : π β π€ Μ )
β P L
β P R
β ((x : π) β P x β P (l x))
β ((x : π) β P x β P (r x))
β π€ Μ
π-inductive P a b f g = ((x : π) β is-set (P x))
Γ (a οΌ f L a)
Γ (f R b οΌ g L a)
Γ (b οΌ g R b)
π-induction : (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 : π) β P x
π-induction P a b f g ΞΉ L = a
π-induction P a b f g ΞΉ R = b
π-induction P a b f g ΞΉ (Ξ· center) = 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}
In MLTT, induction principles come with equations. In our case they
are the expected ones.
\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)
β π-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β (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β (prβ ΞΉ))
π-induction-r P a b f g ΞΉ R = prβ (prβ (prβ ΞΉ))
π-induction-r P a b f g ΞΉ (Ξ· x) = refl
\end{code}
\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
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 π€β
π = (π , (L , R , l , r) , (π-is-set , π-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) ((Ξ» _ β prβ ΞΉ) , prβ ΞΉ)
iv : (x : π) β π-rec π (r x) οΌ g (π-rec π x)
iv = π-induction-r (Ξ» _ β A) a b (Ξ» _ β f) (Ξ» _ β g) ((Ξ» _ β prβ ΞΉ) , prβ ΞΉ)
\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-set : (π : BS π€) β is-set β¨ π β©
β¨ (A , (a , b , f , g) , ΞΉ) β©-is-set = prβ ΞΉ
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) Ξ± Ξ² Ο Ξ³
((Ξ» x β props-are-sets β¨ π β©-is-set) ,
eql , eqlr , eqr)
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) β
eql : Ξ± οΌ Ο L Ξ±
eql = β¨ π β©-is-set Ξ± (Ο L Ξ±)
eqlr : Ο R Ξ² οΌ Ξ³ L Ξ±
eqlr = β¨ π β©-is-set (Ο R Ξ²) (Ξ³ L Ξ±)
eqr : Ξ² οΌ Ξ³ R Ξ²
eqr = β¨ π β©-is-set Ξ² (Ξ³ R Ξ²)
π-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 L οΌ a)
Γ (h R οΌ b)
Γ ((x : π) β h (l x) οΌ f x (h x))
Γ ((x : π) β h (r 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 ΞΉ =
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
arbitrary-element-of-π = L
A-is-set : is-set A
A-is-set = ΞΉβ arbitrary-element-of-π
Ξ± = 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) β
set-condition : (x : π) β is-set (h x οΌ k x)
set-condition x = props-are-sets A-is-set
eql : Ξ± οΌ Ο L Ξ±
eql = A-is-set Ξ± (Ο L Ξ±)
eqlr : Ο R Ξ² οΌ Ξ³ L Ξ±
eqlr = A-is-set (Ο R Ξ²) (Ξ³ L Ξ±)
eqr : Ξ² οΌ Ξ³ R Ξ²
eqr = A-is-set Ξ² (Ξ³ R Ξ²)
Ξ΄ : 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 (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 (2) hold, we are left
with condition (3) 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 (3)
and work with the equations
h (l x) = f x,
h (r 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 = l and g = r. 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 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 (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 L) (g R) (Ξ» x _ β f x) (Ξ» x _ β g x) (π-caseable-gives-pinductive _ f g ΞΉ)
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}
We now specialize to A = π for notational convenience:
\begin{code}
ππ-caseable : (f g : π β π) β π€β Μ
ππ-caseable f g = f R οΌ g L
ππ-cases : (f g : π β π) β ππ-caseable f g β (π β π)
ππ-cases f g p = π-cases f g (π-is-set , p)
\end{code}
Here are some examples:
\begin{code}
middle : π β π
middle = ππ-cases (l β r) (r β l) refl
middle-L : middle L οΌ l C
middle-L = refl
middle-R : middle R οΌ r C
middle-R = refl
middle-l : (x : π) β middle (l x) οΌ l (r x)
middle-l = π-cases-l _ _ (π-is-set , refl)
middle-r : (x : π) β middle (r x) οΌ r (l x)
middle-r = π-cases-r _ _ (π-is-set , refl)
l-by-cases : l βΌ ππ-cases (l β l) (middle β l) refl
l-by-cases = π-cases-uniqueness _ _
(π-is-set , refl) l ((Ξ» x β refl) , Ξ» x β (middle-l x)β»ΒΉ)
r-by-cases : r βΌ ππ-cases (middle β r) (r β r) refl
r-by-cases = π-cases-uniqueness _ _
(π-is-set , refl) r ((Ξ» x β (middle-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) (middle β f)
is-π‘-function : (π β π) β π€β Μ
is-π‘-function f = ππ-caseable (middle β f) (r β f)
π : (f : π β π) β is-π-function f β (π β π)
π f = ππ-cases (l β f) (middle β f)
π‘ : (f : π β π) β is-π‘-function f β (π β π)
π‘ f = ππ-cases (middle β f) (r β f)
preservation-ππ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f) β is-π-function (π f π΅)
preservation-ππ f π΅ π» =
l (π f π΅ R) οΌβ¨ refl β©
l (middle (f R)) οΌβ¨ ap l π» β©
l (r (f L)) οΌβ¨ (middle-l (f L))β»ΒΉ β©
middle (l (f L)) οΌβ¨ refl β©
middle (π f π΅ L) β
preservation-ππ‘ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f) β is-π‘-function (π f π΅)
preservation-ππ‘ f π΅ π» =
middle (π f π΅ R) οΌβ¨ refl β©
middle (middle (f R)) οΌβ¨ ap middle π» β©
middle (r (f L)) οΌβ¨ middle-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)) οΌβ¨ (middle-l (f R))β»ΒΉ β©
middle (l (f R)) οΌβ¨ ap middle π΅ β©
middle (middle (f L)) οΌβ¨ refl β©
middle (π‘ f π» L) β
preservation-π‘π‘ : (f : π β π) (π΅ : is-π-function f) (π» : is-π‘-function f) β is-π‘-function (π‘ f π»)
preservation-π‘π‘ f π΅ π» =
middle (π‘ f π» R) οΌβ¨ refl β©
middle (r (f R)) οΌβ¨ π-cases-r (l β r) (r β l) (π-is-set , refl) (f R) β©
r (l (f R)) οΌβ¨ ap r π΅ β©
r (middle (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.
\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) (middle β r) refl (l x) οΌβ¨ π-cases-l _ _ (π-is-set , refl) x β©
l (r x) οΌβ¨ (middle-l x)β»ΒΉ β©
middle (l x) β
ii = Ξ» (x : π) β ππ-cases (l β r) (middle β r) refl (r x) οΌβ¨ π-cases-r _ _ (π-is-set , refl) x β©
middle (r x) οΌβ¨ middle-r x β©
r (l x) β
iii : ππ-cases (l β r) (middle β r) refl
βΌ ππ-cases (middle β l) (r β l) refl
iii = π-cases-uniqueness _ _ (π-is-set , 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-is-set , F-eq-l , F-eq-lr , F-eq-r))
mid : π β F
mid = π-rec π
_β_ : π β π β π
x β y = prβ (mid x) y
β-property : (x : π)
β (l (x β R) οΌ middle (x β L))
Γ (middle (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 οΌ middle (x β R))
Γ (l x β l y οΌ l (x β y))
Γ (l x β r y οΌ middle (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 β_)) (middle β (x β_)) (prβ (β-property x)) y β
u = Ξ± L
v = Ξ± R
w = Ξ± (l y) β π-cases-l (l β (x β_)) (middle β (x β_)) (π-is-set , prβ (β-property x)) y
t = Ξ± (r y) β π-cases-r (l β (x β_)) (middle β (x β_)) (π-is-set , 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 οΌ middle (x β L))
Γ (r x β R οΌ r (x β R))
Γ (r x β l y οΌ middle (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 (middle β (x β_)) (r β (x β_)) (prβ (β-property x)) y β
u = Ξ± L
v = Ξ± R
w = Ξ± (l y) β π-cases-l (middle β (x β_)) (r β (x β_)) (π-is-set , prβ (β-property x)) y
t = Ξ± (r y) β π-cases-r (middle β (x β_)) (r β (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:
( l (x β R) οΌ middle (x β L) )
Γ ( middle (x β R) οΌ r (x β L) )
Γ ( L β y οΌ l y )
Γ ( R β y οΌ r y )
Γ ( l x β L οΌ l (x β L) )
Γ ( l x β R οΌ middle (x β R) )
Γ ( l x β l y οΌ l (x β y) )
Γ ( l x β r y οΌ middle (x β y) )
Γ ( r x β R οΌ r (x β R) )
Γ ( r x β L οΌ middle (x β L) )
Γ ( r x β l y οΌ middle (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 cases analysis.
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.
To be continued.