Skip to content

DedekindReals.Order

Andrew Sneap, March 2021
Updated March 2022

In this file I define order of Dedekind Reals, and prove
some key properties.

{-# OPTIONS --safe --without-K #-}

open import MLTT.Spartan renaming (_+_ to _โˆ”_)

open import Notation.CanonicalMap
open import Notation.Order
open import Rationals.Order

open import UF.FunExt
open import UF.PropTrunc
open import UF.Powerset
open import UF.Subsingletons
open import UF.Subsingletons-FunExt

open import Rationals.Type

module DedekindReals.Order
         (fe : Fun-Ext)
         (pe : Prop-Ext)
         (pt : propositional-truncations-exist)
       where

open import DedekindReals.Type fe pe pt
open PropositionalTruncation pt

_<โ„_ : โ„ โ†’ โ„ โ†’ ๐“คโ‚€ ฬ‡
x <โ„ y = โˆƒ q ๊ž‰ โ„š , (x < q) ร— (q < y)

instance
 Strict-Order-โ„-โ„ : Strict-Order โ„ โ„
 _<_ {{Strict-Order-โ„-โ„}} = _<โ„_

 Strict-Order-Chain-โ„-โ„-โ„ : Strict-Order-Chain โ„ โ„ โ„ _<_ _<_
 _<_<_ {{Strict-Order-Chain-โ„-โ„-โ„}} p q r = (p < q) ร— (q < r)

<-is-prop : (x y : โ„) โ†’ is-prop (x < y)
<-is-prop x y = โˆƒ-is-prop

โ„<-trans : (x y z : โ„) โ†’ x < y โ†’ y < z โ†’ x < z
โ„<-trans x y z x<y y<z = โˆฅโˆฅ-functor I (binary-choice x<y y<z)
 where
  I : (ฮฃ k ๊ž‰ โ„š , x < k < y)
    ร— (ฮฃ l ๊ž‰ โ„š , y < l < z)
    โ†’  ฮฃ m ๊ž‰ โ„š , x < m < z
  I ((k , (x<k , k<y)) , l , (y<l , l<z)) = k , (x<k , k<z)
   where
    k<l : k < l
    k<l = disjoint-from-real y k l (k<y , y<l)
    k<z : k < z
    k<z = rounded-left-c (lower-cut-of z) (rounded-from-real-L z) k l k<l l<z

_โ‰คโ„_ : โ„ โ†’ โ„ โ†’ ๐“คโ‚€ ฬ‡
x โ‰คโ„ y = (q : โ„š) โ†’ q < x โ†’ q < y

instance
 Order-โ„-โ„ : Order โ„ โ„
 _โ‰ค_ {{Order-โ„-โ„}} = _โ‰คโ„_

โ‰ค-is-prop : (x y : โ„) โ†’ is-prop (x โ‰ค y)
โ‰ค-is-prop ((Lx , Rx) , isCutx) ((Ly , Ry) , isCuty) = ฮ โ‚‚-is-prop fe (ฮป q _ โ†’ โˆˆ-is-prop Ly q)

โ„โ‰ค-trans : (x y z : โ„) โ†’ x โ‰ค y โ†’ y โ‰ค z โ†’ x โ‰ค z
โ„โ‰ค-trans ((Lx , Rx) , _) ((Ly , Ry) , _) ((Lz , Rz) , _) f g = ฮป q qLx โ†’ g q (f q qLx)

โ„-archimedean : (x y : โ„)
              โ†’ x < y
              โ†’ โˆƒ q ๊ž‰ โ„š , (x < q) ร— (q < y)
โ„-archimedean x y l = l

weak-linearity : (x y z : โ„) โ†’ x < y โ†’ (x < z) โˆจ (z < y)
weak-linearity x y z l = โˆฅโˆฅ-rec โˆจ-is-prop I l
 where
  I : ฮฃ q ๊ž‰ โ„š , q > x ร— q < y โ†’ (x < z) โˆจ (z < y)
  I (q , qRx , qLy) = โˆฅโˆฅ-rec โˆจ-is-prop II (binary-choice exists-r exists-s)
   where
    exists-r : โˆƒ r ๊ž‰ โ„š , r < q ร— r > x
    exists-r = rounded-right-b (upper-cut-of x) (rounded-from-real-R x) q qRx
    exists-s : โˆƒ s ๊ž‰ โ„š , q < s < y
    exists-s = rounded-left-b (lower-cut-of y) (rounded-from-real-L y) q qLy
    II : (ฮฃ r ๊ž‰ โ„š , r < q ร— r > x) ร— (ฮฃ s ๊ž‰ โ„š , q < s < y) โ†’ (x < z) โˆจ (z < y)
    II ((r , r<q , rRx) , s , q<s , sLy) = โˆฅโˆฅ-rec โˆจ-is-prop IV III
     where
      III : (r < z) โˆจ (z < s)
      III = โ„-locatedness z r s (โ„š<-trans r q s r<q q<s)
      IV : (r < z) โˆ” (z < s) โ†’ (x < z) โˆจ (z < y)
      IV (inl rLz) = โˆฃ inl โˆฃ r , rRx , rLz โˆฃ โˆฃ
      IV (inr sRz) = โˆฃ inr โˆฃ s , sRz , sLy โˆฃ โˆฃ

weak-linearity' : (x y z : โ„) โ†’ x < y โ†’ (x < z) โˆจ (z < y)
weak-linearity' x y z l = do
 (q , x<q , q<y) โ† l
 (r , r<q , x<r) โ† rounded-right-b (upper-cut-of x) (rounded-from-real-R x) q x<q
 (s , q<s , s<y) โ† rounded-left-b (lower-cut-of y) (rounded-from-real-L y) q q<y
 t               โ† โ„-locatedness z r s (โ„š<-trans r q s r<q q<s)
 Cases t (ฮป r<z โ†’ โˆฃ inl โˆฃ r , x<r , r<z โˆฃ โˆฃ)
         (ฮป z<s โ†’ โˆฃ inr โˆฃ s , z<s , s<y โˆฃ โˆฃ)

_โ™ฏ_ : (x y : โ„) โ†’ ๐“คโ‚€ ฬ‡
x โ™ฏ y = (x < y) โˆจ (y < x)

apartness-gives-inequality : (x y : โ„) โ†’ x โ™ฏ y โ†’ ยฌ (x ๏ผ y)
apartness-gives-inequality x y apart e = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop I apart
 where
  I : ยฌ ((x < y) โˆ” (y < x))
  I (inl l) = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop III II
   where
    II : x < x
    II = transport (x <_) (e โปยน) l
    III : ยฌ (ฮฃ q ๊ž‰ โ„š , (x < q) ร— (q < x))
    III (q , x<q , q<x) = โ„š<-not-itself-from-โ„ q x (q<x , x<q)
  I (inr r) = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop III II
   where
    II : y < y
    II = transport (y <_) e r
    III : ยฌ (ฮฃ p ๊ž‰ โ„š , (p > y) ร— (p < y))
    III (p , y<p , p<y) = โ„š<-not-itself-from-โ„ p y (p<y , y<p)

โ„<-โ‰ค-trans : (x y z : โ„) โ†’ x < y โ†’ y โ‰ค z โ†’ x < z
โ„<-โ‰ค-trans x y z x<y yโ‰คz = โˆฅโˆฅ-functor I x<y
 where
  I : ฮฃ q ๊ž‰ โ„š , q > x ร— q < y โ†’ ฮฃ q' ๊ž‰ โ„š , q' > x ร— q' < z
  I (q , qRx , qLy) = q , qRx , yโ‰คz q qLy

โ„-less-than-or-equal-not-greater : (x y : โ„) โ†’ x โ‰ค y โ†’ ยฌ (y < x)
โ„-less-than-or-equal-not-greater x y xโ‰คy y<x = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop I y<x
 where
  I : ยฌ (ฮฃ q ๊ž‰ โ„š , y < q < x)
  I (q , y<q , q<x) = โ„š<-not-itself-from-โ„ q y (xโ‰คy q q<x , y<q)

โ„-less-than-not-greater-or-equal : (x y : โ„) โ†’ x < y โ†’ ยฌ (y โ‰ค x)
โ„-less-than-not-greater-or-equal x y lโ‚ lโ‚‚ = โ„-less-than-or-equal-not-greater y x lโ‚‚ lโ‚

โ„-not-less-is-greater-or-equal : (x y : โ„) โ†’ ยฌ (x < y) โ†’ y โ‰ค x
โ„-not-less-is-greater-or-equal x y nl p pLy = โˆฅโˆฅ-rec (โˆˆ-is-prop (lower-cut-of x) p) I (rounded-left-b (lower-cut-of y) (rounded-from-real-L y) p pLy)
 where
  I : ฮฃ q ๊ž‰ โ„š , p < q < y โ†’ p < x
  I (q , l , q<y) = โˆฅโˆฅ-rec (โˆˆ-is-prop (lower-cut-of x) p) II (โ„-locatedness x p q l)
   where
    II : p < x โˆ” q > x โ†’ p < x
    II (inl p<x) = p<x
    II (inr x<q) = ๐Ÿ˜-elim (nl โˆฃ q , (x<q , q<y) โˆฃ)

โ„โ‰ค-<-trans : (x y z : โ„) โ†’ x โ‰ค y โ†’ y < z โ†’ x < z
โ„โ‰ค-<-trans x y z xโ‰คy y<z = โˆฅโˆฅ-functor I y<z
 where
  I : ฮฃ q ๊ž‰ โ„š , q > y ร— q < z
    โ†’ ฮฃ q' ๊ž‰ โ„š , q' > x ร— q' < z
  I (q , qRy , qLz) = q , โˆฅโˆฅ-rec (โˆˆ-is-prop (upper-cut-of x) q) III II , qLz
   where
    II : โˆƒ k ๊ž‰ โ„š , k < q ร— k > y
    II = rounded-right-b (upper-cut-of y) (rounded-from-real-R y) q qRy

    III : ฮฃ k ๊ž‰ โ„š , k < q ร— k > y โ†’ q > x
    III (k , k<q , kRy) = โˆฅโˆฅ-rec (โˆˆ-is-prop (upper-cut-of x) q) IV (โ„-locatedness x k q k<q)
     where
      IV : k < x โˆ” q > x โ†’ q > x
      IV (inl kLx) = ๐Ÿ˜-elim (โ„š<-irrefl k (disjoint-from-real y k k (xโ‰คy k kLx , kRy)))
      IV (inr qRx) = qRx

<โ„-irreflexive : (x : โ„) โ†’ x โ‰ฎ x
<โ„-irreflexive x l = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop I l
 where
  I : ยฌ (ฮฃ k ๊ž‰ โ„š , x < k < x)
  I (k , x<k , k<x) = โ„š<-not-itself-from-โ„ k x (k<x , x<k)

โ„-zero-less-than-one : 0โ„ < 1โ„
โ„-zero-less-than-one = โˆฃ 1/2 , 0<1/2 , 1/2<1 โˆฃ

โ„-zero-apart-from-one : 0โ„ โ™ฏ 1โ„
โ„-zero-apart-from-one = โˆฃ inl โ„-zero-less-than-one โˆฃ

embedding-preserves-order : (p q : โ„š) โ†’ p < q โ†’ ฮน p < ฮน q
embedding-preserves-order p q l = I (use-rationals-density)
 where
  use-rationals-density : ฮฃ k ๊ž‰ โ„š , p < k < q
  use-rationals-density = โ„š-dense p q l

  I : (ฮฃ k ๊ž‰ โ„š , p < k < q) โ†’ โˆƒ k ๊ž‰ โ„š , p < k < q
  I (k , p<k , k<q) = โˆฃ k , p<k , k<q โˆฃ


Added by Martin Escardo 24th August 2023, adapted from Various.Dedekind.


โ‰ค-โ„-โ„-antisym : (x y : โ„) โ†’ x โ‰ค y โ†’ y โ‰ค x โ†’ x ๏ผ y
โ‰ค-โ„-โ„-antisym = โ„-equality-from-left-cut'

โ™ฏ-is-tight : (x y : โ„) โ†’ ยฌ (x โ™ฏ y) โ†’ x ๏ผ y
โ™ฏ-is-tight x y ฮฝ = โ‰ค-โ„-โ„-antisym x y III IV
 where
  I : x โ‰ฎ y
  I โ„“ = ฮฝ โˆฃ inl โ„“ โˆฃ

  II : y โ‰ฎ x
  II โ„“ = ฮฝ โˆฃ inr โ„“ โˆฃ

  III : x โ‰ค y
  III = โ„-not-less-is-greater-or-equal y x II

  IV : y โ‰ค x
  IV = โ„-not-less-is-greater-or-equal x y I

โ„-is-ยฌยฌ-separated : (x y : โ„) โ†’ ยฌยฌ (x ๏ผ y) โ†’ x ๏ผ y
โ„-is-ยฌยฌ-separated x y ฯ• = โ™ฏ-is-tight x y (c ฯ•)
 where
  c : ยฌยฌ (x ๏ผ y) โ†’ ยฌ (x โ™ฏ y)
  c = contrapositive (apartness-gives-inequality x y)