Andrew Sneap, March 2021
Updated March 2022
In this file I define the Dedekind reals, and prove that the rationals
are embedded in the reals.
\begin{code}
{-# OPTIONS --safe --without-K #-}
open import MLTT.Spartan renaming (_+_ to _โ_)
open import Integers.Type
open import Notation.CanonicalMap
open import Notation.Order
open import Rationals.Order
open import Rationals.Type
open import UF.Base
open import UF.FunExt
open import UF.Powerset
open import UF.PropTrunc
open import UF.Sets
open import UF.Sets-Properties
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.Subsingletons-Properties
module DedekindReals.Type
(fe : Fun-Ext)
(pe : Prop-Ext)
(pt : propositional-truncations-exist)
where
open PropositionalTruncation pt
inhabited-left : (L : ๐ โ) โ ๐คโ ฬ
inhabited-left L = (โ p ๊ โ , p โ L)
inhabited-right : (R : ๐ โ) โ ๐คโ ฬ
inhabited-right R = (โ q ๊ โ , q โ R)
rounded-left : (L : ๐ โ) โ ๐คโ ฬ
rounded-left L = (x : โ) โ (x โ L โ (โ p ๊ โ , (x < p) ร p โ L))
rounded-right : (R : ๐ โ) โ ๐คโ ฬ
rounded-right R = (x : โ) โ x โ R โ (โ q ๊ โ , (q < x) ร q โ R)
disjoint : (L R : ๐ โ) โ ๐คโ ฬ
disjoint L R = (p q : โ) โ p โ L ร q โ R โ p < q
located : (L R : ๐ โ) โ ๐คโ ฬ
located L R = (p q : โ) โ p < q โ p โ L โจ q โ R
isCut : (L R : ๐ โ) โ ๐คโ ฬ
isCut L R = inhabited-left L
ร inhabited-right R
ร rounded-left L
ร rounded-right R
ร disjoint L R
ร located L R
โ : ๐คโ ฬ
โ = ฮฃ (L , R) ๊ ๐ โ ร ๐ โ , isCut L R
subset-of-โ-is-set : is-set (๐ โ)
subset-of-โ-is-set = powersets-are-sets fe pe
inhabited-left-is-prop : (L : ๐ โ) โ is-prop (inhabited-left L)
inhabited-left-is-prop L = โ-is-prop
inhabited-right-is-prop : (R : ๐ โ) โ is-prop (inhabited-right R)
inhabited-right-is-prop R = โ-is-prop
rounded-left-a : (L : ๐ โ) โ rounded-left L โ (x y : โ) โ x โค y โ y โ L โ x โ L
rounded-left-a L r x y l y-L = II (โโค-split x y l)
where
I : (โ p ๊ โ , (x < p) ร p โ L) โ x โ L
I = prโ (r x)
II : (x < y) โ (x ๏ผ y) โ x โ L
II (inl l) = I โฃ y , (l , y-L) โฃ
II (inr r) = transport (_โ L) (r โปยน) y-L
rounded-left-b : (L : ๐ โ) โ rounded-left L โ (x : โ) โ x โ L โ (โ p ๊ โ , (x < p) ร p โ L)
rounded-left-b L r x x-L = (prโ (r x)) x-L
rounded-left-c : (L : ๐ โ) โ rounded-left L โ (x y : โ) โ x < y โ y โ L โ x โ L
rounded-left-c L r x y l yL = prโ (r x) โฃ y , (l , yL) โฃ
rounded-right-a : (R : ๐ โ) โ rounded-right R โ (x y : โ) โ x โค y โ x โ R โ y โ R
rounded-right-a R r x y l x-R = II (โโค-split x y l)
where
I : (โ p ๊ โ , (p < y) ร p โ R) โ y โ R
I = prโ (r y)
II : (x < y) โ (x ๏ผ y) โ y โ R
II (inl r) = I โฃ x , (r , x-R) โฃ
II (inr r) = transport (_โ R) r x-R
rounded-right-b : (R : ๐ โ) โ rounded-right R โ (x : โ) โ x โ R โ (โ q ๊ โ , (q < x) ร q โ R)
rounded-right-b R r x x-R = (prโ (r x)) x-R
rounded-right-c : (R : ๐ โ) โ rounded-right R โ (x y : โ) โ x < y โ x โ R โ y โ R
rounded-right-c R r x y l xR = prโ (r y) โฃ x , (l , xR) โฃ
rounded-left-is-prop : (L : ๐ โ) โ is-prop (rounded-left L)
rounded-left-is-prop L = ฮ -is-prop fe ฮด
where
ฮด : (x : โ) โ is-prop (x โ L โ (โ p ๊ โ , (x < p) ร p โ L))
ฮด x = ร-is-prop (ฮ -is-prop fe (ฮป _ โ โ-is-prop)) (ฮ -is-prop fe (ฮป _ โ โ-is-prop L x))
rounded-right-is-prop : (R : ๐ โ) โ is-prop (rounded-right R)
rounded-right-is-prop R = ฮ -is-prop fe ฮด
where
ฮด : (x : โ) โ is-prop (x โ R โ (โ q ๊ โ , (q < x) ร q โ R))
ฮด x = ร-is-prop (ฮ -is-prop fe (ฮป _ โ โ-is-prop)) (ฮ -is-prop fe (ฮป _ โ โ-is-prop R x))
disjoint-is-prop : (L R : ๐ โ) โ is-prop (disjoint L R)
disjoint-is-prop L R = ฮ โ-is-prop fe (ฮป x y _ โ โ<-is-prop x y)
located-is-prop : (L R : ๐ โ) โ is-prop (located L R)
located-is-prop L R = ฮ โ-is-prop fe (ฮป _ _ _ โ โจ-is-prop)
isCut-is-prop : (L R : ๐ โ) โ is-prop (isCut L R)
isCut-is-prop L R = ร-is-prop (inhabited-left-is-prop L)
(ร-is-prop (inhabited-right-is-prop R)
(ร-is-prop (rounded-left-is-prop L)
(ร-is-prop (rounded-right-is-prop R)
(ร-is-prop (disjoint-is-prop L R)
(located-is-prop L R)))))
โ-is-set : is-set โ
โ-is-set = ฮฃ-is-set (ร-is-set subset-of-โ-is-set subset-of-โ-is-set)
ฮป (L , R) โ props-are-sets (isCut-is-prop L R)
lower-cut-of : โ โ ๐ โ
lower-cut-of ((L , R) , _) = L
upper-cut-of : โ โ ๐ โ
upper-cut-of ((L , R) , _) = R
in-lower-cut : โ โ โ โ ๐คโ ฬ
in-lower-cut q ((L , R) , _) = q โ L
in-upper-cut : โ โ โ โ ๐คโ ฬ
in-upper-cut q ((L , R) , _) = q โ R
โ-locatedness : (((L , R) , _) : โ) โ (p q : โ) โ p < q โ p โ L โจ q โ R
โ-locatedness ((L , R) , _ , _ , _ , _ , _ , located-y) = located-y
inhabited-from-real-L : (((L , R) , i) : โ) โ inhabited-left L
inhabited-from-real-L ((L , R) , inhabited-L , _) = inhabited-L
inhabited-from-real-R : (((L , R) , i) : โ) โ inhabited-left R
inhabited-from-real-R ((L , R) , _ , inhabited-R , _) = inhabited-R
rounded-from-real-L : (((L , R) , i) : โ) โ rounded-left L
rounded-from-real-L ((L , R) , _ , _ , rounded-L , _) = rounded-L
rounded-from-real-R : (((L , R) , i) : โ) โ rounded-right R
rounded-from-real-R ((L , R) , _ , _ , _ , rounded-R , _) = rounded-R
disjoint-from-real : (((L , R) , i) : โ) โ disjoint L R
disjoint-from-real ((L , R) , _ , _ , _ , _ , disjoint , _) = disjoint
โ-rounded-leftโ : (y : โ) (x : โ) โ x < y โ ฮฃ p ๊ โ , (x < p < y)
โ-rounded-leftโ y x l = โ-dense x y l
โ-rounded-leftโ : (y : โ) (x : โ) โ ฮฃ p ๊ โ , (x < p < y) โ x < y
โ-rounded-leftโ y x (p , lโ , lโ) = โ<-trans x p y lโ lโ
โ-rounded-rightโ : (y : โ) (x : โ) โ y < x โ ฮฃ q ๊ โ , (q < x) ร (y < q)
โ-rounded-rightโ y x l = I (โ-dense y x l)
where
I : ฮฃ q ๊ โ , (y < q) ร (q < x)
โ ฮฃ q ๊ โ , (q < x) ร (y < q)
I (q , lโ , lโ) = q , lโ , lโ
โ-rounded-rightโ : (y : โ) (x : โ) โ ฮฃ q ๊ โ , (q < x) ร (y < q) โ y < x
โ-rounded-rightโ y x (q , lโ , lโ) = โ<-trans y q x lโ lโ
_โ<โ_ : โ โ โ โ ๐คโ ฬ
p โ<โ x = p โ lower-cut-of x
_โ<โ_ : โ โ โ โ ๐คโ ฬ
x โ<โ q = q โ upper-cut-of x
instance
Strict-Order-โ-โ : Strict-Order โ โ
_<_ {{Strict-Order-โ-โ}} = _โ<โ_
Strict-Order-โ-โ : Strict-Order โ โ
_<_ {{Strict-Order-โ-โ}} = _โ<โ_
Strict-Order-Chain-โ-โ-โ : Strict-Order-Chain โ โ โ _<_ _<_
_<_<_ {{Strict-Order-Chain-โ-โ-โ}} p q r = (p < q) ร (q < r)
Strict-Order-Chain-โ-โ-โ : Strict-Order-Chain โ โ โ _<_ _<_
_<_<_ {{Strict-Order-Chain-โ-โ-โ}} p q r = (p < q) ร (q < r)
Strict-Order-Chain-โ-โ-โ : Strict-Order-Chain โ โ โ _<_ _<_
_<_<_ {{Strict-Order-Chain-โ-โ-โ}} p q r = (p < q) ร (q < r)
Strict-Order-Chain-โ-โ-โ : Strict-Order-Chain โ โ โ _<_ _<_
_<_<_ {{Strict-Order-Chain-โ-โ-โ}} p q r = (p < q) ร (q < r)
โ<-not-itself-from-โ : (p : โ) โ (x : โ) โ ยฌ (p < x < p)
โ<-not-itself-from-โ p x (lโ , lโ) = โ<-irrefl p (disjoint-from-real x p p (lโ , lโ))
embedding-โ-to-โ : โ โ โ
embedding-โ-to-โ x = (L , R) , inhabited-left'
, inhabited-right'
, rounded-left'
, rounded-right'
, disjoint'
, located'
where
L R : ๐ โ
L p = p < x , โ<-is-prop p x
R q = x < q , โ<-is-prop x q
inhabited-left' : โ p ๊ โ , p < x
inhabited-left' = โฃ โ-no-least-element x โฃ
inhabited-right' : โ q ๊ โ , x < q
inhabited-right' = โฃ โ-no-max-element x โฃ
rounded-left' : (p : โ) โ (p โ L โ (โ p' ๊ โ , p < p' < x))
rounded-left' p = ฮฑ , ฮฒ
where
ฮฑ : p < x โ (โ p' ๊ โ , p < p' < x)
ฮฑ l = โฃ โ-dense p x l โฃ
ฮฒ : (โ p' ๊ โ , p < p' < x โ p < x)
ฮฒ l = โฅโฅ-rec (โ<-is-prop p x) ฮด l
where
ฮด : ฮฃ p' ๊ โ , p < p' < x โ p < x
ฮด (p' , a , b) = โ<-trans p p' x a b
rounded-right' : (q : โ) โ q > x โ (โ q' ๊ โ , (q' < q) ร q' > x)
rounded-right' q = ฮฑ , ฮฒ
where
ฮฑ : q > x โ โ q' ๊ โ , (q' < q) ร q' > x
ฮฑ r = โฃ ฮด (โ-dense x q r) โฃ
where
ฮด : (ฮฃ q' ๊ โ , (x < q') ร (q' < q)) โ ฮฃ q' ๊ โ , (q' < q) ร q' > x
ฮด (q' , a , b) = q' , b , a
ฮฒ : โ q' ๊ โ , (q' < q) ร q' > x โ q > x
ฮฒ r = โฅโฅ-rec (โ<-is-prop x q) ฮด r
where
ฮด : ฮฃ q' ๊ โ , (q' < q) ร q' > x โ x < q
ฮด (q' , a , b) = โ<-trans x q' q b a
disjoint' : (p q : โ) โ p < x < q โ p < q
disjoint' p q (l , r) = โ<-trans p x q l r
located' : (p q : โ) โ p < q โ (p < x) โจ (x < q)
located' p q l = โฃ located-property p q x l โฃ
instance
canonical-map-โ-to-โ : Canonical-Map โ โ
ฮน {{canonical-map-โ-to-โ}} = embedding-โ-to-โ
โค-to-โ : โค โ โ
โค-to-โ z = ฮน (ฮน z)
โ-to-โ : โ โ โ
โ-to-โ n = ฮน (ฮน {{canonical-map-โ-to-โ}} n)
instance
canonical-map-โค-to-โ : Canonical-Map โค โ
ฮน {{canonical-map-โค-to-โ}} = โค-to-โ
canonical-map-โ-to-โ : Canonical-Map โ โ
ฮน {{canonical-map-โ-to-โ}} = โ-to-โ
0โ : โ
0โ = ฮน 0โ
1โ : โ
1โ = ฮน 1โ
1/2โ : โ
1/2โ = ฮน 1/2
โ-equality : (((Lx , Rx) , isCutx) ((Ly , Ry) , isCuty) : โ)
โ (Lx ๏ผ Ly)
โ (Rx ๏ผ Ry)
โ ((Lx , Rx) , isCutx) ๏ผ ((Ly , Ry) , isCuty)
โ-equality ((Lx , Rx) , isCutx) ((Ly , Ry) , isCuty) eโ eโ = to-subtype-๏ผ (ฮป (L , R) โ isCut-is-prop L R) (to-ร-๏ผ' (eโ , eโ))
โ-equality' : (((Lx , Rx) , isCutx) ((Ly , Ry) , isCuty) : โ)
โ (Lx โ Ly)
โ (Ly โ Lx)
โ (Rx โ Ry)
โ (Ry โ Rx)
โ ((Lx , Rx) , isCutx) ๏ผ ((Ly , Ry) , isCuty)
โ-equality' x y a b c d = โ-equality x y (subset-extensionality pe fe a b) (subset-extensionality pe fe c d)
โ-left-cut-equal-gives-right-cut-equal : (((Lx , Rx) , _) ((Ly , Ry) , _) : โ)
โ Lx ๏ผ Ly
โ Rx ๏ผ Ry
โ-left-cut-equal-gives-right-cut-equal ((Lx , Rx) , inhabited-left-x , inhabited-right-x , rounded-left-x , rounded-right-x , disjoint-x , located-x) ((Ly , Ry) , inhabited-left-y , inhabited-right-y , rounded-left-y , rounded-right-y , disjoint-y , located-y) left-cut-equal = I left-subsets
where
left-subsets : (Lx โ Ly) ร (Ly โ Lx)
left-subsets = โ-refl-consequence Lx Ly left-cut-equal
I : (Lx โ Ly) ร (Ly โ Lx) โ Rx ๏ผ Ry
I (LxโLy , LyโLx) = subset-extensionality pe fe RxโRy RyโRx
where
RxโRy : Rx โ Ry
RxโRy q q-Rx = โฅโฅ-rec q-Ry-is-prop II obtain-q'
where
q-Ry-is-prop : is-prop (q โ Ry)
q-Ry-is-prop = โ-is-prop Ry q
obtain-q' : โ q' ๊ โ , (q' < q) ร q' โ Rx
obtain-q' = (prโ (rounded-right-x q)) q-Rx
II : (ฮฃ q' ๊ โ , (q' < q) ร q' โ Rx) โ q โ Ry
II (q' , (q'<q , q'-Rx)) = โฅโฅ-rec q-Ry-is-prop III use-located
where
use-located : q' โ Ly โจ q โ Ry
use-located = located-y q' q q'<q
III : q' โ Ly โ q โ Ry โ q โ Ry
III (inl q'-Ly) = ๐-elim (โ<-irrefl q' from-above)
where
get-contradiction : q' โ Lx
get-contradiction = LyโLx q' q'-Ly
from-above : q' < q'
from-above = disjoint-x q' q' (get-contradiction , q'-Rx)
III (inr q'-Ry) = q'-Ry
RyโRx : Ry โ Rx
RyโRx q q-Ry = โฅโฅ-rec q-Rx-is-prop II obtain-q'
where
q-Rx-is-prop : is-prop (q โ Rx)
q-Rx-is-prop = โ-is-prop Rx q
obtain-q' : โ q' ๊ โ , (q' < q) ร q' โ Ry
obtain-q' = (prโ (rounded-right-y q)) q-Ry
II : ฮฃ q' ๊ โ , (q' < q) ร q' โ Ry โ q โ Rx
II (q' , (q'<q , q'-Ry)) = โฅโฅ-rec q-Rx-is-prop III use-located
where
use-located : q' โ Lx โจ q โ Rx
use-located = located-x q' q q'<q
III : q' โ Lx โ q โ Rx โ q โ Rx
III (inl q'-Lx) = ๐-elim (โ<-irrefl q' from-above)
where
get-contradiction : q' โ Ly
get-contradiction = LxโLy q' q'-Lx
from-above : q' < q'
from-above = disjoint-y q' q' (get-contradiction , q'-Ry)
III (inr q-Rx) = q-Rx
โ-equality-from-left-cut : (((Lx , Rx) , isCutx) ((Ly , Ry) , isCuty) : โ)
โ Lx ๏ผ Ly
โ ((Lx , Rx) , isCutx) ๏ผ ((Ly , Ry) , isCuty)
โ-equality-from-left-cut x y left-cut-equal = โ-equality x y left-cut-equal right-cut-equal
where
right-cut-equal : prโ (prโ x) ๏ผ prโ (prโ y)
right-cut-equal = โ-left-cut-equal-gives-right-cut-equal x y left-cut-equal
โ-equality-from-left-cut' : (((Lx , Rx) , isCutx) ((Ly , Ry) , isCuty) : โ)
โ Lx โ Ly
โ Ly โ Lx
โ ((Lx , Rx) , isCutx) ๏ผ ((Ly , Ry) , isCuty)
โ-equality-from-left-cut' x y s t = โ-equality-from-left-cut x y (subset-extensionality pe fe s t)
rounded-left-d : (x : โ) โ (p : โ) โ p < x โ โ q ๊ โ , p < q < x
rounded-left-d x@((L , _) , _ , _ , rl , _) = rounded-left-b L rl
use-rounded-real-L : (x : โ) (p q : โ) โ p < q โ q < x โ p < x
use-rounded-real-L x@((L , _) , _ , _ , rl , _) = rounded-left-c L rl
use-rounded-real-L' : (x : โ) (p q : โ) โ p โค q โ q < x โ p < x
use-rounded-real-L' x@((L , _) , _ , _ , rl , _) = rounded-left-a L rl
use-rounded-real-R : (x : โ) (p q : โ) โ p < q โ x < p โ x < q
use-rounded-real-R x@((_ , R) , _ , _ , _ , rr , _) = rounded-right-c R rr
use-rounded-real-R' : (x : โ) (p q : โ) โ p โค q โ x < p โ x < q
use-rounded-real-R' x@((_ , R) , _ , _ , _ , rr , _) = rounded-right-a R rr
disjoint-from-real' : (x : โ) โ (p q : โ) โ (p < x) ร (x < q) โ p โค q
disjoint-from-real' x p q (lโ , lโ) = ฮณ
where
I : p < q
I = disjoint-from-real x p q (lโ , lโ)
ฮณ : p โค q
ฮณ = โ<-coarser-than-โค p q I
type-of-locator-for-reals : ๐คโ ฬ
type-of-locator-for-reals = (x : โ) โ (p q : โ) โ (p < x) โ (x < q)
\end{code}