Skip to content

Various.Dedekind

Martin Escardo, 20th December 2021

Some thoughts about Dedekind reals.

A Dedekind real in constructive type theory is defined as a triple
(L , U , p) where L and U are data, namely given sets of rational
numbers, and p is property of (L , U).

But actually, given a lower Dedekind section L, there is at most one
pair (U , p) such that (L , U , p) is a Dedekind real. Hence the
Dedekind data (U , p) is property of the lower real L rather than
data. A more precise statement of this phenomenon is given below.

We generalize the rationals to any type with a proposition-valued,
irreflexive relation _<_, simply to avoid having to define the
rational numbers, but also because we could replace the rationals by
e.g. the dyadic rationals, or indeed by any dense countable subset.
But also it is interesting than nothing other than a
proposition-valued irreflexive relation is needed for the above
discussion.

We also discuss a version of the Dedekind reals proposed by Troelstra.
To show that it agrees with the usual one, we further assume that _<_
is dense, upper open, and satisfies p โ‰  q โ†’ p โ‰ฎ q โ†’ p < q (which the
type of rationals does).

We also discuss what happens when we assume the principle of
excluded middle.

Here we adopt HoTT/UF as our type-theoretic foundation, which, in
particular, is well-suited to discuss the distinction between data and
property. The univalence axiom is not used anywhere here, but we
mention it in some discussions.


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

open import MLTT.Spartan
open import Naturals.Order hiding (<-โ‰ค-trans)
open import Notation.CanonicalMap
open import Notation.Order
open import TypeTopology.CompactTypes
open import UF.Base
open import UF.Embeddings
open import UF.Equiv
open import UF.FunExt
open import UF.Powerset
open import UF.PropTrunc
open import UF.Sets
open import UF.Sets-Properties
open import UF.Size
open import UF.SubtypeClassifier
open import UF.Subsingletons
open import UF.Subsingletons-FunExt

module Various.Dedekind
        (pt                   : propositional-truncations-exist)
        (fe                   : Fun-Ext)
        (pe                   : Prop-Ext)
        {๐“ค                    : Universe}
        (โ„š                    : ๐“ค ฬ‡ )
        (_<-โ„š-โ„š_              : โ„š โ†’ โ„š โ†’ ๐“ค ฬ‡ )
        (<-โ„š-โ„š-is-prop-valued : (p q : โ„š) โ†’ is-prop (p <-โ„š-โ„š q))
        (<-โ„š-โ„š-irrefl         : (q : โ„š) โ†’ ยฌ (q <-โ„š-โ„š q))
       where

open PropositionalTruncation pt
open inhabited-subsets pt

instance
 strict-order-โ„š : Strict-Order โ„š โ„š
 _<_ {{strict-order-โ„š}} = _<-โ„š-โ„š_

๐“คโบ = ๐“ค โบ


Lower-real conditions:


is-lower : ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
is-lower L = (q : โ„š) โ†’ q โˆˆ L โ†’ (p : โ„š) โ†’ p < q โ†’ p โˆˆ L

is-upper-open : ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
is-upper-open L = (p : โ„š) โ†’ p โˆˆ L โ†’ โˆƒ p' ๊ž‰ โ„š , ((p < p') ร— p' โˆˆ L)

is-lower-real : ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
is-lower-real L = is-inhabited L ร— is-lower L ร— is-upper-open L


Upper-real conditions:


is-upper : ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
is-upper U = (p : โ„š) โ†’ p โˆˆ U โ†’ (q : โ„š) โ†’ p < q โ†’ q โˆˆ U

is-lower-open : ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
is-lower-open U = (q : โ„š) โ†’ q โˆˆ U โ†’ โˆƒ q' ๊ž‰ โ„š , ((q' < q) ร— q' โˆˆ U)

is-upper-real : ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
is-upper-real U = is-inhabited U ร— is-upper U ร— is-lower-open U


The conditions are property:


being-lower-is-prop : (L : ๐“Ÿ โ„š) โ†’ is-prop (is-lower L)
being-lower-is-prop L = ฮ โ‚„-is-prop fe (ฮป _ _ _ _ โ†’ โˆˆ-is-prop L _)

being-upper-open-is-prop : (L : ๐“Ÿ โ„š) โ†’ is-prop (is-upper-open L)
being-upper-open-is-prop L = ฮ โ‚‚-is-prop fe (ฮป _ _ โ†’ โˆƒ-is-prop)

being-lower-real-is-prop : (L : ๐“Ÿ โ„š) โ†’ is-prop (is-lower-real L)
being-lower-real-is-prop L = ร—โ‚ƒ-is-prop
                              (being-inhabited-is-prop L)
                              (being-lower-is-prop L)
                              (being-upper-open-is-prop L)

being-upper-is-prop : (L : ๐“Ÿ โ„š) โ†’ is-prop (is-upper L)
being-upper-is-prop L = ฮ โ‚„-is-prop fe (ฮป _ _ _ _ โ†’ โˆˆ-is-prop L _)

being-lower-open-is-prop : (L : ๐“Ÿ โ„š) โ†’ is-prop (is-lower-open L)
being-lower-open-is-prop L = ฮ โ‚‚-is-prop fe (ฮป _ _ โ†’ โˆƒ-is-prop)

being-upper-real-is-prop : (L : ๐“Ÿ โ„š) โ†’ is-prop (is-upper-real L)
being-upper-real-is-prop L = ร—โ‚ƒ-is-prop
                              (being-inhabited-is-prop L)
                              (being-upper-is-prop L)
                              (being-lower-open-is-prop L)

The sets of lower and upper reals:


โ„แดธ : ๐“คโบ ฬ‡
โ„แดธ = ฮฃ L ๊ž‰ ๐“Ÿ โ„š , is-lower-real L

โ„แต : ๐“คโบ ฬ‡
โ„แต = ฮฃ U ๊ž‰ ๐“Ÿ โ„š , is-upper-real U

โ„แดธ-is-set : is-set โ„แดธ
โ„แดธ-is-set = subsets-of-sets-are-sets (๐“Ÿ โ„š)
             is-lower-real
             (powersets-are-sets'' fe fe pe)
             (ฮป {l} โ†’ being-lower-real-is-prop l)

โ„แต-is-set : is-set โ„แต
โ„แต-is-set = subsets-of-sets-are-sets (๐“Ÿ โ„š)
             is-upper-real
             (powersets-are-sets'' fe fe pe)
             (ฮป {l} โ†’ being-upper-real-is-prop l)

โ„แดธ-to-๐“Ÿโ„š : โ„แดธ โ†’ ๐“Ÿ โ„š
โ„แดธ-to-๐“Ÿโ„š = prโ‚

โ„แต-to-๐“Ÿโ„š : โ„แต โ†’ ๐“Ÿ โ„š
โ„แต-to-๐“Ÿโ„š = prโ‚

instance
 canonical-map-โ„แดธ-to-๐“Ÿโ„š : Canonical-Map โ„แดธ (๐“Ÿ โ„š)
 ฮน {{canonical-map-โ„แดธ-to-๐“Ÿโ„š}} = โ„แดธ-to-๐“Ÿโ„š

 canonical-map-โ„แต-to-๐“Ÿโ„š : Canonical-Map โ„แต (๐“Ÿ โ„š)
 ฮน {{canonical-map-โ„แต-to-๐“Ÿโ„š}} = โ„แต-to-๐“Ÿโ„š

โ„แดธ-to-๐“Ÿโ„š-is-embedding : is-embedding (canonical-map โ„แดธ (๐“Ÿ โ„š))
โ„แดธ-to-๐“Ÿโ„š-is-embedding = prโ‚-is-embedding being-lower-real-is-prop

โ„แต-to-๐“Ÿโ„š-is-embedding : is-embedding (canonical-map โ„แต (๐“Ÿ โ„š))
โ„แต-to-๐“Ÿโ„š-is-embedding = prโ‚-is-embedding being-upper-real-is-prop


Next we define the set of Dedekind reals as a subset of the lower
reals, after some preparation.


are-ordered : ๐“Ÿ โ„š โ†’ ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
are-ordered L U = (p q : โ„š) โ†’ p โˆˆ L โ†’ q โˆˆ U โ†’ p < q

are-located : ๐“Ÿ โ„š โ†’ ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
are-located L U = (p q : โ„š) โ†’ p < q โ†’ p โˆˆ L โˆจ q โˆˆ U

being-ordered-is-prop : (L U : ๐“Ÿ โ„š) โ†’ is-prop (are-ordered L U)
being-ordered-is-prop _ _ = ฮ โ‚„-is-prop fe (ฮป _ _ _ _ โ†’ <-โ„š-โ„š-is-prop-valued _ _)

being-located-is-prop : (L U : ๐“Ÿ โ„š) โ†’ is-prop (are-located L U)
being-located-is-prop _ _ = ฮ โ‚ƒ-is-prop fe (ฮป _ _ _ โ†’ โˆจ-is-prop)

order-lemma : (L U L' U' : ๐“Ÿ โ„š)
            โ†’ is-lower-open U'
            โ†’ are-located L  U
            โ†’ are-ordered L' U'
            โ†’ L  โІ L'
            โ†’ U' โІ U
