Todd Waugh Ambridge, 27th April 2020.
We formalize, in univalent mathematics in Agda, some definitions in
M.H. Escardo and A. Simpson. A universal characterization of the
closed Euclidean interval (extended abstract). Proceedings of the 16th
Annual IEEE Symposium on Logic in Computer Science,
pp.115--125. Boston, Massachusetts, June 16-19, 2001.
https://www.cs.bham.ac.uk/~mhe/papers/lics2001-revised.pdf
https://www.cs.bham.ac.uk/~mhe/papers/interval.pdf
https://www.cs.bham.ac.uk/~mhe/.talks/map2011/
\begin{code}
{-# OPTIONS --safe --without-K #-}
open import UF.FunExt
module TWA.Escardo-Simpson-LICS2001 (fe : FunExt) where
open import MLTT.Spartan
open import Naturals.Addition renaming (_+_ to _+β_)
open import Naturals.Sequence fe
open import UF.Sets
open import UF.Subsingletons public
\end{code}
First we give basic properties on binary functions,
as well as a specific property about equality of streams under some arithmetic.
\begin{code}
idempotent transpositional : {X : π€ Μ } β (X β X β X) β π€ Μ
idempotent _β_ = β a β a β a οΌ a
transpositional _β_ = β a b c d β (a β b) β (c β d) οΌ (a β c) β (b β d)
seq-add-push : {A : π€ Μ } (Ξ± : β β A) (n : β)
β (Ξ» (i : β) β Ξ± (succ i +β n)) οΌ (Ξ» (i : β) β Ξ± (succ (i +β n)))
seq-add-push Ξ± 0 = refl
seq-add-push Ξ± (succ n) = seq-add-push (Ξ± β succ) n
\end{code}
The initial structure we define is a Midpoint-algebra.
\begin{code}
midpoint-algebra-axioms : (A : π€ Μ ) β (A β A β A) β π€ Μ
midpoint-algebra-axioms {π€} A _β_ = is-set A
Γ idempotent _β_ Γ commutative _β_ Γ transpositional _β_
Midpoint-algebra : (π€ : Universe) β π€ βΊ Μ
Midpoint-algebra π€ = Ξ£ A κ π€ Μ , Ξ£ _β_ κ (A β A β A) , (midpoint-algebra-axioms A _β_)
\end{code}
We introduce two more properties on binary functions: cancellation and iteration.
For a particular type, the iterator is unique.
\begin{code}
cancellative : {X : π€ Μ } β (X β X β X) β π€ Μ
cancellative _β_ = β a b c β a β c οΌ b β c β a οΌ b
iterative : {A : π€ Μ } β (A β A β A) β π€ Μ
iterative {π€} {A} _β_ = Ξ£ M κ ((β β A) β A) , ((a : β β A) β M a οΌ a 0 β M (tail a))
Γ ((a x : β β A)
β ((i : β) β a i οΌ x i β a (succ i))
β a 0 οΌ M x)
iterative-uniquenessΒ· : {A : π€ Μ } β (_β_ : A β A β A)
β (F M : iterative _β_)
β prβ F βΌ prβ M
iterative-uniquenessΒ· {π€} {π} _β_ (F , pβ , qβ) (M , pβ , qβ) x = qβ M' x Ξ³
where M' : β β π
M' i = F (Ξ» n β x (n +β i))
Ξ³ : (i : β) β M' i οΌ (x i β M' (succ i))
Ξ³ i = pβ (Ξ» n β x (n +β i))
β ap (Ξ» - β x - β F (Ξ» n β x (succ n +β i))) (zero-left-neutral i)
β ap (Ξ» - β x i β F -) (seq-add-push x i)
iterative-uniqueness : {A : π€ Μ } β (_β_ : A β A β A)
β (F M : iterative _β_)
β prβ F οΌ prβ M
iterative-uniqueness {π€} _β_ F M = dfunext (fe π€ π€) (iterative-uniquenessΒ· _β_ F M)
\end{code}
A Convex-body is a cancellative, iterative Midpoint-algebra.
\begin{code}
convex-body-axioms : (A : π€ Μ ) β (A β A β A) β π€ Μ
convex-body-axioms {π€} A _β_ = (midpoint-algebra-axioms A _β_)
Γ (cancellative _β_)
Γ (iterative _β_)
Convex-body : (π€ : Universe) β π€ βΊ Μ
Convex-body π€ = Ξ£ A κ π€ Μ , Ξ£ _β_ κ (A β A β A) , (convex-body-axioms A _β_)
β¨_β© : Convex-body π€ β π€ Μ
β¨ A , _ β© = A
midpoint-operation : (π : Convex-body π€) β β¨ π β© β β¨ π β© β β¨ π β©
midpoint-operation (A , _β_ , _) = _β_
syntax midpoint-operation π x y = x ββ¨ π β© y
\end{code}
Definition of a midpoint-homomorphism.
The identity function is a midpoint-hom.
The unary functions given by a constant midpoint are midpoint-homs.
The composition of two midpoint-homs is a midpoint-hom.
\begin{code}
is-β-homomorphism : (π : Convex-body π€) (π : Convex-body π₯)
β (β¨ π β© β β¨ π β©) β π€ β π₯ Μ
is-β-homomorphism π π h = (x y : β¨ π β©) β h (x ββ¨ π β© y) οΌ h x ββ¨ π β© h y
id-is-β-homomorphism : (π : Convex-body π€) β is-β-homomorphism π π id
id-is-β-homomorphism π x y = refl
β-is-β-homomorphism-r : (π : Convex-body π€)
β (a : β¨ π β©) β is-β-homomorphism π π (Ξ» y β a ββ¨ π β© y)
β-is-β-homomorphism-r (π , _β_ , (_ , β-idem , _ , β-tran) , _) a x y
= a β (x β y) οΌβ¨ ap (_β (x β y)) (β-idem a β»ΒΉ) β©
(a β a) β (x β y) οΌβ¨ β-tran a a x y β©
(a β x) β (a β y) β
β-is-β-homomorphism-l : (π : Convex-body π€)
β (b : β¨ π β©) β is-β-homomorphism π π (Ξ» x β x ββ¨ π β© b)
β-is-β-homomorphism-l (π , _β_ , (_ , β-idem , _ , β-tran) , _) b x y
= (x β y) β b οΌβ¨ ap ((x β y) β_) (β-idem b β»ΒΉ) β©
(x β y) β (b β b) οΌβ¨ β-tran x y b b β©
(x β b) β (y β b) β
β-hom-composition : (π : Convex-body π€) (π : Convex-body π₯) (π : Convex-body π¦)
β (hβ : β¨ π β© β β¨ π β©) β (hβ : β¨ π β© β β¨ π β©)
β is-β-homomorphism π π hβ β is-β-homomorphism π π hβ
β is-β-homomorphism π π (hβ β hβ)
β-hom-composition {π€} {π₯} {π¦} π π π hβ hβ iβ iβ x y
= (hβ β hβ) (x ββ¨ π β© y) οΌβ¨ ap hβ (iβ x y) β©
hβ ((hβ x) ββ¨ π β© (hβ y)) οΌβ¨ iβ (hβ x) (hβ y) β©
((hβ β hβ) x) ββ¨ π β© ((hβ β hβ) y) β
\end{code}
The key structure of the axiomatisation: an interval object.
An interval object is defined by a Convex-body π and two points u,v : β¨πβ©.
For every two points a,b : β¨πβ© of a Convex-body π,
there exists a unique h : β¨πβ© β β¨πβ© such that:
* h u οΌ a,
* h v οΌ b,
* β x,y : β¨πβ©. h (x ββ¨ π β© y) οΌ h x ββ¨ π β© h y).
\begin{code}
is-interval-object : (π : Convex-body π€) (π₯ : Universe) β β¨ π β© β β¨ π β© β π€ β π₯ βΊ Μ
is-interval-object π π₯ u v =
(π : Convex-body π₯) (a b : β¨ π β©)
β β! h κ (β¨ π β© β β¨ π β©) , (h u οΌ a)
Γ (h v οΌ b)
Γ ((x y : β¨ π β©) β h (x ββ¨ π β© y) οΌ h x ββ¨ π β© h y)
\end{code}
The type of an interval object axiomatisation as a record.
\begin{code}
record Interval-object (π€ : Universe) : π€Ο where
field
π : π€ Μ
_β_ : π β π β π
u v : π
mpaa : midpoint-algebra-axioms π _β_
ca : cancellative _β_
ia : iterative _β_
universal-property : is-interval-object (π , _β_ , mpaa , ca , ia) π€ u v
\end{code}
The type of a doubling function axiomatisation.
\begin{code}
has-double : (π₯ : Universe) (io : Interval-object π₯) β π₯ Μ
has-double π₯ io = Ξ£ double κ (π β π)
, ((x : π) β double (x β (u β v)) οΌ x)
Γ ((x : π) β double (u β (u β x)) οΌ u)
Γ ((x : π) β double (v β (v β x)) οΌ v)
where
π = Interval-object.π io
u = Interval-object.u io
v = Interval-object.v io
_β_ = Interval-object._β_ io
\end{code}
We now prove things within a universe
with an Interval-object and a doubling function.
\begin{code}
module basic-interval-object-development {π€ : Universe}
(io : Interval-object π€) (hd : has-double π€ io) where
\end{code}
First we unpack all of the axioms from the Interval-object
affine : π β π β π β π is given by the unique map h : π β π.
\begin{code}
open Interval-object io public
β-idem : idempotent _β_
β-idem = prβ (prβ mpaa)
β-comm : commutative _β_
β-comm = prβ (prβ (prβ mpaa))
β-tran : transpositional _β_
β-tran = prβ (prβ (prβ mpaa))
β-canc : cancellative _β_
β-canc = Interval-object.ca io
π : Convex-body π€
π = π , _β_ , mpaa , β-canc , ia
affine : π β π β π β π
affine x y = β!-witness (universal-property π x y)
affine-equation-l : (x y : π) β affine x y u οΌ x
affine-equation-l x y = prβ (β!-is-witness (universal-property π x y))
affine-equation-r : (x y : π) β affine x y v οΌ y
affine-equation-r x y = prβ (prβ (β!-is-witness (universal-property π x y)))
affine-is-β-homomorphism : (x y : π) (a b : π)
β affine x y (a β b) οΌ affine x y a β affine x y b
affine-is-β-homomorphism x y = prβ (prβ (β!-is-witness (universal-property π x y)))
affine-uniqueness : (f : π β π) (a b : π)
β f u οΌ a
β f v οΌ b
β is-β-homomorphism π π f
β affine a b οΌ f
affine-uniqueness f a b l r i
= ap prβ (β!-uniqueness' (universal-property π a b) (f , l , r , i))
affine-uniquenessΒ· : (f : π β π) (a b : π)
β f u οΌ a
β f v οΌ b
β is-β-homomorphism π π f
β affine a b βΌ f
affine-uniquenessΒ· f a b l r i x = ap (Ξ» - β - x) (affine-uniqueness f a b l r i)
\end{code}
Many of the following proofs follow from the uniqueness of affine.
For example, affine u v is point-wise equivalent to the identity function.
\begin{code}
affine-uv-involutive : affine u v βΌ id
affine-uv-involutive = affine-uniquenessΒ· id u v refl refl (id-is-β-homomorphism π)
affine-constant : (a : π) (x : π) β affine a a x οΌ a
affine-constant a = affine-uniquenessΒ· (Ξ» _ β a) a a refl refl (Ξ» _ _ β β-idem a β»ΒΉ)
\end{code}
The iterator is called M.
We prove that it is idempotent, symmetric and is a midpoint-hom.
\begin{code}
M : (β β π) β π
M = prβ ia
M-propβ : (a : β β π) β M a οΌ a 0 β (M (a β succ))
M-propβ = prβ (prβ ia)
M-propβ : (a x : β β π) β ((i : β) β a i οΌ x i β a (succ i)) β a 0 οΌ M x
M-propβ = prβ (prβ ia)
M-idem : (x : π) β M (Ξ» _ β x) οΌ x
M-idem x = M-propβ (Ξ» _ β x) (Ξ» _ β x) (Ξ» _ β β-idem x β»ΒΉ) β»ΒΉ
M-hom : (x y : β β π) β (M x β M y) οΌ M (Ξ» i β x i β y i)
M-hom x y = M-propβ M' (Ξ» i β x i β y i) Ξ³ where
M' : β β π
M' i = M (Ξ» n β x (n +β i)) β M (Ξ» n β y (n +β i))
Ξ³ : (i : β) β M' i οΌ ((x i β y i) β M' (succ i))
Ξ³ i = M (Ξ» n β x (n +β i)) β M (Ξ» n β y (n +β i))
οΌβ¨ ap (_β M (Ξ» n β y (n +β i)))
(M-propβ (Ξ» n β x (n +β i))) β©
(x (0 +β i) β M (Ξ» n β x (succ n +β i))) β M (Ξ» n β y (n +β i))
οΌβ¨ ap ((x (0 +β i) β M (Ξ» n β x (succ n +β i))) β_)
(M-propβ (Ξ» n β y (n +β i))) β©
(x (0 +β i) β M (Ξ» n β x (succ n +β i))) β (y (0 +β i) β M (Ξ» n β y (succ n +β i)))
οΌβ¨ β-tran
(x (0 +β i)) (M (Ξ» n β x (succ n +β i)))
(y (0 +β i)) (M (Ξ» n β y (succ n +β i))) β©
((x (0 +β i) β y (0 +β i)) β (M (Ξ» n β x (succ n +β i)) β M (Ξ» n β y (succ n +β i))))
οΌβ¨ ap (Ξ» - β (x - β y -)
β (M (Ξ» n β x (succ n +β i)) β M (Ξ» n β y (succ n +β i))))
(zero-left-neutral i) β©
((x i β y i) β (M (Ξ» n β x (succ n +β i)) β M (Ξ» n β y (succ n +β i))))
οΌβ¨ ap (Ξ» - β (x i β y i) β (M - β M (Ξ» n β y (succ n +β i))))
(seq-add-push x i) β©
((x i β y i) β (M (Ξ» n β x (succ (n +β i))) β M (Ξ» n β y (succ n +β i))))
οΌβ¨ ap (Ξ» - β (x i β y i) β (M (Ξ» n β x (succ (n +β i))) β M -))
(seq-add-push y i) β©
(x i β y i) β M' (succ i) β
M-propβ-inner : (x : β β β β π) β M (Ξ» i β M (Ξ» j β x i j))
οΌ M (Ξ» i β x i 0 β M (Ξ» j β x i (succ j)))
M-propβ-inner x = ap M (dfunext (fe π€β π€) (Ξ» i β M-propβ (x i)))
M-symm : (x : β β β β π) β M (Ξ» i β M (Ξ» j β x i j)) οΌ M (Ξ» i β (M Ξ» j β x j i))
M-symm x = M-propβ M' (Ξ» i β M (Ξ» j β x j i)) Ξ³ where
M' : β β π
M' n = M (Ξ» i β M (Ξ» j β x i (j +β n)))
Ξ³ : (i : β) β M' i οΌ (prβ ia (Ξ» j β x j i) β M' (succ i))
Ξ³ n = M (Ξ» i β M (Ξ» j β x i (j +β n)))
οΌβ¨ M-propβ-inner (Ξ» i j β x i (j +β n)) β©
M (Ξ» i β x i (0 +β n) β M (Ξ» j β x i (succ j +β n)))
οΌβ¨ M-hom (Ξ» i β x i (0 +β n))
(Ξ» i β M (Ξ» j β x i (succ j +β n))) β»ΒΉ β©
M (Ξ» i β x i (0 +β n)) β M (Ξ» i β M (Ξ» j β x i (succ j +β n)))
οΌβ¨ ap (Ξ» - β M (Ξ» i β x i -)
β M (Ξ» i β M (Ξ» j β x i (succ j +β n))))
(zero-left-neutral n) β©
M (Ξ» i β x i n) β M (Ξ» i β M (Ξ» j β x i (succ j +β n)))
οΌβ¨ ap (M (Ξ» j β x j n) β_) (seq-seq-add-push x n) β©
M (Ξ» j β x j n) β M' (succ n) β
where
seq-seq-add-push : (x : β β β β π) (n : β)
β M (Ξ» i β M (Ξ» j β x i (succ j +β n)))
οΌ M (Ξ» i β M (Ξ» j β x i (succ (j +β n))))
seq-seq-add-push x 0 = refl
seq-seq-add-push x (succ n) = seq-seq-add-push (Ξ» i j β x i (succ j)) n
\end{code}
Any midpoint-hom is automatically an M-hom.
Thus, M is an M-hom.
\begin{code}
β-homs-are-M-homs : (h : π β π) β is-β-homomorphism π π h
β (z : β β π) β h (M z) οΌ M (Ξ» n β h (z n))
β-homs-are-M-homs h hom z = M-propβ M' (Ξ» n β h (z n)) Ξ³ where
M' : β β π
M' i = h (M (Ξ» n β z (n +β i)))
Ξ³ : (i : β) β M' i οΌ (h (z i) β M' (succ i))
Ξ³ i = h (M (Ξ» n β z (n +β i)))
οΌβ¨ ap h (M-propβ (Ξ» n β z (n +β i))) β©
h (z (0 +β i) β M (Ξ» n β z (succ n +β i)))
οΌβ¨ hom (z (0 +β i)) (M (Ξ» n β z (succ n +β i))) β©
h (z (0 +β i)) β h (M (Ξ» n β z (succ n +β i)))
οΌβ¨ ap (Ξ» - β h (z -) β h (M (Ξ» n β z (succ n +β i))))
(zero-left-neutral i) β©
h (z i) β h (M (Ξ» n β z (succ n +β i)))
οΌβ¨ ap (Ξ» - β h (z i) β h (M -))
(seq-add-push z i) β©
h (z i) β M' (succ i)
β
affine-M-hom : (x y : π) (z : β β π) β affine x y (M z) οΌ M (Ξ» n β affine x y (z n))
affine-M-hom x y z = β-homs-are-M-homs (affine x y) (affine-is-β-homomorphism x y) z
\end{code}
We adopt the convention u = β1 and v = +1 for the following.
\begin{code}
β1 O +1 : π
β1 = u
+1 = v
O = β1 β +1
\end{code}
The negation function and related properties,
culminating in proving negation is involutive.
\begin{code}
β_ : π β π
β_ = affine +1 β1
infixl 100 β_
β-is-β-homomorphism : (a b : π) β β (a β b) οΌ β a β β b
β-is-β-homomorphism = affine-is-β-homomorphism +1 β1
β1-inverse : β β1 οΌ +1
β1-inverse = affine-equation-l +1 β1
+1-inverse : β +1 οΌ β1
+1-inverse = affine-equation-r +1 β1
O-inverse : β O οΌ O
O-inverse = β O οΌβ¨ β-is-β-homomorphism β1 +1 β©
β β1 β β +1 οΌβ¨ ap (_β β +1) β1-inverse β©
+1 β β +1 οΌβ¨ ap (+1 β_) +1-inverse β©
+1 β β1 οΌβ¨ β-comm +1 β1 β©
O β
β1-neg-inv : β β β1 οΌ β1
β1-neg-inv = β β β1 οΌβ¨ ap β_ β1-inverse β©
β +1 οΌβ¨ +1-inverse β©
β1 β
+1-neg-inv : β β +1 οΌ +1
+1-neg-inv = β β +1 οΌβ¨ ap β_ +1-inverse β©
β β1 οΌβ¨ β1-inverse β©
+1 β
β-involutive : (x : π) β β β x οΌ x
β-involutive x = β β x οΌβ¨ negation-involutive' x β»ΒΉ β©
affine β1 +1 x οΌβ¨ affine-uv-involutive x β©
x β
where
ββ-is-β-homomorphism : is-β-homomorphism π π (Ξ» x β β (β x))
ββ-is-β-homomorphism = β-hom-composition π π π β_ β_
β-is-β-homomorphism β-is-β-homomorphism
negation-involutive' : (x : π) β affine β1 +1 x οΌ β (β x)
negation-involutive' = affine-uniquenessΒ· (Ξ» x β β (β x))
β1 +1 β1-neg-inv +1-neg-inv
ββ-is-β-homomorphism
fact : (x y : π) β x β β y οΌ β (β x β y)
fact x y = x β β y οΌβ¨ ap (_β (β y)) (β-involutive x β»ΒΉ) β©
β β x β β y οΌβ¨ β-is-β-homomorphism (β x) y β»ΒΉ β©
β (β x β y) β
\end{code}
The "midpoint subtraction" function from midpoint and negation.
The midpoint subtraction of any x with itself is O.
\begin{code}
_β_ : π β π β π
x β y = x β (β y)
β-zero : (x : π) β x β x οΌ O
β-zero x = x β x οΌβ¨ β-fact' β»ΒΉ β©
affine O O x οΌβ¨ affine-constant O x β©
O β
where
β-fact' : affine O O x οΌ x β x
β-fact' = affine-uniquenessΒ· (Ξ» x β x β x) O O
(ap (β1 β_) β1-inverse)
(ap (+1 β_) +1-inverse β β-comm +1 β1)
(Ξ» x y β ap ((x β y) β_)
(β-is-β-homomorphism x y)
β β-tran x y (β x) (β y))
x
\end{code}
The multiplication function and related properties,
culminating in proving multiplication is
commutative and associative'.
\begin{code}
_*_ : π β π β π
x * y = affine (β x) x y
infixl 99 _*_
*-gives-negation-l : (x : π) β x * β1 οΌ β x
*-gives-negation-l x = affine-equation-l (β x) x
*-gives-negation-r : (y : π) β β1 * y οΌ β y
*-gives-negation-r y = ap (Ξ» - β affine - β1 y) β1-inverse
*-gives-id-l : (x : π) β x * +1 οΌ x
*-gives-id-l x = affine-equation-r (β x) x
*-gives-id-r : (y : π) β +1 * y οΌ y
*-gives-id-r y = ap (Ξ» - β affine - +1 y) +1-inverse β affine-uv-involutive y
*-is-β-homomorphism-l : (a : π) β is-β-homomorphism π π (a *_)
*-is-β-homomorphism-l a x y = affine-is-β-homomorphism (β a) a x y
*-commutative : commutative _*_
*-commutative x y = Ξ³ y
where
j : (a b : π) β is-β-homomorphism π π (Ξ» x β a * x β b * x)
j a b x y
= ap (_β b * (x β y)) (*-is-β-homomorphism-l a x y)
β ap ((a * x β a * y) β_) (*-is-β-homomorphism-l b x y)
β β-tran (a * x) (a * y) (affine (β b) b x) (affine (β b) b y)
i : is-β-homomorphism π π (Ξ» y β y * x)
i y z = p
where
p : (y β z) * x οΌ (y * x β z * x)
p = affine-uniquenessΒ· (Ξ» x β y * x β z * x) (β (y β z)) (y β z)
(ap (_β z * u) (*-gives-negation-l y)
β ap ((β y) β_) (*-gives-negation-l z)
β affine-is-β-homomorphism +1 β1 y z β»ΒΉ)
(ap (_β z * v) (*-gives-id-l y)
β ap (y β_) (*-gives-id-l z))
(j y z) x
Ξ³ : (Ξ» y β x * y) βΌ (Ξ» y β y * x)
Ξ³ = affine-uniquenessΒ· (Ξ» y β y * x)
(β x) x (*-gives-negation-r x) (*-gives-id-r x)
i
*-is-β-homomorphism-r : (b : π) β is-β-homomorphism π π (_* b)
*-is-β-homomorphism-r b x y =
(x β y) * b οΌβ¨ *-commutative (x β y) b β©
b * (x β y) οΌβ¨ *-is-β-homomorphism-l b x y β©
(b * x) β (b * y) οΌβ¨ ap ((b * x) β_) (*-commutative b y) β©
(b * x) β (y * b) οΌβ¨ ap (_β (y * b)) (*-commutative b x) β©
(x * b) β (y * b) β
*-prop : (x y : π) β x * y οΌ β (x * β y)
*-prop x y = affine-uniquenessΒ· (Ξ» - β β (x * (β -))) (β x) x l r i y
where
l = β (x * (β β1)) οΌβ¨ ap (Ξ» - β β (x * -)) β1-inverse β©
β (x * +1 ) οΌβ¨ ap β_ (*-gives-id-l x) β©
β x β
r = β (x * (β +1)) οΌβ¨ ap (Ξ» - β β (x * -)) +1-inverse β©
β (x * β1 ) οΌβ¨ ap β_ (*-gives-negation-l x) β©
β (β x) οΌβ¨ β-involutive x β©
x β
i : is-β-homomorphism π π (Ξ» - β β (x * (β -)))
i a b = β (x * (β (a β b)))
οΌβ¨ ap (Ξ» - β β (x * -)) (β-is-β-homomorphism a b) β©
β (x * (β a β β b))
οΌβ¨ ap β_ (affine-is-β-homomorphism (β x) x (β a) (β b)) β©
β ((x * β a) β (x * β b))
οΌβ¨ affine-is-β-homomorphism +1 β1 (x * (β a)) (x * (β b)) β©
β (x * β a) β β (x * β b) β
*-assoc : (x y z : π) β x * (y * z) οΌ (x * y) * z
*-assoc x y z = Ξ³ z β»ΒΉ
where
l = x * (y * β1) οΌβ¨ ap (x *_) (*-gives-negation-l y) β©
x * (β y) οΌβ¨ β-involutive (x * (β y)) β»ΒΉ β©
(β (β (x * β y))) οΌβ¨ ap β_ (*-prop x y β»ΒΉ) β©
β (x * y) β
r = x * (y * +1) οΌβ¨ ap (x *_) (*-gives-id-l y) β©
x * y β
i : is-β-homomorphism π π (Ξ» z β x * (y * z))
i a b = x * (y * (a β b))
οΌβ¨ ap (x *_) (*-is-β-homomorphism-l y a b) β©
x * (y * a β y * b)
οΌβ¨ affine-is-β-homomorphism (β x) x (y * a) (y * b) β©
x * (y * a) β x * (y * b) β
Ξ³ : (Ξ» z β (x * y) * z) βΌ (Ξ» z β x * (y * z))
Ξ³ = affine-uniquenessΒ· (Ξ» z β x * (y * z)) (β (x * y)) (x * y) l r i
\end{code}
Power series can be implemented from multiplication.
We also define a halving function from the midpoint.
\begin{code}
_**_ : π β β β π
a ** 0 = +1
a ** succ n = a * (a ** n)
powerseries : (β β π) β (π β π)
powerseries a = Ξ» x β M (Ξ» n β (a n) * (x ** n))
_/2 : π β π
_/2 = _β O
+1/2 = +1 /2
β1/2 = β1 /2
infixl 99 _/2
β-half : (x : π) β β (x /2) οΌ β x /2
β-half x = β-is-β-homomorphism x O β ap (β x β_) O-inverse
O-half : O /2 οΌ O
O-half = β-idem O
β1-half : β +1/2 οΌ β1/2
β1-half = β-half +1 β ap _/2 +1-inverse
+1-half : β β1/2 οΌ +1/2
+1-half = β-half β1 β ap _/2 β1-inverse
half-is-β-homomorphism : is-β-homomorphism π π _/2
half-is-β-homomorphism = β-is-β-homomorphism-l π O
half-same : (x : π) β +1/2 * x οΌ x /2
half-same x = ap (Ξ» - β affine - +1/2 x) β1-half
β affine-uniquenessΒ· _/2 β1/2 +1/2
refl refl half-is-β-homomorphism x
\end{code}
Now we assume that we have a doubling function.
This allows the definition
of truncated addition and subtraction.
\begin{code}
double : π β π
double = prβ hd
double-mid : (x : π) β double (x /2) οΌ x
double-mid = prβ (prβ hd)
double-left : (x : π) β double (β1 β (β1 β x)) οΌ β1
double-left = prβ (prβ (prβ hd))
double-right : (x : π) β double (+1 β (+1 β x)) οΌ +1
double-right = prβ (prβ (prβ hd))
_+π_ _βπ_ : π β π β π
x +π y = double (x β y)
x βπ y = double (x β y)
+π-comm : commutative _+π_
+π-comm x y = ap double (β-comm x y)
+π-itself : (x : π) β x +π x οΌ double x
+π-itself x = ap double (β-idem x)
+π-tran : (x y s t : π) β (x β y) +π (s β t) οΌ (x β s) +π (y β t)
+π-tran x y s t = ap double (β-tran x y s t)
+π-fact : (x y : π) β x +π β y οΌ double (β (y β x))
+π-fact x y = ap double (fact x y β ap β_ (β-comm (β x) y))
\end{code}
Double and half allows it to define a max operation.
First, there is an operation for maxO,
this is then used to define max itself.
We wish to prove that max is a semi-lattice
(idempotent, commutative and associative').
\begin{code}
maxO : π β π
maxO x = double (β1/2 +π x) /2 +π +1/2
O-midpoint-of-halves : β1/2 β +1/2 οΌ O
O-midpoint-of-halves = β1/2 β +1/2 οΌβ¨ ap (β1/2 β_) (+1-half β»ΒΉ) β©
β1/2 β (β β1/2) οΌβ¨ β-zero β1/2 β©
O β
double-O-is-O : double O οΌ O
double-O-is-O = double O οΌβ¨ ap double (β-idem O β»ΒΉ) β©
double (O β O) οΌβ¨ double-mid O β©
O β
double-β1/2-is-β1 : double β1/2 οΌ β1
double-β1/2-is-β1 = double-mid β1
double-+1/2-is-+1 : double +1/2 οΌ +1
double-+1/2-is-+1 = double-mid +1
double-β1-is-β1 : double β1 οΌ β1
double-β1-is-β1 = ap double (β-idem β1 β»ΒΉ β ap (β1 β_) (β-idem β1 β»ΒΉ)) β double-left β1
double-+1-is-+1 : double +1 οΌ +1
double-+1-is-+1 = ap double (β-idem +1 β»ΒΉ β ap (+1 β_) (β-idem +1 β»ΒΉ)) β double-right +1
maxO-O-is-O : maxO O οΌ O
maxO-O-is-O = maxO O
οΌβ¨ ap (Ξ» - β (double - /2) +π +1/2) (double-mid β1/2) β©
(double β1/2 /2) +π +1/2
οΌβ¨ ap (Ξ» - β - /2 +π +1/2) (double-left +1) β©
β1/2 +π +1/2
οΌβ¨ ap double O-midpoint-of-halves β double-O-is-O β©
O β
max _β¨_ : π β π β π
max x y = double (x /2 +π maxO (y β x))
_β¨_ = max
max-idem : idempotent _β¨_
max-idem a = a β¨ a
οΌβ¨ ap (Ξ» - β double ((a /2) +π maxO -))
(β-zero a) β©
double (double (a /2 β maxO O))
οΌβ¨ ap (Ξ» - β double ((a /2) +π -))
maxO-O-is-O β©
double (a /2 +π O)
οΌβ¨ ap double (double-mid (a /2)) β©
double (a /2)
οΌβ¨ double-mid a β©
a β
\end{code}
Other functions can be derived from max.
\begin{code}
min : π β π β π
min x y = β (max (β x) (β y))
abs : π β π
abs x = max (β x) x
\end{code}
TODO list:
* max (_β¨_) is a semilattice -- assoc, comm (done idem)
- derive order from this semilattice.
* Page 42. - Prove the limit *is* the limit, as above.
* Binary expansions
(β β β β π)
numerator denominator numer/denom
(binary expansion stream applied to M).