-
Notifications
You must be signed in to change notification settings - Fork 363
/
reals.tex
3313 lines (2984 loc) · 186 KB
/
reals.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\chapter{Real numbers}
\label{cha:real-numbers}
\index{real numbers|(}%
Any foundation of mathematics worthy of its name must eventually address the construction of real numbers as understood by mathematical analysis, namely as a complete archimedean ordered field.
\index{ordered field}%
There are two notions of completeness. The one by Cauchy requires that the reals be closed under limits of Cauchy sequences\index{Cauchy!sequence}, while the stronger one by Dedekind requires closure under Dedekind cuts.\index{cut!Dedekind}
These lead to two ways of constructing reals, which we study in \cref{sec:dedekind-reals} and \cref{sec:cauchy-reals}, respectively. In \cref{RD-final-field,RC-initial-Cauchy-complete} we characterize the two constructions in terms of universal properties: the Dedekind reals are the final archimedean ordered field, and the Cauchy reals the initial Cauchy complete archimedean ordered field.
In traditional constructive mathematics,
\index{mathematics!constructive}%
real numbers always seem to require certain compromises. For example, the Dedekind reals work better with power sets or some other form of impredicativity, while Cauchy reals work well in the presence of countable choice.
\index{axiom!of choice!countable}%
However, we give a new construction of the Cauchy reals as a higher inductive-inductive type that seems to be a third possibility, which requires neither power sets nor countable choice.
In~\cref{sec:comp-cauchy-dedek} we compare the two constructions of reals. The Cauchy reals are included in the Dedekind reals. They coincide if excluded middle or countable choice holds, but in general the inclusion might be proper.
In~\cref{sec:compactness-interval} we consider three notions of compactness of the closed interval~$[0,1]$. We first show that $[0,1]$ is metrically compact\indexdef{metrically compact}\indexdef{compactness!metric} in the sense that it is complete and totally bounded, and that uniformly continuous maps on metrically compact spaces behave as expected. In contrast, the Bolzano--Weierstra\ss{} property that every sequence has a convergent subsequence implies the limited principle of omniscience, which is an instance of excluded middle. Finally, we discuss Heine--Borel compactness. A naive formulation of the finite subcover property does not work, but a proof relevant notion of inductive covers does.
This section is basically standard constructive analysis.
The development of real numbers and analysis in homotopy type theory can be easily made compatible with classical mathematics. By assuming excluded middle and the axiom of choice we get standard classical analysis:\index{mathematics!classical}\index{classical!analysis} the Dedekind and Cauchy reals coincide, foundational questions about the impredicative nature of the Dedekind reals disappear, and the interval is as compact as it could be.
We close the chapter by constructing Conway's surreals as a higher inductive-inductive type in \cref{sec:surreals};
the construction is more natural in univalent type theory than in classical set theory.
In addition to the basic theory of \cref{cha:basics,cha:logic}, as noted above we use ``higher inductive-inductive types'' for the Cauchy reals and the surreals: these combine the ideas of \cref{cha:hits} with the notion of inductive-inductive type mentioned in \cref{sec:generalizations}.
We will also frequently use the traditional logical notation described in \cref{subsec:prop-trunc}, and the fact (proven in \cref{sec:piw-pretopos}) that our ``sets'' behave the way we would expect.
Note that the total space of the universal cover of the circle, which
in \cref{subsec:pi1s1-homotopy-theory} played a role similar to ``the real numbers'' in
classical algebraic topology, is \emph{not} the type of reals we are looking for. That
type is contractible, and thus equivalent to the singleton type, so it cannot be equipped
with a non-trivial algebraic structure.
\section{The field of rational numbers}
\label{sec:field-rati-numb}
\indexdef{rational numbers}%
\indexsee{number!rational}{rational numbers}%
We first construct the rational numbers \Q, as the reals can then be seen as a completion
of~\Q. An expert will point out that \Q could be replaced by any approximate field,
\indexdef{field!approximate}%
i.e., a subring of \Q in which arbitrarily precise approximate inverses
\index{inverse!approximate}%
exist. An example is the
ring of dyadic rationals,
\index{rational numbers!dyadic}%
which are those of the form $n/2^k$.
If we were implementing constructive mathematics on a computer,
an approximate field would be more suitable, but we leave such finesse for those
who care about the digits of~$\pi$.
We constructed the integers \Z in \cref{sec:set-quotients} as a quotient of $\N\times
\N$, and observed that this quotient is generated by an idempotent. In
\cref{sec:free-algebras} we saw that \Z is the free group on \unit; we could similarly
show that it is the free commutative ring\index{ring} on \emptyt. The field of rationals \Q is
constructed along the same lines as well, namely as the quotient
%
\[ \Q \defeq (\Z \times \N)/{\approx} \]
%
where
\[ (u,a) \approx (v,b) \defeq (u (b + 1) = v (a + 1)). \]
%
In other words, a pair $(u, a)$ represents the rational number $u / (1 + a)$. There can be
no division by zero because we cunningly added one to the denominator~$a$. Here too we
have a canonical choice of representatives, namely fractions in lowest terms. Thus we may
apply \cref{lem:quotient-when-canonical-representatives} to obtain a set \Q, which
again has a decidable equality.
\index{decidable!equality}%
We do not bother to write down the arithmetical operations on \Q as we trust that our readers
know how to compute with fractions even in the case when one is added to the denominator.
Let us just record the conclusion that there is an entirely unproblematic construction of
the ordered field of rational numbers \Q, with a decidable equality and decidable order.
It can also be characterized as the initial ordered field.
\index{initial!ordered field}%
\symlabel{positive-rationals}
\indexdef{rational numbers!positive}%
\indexdef{positive!rational numbers}%
Finally, we will denote by $\Qp \defeq \setof{ q : \Q | q > 0 }$ the type of positive rational numbers.
\section{Dedekind reals}
\label{sec:dedekind-reals}
\index{real numbers!Dedekind|(}%
Let us first recall the basic idea of Dedekind's construction. We use two-sided Dedekind
cuts, as opposed to an often used one-sided version, because the symmetry makes
constructions more elegant, and it works constructively as well as classically.
\index{mathematics!constructive}%
A \emph{Dedekind cut}\index{cut!Dedekind} consists of a pair $(L, U)$ of subsets $L, U \subseteq \Q$, called the
\emph{lower} and \emph{upper cut} respectively, which are:
%
\begin{enumerate}
\item \emph{inhabited:} there are $q \in L$ and $r \in U$,
\item \emph{rounded:} $q \in L \Leftrightarrow \exis {r \in \Q} q < r \land r \in L$
and $r \in U \Leftrightarrow \exis {q \in \Q} q \in U \land q < r$,
\index{rounded!Dedekind cut}
\item \emph{disjoint:} $\lnot (q \in L \land q \in U)$, and
\item \emph{located:} $q < r \Rightarrow q \in L \lor r \in U$.
\index{locatedness}%
\end{enumerate}
%
Reading the roundedness condition from left to right tells us that cuts are \emph{open},
\index{open!cut}%
and from right to left that they are \emph{lower}, respectively \emph{upper}, sets. The
locatedness condition states that there is no large gap between $L$ and $U$. Because cuts
are always open, they never include the ``point in between'', even when it is rational. A
typical Dedekind cut looks like this:
%
\begin{center}
\begin{tikzpicture}[x=\textwidth]
\draw[<-),line width=0.75pt] (0,0) -- (0.297,0) node[anchor=south east]{$L\ $};
\draw[(->,line width=0.75pt] (0.300, 0) node[anchor=south west]{$\ U$} -- (0.9, 0) ;
\end{tikzpicture}
\end{center}
%
We might naively translate the informal definition into type theory by saying that a cut
is a pair of maps $L, U : \Q \to \prop$. But we saw in \cref{subsec:prop-subsets} that
$\prop$ is an ambiguous\index{typical ambiguity} notation for $\prop_{\UU_i}$ where~$\UU_i$ is a universe. Once we
use a particular $\UU_i$ to define cuts, the type of reals will reside in the next
universe $\UU_{i+1}$, a property of reals two levels higher in $\UU_{i+2}$, a property of
subsets of reals in $\UU_{i+3}$, etc. In principle we should be able to keep track of the
universe levels\index{universe level}, especially with the help of a proof assistant, but doing so here would
just burden us with bureaucracy that we prefer to avoid. We shall therefore make a
simplifying assumption that a single type of propositions $\Omega$ is sufficient for all
our purposes.
In fact, the construction of the Dedekind reals is quite resilient to logical
manipulations. There are several ways in which we can make sense of using a single type
$\Omega$:
%
\begin{enumerate}
\item We could identify $\Omega$ with the ambiguous $\prop$ and track all the universes
that appear in definitions and constructions.
\item We could assume the propositional resizing axiom,
\index{propositional!resizing}%
as in \cref{subsec:prop-subsets}, which essentially collapses the $\prop_{\UU_i}$'s to the
lowest level\index{universe level}, which we call $\Omega$.
\item A classical mathematician who is not interested in the intricacies of type-theoretic
universes or computation may simply assume the law of excluded middle~\eqref{eq:lem} for
mere propositions so that $\Omega \jdeq \bool$.
\index{excluded middle}
This not only eradicates questions about
levels\index{universe level} of $\prop$, but also turns everything we do into the standard classical\index{mathematics!classical}
construction of real numbers.
\item On the other end of the spectrum one might ask for a minimal requirement that makes
the constructions work. The condition that a mere predicate be a Dedekind cut is
expressible using only conjunctions, disjunctions, and existential quantifiers\index{quantifier!existential} over~\Q, which
is a countable set. Thus we could take $\Omega$ to be the initial \emph{$\sigma$-frame},
\index{initial!sigma-frame@$\sigma$-frame}%
\index{sigma-frame@$\sigma$-frame!initial|defstyle}%
i.e., a lattice\index{lattice} with countable joins\index{join!in a lattice} in which binary meets distribute over countable
joins. (The initial $\sigma$-frame cannot be the two-point lattice $\bool$ because
$\bool$ is not closed under countable joins, unless we assume excluded middle.) This
would lead to a construction of~$\Omega$ as a higher inductive-inductive type, but one
experiment of this kind in \cref{sec:cauchy-reals} is enough.
\end{enumerate}
In all of the above cases $\Omega$ is a set.
%
Without further ado, we translate the informal definition into type theory.
Throughout this chapter, we use the
logical notation from \cref{defn:logical-notation}.
\begin{defn} \label{defn:dedekind-reals}
A \define{Dedekind cut}
\indexsee{Dedekind!cut}{cut, Dedekind}%
\indexdef{cut!Dedekind}%
is a pair $(L, U)$ of mere predicates $L : \Q \to \Omega$ and $U
: \Q \to \Omega$ which is:
%
\begin{enumerate}
\item \label{defn:dedekind-reals-inhabited}
\emph{inhabited (i.e., bounded):} $\exis{q : \Q} L(q)$ and $\exis{r : \Q} U(r)$,
\item \emph{rounded:} for all $q, r : \Q$,
\index{rounded!Dedekind cut}
%
\begin{align*}
L(q) &\Leftrightarrow \exis{r : \Q} (q < r) \land L(r)
\qquad\text{and}\\
U(r) &\Leftrightarrow \exis{q : \Q} (q < r) \land U(q),
\end{align*}
\item \emph{disjoint:} $\lnot (L(q) \land U(q))$ for all $q : \Q$,
\item \emph{located:} $(q < r) \Rightarrow L(q) \lor U(r)$ for all $q, r : \Q$.
\index{locatedness}%
\end{enumerate}
%
We let $\dcut(L, U)$ denote the conjunction of these conditions. The type of
\define{Dedekind reals} is
\indexsee{Dedekind!real numbers}{real numbers, De\-de\-kind}%
\indexdef{real numbers!Dedekind}%
%
\begin{equation*}
\RD \defeq \setof{ (L, U) : (\Q \to \Omega) \times (\Q \to \Omega) | \dcut(L,U)}.
\end{equation*}
\end{defn}
It is apparent that $\dcut(L, U)$ is a mere proposition, and since $\Q \to \Omega$ is a
set the Dedekind reals form a set too. See
\cref{ex:RD-extended-reals,ex:RD-lower-cuts,ex:RD-interval-arithmetic} for variants of
Dedekind cuts which lead to extended reals, lower and upper reals, and the interval
domain.
There is an embedding $\Q \to \RD$ which associates with each rational $q : \Q$ the cut
$(L_q, U_q)$ where
%
\begin{equation*}
L_q(r) \defeq (r < q)
\qquad\text{and}\qquad
U_q(r) \defeq (q < r).
\end{equation*}
%
We shall simply write $q$ for the cut $(L_q, U_q)$ associated with a rational number.
\subsection{The algebraic structure of Dedekind reals}
\label{sec:algebr-struct-dedek}
The construction of the algebraic and order-theoretic structure of Dedekind reals proceeds
as usual in intuitionistic logic. Rather than dwelling on details we point out the
differences between the classical\index{mathematics!classical} and intuitionistic setup. Writing $L_x$ and $U_x$ for
the lower and upper cut of a real number $x : \RD$, we define addition as%
%
\indexdef{addition!of Dedekind reals}%
\begin{align*}
L_{x + y}(q) &\defeq \exis{r, s : \Q} L_x(r) \land L_y(s) \land q = r + s, \\
U_{x + y}(q) &\defeq \exis{r, s : \Q} U_x(r) \land U_y(s) \land q = r + s,
\end{align*}
%
and the additive inverse by
%
\begin{align*}
L_{-x}(q) &\defeq \exis{r : \Q} U_x(r) \land q = - r, \\
U_{-x}(q) &\defeq \exis{r : \Q} L_x(r) \land q = - r.
\end{align*}
%
With these operations $(\RD, 0, {+}, {-})$ is an abelian\index{group!abelian} group. Multiplication is a bit
more cumbersome:
%
\indexdef{multiplication!of Dedekind reals}%
\begin{align*}
L_{x \cdot y}(q) &\defeq
\begin{aligned}[t]
\exis{a, b, c, d : \Q} & L_x(a) \land U_x(b) \land L_y(c) \land U_y(d) \land {}\\
& \qquad q < \min (a \cdot c, a \cdot d, b \cdot c, b \cdot d),
\end{aligned} \\
U_{x \cdot y}(q) &\defeq
\begin{aligned}[t]
\exis{a, b, c, d : \Q} & L_x(a) \land U_x(b) \land L_y(c) \land U_y(d) \land {}\\
& \qquad \max (a \cdot c, a \cdot d, b \cdot c, b \cdot d) < q.
\end{aligned}
\end{align*}
%
\index{interval!arithmetic}%
These formulas are related to multiplication of intervals in interval arithmetic, where
intervals $[a,b]$ and $[c,d]$ with rational endpoints multiply to the interval
%
\begin{equation*}
[a,b] \cdot [c,d] =
[\min(a c, a d, b c, b d), \max(a c, a d, b c, b d)].
\end{equation*}
%
For instance, the formula for the lower cut can be read as saying that $q < x \cdot y$
when there are intervals $[a,b]$ and $[c,d]$ containing $x$ and $y$, respectively, such
that $q$ is to the left of $[a,b] \cdot [c,d]$. It is generally useful to think of an
interval $[a,b]$ such that $L_x(a)$ and $U_x(b)$ as an approximation of~$x$, see
\cref{ex:RD-interval-arithmetic}.
We now have a commutative ring\index{ring} with unit
\index{unit!of a ring}%
$(\RD, 0, 1, {+}, {-}, {\cdot})$. To treat
multiplicative inverses, we must first introduce order. Define $\leq$ and $<$ as
%
\begin{align*}
(x \leq y) &\ \defeq \ \fall{q : \Q} L_x(q) \Rightarrow L_y(q), \\
(x < y) &\ \defeq \ \exis{q : \Q} U_x(q) \land L_y(q).
\end{align*}
\begin{lem} \label{dedekind-in-cut-as-le}
For all $x : \RD$ and $q : \Q$, $L_x(q) \Leftrightarrow (q < x)$ and $U_x(q)
\Leftrightarrow (x < q)$.
\end{lem}
\begin{proof}
If $L_x(q)$ then by roundedness there merely is $r > q$ such that $L_x(r)$, and since
$U_q(r)$ it follows that $q < x$. Conversely, if $q < x$ then there is $r : \Q$ such
that $U_q(r)$ and $L_x(r)$, hence $L_x(q)$ because $L_x$ is a lower set. The other half
of the proof is symmetric.
\end{proof}
\index{partial order}%
\index{transitivity!of . for reals@of $<$ for reals}
\index{transitivity!of . for reals@of $\leq$ for reals}
\index{relation!irreflexive}
\index{irreflexivity!of . for reals@of $<$ for reals}
The relation $\leq$ is a partial order, and $<$ is transitive and irreflexive. Linearity
\index{order!linear}%
\index{linear order}%
%
\begin{equation*}
(x < y) \lor (y \leq x)
\end{equation*}
%
is valid if we assume excluded middle, but without it we get weak linearity
%
\index{order!weakly linear}
\index{weakly linear order}
\begin{equation} \label{eq:RD-linear-order}
(x < y) \Rightarrow (x < z) \lor (z < y).
\end{equation}
%
At first sight it might not be clear what~\eqref{eq:RD-linear-order} has to do with
linear order. But if we take $x \jdeq u - \epsilon$ and $y \jdeq u + \epsilon$ for
$\epsilon > 0$, then we get
%
\begin{equation*}
(u - \epsilon < z) \lor (z < u + \epsilon).
\end{equation*}
%
This is linearity ``up to a small numerical error'', i.e., since it is unreasonable to
expect that we can actually compute with infinite precision, we should not be surprised
that we can decide~$<$ only up to whatever finite precision we have computed.
To see that~\eqref{eq:RD-linear-order} holds, suppose $x < y$. Then there merely exists $q : \Q$ such that $U_x(q)$ and
$L_y(q)$. By roundedness there merely exist $r, s : \Q$ such that $r < q < s$, $U_x(r)$
and $L_y(s)$. Then, by locatedness $L_z(r)$ or $U_z(s)$. In the first case we get $x < z$
and in the second $z < y$.
Classically, multiplicative inverses exist for all numbers which are different from zero.
However, without excluded middle, a stronger condition is required. Say that $x, y : \RD$
are \define{apart}
\indexdef{apartness}%
from each other, written $x \apart y$, when $(x < y) \lor (y < x)$:
%
\symlabel{apart}
\begin{equation*}
(x \apart y) \defeq (x < y) \lor (y < x).
\end{equation*}
%
If $x \apart y$, then $\lnot (x = y)$.
The converse is true if we assume excluded middle, but is not provable constructively.
\index{mathematics!constructive}%
Indeed, if $\lnot (x = y)$ implies $x\apart y$, then a little bit of excluded middle follows; see \cref{ex:reals-apart-neq-MP}.
\begin{thm} \label{RD-inverse-apart-0}
A real is invertible if, and only if, it is apart from $0$.
\end{thm}
\begin{rmk}
We observe that a real is invertible if, and only if, it is merely
invertible. Indeed, the same is true in any ring,\index{ring} since a ring is a set, and
multiplicative inverses are unique if they exist. See the discussion
following \cref{cor:UC}.
\end{rmk}
\begin{proof}
Suppose $x \cdot y = 1$. Then there merely exist $a, b, c, d : \Q$ such that
$a < x < b$, $c < y < d$ and $0 < \min (a c, a d, b c, b d)$. From $0 < a c$ and $0 < b c$ it follows
that $a$, $b$, and $c$ are either all positive or all negative.
Hence either $0 < a < x$ or $x < b < 0$, so that $x \apart 0$.
Conversely, if $x \apart 0$, then either $x > 0$ or $x < 0$.
If $x > 0$, we define $x^{-1}$ as follows:
%
\begin{align*}
L_{x^{-1}}(q) &\defeq
(q > 0) \Rightarrow \exis{r : \Q} U_x(r) \land (q r < 1),
\\
U_{x^{-1}}(q) &\defeq
(q > 0) \land \exis{r : \Q} L_x(r) \land (q r > 1).
\end{align*}
%
If $x < 0$, then we define it by
%
\begin{align*}
L_{x^{-1}}(q) &\defeq
(q < 0) \land \exis{r : \Q} U_x(r) \land (q r > 1),
\\
U_{x^{-1}}(q) &\defeq
(q < 0) \Rightarrow \exis{r : \Q} L_x(r) \land (q r < 1). \qedhere
\end{align*}
\end{proof}
\index{ordered field!archimedean}%
\index{dense}%
\indexsee{order-dense}{dense}%
The archimedean principle can be stated in several ways. We find it most illuminating in the
form which says that $\Q$ is dense in $\RD$.
\begin{thm}[Archimedean principle for $\RD$] \label{RD-archimedean}
%
For all $x, y : \RD$ if $x < y$ then there merely exists $q : \Q$ such that
$x < q < y$.
\end{thm}
\begin{proof}
By definition of $<$.
\end{proof}
Before tackling completeness of Dedekind reals, let us state precisely what algebraic
structure they possess. In the following definition we are not aiming at a minimal
axiomatization, but rather at a useful amount of structure and properties.
\begin{defn} \label{ordered-field} An \define{ordered field}
\indexdef{ordered field}%
\indexsee{field!ordered}{ordered field}%
is a set $F$ together with
constants $0$, $1$, operations $+$, $-$, $\cdot$, $\min$, $\max$, and mere relations
$\leq$, $<$, $\apart$ such that:
%
\begin{enumerate}
\item $(F, 0, 1, {+}, {-}, {\cdot})$ is a commutative ring with unit;
\index{unit!of a ring}%
\index{ring}%
\item $x : F$ is invertible if, and only if, $x \apart 0$;
\item $(F, {\leq}, {\min}, {\max})$ is a lattice;
\item the strict order $<$ is transitive, irreflexive,
\index{relation!irreflexive}
\index{irreflexivity!of . in a field@of $<$ in a field}%
and weakly linear ($x < y \Rightarrow x < z \lor z < y$);\index{transitivity!of . in a field@of $<$ in a field}
\index{order!weakly linear}
\index{weakly linear order}
\index{strict!order}%
\index{order!strict}%
\item apartness $\apart$ is irreflexive, symmetric and cotransitive ($x \apart y \Rightarrow x \apart z \lor y \apart z$);
\index{relation!irreflexive}
\index{irreflexivity!of apartness}%
\indexdef{relation!cotransitive}%
\index{cotransitivity of apartness}%
\item for all $x, y, z : F$:
%
\begin{align*}
x \leq y &\Leftrightarrow \lnot (y < x), &
x < y \leq z &\Rightarrow x < z, \\
x \apart y &\Leftrightarrow (x < y) \lor (y < x), &
x \leq y < z &\Rightarrow x < z, \\
x \leq y &\Leftrightarrow x + z \leq y + z, &
x \leq y \land 0 \leq z &\Rightarrow x z \leq y z, \\
x < y &\Leftrightarrow x + z < y + z, &
0 < z \Rightarrow (x < y &\Leftrightarrow x z < y z), \\
0 < x + y &\Rightarrow 0 < x \lor 0 < y, &
0 &< 1.
\end{align*}
\end{enumerate}
%
Every such field has a canonical embedding $\Q \to F$. An ordered field is
\define{archimedean}
\indexdef{ordered field!archimedean}%
\indexsee{archimedean property}{ordered field, archi\-mede\-an}%
when for all $x, y : F$, if $x < y$ then there merely exists $q :
\Q$ such that $x < q < y$.
\end{defn}
\begin{thm} \label{RD-archimedean-ordered-field}
The Dedekind reals form an ordered archimedean field.
\end{thm}
\begin{proof}
We omit the proof in the hope that what we have demonstrated so far makes the theorem
plausible.
\end{proof}
\subsection{Dedekind reals are Cauchy complete}
\label{sec:RD-cauchy-complete}
Recall that $x : \N \to \Q$ is a \emph{Cauchy sequence}\indexdef{Cauchy!sequence} when it satisfies
%
\begin{equation} \label{eq:cauchy-sequence}
\prd{\epsilon : \Qp} \sm{n : \N} \prd{m, k \geq n} |x_m - x_k| < \epsilon.
\end{equation}
%
Note that we did \emph{not} truncate the inner existential because we actually want to
compute rates of convergence---an approximation without an error estimate carries little
useful information. By \cref{thm:ttac}, \eqref{eq:cauchy-sequence} yields a function $M
: \Qp \to \N$, called the \emph{modulus of convergence}\indexdef{modulus!of convergence}, such that $m, k \geq M(\epsilon)$
implies $|x_m - x_k| < \epsilon$. From this we get $|x_{M(\delta/2)} - x_{M(\epsilon/2)}|<
\delta + \epsilon$ for all $\delta, \epsilon : \Qp$. In fact, the map $(\epsilon \mapsto
x_{M(\epsilon/2)}) : \Qp \to \Q$ carries the same information about the limit as the
original Cauchy condition~\eqref{eq:cauchy-sequence}. We shall work with these
approximation functions rather than with Cauchy sequences.
\begin{defn} \label{defn:cauchy-approximation}
A \define{Cauchy approximation}
\indexdef{Cauchy!approximation}%
is a map $x : \Qp \to \RD$ which satisfies
%
\begin{equation}
\label{eq:cauchy-approx}
\fall{\delta, \epsilon :\Qp} |x_\delta - x_\epsilon| < \delta + \epsilon.
\end{equation}
%
The \define{limit}
\index{limit!of a Cauchy approximation}%
of a Cauchy approximation $x : \Qp \to \RD$ is a number $\ell : \RD$ such
that
%
\begin{equation*}
\fall{\epsilon, \theta : \Qp} |x_\epsilon - \ell| < \epsilon + \theta.
\end{equation*}
\end{defn}
\begin{thm} \label{RD-cauchy-complete}
Every Cauchy approximation in $\RD$ has a limit.
\end{thm}
\begin{proof}
Note that we are showing existence, not mere existence, of the limit.
Given a Cauchy approximation $x : \Qp \to \RD$, define
%
\begin{align*}
L_y(q) &\defeq \exis{\epsilon, \theta : \Qp} L_{x_\epsilon}(q + \epsilon + \theta),\\
U_y(q) &\defeq \exis{\epsilon, \theta : \Qp} U_{x_\epsilon}(q - \epsilon - \theta).
\end{align*}
%
It is clear that $L_y$ and $U_y$ are inhabited, rounded, and disjoint. To establish
locatedness, consider any $q, r : \Q$ such that $q < r$. There is $\epsilon : \Qp$ such
that $5 \epsilon < r - q$. Since $q + 2 \epsilon < r - 2 \epsilon$ merely
$L_{x_\epsilon}(q + 2 \epsilon)$ or $U_{x_\epsilon}(r - 2 \epsilon)$. In the first case
we have $L_y(q)$ and in the second $U_y(r)$.
To show that $y$ is the limit of $x$, consider any $\epsilon, \theta : \Qp$. Because
$\Q$ is dense in $\RD$ there merely exist $q, r : \Q$ such that
%
\begin{narrowmultline*}
x_\epsilon - \epsilon - \theta/2 < q < x_\epsilon - \epsilon - \theta/4
< x_\epsilon < \\
x_\epsilon + \epsilon + \theta/4 < r < x_\epsilon + \epsilon + \theta/2,
\end{narrowmultline*}
%
and thus $q < y < r$. Now either $y < x_\epsilon + \theta/2$ or $x_\epsilon - \theta/2 < y$.
In the first case we have
%
\begin{equation*}
x_\epsilon - \epsilon - \theta/2 < q < y < x_\epsilon + \theta/2,
\end{equation*}
%
and in the second
%
\begin{equation*}
x_\epsilon - \theta/2 < y < r < x_\epsilon + \epsilon + \theta/2.
\end{equation*}
%
In either case it follows that $|y - x_\epsilon| < \epsilon + \theta$.
\end{proof}
For sake of completeness we record the classic formulation as well.
\begin{cor}
Suppose $x : \N \to \RD$ satisfies the Cauchy condition~\eqref{eq:cauchy-sequence}. Then
there exists $y : \RD$ such that
%
\begin{equation*}
\prd{\epsilon : \Qp} \sm{n : \N} \prd{m \geq n} |x_m - y| < \epsilon.
\end{equation*}
\end{cor}
\begin{proof}
By \cref{thm:ttac} there is $M : \Qp \to \N$ such that $\bar{x}(\epsilon) \defeq
x_{M(\epsilon/2)}$ is a Cauchy approximation. Let $y$ be its limit, which exists by
\cref{RD-cauchy-complete}. Given any $\epsilon : \Qp$, let $n \defeq M(\epsilon/4)$
and observe that, for any $m \geq n$,
%
\begin{narrowmultline*}
|x_m - y| \leq |x_m - x_n| + |x_n - y| =
|x_m - x_n| + |\bar{x}(\epsilon/2) - y| < \narrowbreak
\epsilon/4 + \epsilon/2 + \epsilon/4 = \epsilon.\qedhere
\end{narrowmultline*}
\end{proof}
\subsection{Dedekind reals are Dedekind complete}
\label{sec:RD-dedekind-complete}
We obtained $\RD$ as the type of Dedekind cuts on $\Q$. But we could have instead started
with any archimedean ordered field $F$ and constructed Dedekind cuts\index{cut!Dedekind} on $F$. These would
again form an archimedean ordered field $\bar{F}$, the \define{Dedekind completion of $F$},%
\index{completion!Dedekind}%
\indexsee{Dedekind!completion}{completion, Dedekind}
with $F$ contained as a subfield. What happens if we apply this construction to
$\RD$, do we get even more real numbers? The answer is negative. In fact, we shall prove a
stronger result: $\RD$ is final.
Say that an ordered field~$F$ is \define{admissible for $\Omega$}
\indexsee{admissible!ordered field}{ordered field, admissible}%
\indexdef{ordered field!admissible}%
when the strict order
$<$ on~$F$ is a map ${<} : F \to F \to \Omega$.
\begin{thm} \label{RD-final-field}
Every archimedean ordered field which is admissible for $\Omega$ is a subfield of~$\RD$.
\end{thm}
\begin{proof}
Let $F$ be an archimedean ordered field. For every $x : F$ define $L_x, U_x : \Q \to
\Omega$ by
%
\begin{equation*}
L_x(q) \defeq (q < x)
\qquad\text{and}\qquad
U_x(q) \defeq (x < q).
\end{equation*}
%
(We have just used the assumption that $F$ is admissible for $\Omega$.)
Then $(L_x, U_x)$ is a Dedekind cut.\index{cut!Dedekind} Indeed, the cuts are inhabited and rounded because
$F$ is archimedean and $<$ is transitive, disjoint because $<$ is irreflexive, and
located because $<$ is a weak linear order. Let $e : F \to \RD$ be the map $e(x) \defeq (L_x,
U_x)$.
We claim that $e$ is a field embedding which preserves and reflects the order. First of
all, notice that $e(q) = q$ for a rational number $q$. Next we have the equivalences,
for all $x, y : F$,
%
\begin{narrowmultline*}
x < y \Leftrightarrow
(\exis{q : \Q} x < q < y) \Leftrightarrow \narrowbreak
(\exis{q : \Q} U_x(q) \land L_y(q)) \Leftrightarrow
e(x) < e(y),
\end{narrowmultline*}
%
so $e$ indeed preserves and reflects the order. That $e(x + y) = e(x) + e(y)$ holds
because, for all $q : \Q$,
%
\begin{equation*}
q < x + y \Leftrightarrow
\exis{r, s : \Q} r < x \land s < y \land q = r + s.
\end{equation*}
%
The implication from right to left is obvious. For the other direction, if $q < x +
y$ then there merely exists $r : \Q$ such that $q - y < r < x$, and by taking $s \defeq
q - r$ we get the desired $r$ and $s$. We leave preservation of multiplication by $e$ as
an exercise.
\end{proof}
To establish that the Dedekind cuts on $\RD$ do not give us anything new, we need just one
more lemma.
\begin{lem} \label{lem:cuts-preserve-admissibility}
If $F$ is admissible for $\Omega$ then so is its Dedekind completion.
\index{completion!Dedekind}%
\end{lem}
\begin{proof}
Let $\bar{F}$ be the Dedekind completion of $F$. The strict order on $\bar{F}$ is
defined by
%
\begin{equation*}
((L,U) < (L',U')) \defeq \exis{q : \Q} U(q) \land L'(q).
\end{equation*}
%
Since $U(q)$ and $L'(q)$ are elements of $\Omega$, the lemma holds as long as $\Omega$
is closed under conjunctions and countable existentials, which we assumed from the outset.
\end{proof}
\begin{cor} \label{RD-dedekind-complete}
%
\indexdef{complete!ordered field, Dedekind}%
\indexdef{Dedekind!completeness}%
The Dedekind reals are Dedekind complete: for every real-valued Dedekind cut $(L, U)$
there is a unique $x : \RD$ such that $L(y) = (y < x)$ and $U(y) = (x < y)$ for all $y :
\RD$.
\end{cor}
\begin{proof}
By \cref{lem:cuts-preserve-admissibility} the Dedekind completion $\barRD$ of $\RD$
is admissible for $\Omega$, so by \cref{RD-final-field} we have an embedding $\barRD
\to \RD$, as well as an embedding $\RD \to \barRD$. But these embeddings must be
isomorphisms, because their compositions are order-preserving field homomorphisms\index{homomorphism!field} which
fix the dense subfield~$\Q$, which means that they are the identity. The corollary now
follows immediately from the fact that $\barRD \to \RD$ is an isomorphism.
\end{proof}
\index{real numbers!Dedekind|)}%
\section{Cauchy reals}
\label{sec:cauchy-reals}
\index{real numbers!Cauchy|(}%
\index{completion!Cauchy|(}%
\indexsee{Cauchy!completion}{completion, Cauchy}%
The Cauchy reals are, by intent, the completion of \Q under limits of Cauchy sequences.\index{Cauchy!sequence}
In the classical construction of the Cauchy reals, we consider the set $\mathcal{C}$ of all Cauchy sequences in \Q and then form a suitable quotient $\mathcal{C}/{\approx}$.
Then, to show that $\mathcal{C}/{\approx}$ is Cauchy complete, we consider a Cauchy sequence $x : \N \to \mathcal{C}/{\approx}$, lift it to a sequence of sequences $\bar{x} : \N \to \mathcal{C}$, and construct the limit of $x$ using $\bar{x}$. However, the lifting of~$x$ to $\bar{x}$ uses
the axiom of countable choice (the instance of~\eqref{eq:ac} where $X=\N$) or the law of excluded middle, which we may wish to avoid.
\indexdef{axiom!of choice!countable}%
Every construction of reals whose last step is a quotient suffers from this deficiency.
There are three common ways out of the conundrum in constructive mathematics:
\index{mathematics!constructive}%
%
\index{bargaining}%
\begin{enumerate}
\item Pretend that the reals are a setoid $(\mathcal{C}, {\approx})$, i.e., the type of
Cauchy sequences $\mathcal{C}$ with a coincidence\index{coincidence, of Cauchy approximations} relation attached to it by
administrative decree. A sequence of reals then simply \emph{is} a sequence of Cauchy
sequences representing them.
\item Give in to temptation and accept the axiom of countable choice. After all, the axiom
is valid in most models of constructive mathematics based on a computational viewpoint,
such as realizability models.
\item Declare the Cauchy reals unworthy and construct the Dedekind reals instead.
Such a verdict is perfectly valid in certain contexts, such as in sheaf-theoretic models of constructive mathematics.
However, as we saw in \cref{sec:dedekind-reals}, the constructive Dedekind reals have their own problems.
\end{enumerate}
Using higher inductive types, however, there is a fourth solution, which we believe to be preferable to any of the above, and interesting even to a classical mathematician.
The idea is that the Cauchy real numbers should be the \emph{free complete metric space}\index{free!complete metric space} generated by~\Q.
In general, the construction of a free gadget of any sort requires applying the gadget operations repeatedly many times to the generators.
For instance, the elements of the free group on a set $X$ are not just binary products and inverses of elements of $X$, but words obtained by iterating the product and inverse constructions.
Thus, we might naturally expect the same to be true for Cauchy completion, with the relevant ``operation'' being ``take the limit of a Cauchy sequence''.
(In this case, the iteration would have to take place transfinitely, since even after infinitely many steps there will be new Cauchy sequences to take the limit of.)
The argument referred to above shows that if excluded middle or countable choice hold, then Cauchy completion is very special: when building the completion of a space, it suffices to stop applying the operation after \emph{one step}.
This may be regarded as analogous to the fact that free monoids and free groups can be given explicit descriptions in terms of (reduced) words.
However, we saw in \cref{sec:free-algebras} that higher inductive types allow us to construct free gadgets \emph{directly}, whether or not there is also an explicit description available.
In this section we show that the same is true for the Cauchy reals (a similar technique would construct the Cauchy completion of any metric space; see \cref{ex:metric-completion}).
Specifically, higher inductive types allow us to \emph{simultaneously} add limits of Cauchy sequences and quotient by the coincidence relation, so that we can avoid the problem of lifting a sequence of reals to a sequence of representatives.
\index{completion!Cauchy|)}%
\subsection{Construction of Cauchy reals}
\label{sec:constr-cauchy-reals}
The construction of the Cauchy reals $\RC$ as a higher inductive type is a bit more subtle than that of the free algebraic structures considered in \cref{sec:free-algebras}.
We intend to include a ``take the limit'' constructor whose input is a Cauchy sequence of reals, but the notion of ``Cauchy sequence of reals'' depends on having some way to measure the ``distance'' between real numbers.
In general, of course, the distance between two real numbers will be another real number, leading to a potentially problematic circularity.
However, what we actually need for the notion of Cauchy sequence of reals is not the general notion of ``distance'', but a way to say that ``the distance\index{distance} between two real numbers is less than $\epsilon$'' for any $\epsilon:\Qp$.
This can be represented by a family of binary relations, which we will denote $\mathord{\close\epsilon} : \RC\to\RC\to \prop$.
The intended meaning of $x \close\epsilon y$ is $|x - y| < \epsilon$, but since we do not have notions of subtraction, absolute value, or inequality available yet (we are only just defining $\RC$, after all), we will have to define these relations $\close\epsilon$ at the same time as we define $\RC$ itself.
And since $\close\epsilon$ is a type family indexed by two copies of $\RC$, we cannot do this with an ordinary mutual (higher) inductive definition; instead we have to use a \emph{higher inductive-inductive definition}.
\index{inductive-inductive type!higher}
Recall from \cref{sec:generalizations} that the ordinary notion of inductive-inductive definition allows us to define a type and a type family indexed by it by simultaneous induction.
Of course, the ``higher'' version of this allows both the type and the family to have path constructors as well as point constructors.
We will not attempt to formulate any general theory of higher inductive-inductive definitions, but hopefully the description we will give of $\RC$ and $\close\epsilon$ will make the idea transparent.
\begin{rmk}
We might also consider a \emph{higher inductive-recursive definition}, in which $\close\epsilon$ is defined using the \emph{recursion} principle of $\RC$, simultaneously with the \emph{inductive} definition of $\RC$.
We choose the inductive-inductive route instead for two reasons.
Firstly, higher inductive-re\-cur\-sive definitions seem to be more difficult to justify in homotopical semantics.
Secondly, and more importantly, the inductive-inductive definition yields a more powerful induction principle, which we will need in order to develop even the basic theory of Cauchy reals.
\end{rmk}
Finally, as we did for the discussion of Cauchy completeness of the Dedekind reals in \cref{sec:RD-cauchy-complete}, we will work with \emph{Cauchy approximations} (\cref{defn:cauchy-approximation}) instead of Cauchy sequences.
Of course, our Cauchy approximations will now consist of Cauchy reals, rather than Dedekind reals or rational numbers.
\begin{defn}\label{defn:cauchy-reals}
Let $\RC$ and the relation $\closesym:\Qp \times \RC \times \RC \to \type$ be the following higher inductive-inductive type family.
The type $\RC$ of \define{Cauchy reals}
\indexdef{real numbers!Cauchy}%
\indexsee{Cauchy!real numbers}{real numbers, Cau\-chy}%
is generated by the following constructors:
\begin{itemize}
\item \emph{rational points:}
for any $q : \Q$ there is a real $\rcrat(q)$.
\index{rational numbers!as Cauchy real numbers}%
\item \emph{limit points}:
for any $x : \Qp \to \RC$ such that
%
\begin{equation}
\label{eq:RC-cauchy}
\fall{\delta, \epsilon : \Qp} x_\delta \close{\delta + \epsilon} x_\epsilon
\end{equation}
%
there is a point $\rclim(x) : \RC$. We call $x$ a \define{Cauchy approximation}.
\indexdef{Cauchy!approximation}%
\index{limit!of a Cauchy approximation}%
%
\item \emph{paths:}
for $u, v : \RC$ such that
%
\begin{equation}
\label{eq:RC-path}
\fall{\epsilon : \Qp} u \close\epsilon v
\end{equation}
%
then there is a path $\rceq(u, v) : \id[\RC]{u}{v}$.
\end{itemize}
Simultaneously, the type family $\closesym:\RC\to\RC\to\Qp \to\type$ is generated by the following constructors.
Here $q$ and $r$ denote rational numbers; $\delta$, $\epsilon$, and $\eta$ denote positive rationals; $u$ and $v$ denote Cauchy reals; and $x$ and $y$ denote Cauchy approximations:
\begin{itemize}
\item for any $q,r,\epsilon$, if $-\epsilon < q - r < \epsilon$, then $\rcrat(q) \close\epsilon \rcrat(r)$,
\item for any $q,y,\epsilon,\delta$, if $\rcrat(q) \close{\epsilon - \delta} y_\delta$, then $\rcrat(q) \close{\epsilon} \rclim(y)$,
\item for any $x,r,\epsilon,\delta$, if $x_\delta \close{\epsilon - \delta} \rcrat(r)$, then $\rclim(x) \close\epsilon \rcrat(r)$,
\item for any $x,y,\epsilon,\delta,\eta$, if $x_\delta \close{\epsilon - \delta - \eta} y_\eta$, then $\rclim(x) \close\epsilon \rclim(y)$,
\item for any $u,v,\epsilon$, if $\xi,\zeta : u \close{\epsilon} v$, then $\xi=\zeta$ (propositional truncation).
\end{itemize}
\end{defn}
\mentalpause
The first constructor of $\RC$ says that any rational number can be regarded as a real number.
The second says that from any Cauchy approximation to a real number, we can obtain a new real number called its ``limit''.
And the third expresses the idea that if two Cauchy approximations coincide, then their limits are equal.
The first four constructors of $\closesym$ specify when two rational numbers are close, when a rational is close to a limit, and when two limits are close.
In the case of two rational numbers, this is just the usual notion of $\epsilon$-closeness for rational numbers, whereas the other cases can be derived by noting that each approximant $x_\delta$ is supposed to be within $\delta$ of the limit $\rclim(x)$.
We remind ourselves of proof-relevance: a real number obtained from $\rclim$ is represented not
just by a Cauchy approximation $x$, but also a proof $p$ of~\eqref{eq:RC-cauchy}, so we
should technically have written $\rclim(x,p)$ instead of just $\rclim(x)$.
A similar observation also applies to $\rceq$ and~\eqref{eq:RC-path}, but we shall write just
$\rceq : u = v$ instead of $\rceq(u, v, p) : u = v$. These abuses of notation are
mitigated by the fact that we are omitting mere propositions and information that is
readily guessed.
Likewise, the last constructor of $\mathord{\close\epsilon}$ justifies our leaving the other four nameless.
We are immediately able to populate $\RC$ with many real numbers. For suppose $x : \N \to
\Q$ is a traditional Cauchy sequence\index{Cauchy!sequence} of rational numbers, and let $M : \Qp \to \N$ be its
modulus of convergence. Then $\rcrat \circ x \circ M : \Qp \to \RC$ is a Cauchy
approximation, using the first constructor of $\closesym$ to produce the necessary witness.
Thus, $\rclim(\rcrat \circ x \circ m)$ is a real number. Various famous
real numbers such as $\sqrt{2}$, $\pi$, $e$, \dots{} are all limits of such Cauchy sequences of
rationals.
\subsection{Induction and recursion on Cauchy reals}
\label{sec:induct-recurs-cauchy}
In order to do anything useful with $\RC$, of course, we need to give its induction principle.
As is the case whenever we inductively define two or more objects at once, the basic induction principle for $\RC$ and $\closesym$ requires a simultaneous induction over both at once.
Thus, we should expect it to say that assuming two type families over $\RC$ and $\closesym$, respectively, together with data corresponding to each constructor, there exist sections of both of these families.
However, since $\closesym$ is indexed on two copies of $\RC$, the precise dependencies of these families is a bit subtle.
The induction principle will apply to any pair of type families:
\begin{align*}
A&:\RC\to\type\\
B&:\prd{x,y:\RC} A(x) \to A(y) \to \prd{\epsilon:\Qp} (x\close\epsilon y) \to \type.
\end{align*}
The type of $A$ is obvious, but the type of $B$ requires a little thought.
Since $B$ must depend on $\closesym$, but $\closesym$ in turn depends on two copies of $\RC$ and one copy of $\Qp$, it is fairly obvious that $B$ must also depend on the variables $x,y:\RC$ and $\epsilon:\Qp$ as well as an element of $(x\close\epsilon y)$.
What is slightly less obvious is that $B$ must also depend on $A(x)$ and $A(y)$.
This may be more evident if we consider the non-dependent case (the recursion principle), where $A$ is a simple type (rather than a type family).
In this case we would expect $B$ not to depend on $x,y:\RC$ or $x\close\epsilon y$.
But the recursion principle (along with its associated uniqueness principle) is supposed to say that $\RC$ with $\close\epsilon$ is an ``initial object'' in some category, so in this case the dependency structure of $A$ and $B$ should mirror that of $\RC$ and $\close\epsilon$: that is, we should have $B:A\to A\to \Qp \to \type$.
Combining this observation with the fact that, in the dependent case, $B$ must also depend on $x,y:\RC$ and $x\close\epsilon y$, leads inevitably to the type given above for $B$.
\symlabel{RC-recursion}
It is helpful to think of $B$ as an $\epsilon$-indexed family of relations between the types $A(x)$ and $A(y)$.
With this in mind, we may write $B(x,y,a,b,\epsilon,\xi)$ as $(x,a) \bsim_\epsilon^\xi (y,b)$.
Since $\xi:x\close\epsilon y$ is unique when it exists, we generally omit it from the notation and write $(x,a) \bsim_\epsilon (y,b)$; this is harmless as long as we keep in mind that this relation is only defined when $x\close\epsilon y$.
We may also sometimes simplify further and write $a\bsim_\epsilon b$, with $x$ and $y$ inferred from the types of $a$ and $b$, but sometimes it will be necessary to include them for clarity.
\index{induction principle!for Cauchy reals}%
Now, given a type family $A:\RC\to\type$ and a family of relations $\bsim$ as above, the hypotheses of the induction principle consist of the following data, one for each constructor of $\RC$ or $\closesym$:
\begin{itemize}
\item For any $q : \Q$, an element $f_q:A(\rcrat(q))$.
\item For any Cauchy approximation $x$, and any $a:\prd{\epsilon:\Qp} A(x_\epsilon)$ such that
\begin{equation}
\fall{\delta, \epsilon : \Qp}
(x_\delta,a_\delta) \bsim_{\delta+\epsilon} (x_\epsilon,a_\epsilon),
\label{eq:depCauchyappx}
\end{equation}
an element $f_{x,a}:A(\rclim(x))$.
We call such $a$ a \define{dependent Cauchy approximation}
\indexdef{Cauchy!approximation!dependent}%
\indexsee{approximation, Cauchy}{Cauchy approximation}%
\indexdef{dependent!Cauchy approximation}%
over $x$.
\item For $u, v : \RC$ such that $h:\fall{\epsilon : \Qp} u \close\epsilon v$, and all $a:A(u)$ and $b:A(v)$ such that
$\fall{\epsilon:\Qp} (u,a) \bsim_\epsilon (v,b)$,
a dependent path $\dpath{A}{\rceq(u,v)}{a}{b}$.
\item For $q,r:\Q$ and $\epsilon:\Qp$, if $-\epsilon < q - r < \epsilon$, we have
\narrowequation{(\rcrat(q),f_q) \bsim_\epsilon (\rcrat(r),f_r).}
\item For $q:\Q$ and $\delta,\epsilon:\Qp$ and $y$ a Cauchy approximation, and $b$ a dependent Cauchy approximation over $y$, if $\rcrat(q) \close{\epsilon - \delta} y_\delta$, then
\[(\rcrat(q),f_q) \bsim_{\epsilon-\delta} (y_\delta,b_\delta)
\;\Rightarrow\;
(\rcrat(q),f_q) \bsim_\epsilon (\rclim(y),f_{y,b}).\]
\item Similarly, for $r:\Q$ and $\delta,\epsilon:\Qp$ and $x$ a Cauchy approximation, and $a$ a dependent Cauchy approximation over $x$, if $x_\delta \close{\epsilon - \delta} \rcrat(r)$, then
\[(x_\delta,a_\delta) \bsim_{\epsilon-\delta} (\rcrat(r),f_r)
\;\Rightarrow\;
(\rclim(x),f_{x,a}) \bsim_\epsilon (\rcrat(q),f_r).
\]
\item For $\epsilon,\delta,\eta:\Qp$ and $x,y$ Cauchy approximations, and $a$ and $b$ dependent Cauchy approximations over $x$ and $y$ respectively, if we have $x_\delta \close{\epsilon - \delta - \eta} y_\eta$, then
\[ (x_\delta,a_\delta) \bsim_{\epsilon - \delta - \eta} (y_\eta,b_\eta)
\;\Rightarrow\;
(\rclim(x),f_{x,a}) \bsim_\epsilon (\rclim(y),f_{y,b}).\]
\item For $\epsilon:\Qp$ and $x,y:\RC$ and $\xi,\zeta:x\close{\epsilon} y$, and $a:A(x)$ and $b:A(y)$, any two elements of $(x,a) \bsim_\epsilon^\xi (y,b)$ and $(x,a) \bsim_\epsilon^\zeta (y,b)$ are dependently equal over $\xi=\zeta$.
Note that as usual, this is equivalent to asking that $\bsim$ takes values in mere propositions.
\end{itemize}
Under these hypotheses, we deduce functions
\begin{align*}
f&:\prd{x:\RC} A(x)\\
g&:\prd{x,y:\RC}{\epsilon:\Qp}{\xi:x\close{\epsilon} y}
(x,f(x)) \bsim_\epsilon^\xi (y,f(y))
\end{align*}
which compute as expected:
\begin{align}
f(\rcrat(q)) &\defeq f_q, \label{eq:rcsimind1}\\
f(\rclim(x)) &\defeq f_{x,(f,g)[x]}. \label{eq:rcsimind2}
\end{align}
Here $(f,g)[x]$ denotes the result of applying $f$ and $g$ to a Cauchy approximation $x$ to obtain a dependent Cauchy approximation over $x$.
That is, we define $(f,g)[x]_\epsilon \defeq f(x_\epsilon) : A(x_\epsilon)$, and then for any $\epsilon,\delta:\Qp$ we have $g(x_\epsilon,x_\delta,\epsilon+\delta,\xi)$ to witness the fact that $(f,g)[x]$ is a dependent Cauchy approximation, where $\xi: x_\epsilon \close{\epsilon+\delta} x_\delta$ arises from the assumption that $x$ is a Cauchy approximation.
We will never use this notation again, so don't worry about remembering it.
Generally we use the pattern-matching convention, where $f$ is defined by equations such as~\eqref{eq:rcsimind1} and~\eqref{eq:rcsimind2} in which the right-hand side of~\eqref{eq:rcsimind2} may involve the symbols $f(x_\epsilon)$ and an assumption that they form a dependent Cauchy approximation.
However, this induction principle is admittedly still quite a mouthful.
To help make sense of it, we observe that it contains as special cases two separate induction principles for~$\RC$ and for~$\closesym$.
Firstly, suppose given only a type family $A:\RC\to\type$, and define $\bsim$ to be constant at \unit.
Then much of the required data becomes trivial, and we are left with:
\begin{itemize}
\item for any $q : \Q$, an element $f_q:A(\rcrat(q))$,
\item for any Cauchy approximation $x$, and any $a:\prd{\epsilon:\Qp} A(x_\epsilon)$, an element $f_{x,a}:A(\rclim(x))$,
\item for $u, v : \RC$ and $h:\fall{\epsilon : \Qp} u \close\epsilon v$, and $a:A(u)$ and $b:A(v)$, we have $\dpath{A}{\rceq(u,v)}{a}{b}$.
\end{itemize}
Given these data, the induction principle yields a function $f:\prd{x:\RC} A(x)$ such that
\begin{align*}
f(\rcrat(q)) &\defeq f_q,\\
f(\rclim(x)) &\defeq f_{x,f(x)}.
\end{align*}
We call this principle \define{$\RC$-induction}; it says essentially that if we take $\close\epsilon$ as given, then $\RC$ is inductively generated by its constructors.
Note that, if $A$ is a mere property, then the third hypothesis in $\RC$-induction is automatic (we will see in a moment that these are in fact equivalent statements).
Thus, we may prove mere properties of real numbers by simply proving them for rationals and for limits of Cauchy approximations.
Here is an example.
\begin{lem} \label{lem:close-reflexive}
For any $u:\RC$ and $\epsilon:\Qp$, we have $u\close\epsilon u$.
\end{lem}
\begin{proof}
Define $A(u) \defeq \fall{\epsilon:\Qp} (u\close\epsilon u)$.
Since this is a mere proposition (by the last constructor of $\closesym$), by $\RC$-induction, it suffices to prove it when $u$ is $\rcrat(q)$ and when $u$ is $\rclim(x)$.
In the first case, we obviously have $|q-q|<\epsilon$ for any $\epsilon$, hence $\rcrat(q) \close\epsilon \rcrat(q)$ by the first constructor of $\closesym$.
%
And in the second case, we may assume inductively that $x_\delta \close\epsilon x_\delta$ for all $\delta,\epsilon:\Qp$.
Then in particular, we have $x_{\epsilon/3} \close{\epsilon/3} x_{\epsilon/3}$, whence $\rclim(x) \close{\epsilon} \rclim(x)$ by the fourth constructor of $\closesym$.
\end{proof}
From \cref{lem:close-reflexive}, we infer that a direct application of $\RC$-induction only has a chance to succeed if the family $A:\RC\to\type$ is a mere property.
To see this, fix $u:\RC$.
Taking $v$ to be $u$, the third hypothesis of $\RC$-induction tells us that, for any $a : A(u)$, we have $\dpath{A}{\rceq(u,u)}{a}{a}$.
Given a point $b : A(u)$ in addition, we also get $\dpath{A}{\rceq(u,u)}{a}{b}$.
From the definition of the dependent path type, we conclude that the combination of these two paths implies $a = b$, i.e.\ all points in $A(u)$ are equal.
\begin{thm}\label{thm:Cauchy-reals-are-a-set}
$\RC$ is a set.
\end{thm}
\begin{proof}
We have just shown that the mere relation
\narrowequation{P(u,v) \defeq \fall{\epsilon:\Qp} (u\close\epsilon v)}
is reflexive.
Since it implies identity, by the path constructor of $\RC$, the result follows from \cref{thm:h-set-refrel-in-paths-sets}.
\end{proof}
We can also show that although $\RC$ may not be a quotient of the set of Cauchy sequences of \emph{rationals}, it is nevertheless a quotient of the set of Cauchy sequences of \emph{reals}.
(Of course, this is not a valid \emph{definition} of $\RC$, but it is a useful property.)
We define the type of Cauchy approximations to be
%
\symlabel{cauchy-approximations}%
\index{Cauchy!approximation!type of}%
\begin{equation*}
\CAP \defeq
\setof{ x : \Qp \to \RC |
\fall{\epsilon, \delta : \Qp} x_\delta \close{\delta + \epsilon} x_\epsilon
}.
\end{equation*}
The second constructor of $\RC$ gives a function $\rclim:\CAP\to\RC$.
\begin{lem} \label{RC-lim-onto}
Every real merely is a limit point: $\fall{u : \RC} \exis{x : \CAP} u = \rclim(x)$.
In other words, $\rclim:\CAP\to\RC$ is surjective.
\end{lem}
\begin{proof}
By $\RC$-induction, we may divide into cases on $u$.
Of course, if $u$ is a limit $\rclim(x)$, the statement is trivial.
So suppose $u$ is a rational point $\rcrat(q)$; we claim $u$ is equal to $\rclim(\lam{\epsilon} \rcrat(q))$.
By the path constructor of $\RC$, it suffices to show $\rcrat(q) \close\epsilon \rclim(\lam{\epsilon} \rcrat(q))$ for all $\epsilon:\Qp$.
And by the second constructor of $\closesym$, for this it suffices to find $\delta:\Qp$ such that $\rcrat(q)\close{\epsilon-\delta} \rcrat(q)$.
But by the first constructor of $\closesym$, we may take any $\delta:\Qp$ with $\delta<\epsilon$.
\end{proof}
%
\begin{lem} \label{RC-lim-factor}
If $A$ is a set and $f : \CAP \to A$ respects coincidence\index{coincidence!of Cauchy approximations} of Cauchy approximations, in the sense that
%
\begin{equation*}
\fall{x, y : \CAP} \rclim(x) = \rclim(y) \Rightarrow f(x) = f(y),
\end{equation*}
%
then $f$ factors uniquely through $\rclim : \CAP \to \RC$.
\end{lem}
\begin{proof}
Since $\rclim$ is surjective, by \cref{lem:images_are_coequalizers}, $\RC$ is the quotient of $\CAP$ by the kernel pair\index{kernel!pair} of $\rclim$.
But this is exactly the statement of the lemma.
\end{proof}
For the second special case of the induction principle, suppose instead that we take $A$ to be constant at $\unit$.
In this case, $\bsim$ is simply an $\epsilon$-indexed family of relations on $\epsilon$-close pairs of real numbers, so we may write $u\bsim_\epsilon v$ instead of $(u,\ttt)\bsim_\epsilon (v,\ttt)$.
Then the required data reduces to the following, where $q, r$ denote rational numbers, $\epsilon, \delta, \eta$ positive rational numbers, and $x, y$ Cauchy approximations:
\begin{itemize}
\item if $-\epsilon < q - r < \epsilon$, then
$\rcrat(q) \bsim_\epsilon \rcrat(r)$,
\item if $\rcrat(q) \close{\epsilon - \delta} y_\delta$ and
$\rcrat(q)\bsim_{\epsilon-\delta} y_\delta$,
then $\rcrat(q) \bsim_\epsilon \rclim(y)$,