order-lemma L U L' U'
            U'-lower-open
            LU-located
            LU'-ordered
            L-contained-in-L'
            q
            q-in-U'             = ฮณ
 where
  I : โˆƒ q' ๊ž‰ โ„š , (q' < q) ร— q' โˆˆ U'
  I = U'-lower-open q q-in-U'

  II : (ฮฃ q' ๊ž‰ โ„š , (q' < q) ร— q' โˆˆ U') โ†’ q โˆˆ U
  II (q' , l , i) = VI
   where
    III : q' โˆˆ L โˆจ q โˆˆ U
    III = LU-located q' q l

    IV : q' โˆ‰ L
    IV j = <-โ„š-โ„š-irrefl q' b
     where
      a : q' โˆˆ L'
      a = L-contained-in-L' q' j

      b : q' < q'
      b = LU'-ordered q' q' a i

    V : (q' โˆˆ L) + (q โˆˆ U) โ†’ q โˆˆ U
    V (inl j) = ๐Ÿ˜-elim (IV j)
    V (inr k) = k

    VI : q โˆˆ U
    VI = โˆฅโˆฅ-rec (โˆˆ-is-prop U q) V III

  ฮณ : q โˆˆ U
  ฮณ = โˆฅโˆฅ-rec (โˆˆ-is-prop U q) II I

order-lemma-converse : (L U L' U' : ๐“Ÿ โ„š)
                     โ†’ is-upper-open L
                     โ†’ are-located L' U'
                     โ†’ are-ordered L  U
                     โ†’ U' โІ U
                     โ†’ L  โІ L'
order-lemma-converse L U L' U'
                     L-upper-open
                     LU'-located
                     LU-ordered
                     U'-contained-in-U
                     q
                     q-in-L             = ฮณ
 where
  I : โˆƒ q' ๊ž‰ โ„š , (q < q') ร— q' โˆˆ L
  I = L-upper-open q q-in-L

  II : (ฮฃ q' ๊ž‰ โ„š , (q < q') ร— q' โˆˆ L) โ†’ q โˆˆ L'
  II (q' , l , i) = VI
   where
    III : q โˆˆ L' โˆจ q' โˆˆ U'
    III = LU'-located q q' l

    IV : q' โˆ‰ U'
    IV j = <-โ„š-โ„š-irrefl q' b
     where
      a : q' โˆˆ U
      a = U'-contained-in-U q' j

      b : q' < q'
      b = LU-ordered q' q' i a

    V : (q โˆˆ L') + (q' โˆˆ U') โ†’ q โˆˆ L'
    V (inl j) = j
    V (inr k) = ๐Ÿ˜-elim (IV k)

    VI : q โˆˆ L'
    VI = โˆฅโˆฅ-rec (โˆˆ-is-prop L' q) V III

  ฮณ : q โˆˆ L'
  ฮณ = โˆฅโˆฅ-rec (โˆˆ-is-prop L' q) II I


The following definition is of an auxiliary character:


_is-an-upper-section-of_ : ๐“Ÿ โ„š โ†’ ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
U is-an-upper-section-of L = is-lower-open U ร— are-ordered L U ร— are-located L U

any-two-upper-sections-are-equal : (L U U' : ๐“Ÿ โ„š)
                                 โ†’ U  is-an-upper-section-of L
                                 โ†’ U' is-an-upper-section-of L
                                 โ†’ U ๏ผ U'
any-two-upper-sections-are-equal L U U' (a , b , c) (u , v , w) = ฮณ
 where
  i : U โІ U'
  i = order-lemma L U' L U  a w b (โІ-refl' L)

  j : U โЇ U'
  j = order-lemma L U  L U' u c v (โІ-refl' L)

  ฮณ : U ๏ผ U'
  ฮณ = subset-extensionality'' pe fe fe i j


The following is the version of the definition we are interested in:


_is-upper-section-of_ : โ„แต โ†’ โ„แดธ โ†’ ๐“ค ฬ‡
(U , _) is-upper-section-of  (L , _) = are-ordered L U ร— are-located L U

being-upper-section-is-prop : (x : โ„แดธ) (y : โ„แต)
                            โ†’ is-prop (y is-upper-section-of x)
being-upper-section-is-prop (L , _) (U , _) = ร—-is-prop
                                               (being-ordered-is-prop L U)
                                               (being-located-is-prop L U)

We use the above auxiliary definition and lemma to establish the following:


at-most-one-upper-section : (l : โ„แดธ) (uโ‚€ uโ‚ : โ„แต)
                          โ†’ uโ‚€ is-upper-section-of l
                          โ†’ uโ‚ is-upper-section-of l
                          โ†’ uโ‚€ ๏ผ uโ‚
at-most-one-upper-section (L , _)
                          uโ‚€@(Uโ‚€ , _ , _ , Uโ‚€-is-lower-open)
                          uโ‚@(Uโ‚ , _ , _ , Uโ‚-is-lower-open)
                          (luโ‚€-ordered , luโ‚€-located)
                          (luโ‚-ordered , luโ‚-located)      = ฮณ
 where
  ฮณ : uโ‚€ ๏ผ uโ‚
  ฮณ = to-subtype-๏ผ
       being-upper-real-is-prop
       (any-two-upper-sections-are-equal L Uโ‚€ Uโ‚
        (Uโ‚€-is-lower-open , luโ‚€-ordered , luโ‚€-located)
        (Uโ‚-is-lower-open , luโ‚-ordered , luโ‚-located))


The Dedekind condition for a lower real:


is-dedekind : โ„แดธ โ†’ ๐“คโบ ฬ‡
is-dedekind l = ฮฃ u ๊ž‰ โ„แต , (u is-upper-section-of l)

being-dedekind-is-prop : (l : โ„แดธ) โ†’ is-prop (is-dedekind l)
being-dedekind-is-prop l (uโ‚€ , pโ‚€) (uโ‚ , pโ‚) =
 to-subtype-๏ผ
  (being-upper-section-is-prop l)
  (at-most-one-upper-section l uโ‚€ uโ‚ pโ‚€ pโ‚)


We define the Dedekind reals as a subset of the lower reals:


โ„ : ๐“คโบ ฬ‡
โ„ = ฮฃ l ๊ž‰ โ„แดธ , is-dedekind l


The forgetful map of the reals into the lower reals is an embedding
and hence โ„ is a set:


โ„-to-โ„แดธ : โ„ โ†’ โ„แดธ
โ„-to-โ„แดธ = prโ‚

โ„-to-โ„แดธ-is-embedding : is-embedding โ„-to-โ„แดธ
โ„-to-โ„แดธ-is-embedding = prโ‚-is-embedding being-dedekind-is-prop

โ„-is-set : is-set โ„
โ„-is-set = subsets-of-sets-are-sets โ„แดธ
            is-dedekind
            โ„แดธ-is-set
            (ฮป {l} โ†’ being-dedekind-is-prop l)

instance
 canonical-map-โ„-to-โ„แดธ : Canonical-Map โ„ โ„แดธ
 ฮน {{canonical-map-โ„-to-โ„แดธ}} = โ„-to-โ„แดธ


NB. This won't be a *topological* embedding in topological
models. Because โ„ and โ„แดธ are sets, in the sense of HoTT/UF, the
embedding condition merely says that the map is left-cancellable.

We unpack and reorder the definition to emphasize that it amounts to
the usual one:


is-dedekind-section : ๐“Ÿ โ„š ร— ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
is-dedekind-section (L , U) = is-inhabited L ร— is-lower L ร— is-upper-open L
                            ร— is-inhabited U ร— is-upper U ร— is-lower-open U
                            ร— are-ordered L U ร— are-located L U


NBโ‚ : โ„ โ‰ƒ (ฮฃ (L , R) ๊ž‰ ๐“Ÿ โ„š ร— ๐“Ÿ โ„š , is-dedekind-section (L , R))
NBโ‚ = qinveq
       (ฮป ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l)
         โ†’ ((L , U) , Li , Ll , Lo , Ui , Uu , Uo , o , l))
       ((ฮป ((L , U) , Li , Ll , Lo , Ui , Uu , Uo , o , l)
         โ†’ ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l)) ,
        (ฮป _ โ†’ refl) ,
        (ฮป _ โ†’ refl))


The following shows that there is some redundancy in the definition of
Dedekind real:


ordered-located-gives-lower : (L U : ๐“Ÿ โ„š)
                            โ†’ are-ordered L U
                            โ†’ are-located L U
                            โ†’ is-lower L
ordered-located-gives-lower L U LU-ordered LU-located = ฮณ
 where
  ฮณ : is-lower L
  ฮณ q l p m = โˆฅโˆฅ-rec (โˆˆ-is-prop L p) b a
   where
    a : p โˆˆ L โˆจ q โˆˆ U
    a = LU-located p q m

    b : (p โˆˆ L) + (q โˆˆ U) โ†’ p โˆˆ L
    b (inl u) = u
    b (inr v) = ๐Ÿ˜-elim (<-โ„š-โ„š-irrefl q (LU-ordered q q l v))

ordered-located-gives-upper : (L U : ๐“Ÿ โ„š)
                            โ†’ are-ordered L U
                            โ†’ are-located L U
                            โ†’ is-upper U
ordered-located-gives-upper L U LU-ordered LU-located = ฮณ
 where
  ฮณ : is-upper U
  ฮณ q l p m = โˆฅโˆฅ-rec (โˆˆ-is-prop U p) b a
   where
    a : q โˆˆ L โˆจ p โˆˆ U
    a = LU-located q p m

    b : (q โˆˆ L) + (p โˆˆ U) โ†’ p โˆˆ U
    b (inl u) = ๐Ÿ˜-elim (<-โ„š-โ„š-irrefl q (LU-ordered q q u l))
    b (inr v) = v


NBโ‚‚ : โ„ โ‰ƒ (ฮฃ (L , U) ๊ž‰ ๐“Ÿ โ„š ร— ๐“Ÿ โ„š
                     , is-inhabited L ร— is-upper-open L
                     ร— is-inhabited U ร— is-lower-open U
                     ร— are-ordered L U ร— are-located L U)
NBโ‚‚ = qinveq
       (ฮป ((L , Li , _ , Lo) , (U , Ui , _ , Uo) , o , l)
         โ†’ ((L , U) , Li , Lo , Ui , Uo , o , l))

       ((ฮป ((L , U) , Li , Lo , Ui , Uo , o , l)
         โ†’ ((L , Li , ordered-located-gives-lower L U o l , Lo) ,
            (U , Ui , ordered-located-gives-upper L U o l , Uo) ,
            o , l)) ,
        (ฮป ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l)
          โ†’ to-subtype-๏ผ being-dedekind-is-prop
             (to-subtype-๏ผ being-lower-real-is-prop refl)) ,
        (ฮป ((L , U) , Li , Lo , Ui , Uo , o , l)
         โ†’ to-subtype-๏ผ (ฮป (L , U) โ†’ ร—โ‚†-is-prop
                                      (being-inhabited-is-prop L)
                                      (being-upper-open-is-prop L)
                                      (being-inhabited-is-prop U)
                                      (being-lower-open-is-prop U)
                                      (being-ordered-is-prop L U)
                                      (being-located-is-prop L U))
             refl))

Sometimes a disjointness condition rather than the order condition is
used in the definition of Dedekind reals.


disjoint-criterion : (L U : ๐“Ÿ โ„š)
                   โ†’ are-ordered L U
                   โ†’ are-disjoint L U
disjoint-criterion L U o p (p-in-L , p-in-U) = <-โ„š-โ„š-irrefl p (o p p p-in-L p-in-U)


From now on we assume the properties of โ„š and its order alluded above,
and a few more:


module โ„š-assumptions
        (โ„š-density         : (p r : โ„š) โ†’ p < r โ†’ ฮฃ q ๊ž‰ โ„š , (p < q) ร— (q < r))
        (โ„š-transitivity    : (p q r : โ„š) โ†’ p < q โ†’ q < r โ†’ p < r)
        (โ„š-order-criterion : (p q : โ„š) โ†’ q โ‰ฎ p โ†’ p โ‰  q โ†’ p < q)
        (โ„š-cotransitivity  : (p q r : โ„š) โ†’ p < r โ†’ (p < q) โˆจ (q < r))
        (โ„š-tightness       : (p q : โ„š) โ†’ q โ‰ฎ p โ†’ p โ‰ฎ q โ†’ p ๏ผ q)
        (โ„š-is-lower-open   : (q : โ„š) โ†’ โˆƒ p ๊ž‰ โ„š , (p < q))
        (โ„š-is-upper-open   : (p : โ„š) โ†’ โˆƒ q ๊ž‰ โ„š , (p < q))
        (๐ŸŽ ยฝ ๐Ÿ             : โ„š)
        (๐ŸŽ-is-less-than-ยฝ  : ๐ŸŽ < ยฝ)
        (ยฝ-is-less-than-๐Ÿ  : ยฝ < ๐Ÿ)
      where

 ๐ŸŽ-is-less-than-๐Ÿ : ๐ŸŽ < ๐Ÿ
 ๐ŸŽ-is-less-than-๐Ÿ = โ„š-transitivity ๐ŸŽ ยฝ ๐Ÿ ๐ŸŽ-is-less-than-ยฝ ยฝ-is-less-than-๐Ÿ

 instance
  order-โ„š-โ„š : Order โ„š โ„š
  _โ‰ค_ {{order-โ„š-โ„š}} p q = (r : โ„š) โ†’ r < p โ†’ r < q

 โ„š-โ‰ค-antisym : (p q : โ„š) โ†’ p โ‰ค q โ†’ q โ‰ค p โ†’ p ๏ผ q
 โ„š-โ‰ค-antisym p q i j = โ„š-tightness p q (ฮป โ„“ โ†’ <-โ„š-โ„š-irrefl q (i q โ„“))
                                       (ฮป โ„“ โ†’ <-โ„š-โ„š-irrefl p (j p โ„“))

 <-or-๏ผ-gives-โ‰ค-on-โ„š : (p q : โ„š) โ†’ (p < q) + (p ๏ผ q) โ†’ p โ‰ค q
 <-or-๏ผ-gives-โ‰ค-on-โ„š p q (inl โ„“)    r m = โ„š-transitivity r p q m โ„“
 <-or-๏ผ-gives-โ‰ค-on-โ„š p q (inr refl) r โ„“ = โ„“

 โ„š-trichotomy = (p q : โ„š) โ†’ (p < q) + (p ๏ผ q) + (p > q)

 โ‰ค-on-โ„š-gives-๏ผ-or-< : โ„š-trichotomy
                     โ†’ (p q : โ„š) โ†’ p โ‰ค q โ†’ (p < q) + (p ๏ผ q)
 โ‰ค-on-โ„š-gives-๏ผ-or-< ฯ„ p q โ„“ = ฮณ (ฯ„ p q)
  where
   I : q โ‰ฎ p
   I m = <-โ„š-โ„š-irrefl q (โ„“ q m)

   ฮณ : (p < q) + (p ๏ผ q) + (p > q) โ†’ (p < q) + (p ๏ผ q)
   ฮณ (inl i)       = inl i
   ฮณ (inr (inl e)) = inr e
   ฮณ (inr (inr j)) = ๐Ÿ˜-elim (I j)

 ordered-criterion : (L U : ๐“Ÿ โ„š)
                   โ†’ is-lower L
                   โ†’ are-disjoint L U
                   โ†’ are-ordered L U
 ordered-criterion L U L-lower LU-disjoint p q p-in-L q-in-U = ฮณ
  where
   I : p โˆ‰ U
   I p-in-U = LU-disjoint p (p-in-L , p-in-U)

   II : p โ‰  q
   II refl = I q-in-U

   III : q โ‰ฎ p
   III โ„“ = LU-disjoint q (L-lower p p-in-L q โ„“ , q-in-U)

   ฮณ : p < q
   ฮณ = โ„š-order-criterion p q III II


The following alternative definition of the Dedekind reals is often
found in the literature:


 NBโ‚ƒ : โ„ โ‰ƒ (ฮฃ (L , U) ๊ž‰ ๐“Ÿ โ„š ร— ๐“Ÿ โ„š
                      , is-inhabited L ร— is-lower L ร— is-upper-open L
                      ร— is-inhabited U ร— is-upper U ร— is-lower-open U
                      ร— are-disjoint L U ร— are-located L U)
 NBโ‚ƒ =
  qinveq
   (ฮป ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l)
     โ†’ ((L , U) , Li , Ll , Lo , Ui , Uu , Uo , disjoint-criterion L U o , l))
   ((ฮป ((L , U) , Li , Ll , Lo , Ui , Uu , Uo , d , l)
     โ†’ ((L , Li , Ll , Lo) ,
        (U , Ui , Uu , Uo) ,
        ordered-criterion L U Ll d , l)) ,
    (ฮป ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l)
     โ†’ to-subtype-๏ผ being-dedekind-is-prop
        (to-subtype-๏ผ being-lower-real-is-prop
          refl)) ,
    (ฮป ((L , U) , Li , Lo , Ui , Uo , o , l)
     โ†’ to-subtype-๏ผ (ฮป (L , U) โ†’ ร—โ‚ˆ-is-prop
                                  (being-inhabited-is-prop L)
                                  (being-lower-is-prop L)
                                  (being-upper-open-is-prop L)
                                  (being-inhabited-is-prop U)
                                  (being-upper-is-prop U)
                                  (being-lower-open-is-prop U)
                                  (being-disjoint-is-prop fe L U)
                                  (being-located-is-prop L U))
       refl))


