Todd Waugh Ambridge, January 2024 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://doi.org/10.1109/LICS.2001.932488 # Formalisation of the Escardo-Simpson interval object \begin{code} {-# OPTIONS --without-K --safe #-} open import UF.FunExt open import MLTT.Spartan open import Naturals.Addition renaming (_+_ to _+β_) open import UF.Subsingletons open import UF.Sets module TWA.Thesis.Chapter5.IntervalObject (fe : FunExt) where open import Naturals.Sequence fe \end{code} ## Midpoint algebras \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 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 _β_) cancellative : {X : π€ Μ } β (X β X β X) β π€ Μ cancellative _β_ = β a b c β a β c οΌ b β c β a οΌ b \end{code} ## Iteration property \begin{code} 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} ## Convex bodies \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 \end{code} ## Midpoint homomorphisms \begin{code} midpoint-operation : (π : Convex-body π€) β β¨ π β© β β¨ π β© β β¨ π β© midpoint-operation (A , _β_ , _) = _β_ syntax midpoint-operation π x y = x ββ¨ π β© y 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} ## Interval objects \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) 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 module basic-interval-object-development {π€ : Universe} (io : Interval-object π€) where 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 \end{code} ## Affine map \begin{code} 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) 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} ## M properties \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 β-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} ## Representing [-1,1] \begin{code} β1 +1 : π β1 = u +1 = v O : π O = β1 β +1 \end{code} ## Negation \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 _β_ : π β π β π 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} ## Multiplication \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-id-l : (x : π) β x * +1 οΌ x *-gives-id-l x = affine-equation-r (β x) x *-is-β-homomorphism-l : (a : π) β is-β-homomorphism π π (a *_) *-is-β-homomorphism-l a x y = affine-is-β-homomorphism (β a) a x y *-gives-negation-r : (y : π) β β1 * y οΌ β y *-gives-negation-r y = ap (Ξ» - β affine - β1 y) β1-inverse *-gives-id-r : (y : π) β +1 * y οΌ y *-gives-id-r y = ap (Ξ» - β affine - +1 y) +1-inverse β affine-uv-involutive 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 *-gives-zero-l : (x : π) β x * O οΌ O *-gives-zero-l x = *-is-β-homomorphism-l x u v β ap (_β (x * v)) (*-gives-negation-l x) β ap (β x β_) (*-gives-id-l x) β β-comm (β x) x β β-zero x *-gives-zero-r : (x : π) β O * x οΌ O *-gives-zero-r x = *-commutative O x β *-gives-zero-l x *-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} ## Halving \begin{code} _/2 : π β π _/2 = _β O +1/2 = +1 /2 β1/2 = β1 /2 \end{code}