Tom de Jong, 3 - 5 March 2020
As suggested by Martin Escardo.
Dyadic rationals (https://en.wikipedia.org/wiki/Dyadic_rational)
\begin{code}
{-# OPTIONS --safe --without-K #-}
module DyadicsInductive.Dyadics where
open import MLTT.Spartan
open import MLTT.Unit-Properties
open import UF.DiscreteAndSeparated
open import UF.Sets
\end{code}
We inductively construct dyadic rationals in (-1,1), as follows.
Start with the point 0 in the middle (represented by middle below).
Define two functions (represented by left and right below):
l : (-1,1) โ (-1,1)
l x = (x-1)/2
r : (-1,1) โ (-1,1)
r x = (x+1)/2
Some values (ordered) to give an impression:
0 -- just 0
-1/2 1/2 -- l 0 = -1/2 and r 0 = 1/2
-3/4 -1/4 1/4 3/4 -- l (l 0), l (r 0), r (l 0) and r (r 0)
In this module we just define the type and prove that it has decidable
equality. The order on ๐ป is defined in the separate module Dyadic-Order.
\begin{code}
data ๐ป : ๐คโ ฬ where
middle : ๐ป
left : ๐ป โ ๐ป
right : ๐ป โ ๐ป
\end{code}
Using the well-known encode-decode method (cf. Section 2.13 of the HoTT book),
we can show that right and left are injective and that ๐ป is discrete (i.e. it
has decidable equality).
By Hedberg's Theorem, ๐ป is a set.
\begin{code}
middle-is-not-left : {x : ๐ป} โ middle โ left x
middle-is-not-left p = ๐-is-not-๐ (ap f p)
where
f : ๐ป โ ๐คโ ฬ
f middle = ๐
f (left _) = ๐
f (right _) = ๐
middle-is-not-right : {x : ๐ป} โ middle โ right x
middle-is-not-right p = ๐-is-not-๐ (ap f p)
where
f : ๐ป โ ๐คโ ฬ
f middle = ๐
f (left _) = ๐
f (right _) = ๐
left-is-not-right : {x y : ๐ป} โ left x โ right y
left-is-not-right p = ๐-is-not-๐ (ap f p)
where
f : ๐ป โ ๐คโ ฬ
f middle = ๐
f (left x) = ๐
f (right x) = ๐
left-lc : {x y : ๐ป} โ left x ๏ผ left y โ x ๏ผ y
left-lc = ap f
where
f : ๐ป โ ๐ป
f middle = middle
f (left x) = x
f (right x) = right x
right-lc : {x y : ๐ป} โ right x ๏ผ right y โ x ๏ผ y
right-lc = ap f
where
f : ๐ป โ ๐ป
f middle = middle
f (left x) = left x
f (right x) = x
๐ป-is-discrete : is-discrete ๐ป
๐ป-is-discrete middle middle = inl refl
๐ป-is-discrete middle (left y) = inr middle-is-not-left
๐ป-is-discrete middle (right y) = inr middle-is-not-right
๐ป-is-discrete (left x) middle = inr (ฮป p โ middle-is-not-left (p โปยน))
๐ป-is-discrete (left x) (left y) = cases a b (๐ป-is-discrete x y)
where
a : x ๏ผ y โ is-decidable (left x ๏ผ left y)
a = inl โ ap left
b : ยฌ (x ๏ผ y) โ is-decidable (left x ๏ผ left y)
b = inr โ contrapositive left-lc
๐ป-is-discrete (left x) (right y) = inr left-is-not-right
๐ป-is-discrete (right x) middle = inr (ฮป p โ middle-is-not-right (p โปยน))
๐ป-is-discrete (right x) (left y) = inr (ฮป p โ left-is-not-right (p โปยน))
๐ป-is-discrete (right x) (right y) = cases a b (๐ป-is-discrete x y)
where
a : x ๏ผ y โ is-decidable (right x ๏ผ right y)
a = inl โ ap right
b : ยฌ (x ๏ผ y) โ is-decidable (right x ๏ผ right y)
b = inr โ contrapositive right-lc
๐ป-is-set : is-set ๐ป
๐ป-is-set = discrete-types-are-sets ๐ป-is-discrete
\end{code}