We now consider an alternative definition of the Dedekind reals
offered by Troelstra.


 is-bounded-above : ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
 is-bounded-above L = โˆƒ s ๊ž‰ โ„š , s โˆ‰ L

 is-located : ๐“Ÿ โ„š โ†’ ๐“ค ฬ‡
 is-located L = ((r s : โ„š) โ†’ r < s โ†’ r โˆˆ L โˆจ s โˆ‰ L)

 is-troelstra : โ„แดธ โ†’ ๐“ค ฬ‡
 is-troelstra (L , _) = is-bounded-above L ร— is-located L

 being-bounded-above-is-prop : (L : ๐“Ÿ โ„š) โ†’ is-prop (is-bounded-above L)
 being-bounded-above-is-prop L = โˆƒ-is-prop

 being-troelstra-located-is-prop : (L : ๐“Ÿ โ„š) โ†’ is-prop (is-located L)
 being-troelstra-located-is-prop L = ฮ โ‚ƒ-is-prop fe (ฮป _ _ _ โ†’ โˆจ-is-prop)

 being-troelstra-is-prop : (l : โ„แดธ) โ†’ is-prop (is-troelstra l)
 being-troelstra-is-prop (L , _) = ร—-is-prop
                                    (being-bounded-above-is-prop L)
                                    (being-troelstra-located-is-prop L)

The Dedekind and Troelstra conditions are equivalent:


 dedekind-gives-troelstra : (l : โ„แดธ) โ†’ is-dedekind l โ†’ is-troelstra l
 dedekind-gives-troelstra l@(L , _ , _ , _)
                          ((U , U-inhabited , _ , _) ,
                           LU-ordered ,
                           LU-located) = ฮณ
  where
   bounded : (โˆƒ s ๊ž‰ โ„š , s โˆ‰ L)
   bounded = โˆฅโˆฅ-functor f U-inhabited
    where
     f : (ฮฃ q ๊ž‰ โ„š , q โˆˆ U) โ†’ ฮฃ q ๊ž‰ โ„š , q โˆ‰ L
     f (q , q-in-U) = q , (ฮป q-in-L โ†’ <-โ„š-โ„š-irrefl q (c q-in-L))
      where
       c : q โˆˆ L โ†’ q < q
       c q-in-L = LU-ordered q q q-in-L q-in-U

   located : (r s : โ„š) โ†’ r < s โ†’ r โˆˆ L โˆจ s โˆ‰ L
   located r s โ„“ = โˆฅโˆฅ-functor f (LU-located r s โ„“)
    where
     f : (r โˆˆ L) + (s โˆˆ U) โ†’ (r โˆˆ L) + (s โˆ‰ L)
     f (inl r-in-L) = inl r-in-L
     f (inr r-in-L) = inr (ฮป s-in-L โ†’ <-โ„š-โ„š-irrefl s (d s-in-L))
      where
       d : s โˆˆ L โ†’ s < s
       d s-in-L = LU-ordered s s s-in-L r-in-L

   ฮณ : is-troelstra l
   ฮณ = bounded , located


