Alice Laroche, 4th of December 2024
We show that the type of conaturals defined by coinduction is
equivalent to the type of conaturals defined as generic convergent
sequences when assuming funext and that bisimilarity is equality.
\begin{code}
{-# OPTIONS --guardedness #-}
module Unsafe.CoNat-Equiv where
open import CoNaturals.Type
open import MLTT.Spartan
open import MLTT.Plus-Properties
open import MLTT.Two-Properties
open import UF.Equiv
open import UF.FunExt
\end{code}
This implementation of CoNat comes from the Cubical Agda Library.
\begin{code}
CoNat' : π€β Μ
record CoNat : π€β Μ
CoNat' = π + CoNat
record CoNat where
constructor conat
coinductive
field
force : π + CoNat
open CoNat public
pattern cozero = inl β
pattern cosuc n = inr n
\end{code}
Because we can't reason about coinductive type equality in classical
Agda, we define an binary relation which is equivalent to equality.
The correctness of it is proven in the Cubical Agda Library.
Three types are needed in order to convince the termination checker
some functions terminates.
\begin{code}
record _οΌC_ (x y : CoNat) : Set
data _οΌC'_ (x y : CoNat') : Set
_οΌC''_ : CoNat' β CoNat' β Set
cozero οΌC'' cozero = π
cozero οΌC'' cosuc y = π
cosuc x οΌC'' cozero = π
cosuc x οΌC'' cosuc y = x οΌC y
data _οΌC'_ x y where
con : x οΌC'' y β x οΌC' y
record _οΌC_ x y where
coinductive
field
prove : force x οΌC' force y
open _οΌC_
\end{code}
We can at least show that the relation is an equivalence relation.
\begin{code}
οΌC-refl : β {x y} β x οΌ y β x οΌC y
οΌC'-refl : β {x y} β x οΌ y β x οΌC' y
οΌC-refl p .prove = οΌC'-refl (ap force p)
οΌC'-refl {cozero} {cozero} p = con β
οΌC'-refl {cosuc _} {cosuc _} p = con (οΌC-refl (inr-lc p))
οΌC-sym : β {x y} β x οΌC y β y οΌC x
οΌC'-sym : β {x y} β x οΌC' y β y οΌC' x
οΌC-sym p .prove = οΌC'-sym (p .prove)
οΌC'-sym {cozero} {cozero} (con p) = con β
οΌC'-sym {cosuc _} {cosuc _} (con p) = con (οΌC-sym p)
οΌC-trans : β {x y z} β x οΌC y β y οΌC z β x οΌC z
οΌC'-trans : β {x y z} β x οΌC' y β y οΌC' z β x οΌC' z
οΌC-trans p q .prove = οΌC'-trans (p .prove) (q .prove)
οΌC'-trans {cozero} {cozero} {cozero} (con p) (con q) = con β
οΌC'-trans {cosuc _} {cosuc _} {cosuc _} (con p) (con q) = con (οΌC-trans p q)
\end{code}
We give a mapping from CoNat' to β β 2 and use it to define a
criterion for the relationship defined above.
\begin{code}
CoNat'-to-ββπ : CoNat' β (β β π)
CoNat'-to-ββπ cozero zero = β
CoNat'-to-ββπ cozero (succ n) = β
CoNat'-to-ββπ (cosuc x) zero = β
CoNat'-to-ββπ (cosuc x) (succ n) = CoNat'-to-ββπ (x .force) n
CoNat-to-ββπ : CoNat β (β β π)
CoNat-to-ββπ x = CoNat'-to-ββπ (x .force)
CoNat-equality-criterion : (x y : CoNat)
β ((n : β) β CoNat-to-ββπ x n οΌ CoNat-to-ββπ y n)
β x οΌC y
CoNat-equality-criterion' : (x y : CoNat')
β ((n : β) β CoNat'-to-ββπ x n οΌ CoNat'-to-ββπ y n)
β x οΌC' y
CoNat-equality-criterion x y f .prove =
CoNat-equality-criterion' (x .force) (y .force) f
CoNat-equality-criterion' cozero cozero f =
con β
CoNat-equality-criterion' cozero (cosuc x) f =
con (zero-is-not-one (f 0))
CoNat-equality-criterion' (cosuc x) (cozero) f =
con (one-is-not-zero (f 0))
CoNat-equality-criterion' (cosuc x) (cosuc y) f =
con (CoNat-equality-criterion x y (f β succ))
\end{code}
Finally we write functions ββ β CoNat and Conat β ββ and show that
they give an equivalence between ββ and CoNat, assuming function
extensionality and that our equivalence relation is a bisimilarity
relation.
\begin{code}
f : ββ β CoNat
f' : π β ββ β CoNat'
f x .force = f' (ββ-to-ββπ x 0) x
f' β x = cozero
f' β x = cosuc (f (Pred x))
is-decreasing-CoNat'-to-ββπ : β x β is-decreasing (CoNat'-to-ββπ x)
is-decreasing-CoNat'-to-ββπ (cozero) zero = β
is-decreasing-CoNat'-to-ββπ (cozero) (succ n) = β
is-decreasing-CoNat'-to-ββπ (cosuc x) zero = β-top
is-decreasing-CoNat'-to-ββπ (cosuc x) (succ n) = is-decreasing-CoNat'-to-ββπ
(x .force)
n
is-decreasing-CoNat-to-ββπ : β x β is-decreasing (CoNat-to-ββπ x)
is-decreasing-CoNat-to-ββπ x n = is-decreasing-CoNat'-to-ββπ (x .force) n
g : CoNat β ββ
g x = CoNat-to-ββπ x , is-decreasing-CoNat-to-ββπ x
CoNatβββ : funextβ
β (bisim : β x y β x οΌC y β x οΌ y)
β ββ β CoNat
CoNatβββ fe bisim = f , (g , Ξ» - β bisim _ _ (fβgβΌid -)) , (g , gβfβΌid)
where
gβfβΌid : g β f βΌ id
gβfβΌid x = ββ-to-ββπ-lc fe (dfunext fe (I x _ refl))
where
I : (x : ββ)
β (b : π) β b οΌ ββ-to-ββπ x 0
β (n : β)
β ββ-to-ββπ (g (f x)) n οΌ ββ-to-ββπ x n
I x β eq zero = ap (Ξ» - β ββ-to-ββπ (g (conat (f' - x))) zero) eq β»ΒΉ β eq
I x β eq zero = ap (Ξ» - β ββ-to-ββπ (g (conat (f' - x))) zero) eq β»ΒΉ β eq
I x β eq (succ n) = ap (Ξ» - β ββ-to-ββπ (g (conat (f' - x))) (succ n)) eq β»ΒΉ
β ap (Ξ» - β ββ-to-ββπ - (succ n))
( is-Zero-equal-Zero fe {g (conat cozero)} refl
β is-Zero-equal-Zero fe {x} (eq β»ΒΉ) β»ΒΉ)
I x β eq (succ n) = ap (Ξ» - β ββ-to-ββπ (g (conat (f' - x))) (succ n)) eq β»ΒΉ
β I (Pred x) _ refl n
fβgβΌid : (x : CoNat) β f (g x) οΌC x
fβgβΌid x = CoNat-equality-criterion _ _ (I (x .force))
where
I : (x : CoNat')
β (n : β) β CoNat-to-ββπ (f (g (conat x))) n οΌ CoNat-to-ββπ (conat x) n
I (cozero) zero = refl
I (cosuc Ξ±) zero = refl
I (cozero) (succ n) = refl
I (cosuc Ξ±) (succ n) = I (Ξ± .force) n
\end{code}