-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdivthm.tex
1335 lines (1119 loc) · 63.3 KB
/
divthm.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
\documentclass[a4paper, UKenglish,cleveref, autoref, thm-restate]{lipics-v2021}
\bibliographystyle{plainurl}% the mandatory bibstyle
\author{Yury Kudryashov}{University of Toronto at Mississauga, Canada (till July 2022); Texas A\&M University, USA (since August 2022)}{[email protected]}{https://orcid.org/0000-0003-4286-9276}{}
% TODO mandatory, please use full name; only 1 author per \author macro; first two parameters are mandatory, other parameters can be empty. Please provide at least the name of the affiliation and the country. The full address is optional. Use additional curly braces to indicate the correct name splitting when the last name consists of multiple name parts.
\authorrunning{Yu. Kudryashov} %TODO mandatory. First: Use abbreviated first/middle names. Second (only in severe cases): Use first author plus 'et al.'
\Copyright{Yury Kudryashov} %TODO mandatory, please use full first names. LIPIcs license is "CC-BY"; http://creativecommons.org/licenses/by/3.0/
\ccsdesc[500]{Mathematics of computing~Integral calculus}
\ccsdesc[500]{Security and privacy~Logic and verification}
\keywords{divergence theorem, Green's theorem, Gauge integral, Cauchy integral formula, Cauchy-Goursat theorem, complex analysis} %TODO mandatory; please add comma-separated list of keywords
\category{} %optional, e.g. invited paper
\relatedversion{} %optional, e.g. full version hosted on arXiv, HAL, or other respository/website
%\relatedversiondetails[linktext={opt. text shown instead of the URL}, cite=DBLP:books/mk/GrayR93]{Classification (e.g. Full Version, Extended Version, Previous Version}{URL to related version} %linktext and cite are optional
% \supplement{TODO}%optional, e.g. related research data, source code, ... hosted on a repository like zenodo, figshare, GitHub, ...
\supplementdetails[linktext={Github wiki page}]{Documentation website}{https://github.com/leanprover-community/mathlib/wiki/Project:-formalization-of-the-divergence-theorem} %linktext, cite, and subcategory are optional
%\funding{(Optional) general funding statement \dots}%optional, to capture a funding statement, which applies to all authors. Please enter author specific funding statements as fifth argument of the \author macro.
\acknowledgements{I want to thank Patrick Massot for bringing up an
idea of formalizing a sufficiently general version of the divergence
theorem, Sébastien Gouëzel for fruitful discussions and peer review
of most of the code, and my wife Nataliya Goncharuk for constant
support. I also want to thank Anne Baanen, Johan Commelin, Nataliya
Goncharuk, and Robert Y. Lewis for valuable comments on the draft
versions of this paper and I thank my son Konstantin for finding
lots of typos. I am also grateful to the anonymous referees for
their valuable comments.}%optional
% \nolinenumbers %uncomment to disable line numbering
\usepackage{csquotes,braket,upgreek,MnSymbol}
\definecolor{keywordcolor}{rgb}{0.7, 0.1, 0.1} % red
\definecolor{commentcolor}{rgb}{0.4, 0.4, 0.4} % grey
\definecolor{symbolcolor}{rgb}{0.0, 0.1, 0.6} % blue
\definecolor{sortcolor}{rgb}{0.1, 0.5, 0.1} % green
\definecolor{errorcolor}{rgb}{1, 0, 0} % bright red
\definecolor{stringcolor}{rgb}{0.5, 0.3, 0.2} % brown
\usepackage{listings}
\def\lstlanguagefiles{lstlean.tex}
\lstset{language=lean}
\newcommand{\bbR}{\mathbb{R}}
\newcommand{\bbC}{\mathbb{C}}
\newcommand{\bbN}{\mathbb{N}}
\newcommand{\eps}{\varepsilon}
\DeclareMathOperator{\divg}{div}
\DeclareMathOperator{\const}{const}
\undef\Re\DeclareMathOperator{\Re}{Re}
\undef\Im\DeclareMathOperator{\Im}{Im}
\AtBeginDocument{%
\def\sectionautorefname{Sec.}
\def\subsectionautorefname{Sec.}
\def\subsubsectionautorefname{Sec.}}
\title{Formalizing the divergence theorem and the Cauchy integral formula in Lean}
\newcommand{\mathlibref}[2]{\href{https://leanprover-community.github.io/mathlib_docs/find/#1}{#2}}
%Editor-only macros:: begin (do not touch as author)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\EventEditors{June Andronick and Leonardo de Moura}
\EventNoEds{2}
\EventLongTitle{13th International Conference on Interactive Theorem Proving (ITP 2022)}
\EventShortTitle{ITP 2022}
\EventAcronym{ITP}
\EventYear{2022}
\EventDate{August 7--10, 2022}
\EventLocation{Haifa, Israel}
\EventLogo{}
\SeriesVolume{237}
\ArticleNo{31}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\maketitle
\sloppy
\begin{abstract}
I formalize a version of the divergence theorem for a function on a
rectangular box that does not assume regularity of individual
partial derivatives, only Fréchet differentiability of the vector
field and integrability of its divergence. Then I use this theorem
to prove the Cauchy-Goursat theorem (for some simple domains) and
bootstrap complex analysis in the Lean mathematical library. The
main tool is the GP-integral, a version of the Henstock-Kurzweil
integral introduced by J. Mawhin in 1981. The divergence theorem for
this integral does not require integrability of the divergence.
\end{abstract}
\section{Introduction}\label{sec:introduction}
The divergence theorem says that, under certain assumptions, the
integral of the divergence of a vector field over a region is equal to
the flow of this vector field through the boundary of the region. For
a rectangular region on the plane, this can be written as
\begin{multline}
\label{eqn:green-rect}
\int_{a}^{b}\int_{c}^{d}\left(\frac{\partial f(x, y)}{\partial x}+\frac{\partial g(x, y)}{\partial y}\right)dydx=\\
\int_{a}^{b}\left(g(x, d)-g(x, c)\right)dx+\int_{c}^{d}\left(f(b, y)-f(a, y)\right)dy,
\end{multline}
where \(f, g\colon \bbR^{2}\to E\) are functions from the plane to
some Banach space. This statement is also known as Green's theorem.
For continuously differentiable functions \(f\), \(g\), the equality
immediately follows from the Fundamental Theorem of Calculus and the
Fubini Theorem.
If \(F\colon \bbC\to E\) is a complex differentiable function, then, due
to Cauchy-Riemann relations, the left-hand side of Green's theorem
applied to \(f(x, y)=F(x+iy)\) and \(g(x, y)=iF(x+iy)\) is zero, and
we get
\href{https://en.wikipedia.org/wiki/Cauchy's_integral_theorem}{Cauchy's
integral theorem} (a.k.a. the Cauchy-Goursat theorem) for a rectangle.
There is a gap in the proof outlined above: I explained how to prove
Green's formula for a \emph{continuously differentiable} function
but the Cauchy-Goursat theorem works for any \emph{complex
differentiable} function. A common misbelief is that this makes
Green's formula (and divergence theorem) unusable for the Cauchy-Goursat
theorem, and one has to prove it using an explicit infinite descent.
The goal of this project is to formulate a version of the divergence
theorem that implies the Cauchy-Goursat theorem without any
assumptions on the derivative of a complex differentiable function. It
was originally inspired by a version of the divergence theorem by
F.~Acker~\cite{Acker1996} that works for a vector field with
\emph{continuous divergence}, though the actual proof I formalized is
very different.
Here is the list of most important definitions and theorems I
formalize in this project.
\begin{itemize}
\item Riemann, McShane, Henstock-Kurzweil, and GP-integrals of a
function from a box in \(\bbR^{n}\) to a real Banach space, see
\cref{sec:henst-kurzw-informal,sec:GP-impl};
\item the divergence theorem for the GP-integral, see
\cref{thm:divergence,lst:divergence-GP};
\item the divergence theorem for the Bochner integral, see
\cref{thm:divergence-Bochner,lst:divergence-bochner}; the Bochner
integral is a generalization of the Lebesgue integral to functions
that take values in Banach spaces, see \autoref{ssec:Bochner} for
more details;
\item the Cauchy-Goursat theorem for rectangles, annuli, and disks,
see \cref{lst:cauchy-rect,lst:cauchy-annulus,lst:cauchy-circle};
\item the Cauchy integral formula for a disk, see \cref{lst:cauchy-int};
\item analyticity of a complex differentiable function, see
\cref{lst:diff-analytic};
\item the Riemann removable singularity theorem.
\end{itemize}
Most of these theorems were formalized earlier in other theorem
provers. However, this is the first project where the divergence
theorem was formalized in this generality. In particular, the
Cauchy-Goursat theorem becomes a simple corollary of the general
divergence theorem. Also, the assumptions in the Cauchy-Goursat
theorem are slightly weaker than in most textbooks.
The most similar other project is Abdulaziz and Paulson's
formalization of Green's theorem for a large class of domains in
\(\bbR^{2}\) in Isabelle~\cite{Abdulaziz_Paulson}. Neither Isabelle
nor my version of the divergence theorem implies the other. Here are
the key points where one of the formalizations is more general than
the other, see also \autoref{sec:gener-diverg-theor}.
\begin{description}
\item[shape of the domain] The Isabelle formalization works with any
elementary region while my formalization only works for a
rectangular box;
\item[differentiability] The Isabelle formalization only requires
existence of the partial derivatives while I require Fréchet
differentiability of the original function;
\item[regularity of the derivative] The Isabelle formalization
requires integrability of each partial derivative while my
formalization makes no regularity assumptions for the GP-integral
and assumes only integrability of the divergence for the
Henstock-Kurzweil and Bochner integrals; this makes it possible
deduce the Cauchy-Goursat theorem from my version of the divergence
theorem;
\item[domain dimension] The Isabelle formalization only deals with
dimension two while I formalize the divergence theorem in any finite
dimension; this generalization is needed throughout differential
topology, PDE theory and mathematical physics;
\item[codomain dimension] The Isabelle formalization only works for
finite dimensional codomain while my formalization works for any
Banach space; this is needed, for example, in spectral theory for
the resolvent.
\end{description}
The complex analysis part of the project does not try to compete with
the state of the art complex analysis libraries in
Mizar~\cite{harrison-mizar} and Isabelle/HOL~\cite{harrison-hol}, both
originally written by J.~Harrison, and is provided mostly as a proof
of concept (and the begining of a new project).
All these theorems are already in the \texttt{master} branch of the
Lean~\cite{10.1007/978-3-319-21401-6_26} mathematical library
\texttt{mathlib}~\cite{mathlib20}. For presentational purposes, I
changed some names (the \texttt{mathlib} naming convention sometimes
leads to very long names) and notation in the code listings below.
As in most parts of \texttt{mathlib} (and all of its analysis
library), I do not avoid the axiom of choice.
\subsection{Structure of the paper}%
\label{sec:structure-paper}
In \autoref{sec:gener-diverg-theor} I informally discuss different
ways to generalize the divergence theorem mentioned above, including
comparison with the formalization in Isabelle. Then in
\autoref{sec:henst-kurzw-informal} I give various definitions related
to the Henstock-Kurzweil, McShane, and GP-integrals and formulate the
divergence theorem for the GP-integral. In \autoref{sec:GP-impl} I
discuss some design choices I made in this project. Finally, in
\autoref{sec:appl-compl-analys} I explain how to apply this theorem to
prove the Cauchy-Goursat theorem and some other basic theorems from
complex analysis. \autoref{sec:future-plans} is devoted to my future
plans.
\section{Generalizations of the divergence theorem}%
\label{sec:gener-diverg-theor}
The divergence theorem for continuously differentiable vector fields
on rectangular boxes can be generalized in a few different directions,
leading to several theorems, none of which implies the others.
\subsection{Shape of the domain}
One natural direction of generalization is to deal with
non-rectangular domains. This generalization is done by Abdulaziz and
Paulson in Isabelle~\cite{Abdulaziz_Paulson} for regions that can be
divided both into type I regions by vertical lines only and into type
II regions by horizontal lines only. I only deal with rectangular
boxes, so I am not going to discuss this in any more details.
% https://www.cl.cam.ac.uk/~lp15/papers/Formath/Greens-theorem.pdf
\subsection{More general codomain}
Another possible direction of generalization is to deal with functions
\(f\colon \bbR^{n}\to E^{n}\), where \(E\) is a real Banach space,
instead of vector fields \(v\colon \bbR^{n}\to\bbR^{n}\) and \(E^{n}\)
is the direct sum of \(n\) copies of \(E\). Most proofs that work for
a vector field can be generalized to this case with no or little
modifications. I deal with functions \(\bbR^{n}\to E^{n}\) right away.
\subsection{Integrable partial derivatives}
It is easy to see that the standard proof based on Fubini's theorem
and FTC works for a function \(f\colon \bbR^{n}\to E^{n}\) such that
the partial derivatives \(\frac{\partial f^{i}(x)}{\partial x^{i}}\)
exist at all points of the box and are integrable on the whole
box.
\begin{remark}
Here and below I use upper indices for coordinates of vectors to
disambiguate \(i\)-th coordinate of a vector from \(i\)-th element
in a sequence of vectors. I \textsw{do not assume} implicit
summation over indices that appear both as an upper and as a lower
index.
\end{remark}
Neither this generalization nor the next one imply each other. I
formalized the other one because it implies the Cauchy--Goursat theorem.
\subsection{Fréchet differentiability}
A function \(f\colon E_{1}\to E_{2}\) between normed vector spaces is
called \emph{Fréchet differentiable} at a point \(x\) with the
derivative given by a continuous linear map
\(f'\colon E_{1}\to E_{2}\) if \(f(x+y)=f(x)+f'(y)+o(y)\) as
\(y\to 0\). A Fréchet differentiable function \(f\) has all partial
derivatives and they are equal to the values of \(f'\) on the basis
vectors.
In 1981, Mawhin~\cite{Mawhin81} introduced a generalization of the
Henstock-Kurzweil integral he called the \emph{GP-integral} (probably
from \emph{generalized Perron}). This integral allows us to prove the
following theorem.
\begin{theorem}%
[see~\cite{Mawhin81}]%
\label{thm:divergence}
Let \(E\) be a real Banach space. Let \(f\colon \bbR^{n}\to E\) be a
function that is Fréchet differentiable at all points of a closed
box \(\overline I=[a, b]\).
Then for each \(i=1,\dots,n\), the partial derivative
\(\frac{\partial f}{\partial x^{i}}\) is GP-integrable on \(I\) and
its integral is equal to the difference of the integrals of \(f\) over
the faces \(x^{i}=b^{i}\) and \(x^{i}=a^{i}\) of \(I\).
In particular, for a function \(f\colon \bbR^{n}\to E^{n}\), the
divergence
\begin{equation}
\label{eq:divg}
\divg f=\sum_{i=1}^{n}\frac{\partial f^{i}}{\partial x^{i}}
\end{equation}
is GP-integrable on \(I\) and its integral is equal to the sum of
integrals of \(f\) over the faces of \(I\) with appropriate signs.
\end{theorem}
Compared to the previous generalization, this one requires
differentiability in a stronger sense (Fréchet differentiability
instead of existence of one partial derivative) but it requires less
regularity from the derivatives (no requirements for the GP-integral
and integrability of the divergence instead of integrability of
partial derivatives for most other integrals).
\subsection{Weaker assumptions on a subset of the box}
One can push arguments in the proofs discussed above to weaken the
regularity assumptions on a “small” subset of the box.
I prove that \autoref{thm:divergence} works even if on some countable
subset of the box the function is continuous, not differentiable. It
is possible to push these arguments even further (especially if we use
another generalization of the Henstock-Kurzweil integral) but I did
not formalize these theorems (yet).
\section{Henstock-Kurzweil integral: informal description}\label{sec:henst-kurzw-informal}
While my main goal was to prove the divergence theorem for the Bochner
integral, I first proved the divergence theorem for the GP-integral,
see below. This integral is one of possible generalizations of the
Henstock-Kurzweil integral to higher dimension. In this section, I
state the relevant definitions and theorems.
\subsection{Henstock-Kurzweil integral in dimension one}\label{sec:HK-integral-dim1}
I start with the definition of the one-dimensional Henstock-Kurzweil
integral.
\begin{definition}%
\label{def:Henstock}
We say that a tagged partition \(a=x_{0}<x_{1}<\cdots<x_{k}=b\) with
tags \(\xi_{i}\in[x_{i}, x_{i+1}]\), \(0\le i<k\), is
\emph{subordinate} to a function \(\delta\colon[a, b]\to \bbR\) if
\([x_{i}, x_{i+1}]\subset [\xi_{i}-\delta(\xi_{i}),
\xi_{i}+\delta(\xi_{i})]\) for all \(0\le i<k\).
We say that \(f\colon \bbR\to E\) has the Henstock-Kurzweil integral
\(c\) over an interval \([a, b]\), \(\int_{a}^{b}f(x)\,dx=c\), if
for any \(\eps>0\) there exists an everywhere positive function
\(\delta\colon [a, b]\to \bbR\) such that for any tagged partition
\((\set{x_{i}}, \set{\xi_{i}})\) subordinate to \(\delta\), the
Riemann sum
\(\displaystyle\sum_{i=0}^{k-1}f(\xi_{i})(x_{i+1}-x_{i}) \) is
\(\eps\)-close to \(c\).
\end{definition}
Slight modifications of \autoref{def:Henstock} give the integrals of
Riemann (we require \(\delta\) to be a constant) and McShane (we no
longer require that tags belong to their intervals but still require
\(\xi_{i}\in[a, b]\)).
An equivalent (but more complicated) definition was given by A.~Denjoy
to integrate \(\frac{1}{x}\sin\left(\frac{1}{x^{3}}\right)\) over
\([-1, 1]\). This function is instegrable in the sense of the
Henstock-Kurzweil integral but it is not Lebesgue integrable.
A well-known property of the Henstock-Kurzweil integral is the
following form of the Fundamental Theorem of Calculus.
\begin{theorem}
Let \(E\) be a real Banach space. Let \(f\colon \bbR\to E\) be a
function differentiable on an interval \([a, b]\). Then its
derivative is Henstock-Kurzweil integrable on \([a, b]\) and the
integral is equal to \(f(b)-f(a)\).
\end{theorem}
The one-dimensional Henstock-Kurzweil integral is not a part of
\texttt{mathlib} and I decided not to formalize it. When we need it,
it will be easy to define it as a thin wrapper on top of the
Henstock-Kurzweil integral over a box in \lstinline+ℝ¹ = fin 1 → ℝ+.
\subsection{Henstock-Kurzweil integral in higher dimension}%
\label{sec:HK-integral-dim-n}
We will need a few definitions to generalize the Henstock-Kurzweil
integral to functions \(f\colon \bbR^{n}\to E\).
\begin{definition}%
\label{def:box-partition}
For \(a, b \in \bbR^{n}\), the \emph{open box} \((a, b)\) is the
product of open intervals \((a^{i}, b^{i})\), that is
\((a, b)=\set{x\in\bbR^{n}|\forall i, x^{i}\in(a^{i}, b^{i})}\). The
\emph{open-closed box} \((a, b]\) and the \emph{closed box}
\([a, b]\) are defined in a similar way.
The \emph{distortion} (or \emph{irregularity}) \(\sigma(I)\) of an
open-closed box \(I=(a, b]\) is the maximum of the ratios
\(\frac{b^{i}-a^{i}}{b^{j}-a^{j}}\) over all \(i, j\).
A \emph{partition} of an open-closed box \(I=(a, b]\) is a finite
collection of pairwise disjoint boxes \(J_{k}=(a_{k}, b_{k}]\) that
cover \(I\).
A \emph{tagged partition} of an open-closed box \(I=(a, b]\) is a partition
\(\set{J_{k}}\) together with a collection of points called
\emph{tags} \(\xi_{k}\in [a, b]\), one per each box of the partition.
A \emph{Henstock tagged partition} is a tagged partition such that
each tag belongs to the corresponding closed box:
\(\xi_{k}\in [c_{k}, d_{k}]\), where \(J_{k}=(c_{k}, d_{k}]\).
A tagged partition \(\set{(J_{k}, \xi_{k})}\) of a box \(I\) is
\emph{subordinate} to a \emph{gauge function}
\(\delta\colon \bbR^{n}\to\bbR_{>0}\) if each box \(J_{k}\) is
included by the closed box
\(B_{\delta(\xi_{k})}(\xi_{k})=[\xi_{k}-\delta(\xi_{k}),
\xi_{k}+\delta(\xi_{k})]\).
\end{definition}
Now we are ready to define the Henstock-Kurzweil integral of a
function \(f\colon \bbR^{n}\to E\) over a box \(I\).
\begin{definition}%
\label{def:Henstock-dim-n}
Let \(E\) be a real Banach space. We say that a function
\(f\colon \bbR^{n}\to E\) is \emph{Henstock-Kurzweil integrable} on
\(I\) with integral \(c\) if for any \(\eps>0\) there exists a gauge
function \(\delta\colon \bbR^{n}\to \bbR_{>0}\) such that for any
Henstock tagged partition \(\set{(J_{k}, \xi_{k})}\) of \(I\) that
is subordinate to \(\delta\), the Riemann sum of \(f\) over this
partition is \(\eps\)-close to \(c\).
\end{definition}
Similarly to the one-dimensional case, small modifications of
\autoref{def:Henstock-dim-n} provide definitions of Riemann and
McShane integrability, see the paragraph after \autoref{def:Henstock}.
Divergences of some vector fields are not integrable in the sense of
this definition (and any other generalization of the Henstock-Kurzweil
integral that satisfies Fubini's theorem, as shown by
W.~Pfeffer~\cite{Pfeffer93}), so we need another generalization to
prove the divergence theorem.
There are several generalizations of the Henstock-Kurzweil integral
such that the divergence of any Fréchet differentiable function is
integrable, see Bongiorno's survey~\cite{BONGIORNO2002587}. I use the
one suggested by Mawhin~\cite{Mawhin81}.
\begin{definition}%
\label{def:GP-integral}
The \emph{distortion} (or \emph{irregularity}) \(\Sigma(\pi)\) of a
partition \(\pi=\set{J_{k}}\) is the maximum of the distortions
\(\sigma(J_{k})\) of the boxes \(J_{k}\).
A function \(f\colon \bbR^{n}\to E\) is \emph{GP-integrable} on a
box \(I\) with integral \(c\) if for any \(\eps>0\) and a real
number \(d\) there exists a gauge function
\(\delta\colon \bbR^{n}\to \bbR_{>0}\) such that for any Henstock
tagged partition \(\set{(J_{k}, \xi_{k})}\) of \(I\) that is
subordinate to \(\delta\) and has a distortion less than \(d\), the
Riemann sum of \(f\) over this partition is \(\eps\)-close to \(c\).
\end{definition}
I formalized this definition (together with a few other definitions of
“box” integrals) and a proof of \autoref{thm:divergence}.
In dimension two, this theorem implies~\eqref{eqn:green-rect} for any
pair of functions \(f, g \colon \bbR^{2}\to E^{2}\) Fréchet
differentiable on a closed rectangle.
\subsection{Application to the Bochner integral}\label{ssec:Bochner}
The mathlib project uses the Bochner integral as its main
integral~\cite{vandoorn:LIPIcs.ITP.2021.18}. This integral is a
generalization of the Lebesgue integral. It was introduced by Bochner
in~\cite{Bochner1933IntegrationVF}, and it is also formalized in
Coq~\cite{boldo2022coq} and Isabelle~\cite{Avigad17}.
A~Bochner integrable function on a box in \(\bbR^{n}\) is McShane
integrable (hence Henstock-Kurzweil and GP-integrable), thus
\autoref{thm:divergence} holds for the Bochner integral if we assume
that the divergence is Bochner integrable on the box. Taking the limit
over an exhaustion of the box by smaller boxes, one can generalize the
theorem to functions that are differentiable in the interior of a box
and continuous on the whole box. Here is the precise statement of the
divergence theorem for Bochner integral.
\begin{theorem}%
\label{thm:divergence-Bochner}
Let \(E\) be a real Banach space. Let \(I=(a,b]\subset\bbR^{n}\) be
an open-closed box. Let \(s \subset\bbR^{n}\) be a countable
set. Let \(f\colon \bbR^{n}\to E^{n}\) be a function that is
continuous on \(\overline I\) and is Fréchet differentiable at all
points of \(\mathring I \setminus s\). Assume that the divergence
\(\divg f\) defined by~\eqref{eq:divg} is Bochner integrable on
\(I\). Then its integral is equal to the sum of integrals of \(f\)
over the faces of \(\overline I\) taken with appropriate signs (plus
for the integral over a front face \(x^{i}=b^{i}\) and minus for the
integral over a back face \(x^{i}=a^{i}\)).
\end{theorem}
\section{Divergence theorem: design choices and implementation details}%
\label{sec:GP-impl}
The code below uses some notation that is specific either to
\texttt{mathlib} or this project.
\noindent
\begin{tabular}{rp{12cm}}
\lstinline=Icc a b=& the closed interval \([a, b]\);\\
\lstinline=Ioo a b=& the open interval \((a, b)\);\\
\lstinline=Ioc a b=& the open-closed interval \((a, b]\);\\
\lstinline=ICC a b=& the unordered closed interval \([\min(a, b), \max(a, b)]\);\\
\lstinline=IOO a b=& the unordered open interval \((\min(a, b), \max(a, b))\);\\
\lstinline=ℝⁿ=& the vector space \(\bbR^{n}\), implemented as \lstinline=fin n → ℝ=,
where \lstinline+fin n+ is the canonical type with \(n\) elements;\\
\lstinline=Eⁿ=& the direct sum of \(n\) copies of a vector space \(E\), implemented as \lstinline=fin n → E=;
if \(E=\bbR\), then this notation agrees with the previous one;\\
\lstinline=ℝ>0, ℝ≥0=& the types of positive and nonnegative real numbers, respectively;\\
\lstinline=e i=& \(i\)-th basis vector in \(\bbR^{n}\);\\
\lstinline=𝑖=& the imaginary unit;\\
\lstinline=s ×ℂ t=& the product of sets on the real and imaginary axes in \(\bbC\).
\end{tabular}
\subsection{Boxes}\label{sec:boxes}
I use open-closed boxes in \(\bbR^{n}\), see \autoref{lst:box}, as
elements of partition because, this way, the boxes are disjoint as
sets and cover the whole ambient box, so one does not have to deal
with interiors or closures to define a partition.
\begin{lstlisting}[caption={Definition of a box}, label=lst:box]
structure box (n : ℕ) : Type :=
(lower upper : ℝⁿ)
(lower_lt_upper : ∀ i, lower i < upper i)
\end{lstlisting}
Each box can be interpreted as a set in \(\bbR^{n}\), see \autoref{lst:box-set}.
\begin{lstlisting}[caption={Box as a set}, label=lst:box-set]
instance : has_mem (ℝⁿ) (box n) :=
⟨λ x I, ∀ i, x i ∈ Ioc (I.lower i) (I.upper i)⟩
instance : has_coe_t (box n) (set ℝⁿ) := ⟨λ I, {x | x ∈ I}⟩
\end{lstlisting}
The order on the boxes is the inclusion order on the corresponding
sets.
I chose to explicitly deny empty boxes because this way the
\lstinline{lower} and \lstinline{upper} vertices are uniquely defined
by the set of points that belong to the box. The empty box is
represented as the bottom element \lstinline{⊥ : with_bot (box n)},
where \lstinline{with_bot α} is the type \lstinline={⊥} ∪ α=,
implemented as a type synonym for \lstinline{option α} with custom order.
From the order theory point of view, the type
\lstinline=with_bot (box n)= is a lattice, where the meet of two boxes
is their intersection and the join of two boxes is the minimal box
that includes both of them.
For an open-closed box \lstinline{I : box n}, \lstinline{I.Ioo} and
\lstinline{I.Icc} are the corresponding open and closed boxes,
respectively.
Given a box \lstinline=I : box (n + 1)= and an index
\lstinline=i : fin (n + 1)=, I define the \(i\)-th \emph{face} of
\(I\) to be the box in \(\bbR^{n}\) with lower and upper vertices given by
\lstinline=I.lower ∘ i.succ_above= and
\lstinline=I.upper ∘ i.succ_above=, where
\lstinline=i.succ_above : fin n → fin (n + 1)= is the unique monotone
embedding leaving a \enquote{hole} at \(i\): it sends \(j<i\) to \(j\)
and \(j\ge i\) to \(j+1\). I also define two embeddings
\lstinline=I.front_face i, I.back_face i : ℝⁿ → ℝⁿ⁺¹= that insert
\lstinline=I.upper i= and \lstinline=I.lower i=, respectively, as the
\(i\)-th coordinate. These embeddings map \lstinline=I.face i= to
the faces \lstinline+x i = I.upper i+ and \lstinline+x i = I.lower i+
of \(I\).
\subsection{Partitions}\label{sec:partitions}
A \emph{partition} of a box \(I\) is a finite collection of pairwise
disjoint boxes that cover \(I\). Sometimes, it is useful to deal with
a collection of pairwise disjoint boxes that cover only a part of
\(I\), so I define a \emph{prepartition} of a box and a predicate
saying that a prepartition is actually a partition, see
\autoref{lst:prepartition}.
I do not use two separate structures \lstinline=prepartition= and
\lstinline=partition= because with my approach I can define a function
of prepartitions (e.g., the Riemann integral sum), then prove
statements about its limits along various filters; some of these
filters require a prepartition to be a partition, some do not. Also, I
can define operations on prepartitions, then freely mix partitions and
prepartitions in the arguments instead of adding an explicit
\lstinline=to_prepartition= or an implicit coercion here and there.
On the other hand, I have to use
\lstinline=(π : prepartion I) (hπ : is_partition π)= instead of
\lstinline=(π : partition I)= whenever I want to argue about a
partition.
\begin{lstlisting}[caption={Definition of a (pre)partition}, label=lst:prepartition]
structure prepartition (I : box n) : Type :=
(boxes : finset (box n))
(le_of_mem' : ∀ J ∈ boxes, J ≤ I)
(pairwise_disjoint : pairwise boxes (disjoint on (coe : box n → set ℝⁿ)))
def is_partition (π : prepartition I) : Prop :=
∀ x ∈ I, ∃ J ∈ π, x ∈ J
\end{lstlisting}
Then I establish basic API about (pre)partitions, most notably the
following predicates, relations, and operations.
\noindent%
\begin{tabular}{rp{10cm}}
\(\pi_{1}\le\pi_{2}\)&we say that one prepartition is less than or equal to another if each box of the former is included in some box of the latter; with this order, we get a bounded meet-semilattice structure on prepartitions of a box;\\
\lstinline=Union=&the union of all boxes of a prepartition, as a set in \(\bbR^{n}\); for a partition, this union is equal to the original box;\\
\lstinline=bUnion=&given a prepartition \(\pi\) of \(I\) and a function \(\pi'\) that sends each box in \(\bbR^{n}\) to a prepartition of that box, returns the prepartition of \(I\) formed by the boxes of \(\pi' J\), \(J \in \pi\);\\
\lstinline=split_center=&the partition of a box into \(2^{n}\) subboxes by the coordinate hyperplanes passing through the center of the box;\\
\lstinline=split=&the partition of a box into two subboxes by a coordinate hyperplane (or the trivial one-box partition if the hyperplane does not meet the box);\\
\lstinline=split_many=&the partition of a box into subboxes by a finite set of coordinate hyperplanes;\\
\lstinline=compl=&an unspecified prepartition such that \lstinline~π.compl.Union = I \ π.Union~; I prove that it exists, then use the axiom of choice to get a witness.
\end{tabular}
\subsection{Tagged partitions}%
\label{sec:tagged-partitions}
Recall that a \emph{tagged (pre)partition} is a (pre)partition~\(\pi\)
with a point (\enquote{tag}) chosen in each box of~\(\pi\). In the
formal definition, see \autoref{lst:tagged-partition}, I require that
the \lstinline=tag= function is defined on all boxes. This way I can
write \lstinline=π.tag J= without proving that \(J\) is one of the
boxes of \(\pi\).
\begin{lstlisting}[caption={Definition of a tagged (pre)partition}, label=lst:tagged-partition]
structure tagged_prepartition (I : box n) extends prepartition I :=
(tag : box n → ℝⁿ)
(tag_mem_Icc : ∀ J, tag J ∈ I.Icc)
\end{lstlisting}
Here the \lstinline=extends= keyword implicitly adds a field
\lstinline=to_prepartition= to the structure and introduces some
syntatic sugar for composed projections (e.g., given \lstinline=π= of
type \lstinline=tagged_prepartition I=, Lean unfolds
\lstinline=π.boxes= to \lstinline=π.to_prepartition.boxes=) and
constructors.
Unfortunately, similar syntax does not work for other definitions and
lemmas in the same namespace, so I have to repeat some definitions and
lemmas about prepartition once more (with one line proofs that
reference the corresponding lemma about prepartitions). I hope that
this tedious work will be automized in a future version of Lean or
mathlib.
There are a few new definitions about tagged prepartitions that
essentially use the tags, see \cref{def:box-partition,lst:Henstock}.
\begin{lstlisting}[caption={Henstock tagged (pre)partitions and (pre)partitions subordinate to a gauge function},label=lst:Henstock]
def is_Henstock (π : tagged_prepartition I) : Prop :=
∀ J ∈ π, π.tag J ∈ J.Icc
def is_subordinate (π : tagged_prepartition I) (r : ℝⁿ → ℝ>0) : Prop :=
∀ J ∈ π, J.Icc ⊆ closed_ball (π.tag J) (r (π.tag J))
\end{lstlisting}
\subsection{Cousin's lemma}\label{sec:cousins-lemma}
Cousin's lemma says that for any gauge function
\(\delta\colon\bbR^{n}\to\bbR_{>0}\) and a box, there exists a tagged
partition of this box that is subordinate to \(\delta\). This lemma is
needed to show that the Henstock-Kurzweil integral is well defined: if
it was false, any number would be the Henstock-Kurzweil integral of
any function.
I prove two versions of this lemma. First I prove the lemma as stated
in the previous paragraph with an additional assertion that all boxes
of the partition are homothetic to the original box, see \autoref{lst:cousin-box}.
\begin{lstlisting}[caption={Cousin's lemma for a box},label=lst:cousin-box]
lemma exists_subordinate_Henstock (I : box n) (r : ℝⁿ → ℝ>0) :
∃ π : tagged_prepartition I, π.is_partition ∧ π.is_Henstock ∧
π.is_subordinate r ∧
(∀ J ∈ π, ∃ m : ℕ, ∀ i, J.upper i - J.lower i =
(I.upper i - I.lower i) / 2 ^ m) ∧
π.distortion = I.distortion
\end{lstlisting}
Here is the sketch of the proof. If a box \(I\) does not admit a
tagged partition with these properties, then the same is true for one
of the \(2^{n}\) boxes of the partition
\lstinline=I.split_center=. Thus we obtain an infinite sequence of
boxes \(J_{k}\), each one is twice smaller than the previous one in
each direction, such that none of these boxes admit a partition with
these properties. Let \(a\) be the unique common point of these
boxes. For sufficiently large \(k\), \(J_{k}\) is included in the
closed ball with center~\(a\) and radius~\(r(a)\), hence the one-box
partition of \(J_{k}\) with tag at \(a\) satisfies all the required
properties. This contradiction proves the lemma.
Then I use it to prove that for any prepartition \(\pi\) there exists
a refinement of this prepartition with the same distortion, see
\autoref{def:GP-integral}, and a choice of tags such that the
resulting tagged prepartition is Henstock and is subordinate to a
given gauge function, see \autoref{lst:cousin-partition}. To prove
this, I apply the previous lemma to each box of \(\pi\), then merge
these partitions using \lstinline=prepartition.bUnion=. I use this
version of Cousin's lemma to prove that the GP-integral is well
defined.
\begin{lstlisting}[caption={Cousin's lemma for a prepartition},label=lst:cousin-partition]
lemma exists_le_Henstock_Union_eq (r : ℝⁿ → ℝ>0) (π : prepartition I) :
∃ π' : tagged_prepartition I, π'.to_prepartition ≤ π ∧
π'.is_Henstock ∧ π'.is_subordinate r ∧ π'.distortion = π.distortion ∧
π'.Union = π.Union :=
\end{lstlisting}
\subsection{The filters}\label{sec:filters}
Different “box” integrals (Riemann, McShane, Henstock-Kurzweil, GP)
are defined as the limits of the Riemann sums along some filters on
the space of partitions of a box.
I define the structure \lstinline=integration_params=, see
\autoref{lst:integration-params} that holds data needed to define
either of these four integrals and a few more.
\begin{lstlisting}[caption={Structure holding parameters needed to define a box integral},label=lst:integration-params]
structure integration_params : Type :=
(bRiemann bHenstock bDistortion : bool)
\end{lstlisting}
The parameters have the following meaning:
\noindent%
\begin{tabular}{rp{10cm}}
\lstinline=bRiemann=&this is a Riemann integral, the gauge function must be a constant;\\
\lstinline=bHenstock=&tags must belong to the closure of their boxes;\\
\lstinline=bDistortion=&the gauge function may depend on the distortion of a partition.
\end{tabular}
The integration parameters used to define the Riemann,
Henstock-Kurzweil, McShane, and GP-integrals are listed in
\cref{lst:well-known-params}.
\begin{lstlisting}[caption={Parameters corresponding to well-known integrals},label=lst:well-known-params]
def Riemann : integration_params :=
{ bRiemann := tt,
bHenstock := tt,
bDistortion := ff }
def Henstock : integration_params :=
{ bRiemann := ff,
bHenstock := tt,
bDistortion := ff }
def McShane : integration_params :=
{ bRiemann := ff,
bHenstock := ff,
bDistortion := ff }
def GP : integration_params :=
{ bRiemann := ff,
bHenstock := tt,
bDistortion := tt }
\end{lstlisting}
On one hand, this design choice allows me to prove some lemmas (e.g.,
Henstock-Sacks inequality, see \autoref{sec:henst-sacks-ineq})
uniformly for all these integrals. On the other hand, it is hard to
add more integrals to the collection, see Bongiorno's
survey~\cite{BONGIORNO2002587} for other reasonable generalizations of
the Henstock-Kurzweil integral to higher dimension.
I require that the gauge function satisfies the following condition,
see \autoref{lst:r-cond}. If \lstinline=l.bRiemann= is false, then
this condition is trivial, otherwise it says that the gauge function
is actually a constant function.
\begin{lstlisting}[caption={Condition on the gauge function},label=lst:r-cond]
def r_cond {n : ℕ} (l : integration_params) (r : ℝⁿ → ℝ>0) : Prop :=
l.bRiemann → ∀ x, r x = r 0
\end{lstlisting}
For each set of parameters \lstinline=l : integration_params= and a
box~\(I\), we define several filters on the space of prepartitions of
\(I\). All these filters have basis sets of the same type, see
\autoref{lst:mem-base-set}.
\begin{lstlisting}[caption={Basis sets used to define filters related to integration parameters.},label=lst:mem-base-set]
structure mem_base_set (l : integration_params) (I : box n) (c : ℝ≥0)
(r : ℝⁿ → ℝ>0) (π : tagged_prepartition I) : Prop :=
(is_subordinate : π.is_subordinate r)
(is_Henstock : l.bHenstock → π.is_Henstock)
(distortion_le : l.bDistortion → π.distortion ≤ c)
(exists_compl : l.bDistortion → ∃ π' : prepartition I,
π'.Union = I \ π.Union ∧ π'.distortion ≤ c)
\end{lstlisting}
We already saw the first three assumptions in the informal definition
of the GP-integral. The last assumption is trivial if \(\pi\) is a
partition (then we can choose \(\pi'\) to be the empty
prepartition). One can show that it is also trivial whenever \(c>1\)
but I decided to cut a corner here and introduce this assumption
instead of adding an explicit assumption \(c>1\) here and there and
proving one more lemma.
The most important filter related to a set of integration parameters
is the filter \lstinline=to_filter_Union= below. Cousin's lemma from
\autoref{sec:cousins-lemma} implies that this filter is
nontrivial. The actual definition uses more intermediate filters but
the result is equal (though not definitionally equal) to the code in
\autoref{lst:filters}.
\begin{lstlisting}[caption=Filters defined by a set of integration parameters and a box,label=lst:filters]
def to_filter (l : integration_params) (I : box n) :
filter (tagged_prepartition I) :=
⨆ c : ℝ≥0, ⨅ (r : ℝⁿ → ℝ>0) (hr : l.r_cond r),
𝓟 {π | l.mem_base_set I c r π}
def to_filter_Union (l : integration_params) (I : box n)
(π₀ : prepartition I) :=
l.to_filter I ⊓ 𝓟 {π | π.Union = π₀.Union}
\end{lstlisting}
The filter \lstinline=to_filter= is useful to prove facts about
integrals on subboxes.
\subsection{Box-additive function}%
\label{sec:box-addit-funct}
I introduce the following definition.
\begin{definition}
A function on boxes in \(\bbR^{n}\) taking values in an additive
group is said to be \emph{box-additive} if for any box \(I\) and its
partition \(\pi\), the sum of its values on the boxes of \(\pi\) is
equal to its value on \(I\).
A function is said to be \emph{box-additive on subboxes of
\(I_{0}\)} if the same property holds true whenever \(I\le I_{0}\).
\end{definition}
In order to deal with these two notions simultaneously, the actual
definition takes an argument of the type \lstinline=with_top (box n)=,
see \autoref{lst:box-additive}. Similarly to the type
\lstinline=with_bot (box n)=, this type is the disjoint union of
\lstinline=box n= and the top element \lstinline=⊤=.
\begin{lstlisting}[caption={Definition of a box-additive map},label=lst:box-additive]
structure box_additive_map (n : ℕ) (G : Type*) [add_comm_group G]
(I : with_top (box n)) : Type* :=
(to_fun : box n → G)
(sum_partition_boxes' : ∀ J : box n, (J : with_top (box n)) ≤ I →
∀ π : prepartition J, π.is_partition →
∑ Ji in π.boxes, to_fun Ji = to_fun J)
\end{lstlisting}
I use notation \lstinline=n →ᵇᵃ G= for functions that are box-additive
on the whole space and \lstinline=n →ᵇᵃ[I] G= for functions that are
box-additive on subboxes of \(I\).
It suffices to verify additivity only on the two-box partitions
\lstinline=split= introduced above, see
\autoref{lst:of-map-split-add}. Indeed, let \(t\) be the set of all
hyperplanes that contain faces of a partition~\(\pi\) of \(I\). Then
the partition \lstinline=split_many I t= can be obtained by a series
of splits along a single hyperplane both from the trivial one-box
partition and from~\(\pi\). Therefore, if \(f\) is additive on the
two-box partitions, then the sum of values of \(f\) over all boxes of
\lstinline=split_many I t= is equal both to \(f(I)\) and to the sum of
its values over all boxes of~\(\pi\).
\begin{lstlisting}[caption={A map additive on splits by a hyperplane is a box-additive map},label=lst:of-map-split-add]
def of_map_split_add (f : box n → G) (I₀ : with_top (box n))
(hf : ∀ I : box n, (I : with_top (box n)) ≤ I₀ →
∀ {i x}, x ∈ Ioo (I.lower i) (I.upper i) →
f (I.split_lower i x) + f (I.split_upper i x) = f I) :
n →ᵇᵃ[I₀] G
\end{lstlisting}
Here \lstinline=I.split_lower i x= and \lstinline=I.split_upper i x=
are the boxes of the partition \lstinline=split I=. Since one of them
can be empty, they have type \lstinline=with_bot (box n)=, so the
actual code looks like \lstinline=option.elim (I.split_lower i x) 0 f=
instead of \lstinline=f (I.split_lower i x)=.
Each locally finite measure \(\mu\) defines a box-additive function.
Next, if \(f\colon\bbR^{n}\to E\) is integrable (in any reasonable
sense) on a box~\(I\), then its integral over a box is a box-additive
function on subboxes of \(I\), see \autoref{sec:henst-sacks-ineq}.
One more construction of box-additive functions appears in the proof
of the divergence theorem. Given a box-additive function \(f_{y}\) on
each cross-section \(x^{i}=y\), \(y \in [a^{i}, b^{i}]\) of a closed
box \lstinline~I₀.Icc = [a, b]~, the function given by
\lstinline~g J = f (J.upper i) (J.face i) - f (J.lower i) (J.face i)~
is box additive on subboxes of~\(I_{0}\).
To ensure nice definitional equality properties of the result, the
actual definition involves two functions and a proof that they are
equal on all the boxes relevant to the definition, see
\autoref{lst:upper-sub-lower}.
\begin{lstlisting}[caption={Difference of values of a box-additive map on the front and back faces of a box is a box-additive map},label=lst:upper-sub-lower]
def upper_sub_lower {G : Type u} [add_comm_group G]
(I₀ : box (n + 1)) (i : fin (n + 1)) (f : ℝ → box n → G)
(fb : Icc (I₀.lower i) (I₀.upper i) → n →ᵇᵃ[I₀.face i] G)
(hf : ∀ x (hx : x ∈ Icc (I₀.lower i) (I₀.upper i)) J,
f x J = fb ⟨x, hx⟩ J) :
(n + 1) →ᵇᵃ[I₀] G :=
\end{lstlisting}
\subsection{Box integral}%
\label{sec:box-integral}
The box integral of a function \(f\colon\bbR^{n}\to E\) on an
open-closed box \(I\) in the sense of integration parameters \(l\) is
defined as the limit of the Riemann sum over a partition \(\pi\) of
\(I\) along the filter \lstinline=l.to_filter_Union ⊤=, where
\lstinline=⊤= is the one-box partition of~\(I\). If the limit does not
exist, then the integral is defined to be zero, see
\autoref{lst:box-integral}.
I define the integral of a function \(f\colon \bbR^{n}\to E\) with
respect to a box-additive volume taking values in the space of
continuous linear functions \lstinline=E →L[ℝ] F=. This way one can
use the same definition, e.g., for Riemann-Stieltjes integrals.
However, I only used this definition in the case \(E=F\) and
\lstinline+vol J x = (μ J).to_real • x+ for some measure \(\mu\). So,
this generalization might be a case of overengineering.
\begin{lstlisting}[caption={Definition of a box integral},label=lst:box-integral]
def integral_sum (f : ℝⁿ → E) (vol : n →ᵇᵃ (E →L[ℝ] F))
(π : tagged_prepartition I) : F :=
∑ J in π.boxes, vol J (f (π.tag J))
def has_integral (I : box n) (l : integration_params) (f : ℝⁿ → E)
(vol : n →ᵇᵃ (E →L[ℝ] F)) (y : F) : Prop :=
tendsto (integral_sum f vol) (l.to_filter_Union I ⊤) (𝓝 y)
def integrable (I : box n) (l : integration_params) (f : ℝⁿ → E)
(vol : n →ᵇᵃ (E →L[ℝ] F)) : Prop :=
∃ y, has_integral I l f vol y
def integral (I : box n) (l : integration_params) (f : ℝⁿ → E)
(vol : n →ᵇᵃ (E →L[ℝ] F)) : F :=
if h : integrable I l f vol then h.some else 0
\end{lstlisting}
Usual theorems (uniqueness of the integral, Cauchy convergence test,
additivity) immediately follow from the definition and properties of
the limit.
\subsection{The Henstock-Sacks inequality}%
\label{sec:henst-sacks-ineq}
The Henstock-Sacks inequality for the Henstock-Kurzweil integral says
the following. Let \(f\) be a function integrable on a box \(I\); let
\(\delta\colon \bbR^{n} \to \bbR_{>0}\) be a gauge function such that
for any tagged partition of \(I\) subordinate to \(\delta\), the
integral sum over this partition is \(\eps\)-close to the
integral. Then for any tagged \emph{prepartition} \(\pi\), the
integral sum over \(\pi\) differs from the integral of \(f\) over the
part of \(I\) covered by \(\pi\) by at most \(\eps\).
This inequality is used, e.g., to prove that a function that is
Henstock-Kurzweil integrable on a box \(I\), is Henstock-Kurzweil
integrable on any subbox of \(I\) and defines a box-additive function
on subboxes of \(I\). I prove several versions of this inequality for
any of the \enquote{box} integrals.
Instead of using predicate assumptions on \(\delta\), I define
\lstinline=convergence_r= (see \autoref{lst:conv-r}) to be a function
\(\delta\colon\mathbb R^{n}\to\mathbb R_{>0}\) such that
\begin{itemize}
\item if \lstinline=l.bRiemann=, then \(\delta\) is a constant;
\item if \(\eps > 0\), then for any tagged partition \(\pi\) of \(I\)
satisfying the predicate \lstinline=l.mem_base_set I c δ=, the
integral sum of \(f\) over \(\pi\) differs from the integral of
\(f\) over \(I\) by at most~\(\eps\).
\end{itemize}
\begin{lstlisting}[caption={Gauge function that provides a witness of integrability},label=lst:conv-r]
def convergence_r (h : integrable I l f vol) (ε : ℝ) (c : ℝ≥0) :
ℝⁿ → ℝ>0
\end{lstlisting}
Let me quote two versions of the Henstock-Sacks inequality here. One
version compares the Riemann sums of a function over two prepartitions
that cover the same part of the box, see \autoref{lst:henstock-sacks}.
\begin{lstlisting}[caption={Henstock-Sacks inequality for two integral sums},label=lst:henstock-sacks]
lemma dist_integral_sum_le_of_mem_base_set (h : integrable I l f vol)
(hpos₁ : 0 < ε₁) (hpos₂ : 0 < ε₂)
(hπ₁ : l.mem_base_set I c₁ (h.convergence_r ε₁ c₁) π₁)
(hπ₂ : l.mem_base_set I c₂ (h.convergence_r ε₂ c₂) π₂)
(hU : π₁.Union = π₂.Union) :
dist (integral_sum f vol π₁) (integral_sum f vol π₂) ≤ ε₁ + ε₂
\end{lstlisting}
The other replaces one of these Riemann sums with the sum of integrals
of the function over the boxes of the partition, see
\autoref{lst:henstock-sacks2}.
\begin{lstlisting}[caption={Henstock-Sacks inequality on the distance between an integral sum and a sum of integrals},label=lst:henstock-sacks2]
lemma dist_integral_sum_sum_integral_le_of_mem_base_set_of_Union_eq
(h : integrable I l f vol) (hpos : 0 < ε)
(hπ : l.mem_base_set I c (h.convergence_r ε c) π)
(hU : π.Union = π₀.Union) :