A lower Dedekind real may or may not have an upper section. If it
does, it is given by the following candidate.


 candidate-upper-section : ๐“Ÿ โ„š โ†’ ๐“Ÿ โ„š
 candidate-upper-section L = ฮป q โ†’ (โˆƒ p ๊ž‰ โ„š , (p < q) ร— (p โˆ‰ L)) , โˆƒ-is-prop

 candidate-upper-section-is-lower-open
  : (L : ๐“Ÿ โ„š)
  โ†’ is-lower-open (candidate-upper-section L)
 candidate-upper-section-is-lower-open L q q-in-U = ฮณ
  where
   f : (ฮฃ p ๊ž‰ โ„š , (p < q) ร— (p โˆ‰ L))
     โ†’ โˆƒ p' ๊ž‰ โ„š , (p' < q) ร— (โˆƒ p ๊ž‰ โ„š , (p < p') ร— (p โˆ‰ L))
   f (p , i , p-not-in-L) = g (โ„š-density p q i)
    where
     g : (ฮฃ p' ๊ž‰ โ„š , (p < p') ร— (p' < q))
       โ†’  โˆƒ p' ๊ž‰ โ„š , (p' < q) ร— (โˆƒ p ๊ž‰ โ„š , (p < p') ร— (p โˆ‰ L))
     g (p' , j , k) = โˆฃ p' , k , โˆฃ p , j , p-not-in-L โˆฃ โˆฃ

   ฮณ : โˆƒ q' ๊ž‰ โ„š , ((q' < q) ร— (q' โˆˆ candidate-upper-section L))
   ฮณ = โˆฅโˆฅ-rec โˆƒ-is-prop f q-in-U

 candidate-upper-section-is-ordered
  : (L : ๐“Ÿ โ„š)
  โ†’ is-lower L
  โ†’ is-located L
  โ†’ are-ordered L (candidate-upper-section L)
 candidate-upper-section-is-ordered L L-lower located p q p-in-L q-in-U = ฮณ
  where
   f : (ฮฃ r ๊ž‰ โ„š , (r < q) ร— (r โˆ‰ L)) โ†’ p < q
   f (r , i , r-not-in-L) = โˆฅโˆฅ-rec (<-โ„š-โ„š-is-prop-valued p q) g (located r q i)
    where
     g : (r โˆˆ L) + (q โˆ‰ L) โ†’ p < q
     g (inl r-in-L)     = ๐Ÿ˜-elim (r-not-in-L r-in-L)
     g (inr q-not-in-L) = โ„š-order-criterion p q II I
      where
       I : p โ‰  q
       I refl = q-not-in-L p-in-L

       II : q โ‰ฎ p
       II โ„“ = q-not-in-L (L-lower p p-in-L q โ„“)

   ฮณ : p < q
   ฮณ = โˆฅโˆฅ-rec (<-โ„š-โ„š-is-prop-valued p q) f q-in-U

 candidate-upper-section-is-located
  : (L : ๐“Ÿ โ„š)
  โ†’ is-located L
  โ†’ are-located L (candidate-upper-section L)
 candidate-upper-section-is-located L located p q โ„“ = โˆฅโˆฅ-rec โˆจ-is-prop II I
  where
   I : โˆƒ p' ๊ž‰ โ„š , (p < p') ร— (p' < q)
   I = โˆฃ โ„š-density p q โ„“ โˆฃ

   II : (ฮฃ p' ๊ž‰ โ„š , (p < p') ร— (p' < q)) โ†’ p โˆˆ L โˆจ q โˆˆ candidate-upper-section L
   II (p' , i , j) = โˆฅโˆฅ-rec โˆจ-is-prop IV III
    where
     III : p โˆˆ L โˆจ p' โˆ‰ L
     III = located p p' i

     IV : (p โˆˆ L) + (p' โˆ‰ L) โ†’ p โˆˆ L โˆจ q โˆˆ candidate-upper-section L
     IV (inl p-in-L)      = โˆฃ inl p-in-L โˆฃ
     IV (inr p'-not-in-L) = โˆฃ inr โˆฃ (p' , j , p'-not-in-L) โˆฃ โˆฃ

 candidate-upper-section-is-inhabited
  : (L : ๐“Ÿ โ„š)
  โ†’ is-bounded-above L
  โ†’ is-inhabited (candidate-upper-section L)
 candidate-upper-section-is-inhabited L bounded =  ฮณ
  where
   f : (ฮฃ s ๊ž‰ โ„š , s โˆ‰ L) โ†’ is-inhabited (candidate-upper-section L)
   f (s , ฮฝ) = โˆฅโˆฅ-functor g (โ„š-is-upper-open s)
    where
     g : (ฮฃ p ๊ž‰ โ„š , s < p) โ†’ ฮฃ p ๊ž‰ โ„š , p โˆˆ candidate-upper-section L
     g (p , i) = p , โˆฃ s , i , ฮฝ โˆฃ

   ฮณ : is-inhabited (candidate-upper-section L)
   ฮณ = โˆฅโˆฅ-rec (being-inhabited-is-prop (candidate-upper-section L)) f bounded

 candidate-upper-section-is-upper
  : (L : ๐“Ÿ โ„š)
  โ†’ is-lower L
  โ†’ is-located L
  โ†’ is-upper (candidate-upper-section L)
 candidate-upper-section-is-upper L lower located p p-in-U q โ„“ = ฮณ
  where
   ฮณ : โˆƒ q' ๊ž‰ โ„š , (q' < q) ร— (q' โˆ‰ L)
   ฮณ = โˆฃ p ,
        โ„“ ,
        (ฮป p-in-L โ†’ <-โ„š-โ„š-irrefl p
                     (candidate-upper-section-is-ordered
                       L lower located p p p-in-L p-in-U)) โˆฃ

The candidate upper section is the unique candidate in the following
sense:


 unique-candidate
  : (L U : ๐“Ÿ โ„š)
  โ†’ is-dedekind-section (L , U)
  โ†’ U ๏ผ candidate-upper-section L
 unique-candidate L U (Li , Ll , Lo , Ui , Uu , Uo , ordered , located) = ฮณ
  where
   l : โ„แดธ
   l = (L , Li , Ll , Lo)

   u : โ„แต
   u = (U , Ui , Uu , Uo)

   I : is-dedekind l
   I = u , ordered , located

   II : is-located L
   II = prโ‚‚ (dedekind-gives-troelstra l I)

   III : (candidate-upper-section L) is-an-upper-section-of L
   III = candidate-upper-section-is-lower-open L ,
         candidate-upper-section-is-ordered L Ll II ,
         candidate-upper-section-is-located L II

   ฮณ : U ๏ผ candidate-upper-section L
   ฮณ = any-two-upper-sections-are-equal L U
        (candidate-upper-section L)
        (Uo , ordered , located)
        III


And, as promised, the Troelstra condition implies the Dedekind condition:


 troelstra-gives-dedekind : (l : โ„แดธ) โ†’ is-troelstra l โ†’ is-dedekind l
 troelstra-gives-dedekind l@(L , L-inhabited , L-lower , L-upper-open)
                            (bounded , located) = ฮณ
  where
   ฮณ : is-dedekind l
   ฮณ = ((candidate-upper-section L ,
         (candidate-upper-section-is-inhabited L bounded ,
          candidate-upper-section-is-upper L L-lower located ,
          candidate-upper-section-is-lower-open L)) ,
        candidate-upper-section-is-ordered L L-lower located ,
        candidate-upper-section-is-located L located)


The set of Troelstra reals, again as a subset of the lower reals:


 โ„แต€ : ๐“คโบ ฬ‡
 โ„แต€ = ฮฃ l ๊ž‰ โ„แดธ , is-troelstra l


Question. Can we prove that โ„ = โ„แต€ with propositional and functional
extensionality, without univalence? The problem is that the Dedekind
condition and the troelstra condition have different universe levels,
and hence propositional extensionality is not applicable to show that
they are equal, as their equality doesn't even type check. Would
universe lifting help? I haven't thought about this.


 dedekind-agrees-with-troelstra : โ„ โ‰ƒ โ„แต€
 dedekind-agrees-with-troelstra = ฮณ
  where
   f : โ„ โ†’ โ„แต€
   f (l , h) = l , dedekind-gives-troelstra l h

   g : โ„แต€ โ†’ โ„
   g (l , k) = l , troelstra-gives-dedekind l k

   ฮณ : โ„ โ‰ƒ โ„แต€
   ฮณ = qinveq f (g ,
                (ฮป (l , h) โ†’ to-subtype-๏ผ being-dedekind-is-prop refl) ,
                (ฮป (l , k) โ†’ to-subtype-๏ผ being-troelstra-is-prop refl))

We now consider consequences of excluded middle. Notice that if A is a
proposition, then so is A + ยฌ A, and thus A + ยฌ A is equivalent to A โˆจ ยฌ A.


 LEM = (A : ๐“ค ฬ‡ ) โ†’ is-prop A โ†’ A + ยฌ A

 LEM-gives-locatedness : LEM โ†’ ((L , _) : โ„แดธ) โ†’ is-located L
 LEM-gives-locatedness
  lem l@(L , L-inhabited , L-lower , L-upper-open) r s โ„“ = ฮณ ฮด
  where
   ฮด : (s โˆˆ L) + (s โˆ‰ L)
   ฮด = lem (s โˆˆ L) (โˆˆ-is-prop L s)

   ฮณ : type-of ฮด โ†’ (r โˆˆ L) โˆจ (s โˆ‰ L)
   ฮณ (inl s-in-L)     = โˆฃ inl (L-lower s s-in-L r โ„“) โˆฃ
   ฮณ (inr s-not-in-L) = โˆฃ inr s-not-in-L โˆฃ


The bounded lower reals:


 โ„แดฎแดธ : ๐“คโบ ฬ‡
 โ„แดฎแดธ = ฮฃ (L , _) ๊ž‰ โ„แดธ , is-bounded-above L


The boundedness condition only excludes a point at infinity in the
lower reals:


 infty : ๐“Ÿ โ„š
 infty = ฮป _ โ†’ โŠค

 infty-is-lower-real : is-lower-real infty
 infty-is-lower-real = โˆฃ ๐ŸŽ , โ‹† โˆฃ ,
                       (ฮป _ _ _ _ โ†’ โ‹†) ,
                       (ฮป p โ‹† โ†’ โˆฅโˆฅ-rec
                                 โˆƒ-is-prop
                                 (ฮป (q , i) โ†’ โˆฃ q , i , โ‹† โˆฃ)
                                 (โ„š-is-upper-open p))

 infty-is-not-bounded-above : ยฌ is-bounded-above infty
 infty-is-not-bounded-above bounded =
  โˆฅโˆฅ-rec
   ๐Ÿ˜-is-prop
   (ฮป (q , q-not-in-infty) โ†’ q-not-in-infty โ‹†)
   bounded


In connection with a discussion above, notice that we don't need
univalence for the following, which says that the Troelstra reals
agree with the bounded lower reals if we assume excluded middle:


 โ„แต€-and-โ„แดฎแดธ-agree-under-LEM : LEM โ†’ โ„แต€ ๏ผ โ„แดฎแดธ
 โ„แต€-and-โ„แดฎแดธ-agree-under-LEM lem = ap ฮฃ ฮณ
  where
   ฮด : is-troelstra โˆผ ฮป (L , _) โ†’ is-bounded-above L
   ฮด l@(L , _) = pe (being-troelstra-is-prop l)
                    (being-bounded-above-is-prop L)
                    prโ‚
                    (ฮป ฮฒ โ†’ ฮฒ , LEM-gives-locatedness lem l)

   ฮณ : is-troelstra ๏ผ (ฮป (L , _) โ†’ is-bounded-above L)
   ฮณ = dfunext fe ฮด


Therefore, under excluded middle, the Dedekind reals agree with the
bounded lower reals:


 โ„-and-โ„แดฎแดธ-agree-under-LEM : LEM โ†’ โ„ โ‰ƒ โ„แดฎแดธ
 โ„-and-โ„แดฎแดธ-agree-under-LEM lem = transport (โ„ โ‰ƒ_)
                                  (โ„แต€-and-โ„แดฎแดธ-agree-under-LEM lem)
                                  (dedekind-agrees-with-troelstra)

It follows that bounded lower reals are Dedekind under excluded middle.


 LEM-gives-all-bounded-lower-reals-are-dedekind
  : LEM
  โ†’ ((l , _) : โ„แดฎแดธ) โ†’ is-dedekind l
 LEM-gives-all-bounded-lower-reals-are-dedekind lem (l , bounded) = ฮณ
  where
   ฮณ : is-dedekind l
   ฮณ = troelstra-gives-dedekind l (bounded , LEM-gives-locatedness lem l)


And the converse also holds. We use a method of proof suggested
independently by Steve Vickers and Toby Bartels.


 all-bounded-lower-reals-are-dedekind-gives-LEM
  : (((l , _) : โ„แดฎแดธ) โ†’ is-dedekind l)
  โ†’ LEM
 all-bounded-lower-reals-are-dedekind-gives-LEM ฮฑ A A-is-prop = ฮณ
  where
   L : ๐“Ÿ โ„š
   L p = ((p < ๐ŸŽ) โˆจ (A ร— (p < ๐Ÿ))) , โˆจ-is-prop

   L-inhabited : is-inhabited L
   L-inhabited = โˆฅโˆฅ-functor h (โ„š-is-lower-open ๐ŸŽ)
    where
     h : (ฮฃ p ๊ž‰ โ„š , p < ๐ŸŽ) โ†’ ฮฃ p ๊ž‰ โ„š , p โˆˆ L
     h (p , โ„“) = p , โˆฃ inl โ„“ โˆฃ

   L-lower : is-lower L
   L-lower p p-in-L p' j = โˆฅโˆฅ-functor h p-in-L
    where
     h : (p < ๐ŸŽ) + (A ร— (p < ๐Ÿ)) โ†’ (p' < ๐ŸŽ) + (A ร— (p' < ๐Ÿ))
     h (inl โ„“)       = inl (โ„š-transitivity p' p ๐ŸŽ j โ„“)
     h (inr (a , โ„“)) = inr (a , โ„š-transitivity p' p ๐Ÿ j โ„“)

   L-upper-open : is-upper-open L
   L-upper-open p p-in-L = โˆฅโˆฅ-rec โˆƒ-is-prop h p-in-L
    where
     h : (p < ๐ŸŽ) + (A ร— (p < ๐Ÿ)) โ†’ โˆƒ p' ๊ž‰ โ„š , (p < p') ร— (p' โˆˆ L)
     h (inl โ„“) = k (โ„š-density p ๐ŸŽ โ„“)
      where
       k : (ฮฃ p' ๊ž‰ โ„š , (p < p') ร— (p' < ๐ŸŽ)) โ†’ โˆƒ p' ๊ž‰ โ„š , (p < p') ร— (p' โˆˆ L)
       k (p' , i , j) = โˆฃ p' , i , โˆฃ inl j โˆฃ โˆฃ
     h (inr (a , โ„“)) = k (โ„š-density p ๐Ÿ โ„“)
      where
       k : (ฮฃ p' ๊ž‰ โ„š , (p < p') ร— (p' < ๐Ÿ)) โ†’ โˆƒ p' ๊ž‰ โ„š , (p < p') ร— p' โˆˆ L
       k (p' , i , j) = โˆฃ p' , i , โˆฃ inr (a , j) โˆฃ โˆฃ

   l : โ„แดธ
   l = (L , L-inhabited , L-lower , L-upper-open)

   l-dedekind-gives-A-decidable : is-dedekind l โ†’ A + ยฌ A
   l-dedekind-gives-A-decidable ((U , _ , _) , LU-ordered , LU-located) = ฮด
    where
     ฮด : A + ยฌ A
     ฮด = โˆฅโˆฅ-rec
          (decidability-of-prop-is-prop fe A-is-prop)
          h
          (LU-located ๐ŸŽ ยฝ ๐ŸŽ-is-less-than-ยฝ)
      where
       h : (๐ŸŽ โˆˆ L) + (ยฝ โˆˆ U) โ†’ A + ยฌ A
       h (inl ๐Ÿ˜-in-L) = inl (โˆฅโˆฅ-rec A-is-prop k ๐Ÿ˜-in-L)
        where
         k : (๐ŸŽ < ๐ŸŽ) + (A ร— (๐ŸŽ < ๐Ÿ)) โ†’ A
         k (inl โ„“)       = ๐Ÿ˜-elim (<-โ„š-โ„š-irrefl ๐ŸŽ โ„“)
         k (inr (a , _)) = a
       h (inr ยฝ-in-U) = inr ฮฝ
        where
         ฮฝ : ยฌ A
         ฮฝ a = disjoint-criterion L U LU-ordered ยฝ (ยฝ-in-L , ยฝ-in-U)
          where
           ยฝ-in-L : ยฝ โˆˆ L
           ยฝ-in-L = โˆฃ inr (a , ยฝ-is-less-than-๐Ÿ) โˆฃ

   L-bounded-above : is-bounded-above L
   L-bounded-above = โˆฃ ๐Ÿ , (ฮป ๐Ÿ-in-L โ†’ โˆฅโˆฅ-rec ๐Ÿ˜-is-prop h ๐Ÿ-in-L) โˆฃ
    where
     h : ยฌ((๐Ÿ < ๐ŸŽ) + (A ร— (๐Ÿ < ๐Ÿ)))
     h (inl โ„“)       = <-โ„š-โ„š-irrefl ๐ŸŽ (โ„š-transitivity ๐ŸŽ ๐Ÿ ๐ŸŽ ๐ŸŽ-is-less-than-๐Ÿ โ„“)
     h (inr (_ , โ„“)) = <-โ„š-โ„š-irrefl ๐Ÿ โ„“

   b : โ„แดฎแดธ
   b = (l , L-bounded-above)

   ฮณ : A + ยฌ A
   ฮณ = l-dedekind-gives-A-decidable (ฮฑ b)


The canonical embedding of the rationals into the reals:


 โ„š-to-โ„แดธ : โ„š โ†’ โ„แดธ
 โ„š-to-โ„แดธ q = (ฮป p โ†’ (p < q) , <-โ„š-โ„š-is-prop-valued p q) ,
             โ„š-is-lower-open q ,
             (ฮป p i r j โ†’ โ„š-transitivity r p q j i) ,
             (ฮป p i โ†’ โˆฃ โ„š-density p q i โˆฃ)

 โ„š-to-โ„แต : โ„š โ†’ โ„แต
 โ„š-to-โ„แต q = (ฮป p โ†’ (q < p) , <-โ„š-โ„š-is-prop-valued q p) ,
             โ„š-is-upper-open q ,
             (ฮป p i r j โ†’ โ„š-transitivity q p r i j) ,
             (ฮป p i โ†’ โˆฃ(ฮป (r , j , k) โ†’ r , k , j) (โ„š-density q p i)โˆฃ)

 โ„š-to-โ„แต-is-upper-section-of-โ„š-to-โ„แดธ
  : (q : โ„š)
  โ†’ (โ„š-to-โ„แต q) is-upper-section-of (โ„š-to-โ„แดธ q)
 โ„š-to-โ„แต-is-upper-section-of-โ„š-to-โ„แดธ q
  = (ฮป p โ†’ โ„š-transitivity p q) ,
    (ฮป p โ†’ โ„š-cotransitivity p q)

 โ„š-to-โ„แดธ-is-dedekind : (q : โ„š) โ†’ is-dedekind (โ„š-to-โ„แดธ q)
 โ„š-to-โ„แดธ-is-dedekind q = โ„š-to-โ„แต q ,
                         โ„š-to-โ„แต-is-upper-section-of-โ„š-to-โ„แดธ q

 โ„š-to-โ„ : โ„š โ†’ โ„
 โ„š-to-โ„ q = โ„š-to-โ„แดธ q , โ„š-to-โ„แดธ-is-dedekind q

 โ„š-to-โ„แดธ-is-embedding : is-embedding โ„š-to-โ„แดธ
 โ„š-to-โ„แดธ-is-embedding l (p , a) (q , b) = ฮณ
  where
   I = โ„š-to-โ„แดธ p ๏ผโŸจ a โŸฉ
       l         ๏ผโŸจ b โปยน โŸฉ
       โ„š-to-โ„แดธ q โˆŽ

   II : (ฮป r โ†’ (r < p) , _) ๏ผ (ฮป r โ†’ (r < q) , _)
   II = ap prโ‚ I

   III : (ฮป r โ†’ r < p) ๏ผ (ฮป r โ†’ r < q)
   III = ap (ฮป f r โ†’ prโ‚ (f r)) II

   A : (r : โ„š) โ†’ r < p โ†’ r < q
   A r = idtofun (r < p) (r < q) (happly III r)

   B : (r : โ„š) โ†’ r < q โ†’ r < p
   B r = idtofun (r < q) (r < p) (happly (III โปยน) r)

   V : p ๏ผ q
   V =  โ„š-โ‰ค-antisym p q A B

   ฮณ : (p , a) ๏ผ (q , b)
   ฮณ = to-subtype-๏ผ (ฮป _ โ†’ โ„แดธ-is-set) V

 instance
  canonical-map-โ„š-to-โ„ : Canonical-Map โ„š โ„
  ฮน {{canonical-map-โ„š-to-โ„}} = โ„š-to-โ„

 โ„š-to-โ„-is-embedding : is-embedding (canonical-map โ„š โ„)
 โ„š-to-โ„-is-embedding = factor-is-embedding
                        โ„š-to-โ„
                        โ„-to-โ„แดธ
                        โ„š-to-โ„แดธ-is-embedding
                        โ„-to-โ„แดธ-is-embedding
  where
   notice-that : โ„-to-โ„แดธ โˆ˜ โ„š-to-โ„ ๏ผ โ„š-to-โ„แดธ
   notice-that = refl

 is-rational : โ„ โ†’ ๐“คโบ ฬ‡
 is-rational x = ฮฃ q ๊ž‰ โ„š , ฮน q ๏ผ x

 being-rational-is-prop : (x : โ„) โ†’ is-prop (is-rational x)
 being-rational-is-prop = โ„š-to-โ„-is-embedding


We could also define

 instance
  canonical-map-โ„š-to-โ„แดธ : Canonical-Map โ„š โ„แดธ
  ฮน {{canonical-map-โ„š-to-โ„แดธ}} = โ„š-to-โ„แดธ

  canonical-map-โ„š-to-โ„แต : Canonical-Map โ„š โ„แต
  ฮน {{canonical-map-โ„š-to-โ„แต}} = โ„š-to-โ„แต

but this would give us trouble with unsolved constraints.

We now consider order and apartness on real numbers.


 lowercut : โ„ โ†’ ๐“Ÿ โ„š
 lowercut ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = L

 uppercut : โ„ โ†’ ๐“Ÿ โ„š
 uppercut ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = U

 instance
  strict-order-โ„š-โ„ : Strict-Order โ„š โ„
  _<_ {{strict-order-โ„š-โ„}} p x = p โˆˆ lowercut x

  strict-order-โ„-โ„š : Strict-Order โ„ โ„š
  _<_ {{strict-order-โ„-โ„š}} x q = q โˆˆ uppercut x

  strict-order-โ„-โ„ : Strict-Order โ„ โ„
  _<_ {{strict-order-โ„-โ„}} x y = โˆƒ q ๊ž‰ โ„š , (x < q) ร— (q < y)

 <-โ„š-โ„-is-prop-valued : (p : โ„š) (x : โ„) โ†’ is-prop (p < x)
 <-โ„š-โ„-is-prop-valued p x = โˆˆ-is-prop (lowercut x) p

 <-โ„-โ„š-is-prop-valued : (x : โ„) (q : โ„š) โ†’ is-prop (x < q)
 <-โ„-โ„š-is-prop-valued x q = โˆˆ-is-prop (uppercut x) q

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


We now name all the remaining projections out of โ„. We first give
their types and then define them, for the sake of clarity.


 lowercut-is-inhabited  : (x : โ„) โ†’ โˆƒ p ๊ž‰ โ„š , p < x
 uppercut-is-inhabited  : (x : โ„) โ†’ โˆƒ q ๊ž‰ โ„š , x < q
 lowercut-is-lower      : (x : โ„) (q : โ„š) โ†’ q < x โ†’ (p : โ„š) โ†’ p < q โ†’ p < x
 uppercut-is-upper      : (x : โ„) (p : โ„š) โ†’ x < p โ†’ (q : โ„š) โ†’ p < q โ†’ x < q
 lowercut-is-upper-open : (x : โ„) (p : โ„š) โ†’ p < x โ†’ โˆƒ q ๊ž‰ โ„š , (p < q) ร— (q < x)
 uppercut-is-lower-open : (x : โ„) (q : โ„š) โ†’ x < q โ†’ โˆƒ p ๊ž‰ โ„š , (p < q) ร— (x < p)
 cuts-are-ordered       : (x : โ„) (p q : โ„š) โ†’ p < x โ†’ x < q โ†’ p < q
 cuts-are-located       : (x : โ„) (p q : โ„š) โ†’ p < q โ†’ (p < x) โˆจ (x < q)
 cuts-are-disjoint      : (x : โ„) (p : โ„š) โ†’ p < x โ†’ x โ‰ฎ p
 lowercut-is-bounded    : (x : โ„) โ†’ โˆƒ p ๊ž‰ โ„š , p โ‰ฎ x
 lowercut-is-located    : (x : โ„) (p q : โ„š) โ†’ p < q โ†’ (p < x) โˆจ (q โ‰ฎ x)

 lowercut-is-inhabited  ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = Li
 uppercut-is-inhabited  ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = Ui
 lowercut-is-lower      ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = Ll
 uppercut-is-upper      ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = Uu
 lowercut-is-upper-open ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = Lo
 uppercut-is-lower-open ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = Uo
 cuts-are-ordered       ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = o
 cuts-are-located       ((L , Li , Ll , Lo) , (U , Ui , Uu , Uo) , o , l) = l

 cuts-are-disjoint x p l m = disjoint-criterion
                              (lowercut x) (uppercut x)
                              (cuts-are-ordered x)
                              p
                              (l , m)

 lowercut-is-bounded (l , ฮด) = prโ‚ (dedekind-gives-troelstra l ฮด)
 lowercut-is-located (l , ฮด) = prโ‚‚ (dedekind-gives-troelstra l ฮด)


The lower and upper cut projections are left-cancellable (and hence
embeddings, as the types under consideration are all sets).


 lowercut-lc : (x y : โ„) โ†’ lowercut x ๏ผ lowercut y โ†’ x ๏ผ y
 lowercut-lc x y e = to-subtype-๏ผ being-dedekind-is-prop
                      (to-subtype-๏ผ being-lower-real-is-prop e)

 uppercut-lc : (x y : โ„) โ†’ uppercut x ๏ผ uppercut y โ†’ x ๏ผ y
 uppercut-lc x y p = lowercut-lc x y III
  where
   I : lowercut x โІ lowercut y
   I = order-lemma-converse (lowercut x) (uppercut x) (lowercut y) (uppercut y)
        (lowercut-is-upper-open x) (cuts-are-located y) (cuts-are-ordered x)
        (transport (_โІ uppercut x) p (โІ-refl (uppercut x)))

   II : lowercut x โЇ lowercut y
   II = order-lemma-converse (lowercut y) (uppercut y) (lowercut x) (uppercut x)
         (lowercut-is-upper-open y) (cuts-are-located x) (cuts-are-ordered y)
         (transport (uppercut x โІ_) p (โІ-refl (uppercut x)))

   III : lowercut x ๏ผ lowercut y
   III = subset-extensionality'' pe fe fe I II


We now develop the basic properties of the _<_ order.


 <-irrefl : (x : โ„) โ†’ x โ‰ฎ x
 <-irrefl x โ„“ = ฮณ
  where
   ฮด : ยฌ (ฮฃ q ๊ž‰ โ„š , ((x < q) ร— (q < x)))
   ฮด (q , a , b) = cuts-are-disjoint x q b a

   ฮณ : ๐Ÿ˜
   ฮณ = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop ฮด โ„“

 <-โ„-โ„-trans : (x y z : โ„) โ†’ x < y โ†’ y < z โ†’ x < z
 <-โ„-โ„-trans x y z i j = โˆฅโˆฅ-functorโ‚‚ f i j
  where
   f : (ฮฃ p ๊ž‰ โ„š , (x < p) ร— (p < y))
     โ†’ (ฮฃ q ๊ž‰ โ„š , (y < q) ร— (q < z))
     โ†’  ฮฃ r ๊ž‰ โ„š , (x < r) ร— (r < z)
   f (p , i , j) (q , k , l) = p , i , v
    where
     u : p < q
     u = cuts-are-ordered y p q j k

     v : p < z
     v = lowercut-is-lower z q l p u

 <-cotrans-โ„š : (p q : โ„š) โ†’ p < q โ†’ (z : โ„) โ†’ (p < z) โˆจ (z < q)
 <-cotrans-โ„š p q โ„“ z = cuts-are-located z p q โ„“

 <-cotrans : (x y : โ„) โ†’ x < y โ†’ (z : โ„) โ†’ (x < z) โˆจ (z < y)
 <-cotrans x y โ„“ z = V
  where
   I : (ฮฃ q ๊ž‰ โ„š , ((x < q) ร— (q < y))) โ†’ (x < z) โˆจ (z < y)
   I (q , a , b) = โˆฅโˆฅ-rec โˆจ-is-prop III II
    where
     II : โˆƒ p ๊ž‰ โ„š , (p < q) ร— (x < p)
     II = uppercut-is-lower-open x q a

     III : (ฮฃ p ๊ž‰ โ„š , (p < q) ร— (x < p)) โ†’ (x < z) โˆจ (z < y)
     III (p , c , d) = โˆฅโˆฅ-functor IV (<-cotrans-โ„š p q c z)
       where
        IV : (p < z) + (z < q) โ†’ (x < z) + (z < y)
        IV (inl โ„“) = inl โˆฃ p , d , โ„“ โˆฃ
        IV (inr โ„“) = inr โˆฃ q , โ„“ , b โˆฃ

   V : (x < z) โˆจ (z < y)
   V = โˆฅโˆฅ-rec โˆจ-is-prop I โ„“


There are a number of equivalent ways to define the _โ‰ค_ order on โ„. We
give four for now, and three more later.


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


Definition (3) has the advantage that it is applicable when x is a
lower real and y is an upper real. See the interval domain below. But
we adopted the first definition for reals before we realized that. It
doesn't matter much, because we can switch between all the definitions
in the case of the Dedekind reals.


 โ‰คโ‚€-is-prop-valued : (x y : โ„) โ†’ is-prop (x โ‰คโ‚€ y)
 โ‰คโ‚-is-prop-valued : (x y : โ„) โ†’ is-prop (x โ‰คโ‚ y)
 โ‰คโ‚‚-is-prop-valued : (x y : โ„) โ†’ is-prop (x โ‰คโ‚‚ y)
 โ‰คโ‚ƒ-is-prop-valued : (x y : โ„) โ†’ is-prop (x โ‰คโ‚ƒ y)

 โ‰คโ‚€-is-prop-valued x y = ฮ โ‚‚-is-prop fe (ฮป _ _ โ†’ <-โ„š-โ„-is-prop-valued _ y)
 โ‰คโ‚-is-prop-valued x y = ฮ โ‚‚-is-prop fe (ฮป _ _ โ†’ <-โ„-โ„š-is-prop-valued x _)
 โ‰คโ‚‚-is-prop-valued x y = negations-are-props fe
 โ‰คโ‚ƒ-is-prop-valued x y = ฮ โ‚„-is-prop fe (ฮป _ _ _ _ โ†’ <-โ„š-โ„š-is-prop-valued _ _)

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

 โ‰ค-gives-โ‰คโ‚ : (x y : โ„) โ†’ x โ‰ค y โ†’ x โ‰คโ‚ y
 โ‰ค-gives-โ‰คโ‚ x y โ„“ = order-lemma
                     (lowercut x) (uppercut x)
                     (lowercut y) (uppercut y)
                     (uppercut-is-lower-open y)
                     (cuts-are-located x)
                     (cuts-are-ordered y)
                     โ„“

 โ‰คโ‚-gives-โ‰ค : (x y : โ„) โ†’ x โ‰คโ‚ y โ†’ x โ‰ค y
 โ‰คโ‚-gives-โ‰ค x y โ„“ = order-lemma-converse
                     (lowercut x) (uppercut x)
                     (lowercut y) (uppercut y)
                     (lowercut-is-upper-open x)
                     (cuts-are-located y)
                     (cuts-are-ordered x)
                     โ„“

 โ‰คโ‚‚-gives-โ‰ค : (x y : โ„) โ†’ x โ‰คโ‚‚ y โ†’ x โ‰ค y
 โ‰คโ‚‚-gives-โ‰ค x y ฮฝ q โ„“ = VI
  where
   I : (p : โ„š) โ†’ p < x โ†’ y โ‰ฎ p
   I p m l = ฮฝ โˆฃ p , l , m โˆฃ

   II : โˆƒ p ๊ž‰ โ„š , (q < p) ร— (p < x)
   II = lowercut-is-upper-open x q โ„“

   III : (ฮฃ p ๊ž‰ โ„š , (q < p) ร— (p < x)) โ†’ q < y
   III (p , i , j) = โˆฅโˆฅ-rec (<-โ„š-โ„-is-prop-valued q y) V IV
    where
     IV : (q < y) โˆจ (y < p)
     IV = <-cotrans-โ„š q p i y

     V : (q < y) + (y < p) โ†’ q < y
     V (inl k) = k
     V (inr l) = ๐Ÿ˜-elim (I p j l)

   VI : q < y
   VI = โˆฅโˆฅ-rec (<-โ„š-โ„-is-prop-valued q y) III II

 โ‰ค-gives-โ‰คโ‚‚ : (x y : โ„) โ†’ x โ‰ค y โ†’ x โ‰คโ‚‚ y
 โ‰ค-gives-โ‰คโ‚‚ x y โ„“ i = II
  where
   I : ยฌ (ฮฃ p ๊ž‰ โ„š , (y < p) ร— (p < x))
   I (p , j , k) = cuts-are-disjoint y p (โ„“ p k) j

   II : ๐Ÿ˜
   II = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop I i

 โ‰คโ‚ƒ-gives-โ‰ค : (x y : โ„) โ†’ x โ‰คโ‚ƒ y โ†’ x โ‰ค y
 โ‰คโ‚ƒ-gives-โ‰ค x y l = III
  where
   I : ยฌ (ฮฃ p ๊ž‰ โ„š , (y < p) ร— (p < x))
   I (p , i , j) = <-โ„š-โ„š-irrefl p (l p p j i)

   II : y โ‰ฎ x
   II m = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop I m

   III : x โ‰ค y
   III = โ‰คโ‚‚-gives-โ‰ค x y II

 โ‰ค-gives-โ‰คโ‚ƒ : (x y : โ„) โ†’ x โ‰ค y โ†’ x โ‰คโ‚ƒ y
 โ‰ค-gives-โ‰คโ‚ƒ x y l p q i j = II
  where
   I : p < y
   I = l p i

   II : p < q
   II = cuts-are-ordered y p q I j

 โ‰ค-โ„-refl : (x : โ„) โ†’ x โ‰ค x
 โ‰ค-โ„-refl x q โ„“ = โ„“

 โ‰ค-โ„-โ„-trans : (x y z : โ„) โ†’ x โ‰ค y โ†’ y โ‰ค z โ†’ x โ‰ค z
 โ‰ค-โ„-โ„-trans x y z l m p i = m p (l p i)

 โ‰ค-โ„-โ„-antisym : (x y : โ„) โ†’ x โ‰ค y โ†’ y โ‰ค x โ†’ x ๏ผ y
 โ‰ค-โ„-โ„-antisym x y l m = lowercut-lc x y ฮณ
  where
   ฮณ : lowercut x ๏ผ lowercut y
   ฮณ = subset-extensionality'' pe fe fe l m


The type โ„ is large, in the sense that it lives in ๐“คโบ rather than ๐“ค,
but it is locally small, in the sense that each identity type x ๏ผ y
with x,y:โ„, which also lives in ๐“คโบ, has copy in the universe ๐“ค, namely
the type (x โ‰ค y) ร— (y โ‰ค x).


 โ„-is-locally-small : is-locally-small โ„
 โ„-is-locally-small x y = ฮณ
  where
   f : (x โ‰ค y) ร— (y โ‰ค x) โ†’ x ๏ผ y
   f = uncurry (โ‰ค-โ„-โ„-antisym x y)

   g : x ๏ผ y โ†’ (x โ‰ค y) ร— (y โ‰ค x)
   g refl = โ‰ค-โ„-refl x , โ‰ค-โ„-refl x

   e : ((x โ‰ค y) ร— (y โ‰ค x)) โ‰ƒ (x ๏ผ y)
   e = qinveq
        f
        (g ,
         (ฮป a โ†’ ร—-is-prop
                 (โ‰คโ‚€-is-prop-valued x y)
                 (โ‰คโ‚€-is-prop-valued y x)
                 (g (f a)) a) ,
         (ฮป b โ†’ โ„-is-set (f (g b)) b))

   ฮณ : (x ๏ผ y) is ๐“ค small
   ฮณ = ((x โ‰ค y) ร— (y โ‰ค x)) , e


Relationship between the orders of โ„š and โ„:


 โ„š-to-โ„-preserves-< : (p q : โ„š) โ†’ p < q โ†’ ฮน p < ฮน q
 โ„š-to-โ„-preserves-< p q l = โˆฃ โ„š-density p q l โˆฃ

 โ„š-to-โ„-reflects-< : (p q : โ„š) โ†’ ฮน p < ฮน q โ†’ p < q
 โ„š-to-โ„-reflects-< p q = โˆฅโˆฅ-rec
                          (<-โ„š-โ„š-is-prop-valued p q)
                          (ฮป (r , i , j) โ†’ โ„š-transitivity p r q i j)

 โ‰ค-on-โ„š-agrees-with-โ‰ค-on-โ„ : (p q : โ„š) โ†’ (p โ‰ค q) ๏ผ (ฮน p โ‰ค ฮน q)
 โ‰ค-on-โ„š-agrees-with-โ‰ค-on-โ„ p q = refl

 โ‰ค-on-โ„š-is-prop-valued : (p q : โ„š) โ†’ is-prop (ฮน p โ‰ค ฮน q)
 โ‰ค-on-โ„š-is-prop-valued p q = โ‰คโ‚€-is-prop-valued (ฮน p) (ฮน q)

 โ„š-to-โ„-preserves-โ‰ค : (p q : โ„š) โ†’ p โ‰ค q โ†’ ฮน p โ‰ค ฮน q
 โ„š-to-โ„-preserves-โ‰ค p q = id

 โ„š-to-โ„-reflects-โ‰ค : (p q : โ„š) โ†’ ฮน p โ‰ค ฮน q โ†’ p โ‰ค q
 โ„š-to-โ„-reflects-โ‰ค p q = id

 โ„š-to-โ„-left : (p : โ„š) (x : โ„) โ†’ p < x โ†’ ฮน p < x
 โ„š-to-โ„-left p x = lowercut-is-upper-open x p

 โ„š-to-โ„-left-converse : (p : โ„š) (x : โ„) โ†’ ฮน p < x โ†’ p < x
 โ„š-to-โ„-left-converse p x = โˆฅโˆฅ-rec
                             (<-โ„š-โ„-is-prop-valued p x)
                             (ฮป (q , m , o) โ†’ lowercut-is-lower x q o p m)

 โ„š-to-โ„-right : (x : โ„) (q : โ„š) โ†’ x < q โ†’ x < ฮน q
 โ„š-to-โ„-right x q l = โˆฅโˆฅ-functor
                       (ฮป (p , m , o) โ†’ p , o , m)
                       (uppercut-is-lower-open x q l)

 โ„š-to-โ„-right-converse : (x : โ„) (q : โ„š) โ†’ x < ฮน q โ†’ x < q
 โ„š-to-โ„-right-converse x q = โˆฅโˆฅ-rec
                              (<-โ„-โ„š-is-prop-valued x q)
                              (ฮป (p , m , o) โ†’ uppercut-is-upper x p m q o)

The promised three more ways to define _โ‰ค_ on โ„:


 _โ‰คโ‚€โ‚_ _โ‰คโ‚โ‚_ _โ‰คโ‚ƒโ‚_ : โ„ โ†’ โ„ โ†’ ๐“คโบ ฬ‡
 x โ‰คโ‚€โ‚ y = (z : โ„) โ†’ z < x โ†’ z < y
 x โ‰คโ‚โ‚ y = (z : โ„) โ†’ y < z โ†’ x < z
 x โ‰คโ‚ƒโ‚ y = (z t : โ„) โ†’ z < x โ†’ y < t โ†’ z < t

 โ‰คโ‚€โ‚-is-prop-valued : (x y : โ„) โ†’ is-prop (x โ‰คโ‚€โ‚ y)
 โ‰คโ‚โ‚-is-prop-valued : (x y : โ„) โ†’ is-prop (x โ‰คโ‚โ‚ y)
 โ‰คโ‚ƒโ‚-is-prop-valued : (x y : โ„) โ†’ is-prop (x โ‰คโ‚ƒโ‚ y)

 โ‰คโ‚€โ‚-is-prop-valued x y = ฮ โ‚‚-is-prop fe (ฮป z _ โ†’ <-โ„-โ„-is-prop-valued z y)
 โ‰คโ‚โ‚-is-prop-valued x y = ฮ โ‚‚-is-prop fe (ฮป z _ โ†’ <-โ„-โ„-is-prop-valued x z)
 โ‰คโ‚ƒโ‚-is-prop-valued x y = ฮ โ‚„-is-prop fe (ฮป z t _ _ โ†’ <-โ„-โ„-is-prop-valued z t)

 โ‰คโ‚€-gives-โ‰คโ‚€โ‚ : (x y : โ„) โ†’ x โ‰คโ‚€ y โ†’ x โ‰คโ‚€โ‚ y
 โ‰คโ‚€-gives-โ‰คโ‚€โ‚ x y l z = โˆฅโˆฅ-functor f
  where
   f : (ฮฃ p ๊ž‰ โ„š , (z < p) ร— (p < x))
     โ†’ (ฮฃ p ๊ž‰ โ„š , (z < p) ร— (p < y))
   f (p , u , v) = p , u , l p v

 โ‰คโ‚€โ‚-gives-โ‰คโ‚€ : (x y : โ„) โ†’ x โ‰คโ‚€โ‚ y โ†’ x โ‰คโ‚€ y
 โ‰คโ‚€โ‚-gives-โ‰คโ‚€ x y l p m = II
  where
   I : ฮน p < y
   I = l (ฮน p) (โ„š-to-โ„-left p x m)

   II : p < y
   II = โ„š-to-โ„-left-converse p y I

 โ‰คโ‚-gives-โ‰คโ‚โ‚ : (x y : โ„) โ†’ x โ‰คโ‚ y โ†’ x โ‰คโ‚โ‚ y
 โ‰คโ‚-gives-โ‰คโ‚โ‚ x y l z = โˆฅโˆฅ-functor f
  where
   f : (ฮฃ p ๊ž‰ โ„š , (y < p) ร— (p < z))
     โ†’ (ฮฃ p ๊ž‰ โ„š , (x < p) ร— (p < z))
   f (p , u , v) = p , l p u , v

 โ‰คโ‚โ‚-gives-โ‰คโ‚ : (x y : โ„) โ†’ x โ‰คโ‚โ‚ y โ†’ x โ‰คโ‚ y
 โ‰คโ‚โ‚-gives-โ‰คโ‚ x y l p m = II
  where
   I : x < ฮน p
   I = l (ฮน p) (โ„š-to-โ„-right y p m)

   II : x < p
   II = โ„š-to-โ„-right-converse x p I

 โ‰คโ‚ƒโ‚-gives-โ‰คโ‚ƒ : (x y : โ„) โ†’ x โ‰คโ‚ƒโ‚ y โ†’ x โ‰คโ‚ƒ y
 โ‰คโ‚ƒโ‚-gives-โ‰คโ‚ƒ x y l p q m o = โ„š-to-โ„-reflects-< p q ฮณ
  where
   ฮณ : ฮน p < ฮน q
   ฮณ = l (ฮน p) (ฮน q) (โ„š-to-โ„-left p x m) (โ„š-to-โ„-right y q o)

 โ‰คโ‚ƒ-gives-โ‰คโ‚ƒโ‚ : (x y : โ„) โ†’ x โ‰คโ‚ƒ y โ†’ x โ‰คโ‚ƒโ‚ y
 โ‰คโ‚ƒ-gives-โ‰คโ‚ƒโ‚ x y l z t m o = โˆฅโˆฅ-functorโ‚‚ f m o
  where
   f : (ฮฃ p ๊ž‰ โ„š , (z < p) ร— (p < x))
     โ†’ (ฮฃ q ๊ž‰ โ„š , (y < q) ร— (q < t))
     โ†’ (ฮฃ p ๊ž‰ โ„š , (z < p) ร— (p < t))
   f (p , i , j) (q , u , v) = p , i , II
    where
     I : p < q
     I = l p q j u

     II : p < t
     II = lowercut-is-lower t q v p I


Relationship between _<_ and _โ‰ค_ on โ„:


 <-gives-โ‰ค' : (x y : โ„) โ†’ x < y โ†’ x โ‰ค y
 <-gives-โ‰ค' x y l = โ‰คโ‚€โ‚-gives-โ‰คโ‚€ x y f
  where
   f : (z : โ„) โ†’ z < x โ†’ z < y
   f z m = <-โ„-โ„-trans z x y m l

 <-โ‰ค-trans : (x y z : โ„) โ†’ x < y โ†’ y โ‰ค z โ†’ x < z
 <-โ‰ค-trans x y z l m = โ‰คโ‚€-gives-โ‰คโ‚€โ‚ y z m x l

 โ‰ค-<-โ„-โ„-trans : (x y z : โ„) โ†’ x โ‰ค y โ†’ y < z โ†’ x < z
 โ‰ค-<-โ„-โ„-trans x y z l m = โ‰คโ‚-gives-โ‰คโ‚โ‚ x y (โ‰ค-gives-โ‰คโ‚ x y l) z m


Apartness of real numbers and its basic properties:


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

 โ™ฏ-is-prop-valued : (x y : โ„) โ†’ is-prop (x โ™ฏ y)
 โ™ฏ-is-prop-valued x y = sum-of-contradictory-props
                         (<-โ„-โ„-is-prop-valued x y)
                         (<-โ„-โ„-is-prop-valued y x)
                         (ฮป i j โ†’ <-irrefl x (<-โ„-โ„-trans x y x i j))

 โ™ฏ-irrefl : (x : โ„) โ†’ ยฌ (x โ™ฏ x)
 โ™ฏ-irrefl x (inl โ„“) = <-irrefl x โ„“
 โ™ฏ-irrefl x (inr โ„“) = <-irrefl x โ„“

 โ™ฏ-gives-โ‰  : (x y : โ„) โ†’ x โ™ฏ y โ†’ x โ‰  y
 โ™ฏ-gives-โ‰  x x s refl = โ™ฏ-irrefl x s

 โ™ฏ-sym : (x y : โ„) โ†’ x โ™ฏ y โ†’ y โ™ฏ x
 โ™ฏ-sym x y (inl โ„“) = inr โ„“
 โ™ฏ-sym x y (inr โ„“) = inl โ„“

 โ™ฏ-cotrans : (x y : โ„) โ†’ x โ™ฏ y โ†’ (z : โ„) โ†’ (x โ™ฏ z) โˆจ (y โ™ฏ z)
 โ™ฏ-cotrans x y (inl โ„“) z = โˆฅโˆฅ-functor
                            (cases (ฮป (โ„“ : x < z) โ†’ inl (inl โ„“))
                                   (ฮป (โ„“ : z < y) โ†’ inr (inr โ„“)))
                            (<-cotrans x y โ„“ z)
 โ™ฏ-cotrans x y (inr โ„“) z = โˆฅโˆฅ-functor
                            (cases (ฮป (โ„“ : y < z) โ†’ inr (inl โ„“))
                                   (ฮป (โ„“ : z < x) โ†’ inl (inr โ„“)))
                            (<-cotrans y x โ„“ z)

 โ™ฏ-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 = โ‰คโ‚‚-gives-โ‰ค x y II

   IV : y โ‰ค x
   IV = โ‰คโ‚‚-gives-โ‰ค y x 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 (โ™ฏ-gives-โ‰  x y)

 strict-โ„-order-criterion : (x y : โ„) โ†’ x โ‰ค y โ†’ x โ™ฏ y โ†’ x < y
 strict-โ„-order-criterion x y โ„“ (inl m) = m
 strict-โ„-order-criterion x y โ„“ (inr m) = ๐Ÿ˜-elim (โ‰ค-gives-โ‰คโ‚‚ x y โ„“ m)

 is-irrational : โ„ โ†’ ๐“คโบ ฬ‡
 is-irrational x = ยฌ (ฮฃ q ๊ž‰ โ„š , ฮน q ๏ผ x)

 is-strongly-irrational : โ„ โ†’ ๐“ค ฬ‡
 is-strongly-irrational x = (q : โ„š) โ†’ ฮน q โ™ฏ x

 being-irrational-is-prop : (x : โ„) โ†’ is-prop (is-irrational x)
 being-irrational-is-prop x = negations-are-props fe

 being-strongly-irrational-is-prop
  : (x : โ„)
  โ†’ is-prop (is-strongly-irrational x)
 being-strongly-irrational-is-prop x
  = ฮ -is-prop fe (ฮป q โ†’ โ™ฏ-is-prop-valued (ฮน q) x)


We now consider the existence of least upper bounds of bounded
families x : ๐ผ โ†’ โ„ with ๐ผ inhabited.

A sufficient condition, given by Bishop (using his version of Cauchy
reals, rather than our version of Dedekind reals, which is what we are
working with here), is that

  (p q : โ„š) โ†’ p < q โ†’ (โˆƒ i ๊ž‰ ๐ผ , p < x i)
                    โˆจ (ฮ  i ๊ž‰ ๐ผ , x i < q).

We observe that the weaker condition

  (p q : โ„š) โ†’ p < q โ†’  (โˆƒ i ๊ž‰ ๐ผ , p < x i)
                    โˆจ ยฌ(โˆƒ i ๊ž‰ ๐ผ , q < x i)

suffices (see below for the formal fact that it is indeed weaker).

If we define (p < x) = (โˆƒ i ๊ž‰ ๐ผ , p < x i), then this weaker sufficient
condition reads

  (p q : โ„š) โ†’ p < q โ†’ (p < x) โˆจ (q โ‰ฎ x)

so that we see that it is analogous to Troelstra's locatedness
condition discussed above.

In the following, we write x โ‰ค y to mean that the real number y is an
upper bound of the family x.


 module _ {๐ผ : ๐“ค ฬ‡ } where

  private
   F = ๐ผ โ†’ โ„

  instance
   order-F-โ„ : Order F โ„
   _โ‰ค_ {{order-F-โ„}} x y = (i : ๐ผ) โ†’ x i โ‰ค y

  โ‰ค-F-โ„-is-prop-valued : (x : F) (y : โ„)
                       โ†’ is-prop (x โ‰ค y)
  โ‰ค-F-โ„-is-prop-valued x y = ฮ -is-prop fe (ฮป i โ†’ โ‰คโ‚€-is-prop-valued (x i) y)

  _has-lub_ : F โ†’ โ„ โ†’ ๐“คโบ ฬ‡
  x has-lub y = (x โ‰ค y) ร— ((z : โ„) โ†’ x โ‰ค z โ†’ y โ‰ค z)

  _has-a-lub : F โ†’ ๐“คโบ ฬ‡
  x has-a-lub = ฮฃ y ๊ž‰ โ„ , (x has-lub y)

  having-lub-is-prop : (x : F) (y : โ„)
                     โ†’ is-prop (x has-lub y)
  having-lub-is-prop x y = ร—-is-prop
                            (โ‰ค-F-โ„-is-prop-valued x y)
                            (ฮ โ‚‚-is-prop fe (ฮป z _ โ†’ โ‰คโ‚€-is-prop-valued y z))

  having-a-lub-is-prop : (x : F) โ†’ is-prop (x has-a-lub)
  having-a-lub-is-prop x (y , a , b) (y' , a' , b') = ฮณ
   where
    I : y ๏ผ y'
    I = โ‰ค-โ„-โ„-antisym y y' (b y' a') (b' y a)

    ฮณ : (y , a , b) ๏ผ (y' , a' , b')
    ฮณ = to-subtype-๏ผ (having-lub-is-prop x) I

  instance
   strict-order-โ„š-F : Strict-Order โ„š F
   _<_ {{strict-order-โ„š-F}} p x = โˆƒ i ๊ž‰ ๐ผ , p < x i

  strict-order-โ„š-F-is-prop : (p : โ„š) (x : F) โ†’ is-prop (p < x)
  strict-order-โ„š-F-is-prop p x = โˆƒ-is-prop

  strict-order-โ„š-F-observation : (p : โ„š) (x : F)
                               โ†’ (p โ‰ฎ x) โ†” (x โ‰ค ฮน p)
  strict-order-โ„š-F-observation p x = f , g
   where
    f : p โ‰ฎ x โ†’ x โ‰ค ฮน p
    f ฮฝ i = I
     where
      I : (q : โ„š) โ†’ q < x i โ†’ q < p
      I q l = โ„š-order-criterion q p II III
       where
        II : p โ‰ฎ q
        II m = ฮฝ โˆฃ i , lowercut-is-lower (x i) q l p m โˆฃ

        III : q โ‰  p
        III refl = ฮฝ โˆฃ i , l โˆฃ

    g : x โ‰ค ฮน p โ†’ p โ‰ฎ x
    g l = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop I
     where
      I : ยฌ (ฮฃ i ๊ž‰ ๐ผ , p < x i)
      I (i , m) = <-โ„š-โ„š-irrefl p (l i p m)

  is-upper-bounded : F โ†’ ๐“คโบ ฬ‡
  is-upper-bounded x = โˆƒ y ๊ž‰ โ„ , (x โ‰ค y)

  is-located-family : F โ†’ ๐“ค ฬ‡
  is-located-family x = (p q : โ„š) โ†’ p < q โ†’ (p < x) โˆจ (q โ‰ฎ x)

  lub-sufficient-conditions : F โ†’ ๐“คโบ ฬ‡
  lub-sufficient-conditions x = โˆฅ ๐ผ โˆฅ
                              ร— is-upper-bounded x
                              ร— is-located-family x

  lub : (x : F) โ†’ lub-sufficient-conditions x โ†’ x has-a-lub
  lub x (๐ผ-inhabited , x-bounded , x-located) = y , a , b
   where
    L : ๐“Ÿ โ„š
    L p = (p < x) , strict-order-โ„š-F-is-prop p x

    L-inhabited : โˆƒ p ๊ž‰ โ„š , p < x
    L-inhabited = โˆฅโˆฅ-rec โˆƒ-is-prop I ๐ผ-inhabited
     where
      I : ๐ผ โ†’ โˆƒ p ๊ž‰ โ„š , โˆƒ i ๊ž‰ ๐ผ , p < x i
      I i = III II
       where
        II : ฮฃ i ๊ž‰ ๐ผ , โˆƒ p ๊ž‰ โ„š , p < x i
        II = i , lowercut-is-inhabited (x i)

        III : type-of II โ†’ โˆƒ p ๊ž‰ โ„š , โˆƒ i ๊ž‰ ๐ผ , p < x i
        III (i , s) = โˆฅโˆฅ-functor IV s
         where
          IV : (ฮฃ p ๊ž‰ โ„š , p < x i) โ†’ ฮฃ p ๊ž‰ โ„š , โˆƒ i ๊ž‰ ๐ผ , p < x i
          IV (p , l) = p , โˆฃ i , l โˆฃ

    L-lower : (q : โ„š) โ†’ q < x โ†’ (p : โ„š) โ†’ p < q โ†’ p < x
    L-lower q l p m = โˆฅโˆฅ-functor
                       (ฮป (i , k) โ†’ i , lowercut-is-lower (x i) q k p m)
                       l

    L-upper-open : (p : โ„š) โ†’ p < x โ†’ โˆƒ p' ๊ž‰ โ„š , ((p < p') ร— (p' < x))
    L-upper-open p = โˆฅโˆฅ-rec โˆƒ-is-prop f
     where
      f : (ฮฃ i ๊ž‰ ๐ผ , p < x i) โ†’ โˆƒ p' ๊ž‰ โ„š , ((p < p') ร— (p' < x))
      f (i , l) = โˆฅโˆฅ-functor g (lowercut-is-upper-open (x i) p l)
       where
        g : (ฮฃ p' ๊ž‰ โ„š , (p < p') ร— (p' < x i))
          โ†’ (ฮฃ p' ๊ž‰ โ„š , (p < p') ร— (p' < x))
        g (p' , m , o) = p' , m , โˆฃ i , o โˆฃ

    yแดธ : โ„แดธ
    yแดธ = (L , L-inhabited , L-lower , L-upper-open)

    L-bounded-above : โˆƒ q ๊ž‰ โ„š , q โ‰ฎ x
    L-bounded-above = โˆฅโˆฅ-rec โˆƒ-is-prop I x-bounded
     where
      I : (ฮฃ ฮฒ ๊ž‰ โ„ , x โ‰ค ฮฒ) โ†’ โˆƒ q ๊ž‰ โ„š , q โ‰ฎ x
      I (ฮฒ , l) = โˆฅโˆฅ-functor II (uppercut-is-inhabited ฮฒ)
       where
        II : (ฮฃ q ๊ž‰ โ„š , ฮฒ < q) โ†’ ฮฃ q ๊ž‰ โ„š , q โ‰ฎ x
        II (q , m) = q , โˆฅโˆฅ-rec ๐Ÿ˜-is-prop III
         where
          III : ยฌ (ฮฃ i ๊ž‰ ๐ผ , q < x i)
          III (i , o) = <-โ„š-โ„š-irrefl q (cuts-are-ordered ฮฒ q q (l i q o) m)

    L-located : (p q : โ„š) โ†’ p < q โ†’ (p < x) โˆจ (q โ‰ฎ x)
    L-located = x-located

    ฯ„ : is-troelstra yแดธ
    ฯ„ = L-bounded-above , L-located

    y : โ„
    y = (yแดธ , troelstra-gives-dedekind yแดธ ฯ„)

    a : x โ‰ค y
    a i p l = โˆฃ i , l โˆฃ

    b : (z : โ„) โ†’ x โ‰ค z โ†’ y โ‰ค z
    b z l p = โˆฅโˆฅ-rec (<-โ„š-โ„-is-prop-valued p z) f
     where
      f : (ฮฃ i ๊ž‰ ๐ผ , p < x i) โ†’ p < z
      f (i , m) = l i p m

  instance
   strict-order-F-โ„š : Strict-Order F โ„š
   _<_ {{strict-order-F-โ„š}} x q = (i : ๐ผ) โ†’ x i < q

  <-F-โ„š-is-prop-valued : (q : โ„š) (x : F) โ†’ is-prop (x < q)
  <-F-โ„š-is-prop-valued q x = ฮ -is-prop fe (ฮป i โ†’ <-โ„-โ„š-is-prop-valued (x i) q)

  is-bishop-located : F โ†’ ๐“ค ฬ‡
  is-bishop-located x = (p q : โ„š) โ†’ p < q โ†’ (p < x) โˆจ (x < q)

  bishop-located-families-are-located
   : (x : F)
   โ†’ is-bishop-located x
   โ†’ is-located-family x
  bishop-located-families-are-located x located p q l = IV
   where
    I : x < q โ†’ q โ‰ฎ x
    I m = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop II
     where
      II : ยฌ (ฮฃ i ๊ž‰ ๐ผ , q < x i)
      II (i , o) = <-โ„š-โ„š-irrefl q (cuts-are-ordered (x i) q q o (m i))

    III : (p < x) + (x < q) โ†’ (p < x) + (q โ‰ฎ x)
    III (inl l) = inl l
    III (inr m) = inr (I m)

    IV : (p < x) โˆจ (q โ‰ฎ x)
    IV = โˆฅโˆฅ-functor III (located p q l)


The partial reals, or interval domain, arise from dropping the
locatedness condition from the Dedekind reals.


 instance
  strict-order-โ„š-โ„แดธ : Strict-Order โ„š โ„แดธ
  _<_ {{strict-order-โ„š-โ„แดธ}} p (L , _) = p โˆˆ L

  strict-order-โ„แต-โ„š : Strict-Order โ„แต โ„š
  _<_ {{strict-order-โ„แต-โ„š}} (U , _) p = p โˆˆ U

 instance
  order-โ„แดธ-โ„แต : Order โ„แดธ โ„แต
  _โ‰ค_ {{order-โ„แดธ-โ„แต}} x y = (p q : โ„š) โ†’ p < x โ†’ y < q โ†’ p < q

 ๐“ก : ๐“คโบ ฬ‡
 ๐“ก = ฮฃ (x , y) ๊ž‰ โ„แดธ ร— โ„แต , (x โ‰ค y)

 ๐“ก-is-set : is-set ๐“ก
 ๐“ก-is-set = subsets-of-sets-are-sets (โ„แดธ ร— โ„แต) (ฮป (x , y) โ†’ x โ‰ค y)
             (ร—-is-set โ„แดธ-is-set โ„แต-is-set)
             (ฮ โ‚„-is-prop fe (ฮป _ _ _ _ โ†’ <-โ„š-โ„š-is-prop-valued _ _))

 NBโ‚„ : ๐“ก โ‰ƒ (ฮฃ (L , U) ๊ž‰ ๐“Ÿ โ„š ร— ๐“Ÿ โ„š
                       , (is-inhabited L ร— is-lower L ร— is-upper-open L)
                       ร— (is-inhabited U ร— is-upper U ร— is-lower-open U)
                       ร— are-ordered L U)

 NBโ‚„ = qinveq
        (ฮป (((L , Li , Ll , Lo) , (U , Ui , Uu , Uo)) , o)
          โ†’ (L , U) , (Li , Ll , Lo) , ((Ui , Uu , Uo) , o))
        ((ฮป ((L , U) , (Li , Ll , Lo) , ((Ui , Uu , Uo) , o))
          โ†’ (((L , Li , Ll , Lo) , (U , Ui , Uu , Uo)) , o)) ,
         (ฮป _ โ†’ refl) ,
         (ฮป _ โ†’ refl))

 โ„-to-๐“ก : โ„ โ†’ ๐“ก
 โ„-to-๐“ก (x , y , o , _) = (x , y) , o

 instance
  canonical-map-โ„-to-๐“ก : Canonical-Map โ„ ๐“ก
  ฮน {{canonical-map-โ„-to-๐“ก}} = โ„-to-๐“ก

  order-โ„แดธ-โ„แดธ : Order โ„แดธ โ„แดธ
  _โ‰ค_ {{order-โ„แดธ-โ„แดธ}} x y = (p : โ„š) โ†’ p < x โ†’ p < y

  order-โ„แต-โ„แต : Order โ„แต โ„แต
  _โ‰ค_ {{order-โ„แต-โ„แต}} x y = (p : โ„š) โ†’ y < p โ†’ x < p

  square-order-๐“ก-๐“ก : Square-Order ๐“ก ๐“ก
  _โŠ‘_ {{square-order-๐“ก-๐“ก}} ((x , y) , _) ((x' , y') , _) =
   (x โ‰ค x') ร— (y' โ‰ค y)

 โ„-to-๐“ก-is-embedding : is-embedding (canonical-map โ„ ๐“ก)
 โ„-to-๐“ก-is-embedding ((x , y) , o)
                     ((x , y , o , l) , refl)
                     ((x , y , o , m) , refl) = ฮณ
  where
   ฮด : l ๏ผ m
   ฮด = being-located-is-prop (ฮน x) (ฮน y) l m

   ฮณ : ((x , y , o , l) , refl) ๏ผ ((x , y , o , m) , refl)
   ฮณ = ap (ฮป - โ†’ (x , y , o , -) , refl) ฮด


Notice that this is reverse inclusion of intervals: wider intervals
are lower in the square order.

If we drop the inhabitation conditions, the endpoints can be ยฑโˆž:


 ๐“กโˆž = (ฮฃ (L , U) ๊ž‰ ๐“Ÿ โ„š ร— ๐“Ÿ โ„š
             , (is-lower L ร— is-upper-open L)
             ร— (is-upper U ร— is-lower-open U)
             ร— are-ordered L U)


Added 9 January 2026 by Tom de Jong.  Note that an alternative
formulation of the axioms is given by the following.


 roundness : (x : ๐“Ÿ โ„š ร— ๐“Ÿ โ„š) โ†’ ๐“ค ฬ‡
 roundness (L , U) =
    ((p : โ„š) โ†’ p โˆˆ L โ†” (โˆƒ r ๊ž‰ โ„š , (p < r) ร— (r โˆˆ L)))
  ร— ((q : โ„š) โ†’ q โˆˆ U โ†” (โˆƒ s ๊ž‰ โ„š , (s < q) ร— (s โˆˆ U)))

 roundness-equivalence
  : ((L , U) : ๐“Ÿ โ„š ร— ๐“Ÿ โ„š)
  โ†’ is-lower L ร— is-upper-open L ร— is-upper U ร— is-lower-open U
  โ†” roundness (L , U)
 roundness-equivalence (L , U) = I , II
  where
   I : is-lower L ร— is-upper-open L ร— is-upper U ร— is-lower-open U
     โ†’ roundness (L , U)
   I (L-low , L-uo , U-up , U-lo) =
    (ฮป p โ†’ L-uo p ,
           โˆฅโˆฅ-rec (โˆˆ-is-prop L p) (ฮป (r , l , r-in-L) โ†’ L-low r r-in-L p l)) ,
    (ฮป q โ†’ U-lo q ,
           โˆฅโˆฅ-rec (โˆˆ-is-prop U q) (ฮป (s , l , s-in-U) โ†’ U-up s s-in-U q l))
   II : roundness (L , U)
      โ†’ is-lower L ร— is-upper-open L ร— is-upper U ร— is-lower-open U
   II (ฯโ‚ , ฯโ‚‚) =
    (ฮป q q-in-L p l โ†’ rl-implication (ฯโ‚ p) โˆฃ q , l , q-in-L โˆฃ) ,
    (ฮป p โ†’ lr-implication (ฯโ‚ p)) ,
    (ฮป p p-in-U q l โ†’ rl-implication (ฯโ‚‚ q) โˆฃ p , l , p-in-U โˆฃ) ,
    (ฮป q โ†’ lr-implication (ฯโ‚‚ q))


End of addition.


 ๐“ก-to-๐“กโˆž : ๐“ก โ†’ ๐“กโˆž
 ๐“ก-to-๐“กโˆž (((L , _ , Ll , Lo) , (U , _ , Uu , Uo)) , o)
  = (L , U) , (Ll , Lo) , (Uu , Uo) , o

 โŠฅ๐“กโˆž : ๐“กโˆž
 โŠฅ๐“กโˆž = (โˆ… , โˆ…) , ((ฮป _ ()) , (ฮป _ ())) , ((ฮป _ ()) , (ฮป _ ())) , (ฮป p q ())

 instance
  canonical-map-๐“ก-to-๐“กโˆž : Canonical-Map ๐“ก ๐“กโˆž
  ฮน {{canonical-map-๐“ก-to-๐“กโˆž}} = ๐“ก-to-๐“กโˆž

 ๐“ก-to-๐“กโˆž-is-embedding : is-embedding (canonical-map ๐“ก ๐“กโˆž)
 ๐“ก-to-๐“กโˆž-is-embedding ((L , U) , (Ll , Lo) , (Uu , Uo) , o)
                        ((((L , i , Ll , Lo) , U , k , Uu , Uo) , o) , refl)
                        ((((L , j , Ll , Lo) , U , l , Uu , Uo) , o) , refl)
   = (((L , i , Ll , Lo) , U , k , Uu , Uo) , o) , refl ๏ผโŸจ I โŸฉ
     (((L , j , Ll , Lo) , U , l , Uu , Uo) , o) , refl โˆŽ
  where
   I = apโ‚‚ (ฮป i k โ†’ (((L , i , Ll , Lo) , U , k , Uu , Uo) , o) , refl)
           (being-inhabited-is-prop L i j)
           (being-inhabited-is-prop U k l)

 ๐“กโˆž-is-set : is-set ๐“กโˆž
 ๐“กโˆž-is-set = subsets-of-sets-are-sets (๐“Ÿ โ„š ร— ๐“Ÿ โ„š) _
              (ร—-is-set (๐“Ÿ-is-set' fe pe) (๐“Ÿ-is-set' fe pe))
              (ฮป {(L , U)} โ†’ ร—โ‚ƒ-is-prop
                              (ร—-is-prop (being-lower-is-prop L)
                                         (being-upper-open-is-prop L))
                              (ร—-is-prop (being-upper-is-prop U)
                                         (being-lower-open-is-prop U))
                             (being-ordered-is-prop L U))


TODO. Show that ๐“กโˆž is isomorphic, as a dcpo, to the ideal completion
of the dyadic intervals.

The notion of a locator for a real number was studied by my former PhD
student Auke Booij in his PhD thesis.

 Auke Booij. Extensional constructive real analysis via locators
 Mathematical Structures in Computer Science, Volume 31, Issue 1,
 January 2021, pp. 64 - 88 https://doi.org/10.1017/S0960129520000171
 https://arxiv.org/abs/1805.06781


 locator : โ„ โ†’ ๐“ค ฬ‡
 locator x = (p q : โ„š) โ†’ p < q โ†’ (p < x) + (x < q)


We also consider the following notion of locator for families:


 bishop-locator : {๐ผ : ๐“ค ฬ‡ } โ†’ (๐ผ โ†’ โ„) โ†’ ๐“ค ฬ‡
 bishop-locator {๐ผ} x = (p q : โ„š)
                      โ†’ p < q
                      โ†’ (ฮฃ i ๊ž‰ ๐ผ , p < x i)
                      + (ฮ  i ๊ž‰ ๐ผ , x i < q)

 pointwise-locator-gives-bishop-locator
  : (๐ผ : ๐“ค ฬ‡ ) (x : ๐ผ โ†’ โ„)
  โ†’ is-compactโˆ™ ๐ผ
  โ†’ ((i : ๐ผ) โ†’ locator (x i))
  โ†’ bishop-locator x
 pointwise-locator-gives-bishop-locator ๐ผ x ฮบ โ„“ p q l = ฮณ
  where
   ฮณ : (ฮฃ i ๊ž‰ ๐ผ , p < x i) + (ฮ  i ๊ž‰ ๐ผ , x i < q)
   ฮณ = compact-gives-ฮฃ+ฮ  ๐ผ
        (ฮป i โ†’ p < x i) (ฮป i โ†’ x i < q)
        (compactโˆ™-types-are-compact ฮบ)
        (ฮป i โ†’ โ„“ i p q l)

 lub-with-locators : (๐ผ : ๐“ค ฬ‡ ) (x : ๐ผ โ†’ โ„)
                   โ†’ is-compactโˆ™ ๐ผ
                   โ†’ is-upper-bounded x
                   โ†’ ((i : ๐ผ) โ†’ locator (x i))
                   โ†’ ฮฃ y ๊ž‰ โ„ , (x has-lub y) ร— locator y
 lub-with-locators ๐ผ x ฮบ ฮฒ โ„“ = ฮณ
  where
   h : โˆฅ ๐ผ โˆฅ
   h = โˆฃ compactโˆ™-types-are-pointed ฮบ โˆฃ

   I : bishop-locator x
   I = pointwise-locator-gives-bishop-locator ๐ผ x ฮบ โ„“

   II : (p q : โ„š)
      โ†’ p < q
      โ†’ ((ฮฃ i ๊ž‰ ๐ผ , p < x i) + (ฮ  i ๊ž‰ ๐ผ , x i < q))
      โ†’ (p < x) โˆจ (x < q)
   II p q l (inl (i , m)) = โˆฃ inl โˆฃ i , m โˆฃ โˆฃ
   II p q l (inr ฯ•)       = โˆฃ inr ฯ• โˆฃ

   III : is-bishop-located x
   III p q l = II p q l (I p q l)

   IV : x has-a-lub
   IV = lub x (h , ฮฒ , bishop-located-families-are-located x III)

   y : โ„
   y = prโ‚ IV

   V : x has-lub y
   V = prโ‚‚ IV

   VI : (p q : โ„š) โ†’ p < q โ†’ (p < y) + (y < q)
   VI p q l = ฮด (โ„š-density p q l)
    where
     ฮด : (ฮฃ q' ๊ž‰ โ„š , (p < q') ร— (q' < q)) โ†’ (p < y) + (y < q)
     ฮด (q' , i , j) = VII (I p q' i)
      where
       VII : ((ฮฃ i ๊ž‰ ๐ผ , p < x i) + (ฮ  i ๊ž‰ ๐ผ , x i < q')) โ†’ (p < y) + (y < q)
       VII (inl (o , m)) = inl โˆฃ o , m โˆฃ
       VII (inr ฯ•)       = inr IX
        where
         VIII : q' โ‰ฎ y
         VIII = โˆฅโˆฅ-rec ๐Ÿ˜-is-prop
                 (ฮป (i , o) โ†’ <-โ„š-โ„š-irrefl q'
                               (cuts-are-ordered (x i) q' q' o (ฯ• i)))

         IX : โˆƒ q' ๊ž‰ โ„š , (q' < q) ร— q' โ‰ฎ y
         IX = โˆฃ q' , j , VIII โˆฃ

   ฮณ : ฮฃ y ๊ž‰ โ„ , (x has-lub y) ร— locator y
   ฮณ = (y , V , VI)


Limits of sequences, but using the topological, rather than metric, structure of the reals.


 โฆ…_,_โฆ† : โ„š โ†’ โ„š โ†’ (โ„ โ†’ ฮฉ ๐“ค)
 โฆ… p , q โฆ† = ฮป x โ†’ ((p < x) ร— (x < q)) ,
                    ร—-is-prop
                     (<-โ„š-โ„-is-prop-valued p x)
                     (<-โ„-โ„š-is-prop-valued x q)

 _has-limit_ : (โ„• โ†’ โ„) โ†’ โ„ โ†’ ๐“ค ฬ‡
 x has-limit xโˆž = (p q : โ„š)
                 โ†’ xโˆž โˆˆ โฆ… p , q โฆ†
                 โ†’ โˆƒ n ๊ž‰ โ„• , ((k : โ„•) โ†’ k โ‰ฅ n โ†’ x k โˆˆ โฆ… p , q โฆ†)

 open import CoNaturals.Type

 is-continuous-โ„•โˆž-โ„ : (โ„•โˆž โ†’ โ„) โ†’ ๐“ค ฬ‡
 is-continuous-โ„•โˆž-โ„ x = (๐“ƒ : โ„•โˆž) (p q : โ„š)
                      โ†’ x ๐“ƒ โˆˆ โฆ… p , q โฆ†
                      โ†’ โˆƒ ๐“€ ๊ž‰ โ„•โˆž
                            , (๐“€ โ‰บ ๐“ƒ)
                            ร— ((๐’พ : โ„•โˆž) โ†’ ๐’พ โ‰ฝ ๐“€ โ†’ x ๐’พ โˆˆ โฆ… p , q โฆ†)


TODO. Some (overlapping) problems:


 Problemโ‚ = (x : โ„• โ†’ โ„) (xโˆž : โ„)
          โ†’ x has-limit xโˆž
          โ†’ ฮฃ xฬ‚ ๊ž‰ (โ„•โˆž โ†’ โ„)
                 , ((n : โ„•) โ†’ xฬ‚ (ฮน n) ๏ผ x n)
                 ร— (xฬ‚ โˆž ๏ผ xโˆž)

 Problemโ‚‚ = (x : โ„• โ†’ โ„) (xโˆž : โ„)
          โ†’ ((n : โ„•) โ†’ locator (x n))
          โ†’ locator xโˆž
          โ†’ x has-limit xโˆž
          โ†’ ฮฃ xฬ‚ ๊ž‰ (โ„•โˆž โ†’ โ„)
                 , ((n : โ„•) โ†’ xฬ‚ (ฮน n) ๏ผ x n)
                 ร— (xฬ‚ โˆž ๏ผ xโˆž)
                 ร— ((๐“ƒ : โ„•โˆž) โ†’ locator (xฬ‚ ๐“ƒ))

 Problemโ‚ƒ = (x : โ„•โˆž โ†’ โ„)
          โ†’ (x โˆ˜ ฮน) has-limit (x โˆž)
          โ†’ ((n : โ„•) โ†’ locator (x (ฮน n)))
          โ†’ locator (x โˆž)

 Problemโ‚„ = ฮฃ A ๊ž‰ (โ„ โ†’ ฮฉ ๐“ค) , (ฮฃ x ๊ž‰ โ„ , x โˆˆ A) โ‰ƒ โ„•โˆž

 Problemโ‚… = ฮฃ A ๊ž‰ (โ„ โ†’ ฮฉ ๐“ค)
                , ((ฮฃ x ๊ž‰ โ„ , x โˆˆ A) โ‰ƒ โ„•โˆž)
                ร— ((x : โ„) โ†’ x โˆˆ A โ†’ locator x)

 Problemโ‚† = (A : โ„ โ†’ ฮฉ ๐“ค)
          โ†’ ((ฮฃ x ๊ž‰ โ„ , x โˆˆ A) โ‰ƒ โ„•โˆž)
          โ†’ (x : โ„)
          โ†’ x โˆˆ A
          โ†’ locator x


Should some of the above โˆƒ be ฮฃ and/or vice-versa?

Added 22 August 2023. The lower reals have arbitrary sups if we remove
the inhabitation condition, so that we get a point -โˆž, in addition to
a point โˆž which is already present (this is well known).

TODO. Maybe remove the the inhabitation condition from the lower
reals. It doesn't really belong there.