An Introduction to MathComp-Analysis
An Introduction to MathComp-Analysis
Reynald Affeldt
3
4 CONTENTS
Bibliography 93
A Cheat Sheets 97
Index 108
6 CONTENTS
Abstract
This document is a memo written for a class of about ten hours held at the
Graduate School of Mathematics at Nagoya University from [2022-12-19] to
[2022-12-23]. The intent is to provide the necessary background about the Coq
proof assistant and the MathComp library (for students who already had an
exposition to these pieces of software) to be able to understand and get started
with the MathComp-Analysis library. This document is meant to be self-
contained. Since Coq and MathComp are already explained elsewhere, the
parts about them are rather cursory, relying on pointers to the appropriate lit-
erature such as the Coq reference manual [The Coq Development Team, 2022],
the original SSReflect manual [Gonthier et al., 2016], and the Mathemati-
cal Components book [Mahboubi and Tassi, 2021]. And for Japanese readers:
[Affeldt, 2017], [Hagiwara and Affeldt, 2018].
Revision history:
• First version: [2022-12-23]
• Second version: [2023-01-27] (typos)
7
8 CONTENTS
Chapter 1
Goal of this chapter: This chapter is an overview about proof assistants based
on dependent type theory and serves as an introduction to the topic of this
document which is more specifically about the MathComp-Analysis library.
9
10 CHAPTER 1. OVERVIEW OF COQ AND MATHCOMP
in particular and led to the implementation of LCF among others. As for the
Coq proof assistant (Coq website), its implementation started in France in
1984 and is still thriving.
It is worth noting that in parallel efforts were also undertaken to put more
structure in mathematics. In particular, starting in 1934–1935, Bourbaki has
been using set theory for that purpose. On this occasion, Bourbaki put an
emphasis on the notion of mathematical structure. However:
Theory of Sets was meant to provide a formally rigorous basis for the
whole of the treatise, and the concept of structure represented the ul-
timate stage of this undertaking. The result, however, was different:
Theory of Sets appears as an ad-hoc piece of mathematics imposed
upon Bourbaki by his own declared positions about mathematics,
rather than as a rich and fruitful source of ideas and mathematical
tools. (Leo Corry, [Corry, 1992])
Retrospectively, it seems that the notion of mathematical structure could not re-
ally be used systematically for the lack of a mechanical tool. In some sense, the
Mathematical Components project (Mathematical Components website) that
started at the Inria-Microsoft Research Joint Center in 2005 can be seen as
an attempt at fulfilling this goal. By the way, here is what the hierarchy
of mathematical structures in core MathComp looked like in August 2022:
Monoid_Law eqtype_Sub eqtype_Equality generic_quotient_Quotient GRing_Additive
choice_SubCountable fintype_Finite GRing_Lmodule CountRing_Zmodule GRing_SubZmodule GRing_Ring ring_quotient_ZmodQuotient Num_NormedZmodule Num_POrderedZmodule Order_Lattice
fintype_SubFinite fingroup_BaseFinGroup FinRing_Zmodule GRing_SubLmodule GRing_Lalgebra CountRing_Ring GRing_SubRing GRing_UnitRing GRing_ComRing ring_quotient_RingQuotient Order_FinPOrder Order_DistrLattice Order_BLattice
fingroup_FinGroup FinRing_Lmodule FinRing_Ring GRing_Algebra CountRing_UnitRing GRing_SubUnitRing CountRing_ComRing GRing_ComUnitRing ring_quotient_UnitRingQuotient Order_TBLattice Order_BDistrLattice
FinRing_Lalgebra vector_Vector FinRing_UnitRing GRing_UnitAlgebra FinRing_ComRing GRing_ComAlgebra CountRing_ComUnitRing GRing_IntegralDomain Order_FinLattice Order_TBDistrLattice Order_CBDistrLattice
FinRing_Algebra falgebra_Falgebra FinRing_ComUnitRing GRing_ComUnitAlgebra CountRing_IntegralDomain GRing_Field Num_NumDomain Order_Total Order_FinDistrLattice Order_CTBDistrLattice
With that many structures, it is no wonder that one cannot manage on paper.
See Fig. 3.1, page 41 for a bit more readable hierarchy.
the Flyspeck project in 2003 to formally verify his proof using the Isabelle/HOL
and the HOL Light proof assistants. It took eleven years. Other famous math-
ematicians have recognized the need for formal verification:
A technical argument by a trusted author, which is hard to check
and looks similar to arguments known to be correct, is hardly ever
checked in detail. (Vladimir Voevodsky [Voevodsky, 2014])
The Coq proof assistant is a piece of software used to verify computer pro-
grams and mathematics. Coq has been awarded the ACM SIGPLAN Program-
ming Languages Sofware Award and the ACM Software System Award in 2013.
Xavier Leroy at Collège de France and his colleagues have been awarded the
ACM Software System Award in 2021 for their verification of a C compiler in
Coq. Though there are other proof assistants around (Mizar, Isabelle/HOL,
PVS, Lean, etc.), none has received so much academic recognition so far. Coq
has also been used to formalize mathematics, for example the Four Color The-
orem in 2004 [Gonthier, 2008]
Theorem four_color (m : map R) : simple_map m -> map_colorable 4 m.
the Abel–Ruffini theorem in 2021 [Bernard et al., 2021], etc. These examples
are about algebra, the goal of this class is rather about analysis.
You can find online a list of research papers using MathComp. More gener-
ally, research papers on proof assistants can be found in the proceedings of the
International Conference on Interactive Theorem Proving (ITP) or the ACM
SIGPLAN International Conference on Certified Programs and Proofs (CPP).
Yet, the usage of proof assistants has been spreading to other conferences in
computer science, in particular programming languages.
The author of this memo has been using Coq with colleagues to perform a
few experiments, e.g.:
• Formalization of information theory (e.g., Shannon’s source and channel
coding theorems [Affeldt et al., 2014]), formalization of error-correcting
codes [Affeldt et al., 2020b]
• 3D geometry for robotics [Affeldt and Cohen, 2017]
• Formalization of analysis [Affeldt et al., 2018, Affeldt et al., 2020a], mea-
sure and integration theory [Affeldt and Cohen, 2022]
• Verification of probabilistic programs [Affeldt et al., 2021, Affeldt et al., 2023]
In particular, the formalization of analysis gave rise to an extension of the
MathComp library called MathComp-Analysis. It is available online as open
source software (MathComp-Analysis) and this will be the main topic of this
class.
12 CHAPTER 1. OVERVIEW OF COQ AND MATHCOMP
Fixpoint add n m :=
if n is n'.+1 then (add n' m).+1
else m.
When writing Coq code using the theory X, it is better to go to the file X.v,
copy-paste the header (Require Imports, etc.), and add Require Import X. This
should explain the first two lines above.
We can compute the result of, say, 2 + 3:
Compute add 2 3.
(* = 5 : nat *)
What will turn out to be very important is the type of expressions. Each
expression has a type. The type of 0, 1, 2, etc. is nat, the type of natural
numbers. The type of add is:
About add.
(* add : nat -> nat -> nat *)
In other words, add is a function that takes two natural numbers and returns a
natural number. More precisely, add is a function that given a natural number
returns a function that takes a natural number and returns a natural number,
so that add 2 actually makes sense as an expression:
Check add 2.
(* add 2 : nat -> nat *)
In the simple case of the addition of natural numbers, the type information
should not be surprising since it is what one can find in most typed programming
languages.
Instead of natural numbers, let us consider the data structure of lists (no-
tation: [:: a; b; c]) and their concatenation as implemented by the function
MathComp
cat (which is coming from the file seq.v ):
From mathcomp Require Import seq.
About cat.
(* cat : forall {T : Type}, seq T -> seq T -> seq T *)
Thanks to the type of fixed-size lists, the type system of Coq displays the size of
the list in its type of the form n.-tuple nat. This is already a form of program
verification in the sense that one can use the type system to verify the output
of the cat function:
The fact that the above command succeeds is a proof that the result has the
right size.
The property of the cat function that we just used can be expressed in
general terms:
Check (fun n m (x : n.-tuple nat) (y : m.-tuple nat) => [tuple of cat x y]).
(* : forall n m : nat, n.-tuple nat -> m.-tuple nat -> (n + m).-tuple nat *)
The forall expression indicates that the return type is depending on inputs.
This notation suggests that types can be used to represent lemmas.
Indeed, let us work out some proof now. The following expression is a valid
type ([::] is a notation for the empty list):
Like Type, Prop is a Coq type. Type and Prop are (essentially) the only types
provided by default by Coq. = is a binary predicate for equality. We will come
back to them later.
The following type is also valid:
Check forall l : list nat, cat l l = l.
So, fun l => erefl (whatever it is) is a proof that the statement
forall l : list nat, cat [::] l = l
In Coq, we can regard types as lemmas and terms as proofs. This is the
basic idea of the Curry-Howard correspondence we mentioned in Sect. 1.1.
Let us go back to natural numbers. fun n => erefl is also a proof that
add 0 n = n:
Whatever that term is, it should be clear that it is not going to be practical to
require a user to write such programs to serve as proofs.
In the Coq proof assistant (actually in most proof assistants), proofs are
written incrementally using tactics. Tactics are provided to the proof assistant
in the form of scripts. Here is a script (a one-liner) corresponding to the proof
above:
Lemma addn0 n : add n 0 = n.
Proof. by elim: n => //= n ->. Qed.
About addn0.
(* addn0 : forall n : nat, add n 0 = n *)
1.4. THE REST OF THIS DOCUMENT 15
We will explain the tactics in the next chapter but you can already guess that,
even though it is definitely shorter than providing a term, it is still going to be
a bit technical.
Let us conclude with a proof that the addition of natural numbers is com-
mutative. It requires one more intermediate lemma:
This small example shows that to prove the commutativity of the addition of
natural numbers addC, we needed already two lemmas: addn0 and addnS. When
developing a theory of lemmas, which lemma should be proved? How should
they be organized in files? How should they be named and documented? There
are going to be a lot of them. In fact, when developing a formal theory, many
problems are not so much about the proof, because after all its main idea is
already known, but rather about problems akin to software engineering.
Context d1 d2
(T1 : measurableType d1) (T2 : measurableType d2) (R : realType).
Variables (m1 : {measure set T1 -> \bar R})
(m2 : {measure set T2 -> \bar R}).
Hypotheses (sm1 : sigma_finite setT m1) (sm2 : sigma_finite setT m2).
Variable f : T1 * T2 -> \bar R.
Hypothesis mf : measurable_fun setT f.
Let m := product_measure1 m1 sm2.
Hypothesis imf : m.-integrable setT f.
Theorem Fubini :
\int[m1]_x \int[m2]_y f (x, y) = \int[m2]_y \int[m1]_x f (x, y).
• the commands and tactics of the Coq proof assistant that we will use,
Goal of this chapter: This chapter aims at a technical introduction to the Coq
proof assistant using its SSReflect extension. We try to favor the information
that is the most useful to use the MathComp libraries and refer to the Coq
documentation [The Coq Development Team, 2022] otherwise.
There exist many introductions to the Coq proof assistant, most notably
the standard textbook [Bertot and Castéran, 2004] (whose French translation is
available online [Bertot and Castéran, 2015]). Regarding SSReflect tactics,
there is [Gonthier et al., 2016, Mahboubi and Tassi, 2021] as well as cheat sheets
made available by the developers of SSReflect that might be worth printing.
17
18 CHAPTER 2. INTRODUCTION TO COQ USING SSREFLECT
for constructive reasoning. The core Gallina terms are (approximate syntax):
t ∶= Prop ∣ Set ∣ Type sorts
∣ x, A variables
∣ _ triggers type inference
∣ forall x : A, B dependent product
∣ A -> B non-dependent product
∣ fun x => t function abstraction
∣ let x := t1 in t2 local definition
∣ t1 t2 function application
∣ c constant
∣ match t1 with pattern => t2 end patter-matching
∣ fix f x : A := t anonymous fixpoint
Type is actually one identifier hiding a hierarchy (in the sense of subtyp-
ing) of types (Type1 , Type2 , etc.). We can see the actualy indices by using
Set Printing Universes but that is rarely needed.
Type is predicative, so that, for example, one can write
(forall A : Type, A) : Type
but then if the first Type is Type1 , then the second Type should be, say, Type2 .
See [Affeldt, 2017, slide 58] for a type derivation.
Prop is impredicative, so that for example:
(forall A : Prop, A -> A) : Prop
See [Affeldt, 2017, slide 58] for a type derivation.
Prop is intuitively the type of propositions (and predicates). Strictly speaking
it is different from the type of boolean numbers (see Sect. 2.4.1). We can however
extend the system to blur this difference (see Sect. 3.4.1 and Sect. 4.1) but, in
general, the user should be aware that Prop and bool are different in Coq.
Set can be understood as Type0 . There is a Coq option to make Set impred-
icative which is occasionally useful (see [Affeldt and Nowak, 2021] for example)
but this has not been a concern so far with MathComp and MathComp-
Analysis.
There are two useful notations in MathComp for functions. A function that
ignores its first argument can be write fun _ => xyz or fun=> xyz. The notation
f ^~ x is a replacement for fun y => f y x.
The rest of the syntax is similar to programming languages from the ML
family.
The user can augment this syntax with new constants using definitions
(Definition, see Sect. 2.1.2), inductives (Inductive, See Sect. 2.4), and nota-
tions (see Sect. 2.3.2).
Obviously, formal proof using Definition and Gallina will not scale, hence the
use of tactics.
• move: h1 puts t1 as T (and removes h1 :t1 from the local context, this is
often what the user wants).
• move: (h1 ) puts t1 as T but does not remove h1 from the local context.
exact is a variant of apply that must prove the current goal. This is a
terminating tactic. Terminating tactic appear in red.
Exercise 2.2.3. Prove forall P Q R : Prop, (P -> Q) -> ((Q -> R) -> (P -> R)).
does not give much information but it indicates the existence of a .*2 notation
that gives better results:
Search (_.*2).
does not give much information. The right way to look for it is by knowing the
naming conventions (see Sect. 3.3):
Search "mul" "D".
(* mulnDr: right_distributive muln addn
mulnDl: left_distributive muln addn *)
Locate can be used to search for the location of an identifier, i.e., the file
in which it has been defined. After having discovered the file, you might want
to look at its contents. See Table 2.1 for a few files from the Coq distribution
worth looking at.
In general, when Coq displays symbols that are not characters, this is a
notation. For example, the type of pairs is as follows:
Inductive prod (A B : Type) : Type := pair : A -> B -> A * B.
Another example: What is behind the .*2 notation we saw just above?
Locate ".*2".
(* Notation "n .*2" := (double_rec n) : nat_rec_scope
Notation "n .*2" := (double n) : nat_scope (default interpretation) *)
2.4. INDUCTIVE TYPES 23
Coq libraries
Init/Datatypes.v nat, list, etc.
Init/Logic.v eq_refl, True, etc.
Init/nat.v nat, sub, etc.
Logic/Classical_Prop.v axioms for classical reasoning, etc.
... ...
SSReflect libraries
ssr/ssrfun.v injective, etc.
ssr/ssrbool.v notations for boolean numbers, etc.
ssrmatching/ssrmatching.v LHS, RHS
... ...
Table 2.1: Some files of interest in the Coq source code (directory coq/theories)
You can observe that notations belong to scopes and in case of conflicting nota-
tions this is the latest opened scopes that win. So before starting a proof, one
has to open the right scopes in the right order.
If you think that notations are making it harder to understand the current
goal, you can disable the display of notations by using:
The user can create new notations but designing a notation in a proof assis-
tant is not an easy task: which ASCII/unicode symbols should we use? what
are the right precedence levels? what will happend behind the scene? etc. In
general, when one declares a new notation, one needs to choose a precedence
level and a scope. It is often useful to check the existing notations and their
precedence levels. This is can be done using Print Grammar constr. See also
Syntax extensions and notation scopes in the Coq reference manual.
Summary: When you are facing an unknown notation or definition,
you should locate it, check for its terms, and maybe also search for
related lemmas. That is one way to discover formal libraries.
This introduces the type bool of boolean numbers with two constructors true
and false.
We can do pattern matching with inductive types, e.g.:
Boolean connectives: negb (notation ~~), andb (notation &&), orb (notation
||), implyb (notation ==>), etc.
d-item can be a term, an occurrence switch, or a clear switch (i.e., not an intro-pattern). It
is advanced usage.
2.4. INDUCTIVE TYPES 25
The constructors really are capital letters: O and S. Observe that the type of S
is defined using nat: inductive types can be recursive.
Along with the definition nat, O, and S, Coq generates the nat_ind induction
principle:
Check nat_ind.
(* nat_ind : forall P : nat -> Prop,
P 0 ->
(forall n : nat, P n -> P n.+1) ->
forall n : nat, P n *)
This is a term whose type is the induction principle over natural numbers. Coq
actually proves a standard induction principle for each defined inductive type.
We will see in Sect. 2.4.5 how to use it.
In MathComp, S n appears as n.+1 (.+1 is a notation). There are also the
.+2, the .+3, etc. notations. Strictly speaking, the notation +.1 is not part of
the Coq distribution since it comes from a file of MathComp: ssrnat.v (see
Sect. 3.4.3). We are however anticipating on the next chapter because ssrnat.v
is so much more practical than the theory of natural numbers from the Coq
standard library.
Advanced Induction Principles Note that one can also defined mutually
recursive inductive types in which case the induction principle needs to be de-
fined by the user using the Scheme command. This will not be relevant in this
document, see [The Coq Development Team, 2022]. As for strong induction,
MathComp will provide a solution in the next chapter (Sect. 3.4.3).
Fixpoint fib n :=
if n is n'.+1 then
if n' is n''.+1 then
26 CHAPTER 2. INTRODUCTION TO COQ USING SSREFLECT
Compute fib 5.
Note the if ... is ... then ... else ... notation to perform pattern-matching
in only one branch.
Here is a variant of Fibonacci numbers borrowed from [Appel, 2022]:
Fixpoint loop n a b :=
if n is n'.+1 then
loop n' (a + b) a
else
b.
Compute fastfib 5.
Observe that the parameter is shared by all constructors. We will come back to
lists in Sect. 3.4.5
2.6. THE LEIBNIZ EQUALITY AND REWRITING 27
2.5.2 Vectors
Inductive types can also have indices: a “parameter” that changes for each
constructor. Here is for example the type of vectors from the Coq standard
library:
This defines the predicate “being equal to x” and the only proof is eq_refl.
Observe that the index is not used.
Coq
The corresponding inductive principle is (defined in Logic.v):
It says that given a proof of x = y, what holds for x also holds for y. This is
called the Leibniz equality.
Exercise 2.6.1. Prove the symmetry of equality using eq_ind directly (i.e., no
rewrite).
This is not a typo: there is no constructor at all. ~ A is a notation for A -> False.
Exercise 2.7.1. Prove forall P Q, (P -> Q) -> ( ~ Q -> ~ P).
Definition of truth:
Inductive True : Prop := I : True.
Disjunction:
2.8. PREDICATE LOGIC: THE EXISTENTIAL QUANTIFIER AND SIGMA-TYPES29
\/ is a notation. When the goal is of the form A \/ B, the tactic left turns the
goal into A, and right turns the goal into B. Note that there is also a version of
or that resides in Set:
We can perform case analysis on a proof of a disjunction with the case tactic
or with the intro-pattern [|] (see Sect. 2.4.2).
Conjunction:
Inductive and (A B : Prop) : Prop := conj : A -> B -> A /\ B.
/\ is a notation. Yes, this is really just the Prop-Prop version of the Type-Type
definition of prod we saw page 22. When the goal is of the form A /\ B, it is
customary to use the split tactic. It has the same effect as apply: xyz where
xyz is the only constructor of the inductive type in question. Conversely, to
perform case analysis on a proof of a conjunction with the case tactic or with
the intro-pattern [] (no | since there is no additional subgoal to generate, there
is only one contructor).
Exercise 2.7.2. Prove the commutativity of the conjunction without using tac-
tics.
Exercise 2.7.3. Prove that A ∧ B → A ∨ B without using tactics.
Exercise 2.7.4. Prove that ⊥→ A without using tactics.
Here, A and P are parameters. The constructor has two parameters: the witness
x and a proof that P holds for x, i.e., an object of type P x. This is a dependent
pair, in the sense that the second projection depends on the first one.
Note that the P predicate is Prop-valued and that an existential formula is
Prop-valued. There are variants that are at least as useful:
2.9 Views
Equivalences are very important and are therefore given a special treatment.
There are equivalences between two propositions in Prop (P <-> Q, which is a
notation for (P -> Q) /\ (Q -> P)) and equivalence between a proposition in
Prop and a proposition in bool (contributing to blurring the difference between
Prop and bool). In the latter case, the equivalence is expressed using a reflect
predicate:
Inductive reflect (P : Prop) : bool -> Set :=
ReflectT : P -> reflect P true
| ReflectF : ~ P -> reflect P false.
What happens when one does a case analysis on a proof of reflect P b? Case
analysis is happening w.r.t. b.
Lemma test (P : Prop) (b : bool) : reflect P b -> P = b.
Proof.
case.
P : Prop
b : bool
============================
P -> P = true
goal 2 is:
~ P -> P = false
Coq
Here is an example of reflect taken from ssrbool.v:
Variable b1 b2 : bool.
Lemma andP : reflect (b1 /\ b2) (b1 && b2)
One can apply the view to the goal by using apply/view or exact/view or to the
top of the stack of hypotheses by using move/view. For example:
Lemma andbC' (a b : bool) : a && b -> b && a.
Proof.
2.10. IMPLICIT ARGUMENTS 31
a, b : bool
============================
a && b -> b && a
move=> /andP.
a, b : bool
============================
a /\ b -> b && a
This way, we have switched from a boolean view to a Prop view where we can
use case, move=>, etc.
The parameter T : Type is indicated into curly brackets { ... } to indicate that
it is implicit. It means that Coq will try to infer the parameter T : Type given
the other arguments. The reason why the following command succeeds:
Check cons 0 nil.
(* [:: 0] : seq nat *)
It is because we are in a context where Coq can figure out that 0 is actually
a natural number. In case of doubt, one can disable this automatic inference
using the @ prefix:
Check @cons nat 0 nil.
or
Check @cons _ 0 nil.
Recall that the underscore _ is a place holder that Coq tries to fill using type
inference.
An implicit argument is strict when it is inferable from the type of some
other arguments (this is the case of T in cons).
Implicit arguments may also be marked by square brackets [ ... ]. This
means that the implicit argument is non-maximally inserted.
32 CHAPTER 2. INTRODUCTION TO COQ USING SSREFLECT
By default, the user has to distinguish itself between implicit and non-
implicit arguments by using parentheses, curly or square brackets. The setting
of implicit arguments can be decided globally so that Coq decides automati-
cally which arguments are implicit. That is why most MathComp files start
with the following commands:
See the Coq reference manual on Implicit arguments for more details. In
particular, for an example of an implicit argument that is not strict.
2 https://orgmode.org/
2.11. SCRIPT MANAGEMENT 33
Note the := syntax. With this tactic, T is now lemma_instance and the proof
can go on by using move, etc. It is possible (and better) to put intro-patterns
between have and :=.
The tactic pose can be used to introduce definitions locally inside a script
(see [Gonthier et al., 2016, Sect. 4.1]). set also introduces a local definition
but it does that by pattern-matching an expression in the goal or in the local
context (see [Gonthier et al., 2016, Sect. 4.1]).
Introduction to the
MathComp Library
Goal of this chapter: In this chapter, we review the parts of the MathComp
library that are the most useful for MathComp-Analysis. It is mostly about
algebra, not yet about analysis.
35
36 CHAPTER 3. INTRODUCTION TO THE MATHCOMP LIBRARY
{morph f : x y / x + y}
Identifier Property
A associativity
C commutativity
C set complement
D set theoretic difference
K cancellation
E equality
or
Lemma ltr_addl x y : (x < x + y) = (0 < y).
3. the properties of the operations (one also says the “axioms” of the base
theory, not to be confused with Coq Axioms which are unproved lemmas)
using the class (the “structure”). This is the packed classed methodology. To
make inference work in presence of inheritance, MathComp uses the mechanism
of canonical structures of Coq in a clever way [Garillot et al., 2009].
Until very recently, the construction of hierarchies was done by hand and it
was error-prone. Today, MathComp uses a dedicated tool called Hierarchy-
Builder [Cohen et al., 2020]. Sect. 5.2 will provide an example of usage of
Hierarchy-Builder.
The hierarchy of mathematical structures provided by MathComp is dis-
played in Fig. 3.1. You can also check for [Gonthier et al., 2016, page 65, version
16 not 17)] for an older but easier to read hierarchy.
The main thing to remember is that the definition of a mathematical struc-
ture is to be find in interfaces. In MathComp, they are referred to as mixins.
It is a technical term that comes from object-oriented programming and it can
be understood as an interface.
Table 3.7: Some files of interest in MathComp, see also Table 2.1 for Math-
Comp files distributed with Coq
The effect of that command is that instead of printing is_true b, i.e., b = true
when b is a boolean number (actually, anything that has the type of a boolean
number), Coq displays simply b. Because of the heavy use of boolean numbers
with MathComp, this makes for clearer statements and goals, but it might
surprise you from time to time, so it is good to keep it in mind. In case of
doubt, use
Set Printing Coercions.
choice_SubCountable fintype_Finite GRing_Lmodule CountRing_Zmodule GRing_SubZmodule GRing_Ring ring_quotient_ZmodQuotient Num_NormedZmodule Num_POrderedZmodule Order_Lattice
fintype_SubFinite fingroup_BaseFinGroup FinRing_Zmodule GRing_SubLmodule GRing_Lalgebra CountRing_Ring GRing_SubRing GRing_UnitRing GRing_ComRing ring_quotient_RingQuotient Order_FinPOrder Order_DistrLattice Order_BLattice
FinRing_Lalgebra vector_Vector FinRing_UnitRing GRing_UnitAlgebra FinRing_ComRing GRing_ComAlgebra CountRing_ComUnitRing GRing_IntegralDomain Order_FinLattice Order_TBDistrLattice Order_CBDistrLattice
FinRing_Algebra falgebra_Falgebra FinRing_ComUnitRing GRing_ComUnitAlgebra CountRing_IntegralDomain GRing_Field Num_NumDomain Order_Total Order_FinDistrLattice Order_CTBDistrLattice
and a few boolean predicates such as the predicate that is always true:
Notation xpredT := (fun=> true).
Because of the pervasive use of if ... then .... else ..., there is couple
of useful lemmas about branching. ifT rewrites if b then t1 else t2 into t1
and generates b as a subgoal. Similarly for ifF. To perform a case analysis on
a goal that contains an expression, one can do:
case: ifPn.
contraNT should be easy to guess. Search for "contra" to look for an appropriate
contraposition lemma when in need.
So, an eqType is a type that has an equality relation == that satisfies axiom which
is a reflect relation (Sect. 2.9). The mechanism that associates op with == is a
bit technical (omitted).
Natural numbers and boolean numbers are declared to be eqTypes by pro-
viding the nat_eqType and bool_eqType instances, so that one can check:
3.4. ABOUT MATHEMATICAL STRUCTURES 43
Check 0 == 1.
(* 0 == 1 : bool *)
Check true == false.
(* true == false : bool *)
This is actually the same as @eq_op _ O 1 and @eq_op _ true false but in the
first case Coq fills the placeholder with nat_eqType and bool_eqType in the
second case. nat_eqType is not exactly nat but that will not bother Coq. See
[Mahboubi and Tassi, 2021, Section 6.3–6.4] for more details.
MathComp
eqVneq is a useful lemma from eqtype.v to do case analysis in the course of
proofs with the idiom:
have [->|ab] := eqVneq a b.
In the first subgoal, a is replaced by b, in the second subgoal, the local context
now contains the hypothesis ab : a != b. As a side effect, occurrences of a == b
and b == a are replaced by their truth values.
Case analysis with eqVneq is possible this way because it is specified using
an inductive predicate with two constructors:
Variant eq_xor_neq (T : eqType) (x y : T) : bool -> bool -> Set :=
| EqNotNeq of x = y : eq_xor_neq x y true true
| NeqNotEq of x != y : eq_xor_neq x y false false.
This is the notation m <= n. The notation m < n is really just m.+1 <= n. It
might be surprising at first to define inequalities in such a convoluted way, but
this enables more sharing of proofs and contributes to simplify the theory.
There is a number of useful lemmas that have been designed to make case
analysis more efficient. E.g.:
44 CHAPTER 3. INTRODUCTION TO THE MATHCOMP LIBRARY
Variant leq_xor_gtn m n : nat -> nat -> nat -> nat -> bool -> bool -> Set :=
| LeqNotGtn of m <= n : leq_xor_gtn m n m m n n true false
| GtnNotLeq of n < m : leq_xor_gtn m n n n m m false true.
Case analysis on leqP m n will generate two subgoals. In the first one, m <= n
is true and n < m is false. In the second one, m <= n is false and n < m is true.
Occurrences of m <= n and n < m are replaced by their truth values. In addition,
maxn m n, etc., are also replaced by their adequate values.
Exercise 3.4.1. Prove leqP.
Other interesting contents: the notation .*2 we already saw, the theory of
the predicate odd, etc.
MathComp
Related files: Properties about division div.v (m %/ d, m %% d: quotient
MathComp
and remainder of euclidean division) and prime numbers prime.v (prime p: p
is a prime number)
Lemma ha n : 2 ^ n <= a n.
Proof.
have [m nm] := ubnP n.
n, m : nat
nm : n < m
----------------------------------------
2 ^ n <= a n
elim: m => // m ih in n nm *.
(* this is the same as move: m n nm; elim=> // m ih n nm. *)
m : nat
ih : forall n : nat, n < m -> 2 ^ n <= a n
n : nat
nm : n < m.+1
----------------------------------------
2 ^ n <= a n
foldr f z0 [:: a; b; c] is f a (f b (f c z0 ))
a < K
a <= M
and
M < L
Similarly for lt_le_trans, le_trans, lt_trans. They are (of course) often used
in practice.
Similarly to leqP (Sect. 3.4.3) for natural numbers, we can do case analysis
with any ordered type using:
3.4. ABOUT MATHEMATICAL STRUCTURES 47
There is a number of generic lemmas that are useful for prove properties of
iterated operations. For example, to prove a property for a bigop knowing it is
true for each element, one can use elim/big_ind : _ => // (this is the generic
syntax for case analysis that we mentioned in Sect. 2.4.2) where big_ind is:
big_ind : K idx ->
(forall x y : R, K x -> K y -> K (op x y)) ->
forall (I : Type) (r : seq I) (P : pred I) (F : I -> R),
(forall i : I, P i -> K (F i)) -> K (\big[op/idx]_(i <- r | P i) F i)
MathComp
Reminder: To do the following exercises, you should go to bigop.v and copy
the header to a new file (and append From mathcomp Require Import bigop.)
48 CHAPTER 3. INTRODUCTION TO THE MATHCOMP LIBRARY
Exercise 3.4.3. Prove forall n, 2 * (\sum_(0 <= x < n.+1) x) = n * n.+1. (\sum_
is a notation for \big[addn/O]_)
Exercise 3.4.4. Prove
forall n : nat, \sum_(0 <= x < n.+1) (x + x) = 2 * \sum_(0 <= x < n.+1) x
using big_ind2.
Exercise 3.4.5. Prove 1 + 2 + ⋯ + 2n = 2n+1 − 1
Exercise 3.4.6. Prove
forall n, (6 * \sum_(k < n.+1) k ^ 2) = n * n.+1 * (n.*2).+1.
Iterated operations are generic. It suffices for the operation to meet some
requirements to enjoy a particular lemma. For example, provided that the
MathComp
carrier with the operation op form a monoid ( bigop.v)
Structure law := Law {
operator : T -> T -> T;
_ : associative operator;
_ : left_id idm operator;
_ : right_id idm operator
}.
the lemmas big1, big_nat_recr become available (see Appendix A). This is
because addn, the addition of natural numbers, as been shown to form a monoid
Canonical addn_monoid := Law addnA add0n addn0.
The under Tactic With iterated operators the need to use rewrite below λ-
abstractions became more pressing. The under tactic can be used for that pur-
pose [Martin-Dorel and Tassi, 2019]. A common usage with iterated operators
is under eq_bigr do rewrite ..., with series under eq_eseries do rewrite ....
3.5. MATHEMATICAL STRUCTURES IN ALGEBRA 49
• zmodType for abelian groups. It provides one constant (0), one unary oper-
ation (-%R), one binary operation (+%R) (all in ring_scope, see Table 3.1),
and the axioms of an abelian group (addrA, addrC, add0r, addNr). They are
in the module GRing so to use them one often starts its development with
Import GRing.Theory. (Otherwise, identifiers should be fully qualified.)
1 except maybe for the formalization of finite distributions in [Infotheo, 2022]. . .
50 CHAPTER 3. INTRODUCTION TO THE MATHCOMP LIBRARY
• ringType: rings, provides one constant (1), one binary operation (*%R),
and the axioms of a ring (mulrA, mul1r, mulr1, mulrDl, mulrDr, oner_neq0
for 1 ≠ 0, which means that the trivial ring is excluded).
• comRingType: commutative rings, adds mulrC
• lmodType R: left modules over R which have the following mixin:
Structure mixin_of (R : ringType) (V : zmodType) : Type := Mixin {
scale : R -> V -> V;
_ : forall a b v, scale a (scale b v) = scale (a * b) v;
_ : left_id 1 scale;
_ : right_distributive scale +%R;
_ : forall v, {morph scale^~ v: a b / a + b}
}.
The contents of this mixin should be entirely readable since we have ex-
plained in previous sections all the syntax. The notation for the scaling
operation it *:. Properties are available as the lemmas scalerA, scale1r,
scalerDr, scalerDl. Left modules will be used to define normed modules
in MathComp-Analysis (Sect. 4.6.5).
• idomainType: integral domains, with the axiom
forall x y : R, x * y = 0 -> (x == 0) || (y == 0)
Needless to say, the properties of units will be useful to deal with real
numbers in MathComp-Analysis.
MathComp
Integers The numeric type of relative integers is provided by the file ssrint.v.
Injection of a natural number to an integer: n%:Z. Integers have their impor-
tance when dealing with real numbers in the next chapter because of the flooring
and ceiling functions.
fine
%∶Q
$ z
N ;Z Q >R
E ;R
%∶Z %∶E
%∶˜R
%∶R
Figure 3.2: Some conversions between numeric types. Anticipating on Sect. 5.1
52 CHAPTER 3. INTRODUCTION TO THE MATHCOMP LIBRARY
Chapter 4
Goal of this chapter: This chapter introduces the basics of the formalization
of analysis in MathComp-Analysis. It covers material that can be found in
[Affeldt et al., 2018, Rouhling, 2019, Affeldt et al., 2020a].
The MathComp-Analysis [Affeldt et al., 2017] library contains two direc-
tories: classical and theories. The contents of classical is generic, it essen-
tially develops classical reasoning on top of MathComp. This is the purpose
of the first part of this chapter. The rest of this chapter deals with the topic
MathComp-Analysis MathComp-Analysis
of convergence, which spans the files topology.v , normedtype.v , and
MathComp-Analysis
sequences.v from the directory theories.
Axiom propositional_extensionality :
forall P Q : Prop, P <-> Q -> P = Q.
53
54 CHAPTER 4. CLASSICAL REASONING USING MATHCOMP
set0 is the empty set (the function that returns False) and setT is the full set
(the function that returns True, notation [set: T] where T is the support type).
Any Prop-valued function P gives rise to a set using the notation [set x | P].
Notation scope is classical_set_scope, delimiter classic.
Given an element x : T, we can write x \in A for a set A, this is a bool
expression. Of course, this is equivalent to A x, which is in Prop. Rewriting
with inE turns x \in A expression into a function application A x. Similarly, the
lemma mem_set allows to move from A x to x \in A (and back with the lemma
set_mem). One can use either x \in A or A x to state that an element belongs to
a set.
Basic operations on sets can be formalized using basic logic operators (see
Sect. 2.7). Intersection is essentially conjunction:
One can use the notation A `&` B instead of setI A B in the scope classical_set_scope.
Union is essentially disjunction (notation: A `|` B):
Notations are similar to the ones for finite sets, that is: \bigcup_(i in P) F,
\bigcup_(i : T) F, \bigcup_(i < n) F, etc. And similarly for countable iterated
intersections \bigcap_(i in P) F, etc.
In measure theory in particular, there is a pervasive use of families of pairwise
disjoint sets. trivIset D F is a predicate stating that the family of sets F indexed
by D is pairwise disjoint:
Definition trivIset T I (D : set I) (F : I -> set T) :=
forall i j : I, D i -> D j -> F i `&` F j !=set0 -> i = j.
A supremum is an upper bound that is less than or equal to any other upper
bound:
Definition supremums A := ubound A `&` lbound (ubound A).
2. for any non-empty set E with an upper bound, for any ε, there is an
element e ∈ E such that sup E − ε < e
MathComp-Analysis
Look for the mixin in reals.v . See Sect. 4.6 for the other structures
introduced by MathComp-Analysis.
To construct a real number from a natural number n: n%:R.
Exercise 4.4.1. Let d is a semimetric (d(x, x) = 0, d(x, y) = d(y, x) ≥ 0, d(x, z) ≤
d(x, y) + d(y, z)). Show that 1+d
d
is a semimetric.
4.5 Convergence
4.5.1 Filters
Convergence in MathComp-Analysis is expressed using filters1 . The notion
of filter was introduced by Cartan:
Ça n’avait pas de nom naturellement, cette notion que je venais
de trouver, alors, pour se convaincre que ça marchait, on prenait
des exemples, et puis au moment où l’instrument arrivait, on disait
: “Boum !” Alors on a appelé ça les “boums” ! Évidemment ça ne
pouvait pas rester longtemps les boums, et surtout s’il fallait publier
le résultat. (Henri Cartan, [Broué, 2012])
MathComp-Analysis
The axioms of a filter F of type set (set T) are (see Filter in topology.v ):
1. The full set belongs to F (filterT).
2. F is closed by (binary) intersection (filterI).
3. F is closed by containment:
filterS : forall P Q : set T, P `<=` Q -> F P -> F Q
This corresponds to the definition of a filterbase [Wilansky, 2008, Sect. 3.2] (see
lemma filter_fromT_filter).
Example 4.5.1. The filter based on the sets {n ∣ N ≤ n} for all natural numbers N
(i.e., the “[N, ∞)” for some N ) is the “eventually filter” \oo to talk about the
behavior of sequences when the index tends to infinity. It is defined as follows:
The notation E @[x --> F] is the image of the filter F by the function fun x => E.
E x @[x --> F] is the same as E @ F.
By combining the notation for convergence of filters and the notation for
the image of a filter, we obtain a notation for convergence of functions (and of
sequences): f x @[x --> a] --> l for
f (x) → l.
x→a
Limits
Given a filter F, lim F is defined as being a l such that F --> l. This definition
MathComp-Analysis
uses the get operation seen in Sect. 4.2 (see lim_in in topology.v ). lim F
is essentially a notation, so it should be Searched as (lim _) rather than lim.
Axiom ax5 says that the notion of neighborhood using entourage is the same as
the notion of neighborhoods using topological spaces.
Record mixin_of
(R : numDomainType) (M : Type) (entourage : set (set (M * M))) :=
Mixin {
ball : M -> R -> M -> Prop ;
ax1 : forall x (e : R), 0 < e -> ball x e x ;
ax2 : forall x y (e : R), ball x e y -> ball y e x ;
ax3 : forall x y z e1 e2, ball x e1 y -> ball y e2 z ->
ball x (e1 + e2) z;
ax4 : entourage = entourage_ ball
}.
Axiom ax4 states that the notion of entourage using balls is the same as the
notion of entourage from uniform spaces:
Definition ball_
(R : numDomainType) (V : zmodType) (norm : V -> R) (x : V) (e : R) :=
[set y | norm (x - y) < e].
For example, the type of real numbers (Sect. 4.4.2) can be equipped with
the structure of normed module.
4.7. NEAR NOTATIONS AND TACTICS 63
instead of Qed.
Example: . . . /. . .
64 CHAPTER 4. CLASSICAL REASONING USING MATHCOMP
y : V
----------------------------------------
- x @[x --> y] --> - y
y : V
e : K
e0 : 0 < e
----------------------------------------
\forall t \near y, `|- y - - t| < e
This is a notation to say that the set [set t | `|- y - - t| < e] belongs to
nbhs, the neighboring filter of y. The neighboring filter of y is indeed defined
using the balls that are centered at x: [set z | norm (y - z) < e] for all e
(Sect. 4.6.3).
near=> t.
y : V, e : K, e0 : 0 < e
t : V
_Hyp_ : t \is_near (nbhs y)
----------------------------------------
`|- y - - t| < e
y : V, e : K, e0 : 0 < e
t : V
_Hyp_ : t \is_near (nbhs y)
----------------------------------------
`|y - t| < e
near: t.
y : V, e : K, e0 : 0 < e
----------------------------------------
\forall t \near nbhs y, `|y - t| < e
exact: cvgr_dist_lt.
Unshelve. all: by end_near. Qed.
Another example: . . . /. . .
4.7. NEAR NOTATIONS AND TACTICS 65
============================
`|a - f t + (b - g t)| < e / 2 + e / 2
t : T
_Hyp_ : t \is_near (nbhs F)
============================
`|a - f t| < e / 2
goal 2 is:
`|b - g t| < e / 2
near: t.
e : K
e0 : 0 < e
============================
\forall x \near nbhs F, `|a - f x| < e / 2
e : K
e0 : 0 < e
============================
0 < e / 2
by rewrite divr_gt0.
4.8 Sequences
MathComp-Analysis
Sequences are defined in the eponymous file sequences.v . They are just
functions with domain nat:
Definition sequence R := nat -> R.
e : R
e_gt0 : 0 < e
x : T
_Hyp_ : x \is_near (nbhs a)
============================
`|l - g x| < e
x : T
_Hyp_ : x \is_near (nbhs a)
============================
(x \is_near (nbhs a) -> f x <= g x <= h x) -> `|l - g x| < e
fg : f x <= g x
gh : g x <= h x
============================
`|l - g x| < e
fg : f x <= g x
gh : g x <= h x
============================
h x < l + e
goal 2 is:
l - e < f x
MathComp-Analysis
Countable sums are defined in sequences.v . This is just a combination
of the iterated operations of MathComp (Sect. 3.4.7) and of the notion of limit
MathComp-Analysis
from topology.v (Sect. 4.5.3):
Notation "\big [ op / idx ]_ ( i <oo | P ) F" :=
(lim (fun n => (\big[ op / idx ]_(i < n | P) F))) : big_scope.
Goal of this chapter: We introduce the basics of measure theory with MathComp-
Analysis and illustrate the use of Hierarchy-Builder to build a hierarchy
of mathematical structures for measure theory.
69
70 CHAPTER 5. MEASURE THEORY WITH MATHCOMP-ANALYSIS
Exercise 5.1.1. Define the addition so that ∞−∞ = 0 and show that the addition
is not associative.
We define the supremum of a set extended real numbers using supremum, like
we did for real numbers in Sect. 4.4.2, except that we can now take the default
value to be −∞:
ereal_sup S := supremum -oo S
with its counterpart for real numbers (where +oo refers to the filter seen in
Sect. 4.5.1):
Lemma cvgryPge : f @ F --> +oo <-> forall A, \forall x \near F, A <= f x.
In Sect. 4.8, we explained that countable (generic) sums are formally defined
as a combination of (finite) iterated operations and limits. We instantiate this
definition with the addition of extended real numbers:
Notation "\sum_ ( m <= i <oo | P ) F" :=
(\big[+%E/0%E]_(m <= i <oo | P%B) F%E) : ereal_scope.
and then go one developing the theory of series of extended real numbers with
lemmas reminiscent of iterated operations such as:
Lemma eq_eseries (R : realFieldType) (f g : (\bar R)^nat) (P : pred nat) :
(forall i, P i -> f i = g i) ->
\sum_(i <oo | P i) f i = \sum_(i <oo | P i) g i.
MathComp-Analysis
You can Search for the eseries substring in sequences.v to find out about
generic lemmas about countable sums and for the nneseries substring for lem-
mas about non-negative terms.
The notations for countable sums that we introduced so far were defined
as a combination of MathComp (finite) iterated operations and limit. We in-
troduce another, compatible definition expressed as the combination of finitely-
supported sums (Sect. 3.4.7) and supremum: sums over general sets.
def
∑ ai = sup { ∑ ai | A finite subset of S} .
i∈S i∈A
In Coq:
5.2. BUILDING HIERARCHIES WITH HIERARCHY-BUILDER 71
where fsets S is the set of finite sets (defined using classical sets—Sect. 4.2)
included in S.
#[short(type=structType)]
HB.structure Definition Struct := {carrier of isStruct carrier}
In the case of the extended structure, the sigma-type makes appear the depen-
dency to the parent structure.
#[short(type=newStructType)]
HB.structure NewStruct params :=
{carrier of NewStruct_from_Struct parames carrier
& Struct params carrier}.
This process results in the creation of the types structType and newStructType
such that elements of the latter are also understood to be elements of the former.
72 CHAPTER 5. MEASURE THEORY WITH MATHCOMP-ANALYSIS
SemiRingOfSets
RingOfSets
AlgebraOfSets
Measurable
A semiring of sets is a set of sets called measurable that contains the empty
set, that is closed under intersection (setI_closed) and that is “closed by semi
difference” (semi_setD_closed):
HB.mixin Record isSemiRingOfSets (d : measure_display) T := {
ptclass : Pointed.class_of T;
measurable : set (set T) ;
measurable0 : measurable set0 ;
measurableI : setI_closed measurable;
semi_measurableD : semi_setD_closed measurable;
}.
Here the carrier is T : Type. Do not care too much about the measure_display
parameter, this is a trick to get nice notations (check [Affeldt and Cohen, 2022,
Sect. 3.4]). Do not care too much also about the field ptclass, this is to make
inference work correctly with the current version of MathComp (this field
should become useless with MathComp 2.0).
The definition of setI_closed is obvious:
Definition setI_closed := forall A B, G A -> G B -> G (A `&` B).
The definition of semi_setD_closed is more contrived:
Definition semi_setD_closed := forall A B, G A -> G B -> exists D,
[/\ finite_set D,
D `<=` G,
A `\` B = \bigcup_(X in D) X &
trivIset D id].
To paraphrase, it means that given two sets A and B belonging to G, there
exists a set of sets D such that: (1) D is finite, (2) D ⊆ G, (3) A ∖ B = ⋃X∈D X,
and (4) sets in D are pairwise disjoint.
5.3. FORMALIZATION OF σ-ALGEBRAS 73
Observe that the mixin of ring of sets uses the measurable field of the mixin of
semiring of sets. The notation [the semiRingOfSetsType d of T] is for forcing T
to be recognized as a semiring of sets instead of a mere Type. From Coq version
8.16, we actually do not need to use this complicated syntax anymore but we
are trying to keep the code compatible with earlier versions of Coq for a while.
#[short(type=ringOfSetsType)]
HB.structure Definition RingOfSets d :=
{T of RingOfSets_from_semiRingOfSets d T & SemiRingOfSets d T}.
Lemma bigcap_measurable F P :
(forall k, P k -> measurable (F k)) -> measurable (\bigcap_(i in P) F i).
Proof.
move=> PF; rewrite -[X in measurable X]setCK.
d : measure_display
T : measurableType d
F : (set T) ^nat
P : set nat
PF : forall k : nat, P k -> d.-measurable (F k)
============================
d.-measurable (~` ~` (\bigcap_(i in P) F i))
rewrite setC_bigcap.
============================
d.-measurable (~` (\bigcup_(i in P) ~` F i))
apply: measurableC.
============================
d.-measurable (\bigcup_(i in P) ~` F i)
apply: measurableC.
exact/PF.
Qed.
. . . /. . .
5.4. GENERATED σ-ALGEBRA 75
The difference with a mixin is that the developer has to provide a proof that from
the factory one can build the original mixin that defined the σ-algebra in the first
place. This is performed by the HB.builders command of Hierarchy-Builder
[Cohen et al., 2020]. From the user perspective, this is a simplification: the user
can use either interface to create a σ-algebra.
This is not a type like measurableType, even though its contents are essentially
the axioms of a σ-algebra.
Therefore, the smallest σ-algebra that contains a set of sets G is:
76 CHAPTER 5. MEASURE THEORY WITH MATHCOMP-ANALYSIS
Can we, for any G, use << G >> to instantiate the interface of σ-algebra from
Sect. 5.3?
We start by proving that << G >> is a σ-algebra in the sense of the predicate
salgebra:
Variables (T : Type) (G : set (set T)).
Lemma salgebraC : forall A, << G >> A -> << G >> (~` A).
Proof. ... Qed.
(* don't ask *)
Canonical salgType_eqType := EqType (salgType G) (Equality.class T).
Canonical salgType_choiceType := ChoiceType (salgType G) (Choice.class T).
Canonical salgType_ptType := PointedType (salgType G) (Pointed.class T).
(* /dont' ask *)
Variable T : pointedType.
Variable G : set (set T).
Check << G >> : set (set T).
Check salgType G : measurableType _.
measurable (⋃ Fk ) → ∑ µ(Fk ) → µ (⋃ Fk )
k n→∞ k
k<n
We do not restrict ourselves to the type of real numbers realType but instead use
the more general numFieldType. Similarly, we take the domain of the measure
to be over a semiring of sets. The fact that the measure of the empty set is 0 is
a consequence of semiadditivity.
Measures extend semiadditive measures but by adding semi-σ-additivity:
HB.mixin Record isMeasure0 d
(R : numFieldType) (T : semiRingOfSetsType d)
mu of isAdditiveMeasure d R T mu := {
measure_semi_sigma_additive : semi_sigma_additive mu }.
#[short(type=measure)]
HB.structure Definition Measure d
(R : numFieldType) (T : semiRingOfSetsType d) :=
{mu of isMeasure0 d R T mu & AdditiveMeasure d mu}.
AdditiveMeasure
Measure
. . . /. . .
80 CHAPTER 5. MEASURE THEORY WITH MATHCOMP-ANALYSIS
n : nat
Fna : F n a
============================
(fun n0 : nat => \sum_(0 <= i < n0) (\1_(F i) a)%:E) --> 1
e : R
e_gt0 : (0 < e)%R
m : nat
_Hyp_ : m \is_near (nbhs \oo)
============================
ball 1 e (\sum_(0 <= i < m) (\1_(F i) a)%:E)
mn : (n < m)%N
============================
ball 1 e (\sum_(0 <= i < m) (\1_(F i) a)%:E)
============================
\sum_(0 <= i < m) (\1_(F i) a)%:E = 1
This last goal is easy to prove since there is only one n < m such that a ∈ F n.
The second goal (that was generated by the case analysis at the first line of the
script) is:
Note that this definition does not rely on the definition of measures, only on the
definition of σ-algebra. Measurable functions are precisely the functions that
we will integrate in the next chapter.
MathComp-Analysis
There is fairly large theory of measurable functions developed in measure.v
MathComp-Analysis
and lebesgue_measure.v. You may want to know, e.g., whether the set of
measurable functions is stable by composition (lemma measurable_fun_comp), or
whether the set of real number-valued measurable functions is stable by point-
wise addition:
Context d (T : measurableType d) (R : realType).
Lemma measurable_funD D (f g : T -> R) :
measurable_fun D f -> measurable_fun D g -> measurable_fun D (f \+ g).
Exercise 5.6.1. Show that λx.x2 + x3 is a measurable function. You need to use
lebesgue_measure.v.
82 CHAPTER 5. MEASURE THEORY WITH MATHCOMP-ANALYSIS
Chapter 6
Goal of this chapter: We explain how we use the measure theory of MathComp-
Analysis to develop integration theory.
FImFun MeasurableFun
SimpleFun NonNegFun
NonNegSimpleFun
At the bottom of Fig. 6.1, we find functions with a finite image. Functions
MathComp-Analysis
with a finite image are defined in cardinality.v by:
HB.mixin Record FiniteImage aT rT (f : aT -> rT) := {
fimfunP : finite_set (range f)
83
84CHAPTER 6. INTEGRATION THEORY WITH MATHCOMP-ANALYSIS
}.
HB.structure Definition FImFun aT rT := {f of @FiniteImage aT rT f}.
The interface uses the measurable_fun predicate from Sect. 5.6. This interface
is restricted to real-valued functions. Let {mfun aT >-> R} be the notation for
Hierarchy-Builder-defined measurable functions.
The structure of simple functions is obtained by combining the interfaces of
functions with a finite image and of measurable functions. Notation for simple
functions: {sfun aT >-> R}
Similarly, we can define the interface of non-negative functions with a no-
tation {nnfun T >-> R} and combine with simple functions to get non-negative
simple functions with notation {nnsfun T >-> R}.
Given n and k, we define An,k to be the set D ∩ {x ∣ f (x) ∈ In,k } if k < n2n and
∅ otherwise:
6.1. SIMPLE FUNCTIONS 85
n
k+1
2n
k
2n
0 An,k Bn
k
x↦ ∑ 1A (x) + n1Bn (x)
k<n2n 2n n,k
that we saw in Sect. 3.2. The notation ^~ has been explained in Sect. 2.1.1;
EFin \o g ^~ x means λn.gn (x).
86CHAPTER 6. INTEGRATION THEORY WITH MATHCOMP-ANALYSIS
x∈R
This definition using summation over a finite support (see Sect. 3.4.7), so that
we are truly using the fact that f has a finite image.
The definition does not insist on having f non-negative but this will be necessary
to obtain the desired properties.
with, say,
\big[op/idx]_(x in D) f x
6.3. MONOTONE CONVERGENCE THEOREM 87
∫ f (x)(d µ) = n→∞
lim ∫ gn (x)(d µ).
x x
The proof is by proving the <= part and the >= part. The difficult part is
MathComp-Analysis
sintegral mu f <= lim (sintegral mu \o g). See lebesgue_integral.v.
88CHAPTER 6. INTEGRATION THEORY WITH MATHCOMP-ANALYSIS
Again, the proof is by proving successively the <= part and the >= part.
Lemma monotone_convergence :
\int[mu]_(x in D) lim (g^~ x) = lim (fun n => \int[mu]_(x in D) g n x).
Easy Direction
where f is fun x => lim (g ^~ x). In particular, the domain of integration D has
been put under the integral by using the notation of restriction of a function
(notation \_, see Sect. 4.4.1).
The proof is by appealing to properties of sequences of extended real numbers
and to the fact that the integral is monotone (Sect. 6.2.4). Indeed, we can use
ge0_le_integral to show that:
Therefore, the sequence on the left-hand side is convergent and its limit is
bounded by the right-hand side.
Difficult Direction
which leads to
(Note that g2' is a sequence of sequences.) And then use these g2 functions to
create the desired function h that we call max_g2 because it is defined by taken
the max of all g2 functions:
(* raw functions *)
Let max_g2' : (T -> R)^nat :=
fun k t => (\big[maxr/0]_(i < k) (g2' i k) t)%R.
(* same functions but with their properties embedded in types *)
Let max_g2 : {nnsfun T >-> R}^nat := fun k => bigmax_nnsfun (g2^~ k) k.
∗ If g n t < +∞:
then (approx D (g n))^~ t converges towards g n t,
then lim (EFin \o g2 n ^~ t) = g n t,
we conclude because each g2 is smaller or equal to max_g2.
This is proved by using the approximation theorem (Theorem 6.1.2) and the
monotone convergence theorem (Sect. 6.3.3).
Using the approximation theorem, we turn the function f into a non-decreasing
sequence of non-negative simple functions that converges towards f, thus trans-
forming the problem into an integration problem of non-negative simple func-
tions, which is arguably simpler (see lemma sfun_fubini_tonelli in the file
MathComp-Analysis
lebesgue_integral.v).
Since non-negative simple functions can be expressed as sums of indicator
functions (see lemma fimfunE in Sect. 6.1), we can furthermore simplify the prob-
lem to the integration of indicator functions (see lemma indic_fubini_tonelli
MathComp-Analysis
in the file lebesgue_integral.v).
[Affeldt, 2017] Affeldt, R. (2017). Formal verification using the Coq proof assis-
tant. https://staff.aist.go.jp/reynald.affeldt/ssrcoq/ssrcoq.pdf.
In Japanese. Slides.
[Affeldt et al., 2017] Affeldt, R., Bertot, Y., Cohen, C., Kerjean, M., Mahboubi,
A., Rouhling, D., Roux, P., Sakaguchi, K., Stone, Z., Strub, P.-Y., and Théry,
L. (2017). Mathematical components compliant analysis library. https:
//github.com/math-comp/analysis. Last stable version 0.5.3 (2022).
[Affeldt and Cohen, 2017] Affeldt, R. and Cohen, C. (2017). Formal founda-
tions of 3D geometry to model robot manipulators. In 6th ACM SIGPLAN
Conference on Certified Programs and Proofs (CPP 2017), Paris, France,
January 16–17, 2017, pages 30–42. ACM Press. doi.
[Affeldt and Cohen, 2022] Affeldt, R. and Cohen, C. (2022). Measure construc-
tion by extension in dependent type theory with application to integration.
[Affeldt et al., 2020a] Affeldt, R., Cohen, C., Kerjean, M., Mahboubi, A., Rouh-
ling, D., and Sakaguchi, K. (2020a). Competing inheritance paths in depen-
dent type theory: a case study in functional analysis. In 10th International
Joint Conference on Automated Reasoning (IJCAR 2020), Paris, France,
June 29–July 6, 2020, volume 12167 of Lecture Notes in Artificial Intelli-
gence, pages 3–20. Springer. doi.
[Affeldt et al., 2018] Affeldt, R., Cohen, C., and Rouhling, D. (2018). Formal-
ization techniques for asymptotic reasoning in classical analysis. J. Formalized
Reasoning, 11(1):43–76.
[Affeldt et al., 2023] Affeldt, R., Cohen, C., and Saito, A. (2023). Semantics of
probabilistic programs using s-finite kernels in coq. In 12th ACM SIGPLAN
International Conference on Certified Programs and Proofs (CPP 2023), Jan-
uary 16–17, 2023, Boston, Massachusetts, USA. ACM Press.
[Affeldt et al., 2021] Affeldt, R., Garrigue, J., Nowak, D., and Saikawa, T.
(2021). A trustful monad for axiomatic reasoning with probability and non-
determinism. Journal of Functional Programming, 31(E17). doi arXiv: cs.LO
2003.09993.
93
94 BIBLIOGRAPHY
[Affeldt et al., 2020b] Affeldt, R., Garrigue, J., and Saikawa, T. (2020b). A li-
brary for formalization of linear error-correcting codes. Journal of Automated
Reasoning, 64:1123–1164.
[Affeldt et al., 2014] Affeldt, R., Hagiwara, M., and Sénizergues, J. (2014).
Formalization of Shannon’s theorems. Journal of Automated Reasoning,
53(1):63–103.
[Affeldt and Nowak, 2021] Affeldt, R. and Nowak, D. (2021). Extending equa-
tional monadic reasoning with monad transformers. In 26th International
Conference on Types for Proofs and Programs (TYPES 2020), volume 188
of Leibniz International Proceedings in Informatics, pages 2:1–2:21. Schloss
Dagstuhl.
[Appel, 2022] Appel, A. W. (2022). Coq’s vibrant ecosystem for verification
engineering (invited talk). In CPP ’22: 11th ACM SIGPLAN International
Conference on Certified Programs and Proofs, Philadelphia, PA, USA, Jan-
uary 17 - 18, 2022, pages 2–11. ACM.
[Bernard et al., 2021] Bernard, S., Cohen, C., Mahboubi, A., and Strub, P.-Y.
(2021). Unsolvability of the Quintic Formalized in Dependent Type Theory.
In 12th International Conference on Interactive Theorem Proving (ITP 2021),
volume 193 of Leibniz International Proceedings in Informatics (LIPIcs),
pages 8:1–8:18, Dagstuhl, Germany. Schloss Dagstuhl – Leibniz-Zentrum für
Informatik.
[Bertot and Castéran, 2004] Bertot, Y. and Castéran, P. (2004). Interactive
Theorem Proving and Program Development—Coq’Art: The Calculus of In-
ductive Constructions. Texts in Theoretical Computer Science. An EATCS
Series. Springer.
[Bertot and Castéran, 2015] Bertot, Y. and Castéran, P. (2015). Le Coq’Art
(V8). In French.
[Bertot et al., 2008] Bertot, Y., Gonthier, G., Biha, S. O., and Pasca, I. (2008).
Canonical big operators. In International Conference on Theorem Proving
in Higher Order Logics (TPHOLs 2008), Montreal, Canada, August 18–21,
2008, volume 5170 of Lecture Notes in Computer Science, pages 86–101.
Springer.
[Broué, 2012] Broué, I. (2012). Actes des journées X-UPS 2012, chapter
Quelques Moments de Vie Privilégiés avec Henri et Nicole Cartan. Éditions
de l’École polytechnique.
[Church, 1940] Church, A. (1940). A formulation of the simple theory of types.
The Journal of Symbolic Logic, 5(2):56–68.
[Cohen and Sakaguchi, 2015] Cohen, C. and Sakaguchi, K. (2015). A finset and
finmap library: Finite sets, finite maps, multisets and order. Available at
https://github.com/math-comp/finmap. Last stable release: 1.5.0 (2020).
BIBLIOGRAPHY 95
[Cohen et al., 2020] Cohen, C., Sakaguchi, K., and Tassi, E. (2020). Hierarchy
builder: Algebraic hierarchies made easy in coq with elpi (system description).
In 5th International Conference on Formal Structures for Computation and
Deduction (FSCD 2020), June 29–July 6, 2020, Paris, France (Virtual Con-
ference), volume 167 of LIPIcs, pages 34:1–34:21. Schloss Dagstuhl - Leibniz-
Zentrum für Informatik.
[Corry, 1992] Corry, L. (1992). Nicolas bourbaki and the concept of mathemat-
ical structure. Synthese, 92(3):315–348.
[Garillot et al., 2009] Garillot, F., Gonthier, G., Mahboubi, A., and Rideau, L.
(2009). Packaging mathematical structures. In 22nd International Confer-
ence on Theorem Proving in Higher Order Logics (TPHOLs 2009), Munich,
Germany, August 17–20, 2009, volume 5674 of Lecture Notes in Computer
Science, pages 327–342. Springer.
[Gonthier, 2008] Gonthier, G. (2008). Formal proof—the four-color theorem.
Notices of the AMS, 55(11):1382–1393.
[Gonthier et al., 2013] Gonthier, G., Asperti, A., Avigad, J., Bertot, Y., Cohen,
C., Garillot, F., Roux, S. L., Mahboubi, A., O’Connor, R., Biha, S. O., Pasca,
I., Rideau, L., Solovyev, A., Tassi, E., and Théry, L. (2013). A machine-
checked proof of the odd order theorem. In 4th International Conference on
Interactive Theorem Proving (ITP 2013), Rennes, France, July 22–26, 2013,
volume 7998 of Lecture Notes in Computer Science, pages 163–179. Springer.
[Gonthier et al., 2016] Gonthier, G., Mahboubi, A., and Tassi, E. (2016). A
Small Scale Reflection Extension for the Coq system. Research Report RR-
6455, Inria Saclay Ile de France.
[Gonthier and Tassi, 2012] Gonthier, G. and Tassi, E. (2012). A language of
patterns for subterm selection. In Proceedings of the 3rd International Con-
ference on Interactive Theorem Proving (ITP 2012), Princeton, NJ, USA,
August 13–15, 2012, volume 7406 of Lecture Notes in Computer Science,
pages 361–376. Springer.
[Hagiwara and Affeldt, 2018] Hagiwara, M. and Affeldt, R. (2018). Formal
Proof using Coq/SSReflect/MathComp: Start Formalization of Mathematics
with Free Software. Morikita Publishing. In Japanese.
[Harrison, 2018] Harrison, J. (2018). Let’s make set theory great again. Invited
talk at the 3rd Conference on Artificial Intelligence and Theorem Proving
(AITP 2018), March 25–30, 2018, Aussois, France.
[Howard, 1980] Howard, W. A. (1980). The formulae-as-types notion of con-
struction.
[Infotheo, 2022] Infotheo (2022). A Coq formalization of information the-
ory and linear error-correcting codes. https://github.com/affeldt-aist/
infotheo. Open source software. Since 2009. Version 0.5.0.
96 BIBLIOGRAPHY
Cheat Sheets
97
cheat sheet ssrbool.v (Coq v8.16)
(* bool_scope *)
Notation "~~ b":= (negb b)
Notation "b ==> c" := (implb b c).
Notation "b1 (+) b2":= (addb b1 b2).
Notation "a && b":= (andb a b) Generalized to [&& b1 , b2 , ... , bn & c ]
Notation "a || b" := (orb a b) Generalized to [|| b1 , b2 , ... , bn | c ]
Notation "x \in A" := (in_mem x (mem A)).
Notation "x \notin A" := (~~ (x \in A)).
negbT b = false -> ~~ b
negbTE ~~ b -> b = false
negbK involutive negb
contra (c -> b) -> ~~ b -> ~~ c
contraNF (c -> b) -> ~~ b -> c = false
contraFF (c -> b) -> b = false -> c = false
ifP if_spec (b = false) b (if b then vT else vF)
ifT b -> (if b then vT else vF) = vT
ifF b = false ->(if b then vT else vF) = vF
ifN ~~ b -> (if b then vT else vF) = vF
boolP alt_spec b1 b1 b1
negP reflect (~ b1) (~~ b1)
negPn reflect b1 (~~ ~~ b1)
andP reflect (b1 /\ b2) (b1 && b2)
orP reflect (b1 \/ b2) (b1 || b2)
nandP reflect (~~ b1 \/ ~~ b2) (~~ (b1 && b2))
norP reflect (~~ b1 /\ ~~ b2) (~~ (b1 || b2))
implyP reflect (b1 -> b2) (b1 ==> b2)
andTb left_id true andb
andbT right_id true andb
andbb idempotent andb
andbC commutative andb
andbA associative andb
orFb left_id false orb
orbN b || ~~ b = true
negb_and ~~ (a && b) = ~~ a || ~~ b
negb_or ~~ (a || b) = ~~ a && ~~ b
Variant if_spec ( not_b : Prop ) : bool -> A -> Set : =
| IfSpecTrue of b : if_spec not_b true vT
| IfSpecFalse of not_b : if_spec not_b false vF .
{morph f : x y / aOp x y >-> rOp x y} f (aOp x y) = rOp (f x) (f y) left_zero z op z □ x = z ssrnat.v naming conventions
right_zero z op x □ z = z A(infix) conjunction
self_inverse e op x □ x = e B
D
subtraction
addition
idempotent op x □ x = x p(prefix) positive
commutative op x □ y = y □ x S successor
associative op x □ (y □ z) = (x □ y) □ z V(infix) disjunction
right_commutative op (x □ y) □ z = (x □ z) □ y
left_commutative op x □ (y □ z) = y □ (x □ z)
left_distributive op add (x + y) * z = (x * z) + (y * z)
right_distributive op add x * (y + z) = (x * y) + (x * z)
left_loop inv op cancel (op x) (op (inv x))
(* nat_scope *)
Notation "n .+1" := (succn n). Notation "n .*2" := (double n). Notation "n ‘!":=(factorial n).
Notation "n .-1" := (predn n). Notation "n ./2" := (half n).
Notation "m <n" := (m.+1 <=n). Notation "m ^ n":= (expn m n).
add0n/addn0 left_id 0 addn/right_id 0 addn
ltn_subRL (n < p - m) = (m + n < p)
add1n/addn1 1 + n = n.+1/n + 1 = n.+1
subnKC m <= n -> m + (n - m) = n
addn2 n + 2 = n.+2
subnK m <= n -> (n - m) + m = n
addSn m.+1 + n = (m + n).+1
addnBA p <= n -> m + (n - p) = m + n - p
addnS m + n.+1 = (m + n).+1
subnBA p <= n -> m - (n - p) = m + p - n
addSnnS m.+1 + n = m + n.+1
subKn m <= n -> n - (n - m) = m
addnC commutative addn
mul0n/muln0 left_zero 0 muln/right_zero 0 muln
addnA associative addn
mul1n/muln1 left_id 1 muln/right_id 1 muln
addnCA left_commutative addn
mul2n/muln2 2 * m = m.*2/m * 2 = m.*2
eqn_add2l (p + m == p + n) = (m == n)
mulnC commutative muln
eqn_add2r (m + p == n + p) = (m == n)
mulnA associative muln
sub0n/subn0 left_zero 0 subn/right_id 0 subn
mulSn m.+1 * n = n + m * n
subnn self_inverse 0 subn
mulnS m * n.+1 = m + m * n
subSS m.+1 - n.+1 = m - n
mulnDl left_distributive muln addn
subn1 n - 1 = n.-1
mulnDr right_distributive muln addn
subnDl (p + m) - (p + n) = m - n
mulnBl left_distributive muln subn
subnDr (m + p) - (n + p) = m - n
mulnBr right_distributive muln subn
addKn cancel (addn n) (subn^~ n)
mulnCA left_commutative muln
addnK cancel (addn^~ n) (subn^~ n)
muln_gt0 (0 < m * n) = (0 < m) && (0 < n)
subSnn n.+1 - n = 1
leq_pmulr n > 0 -> m <= m * n
subnDA n - (m + p) = (n - m) - p
leq_mul2l (m * n1 <= m * n2) = (m == 0) || (n1 <= n2)
subnAC right_commutative subn
leq_pmul2r 0 < m -> (n1 * m <= n2 * m) = (n1 <= n2)
ltnS (m < n.+1) = (m <= n)
ltn_pmul2r 0 < m -> (n1 * m < n2 * m) = (n1 < n2)
prednK 0 < n -> n.-1.+1 = n
leqP leq_xor_gtn m n (m <= n) (n < m)
leqNgt (m <= n) = ~~ (n < m)
ltngtP compare_nat m n (m < n) (n < m) (m == n)
ltnNge (m < n) = ~~ (n <= m)
expn0 m ^ 0 = 1
ltnn n < n = false
expn1 m ^ 1 = m
subnDA n - (m + p) = (n - m) - p
expnS m ^ n.+1 = m * m ^ n
leq_eqVlt (m <= n) = (m == n) || (m < n)
exp0n 0 < n -> 0 ^ n = 0
ltn_neqAle (m < n) = (m != n) && (m <=n)
exp1n 1 ^ n =1
ltn_add2l (p + m < p + n) = (m < n)
expnD m ^ (n1 + n2) = m ^ n1 * m ^ n2
leq_addr n <= n + m
expn_gt0 (0 < m ^ n) = (0 < m) || (n == 0)
addn_gt0 (0 < m + n) = (0 < m) || (0 < n)
fact0 0‘! = 1
subn_gt0 (0 < n - m) = (m < n)
factS (n.+1)‘! = n.+1 * n‘!
leq_sub2r m <= n -> m - p <= n - p
odd_add odd (m + n) = odd m (+) odd n
leq_subLR (m - n <= p) = (m <= n + p)
odd_double_half odd n + n./2.*2 = n
ltn_sub2r p < n -> m < n -> m - p < n - p
Variant leq_xor_gtn m n : nat -> nat -> nat -> nat -> bool -> bool -> Set : =
| LeqNotGtn of m < = n : leq_xor_gtn m n m m n n true false
| GtnNotLeq of n < m : leq_xor_gtn m n n n m m false true .
Variant compare_nat m n : nat -> nat -> nat -> nat -> bool -> bool -> bool -> bool -> bool -> bool -> Set : =
| CompareNatLt of m < n : compare_nat m n m m n n false false false true false true
| CompareNatGt of m > n : compare_nat m n n n m m false false true false true false
| CompareNatEq of m = n : compare_nat m n m m m m true true true true false false .
Section Extensionality
P P
eq_bigl P1 = 1 P2 → i←r F (i) = i←r F (i)
P1 (i) P2 (i)
P P
eq_bigr (∀i, P (i) → F1 (i) = F2 (i)) → i←r F1 (i) = i←r F2 (i)
P (i) P (i)
P
big_nil i←∅ F (i) = 0
P (i)
P
big_pred0 P =1 xpred0 → i←r F (i) = 0
P (i)
Q
big_pred1 P =1 pred1(i) → j F (j) = F (i)
P (j)
P
big_ord0 i<0 F (i) = 0
P (i)
P P
big_tnth i←r F (i) = i<size(r) F (ri )
P (i) P (ri )
P P
big_nat_recl m ≤ n → m≤i<n+1 F (i) = F (m) + m≤i<n F (i + 1)
P P
big_ord_recl i<n+1 F (i) = F (ord0) + i<n F (lift((n + 1), ord0, i))
P
big_const_ord i<n x = iter(n, λy.x + y, 0)
Section MonoidProperties
Q
big1 (∀i, P (i) → F (i) = 1) → i←r F (i) = 1
P (i)
Q Q
big_nat_recr m ≤ n → m≤i<n+1 F (i) = i<n F (i) × F (n)
Section Abelian
Q Q Q
big_split i←r (F1 (i)× F2 (i)) = i←r F1 (i) × i←r F2 (i)
P (i) P (i) P (i)
Q Q Q
bigU A ∩ B = ∅ → i∈A∪B F (i) = ( i∈A F (i)) × ( i∈B F (i))
Q Q Q
partition_big (∀i, P (i) → Q(p(i))) → i←s F (i) = j:J i F (i)
P (i) Q(j) P (i) p(i)=j
′
Q Q
reindex_onto (∀i, P (i) → h(h (i)) = i) → i F (i) = j F (h(j))
P (i) P (h(j)) h′ (h(j))=j
Q Q Q
pair_big i j F (i, j) = (p,q) F (p, q)
P (i) Q(j) P (p)∧Q(q)
Q Q Q Q
exchange_big i←rI j←rJ F (i, j) = j←rJ i←rI F (i, j)
P (i) Q(j) Q(j) Q(i)
Section Distributivity
P P
big_distrl i←r F (i) × a = i←r (F (i) × a) (also big_distrr)
P (i) P (i)
Q P P Q
big_distr_big_dep i j F (i, j) = f ∈pfamily(j0 ,P,Q) i F (i, f (i)) pfamily(j0 , P, Q) ≃
P (i) Q(i,j) P (i)
Q P P Q functions QP
big_distr_big i j F (i, j) = f ∈pffun_on(j0 ,P,Q) i F (i, f (i))
P (i) Q(j) P (i)
Q P P Q
bigA_distr_big i F (i, f (i)) = f ∈ffun_on(Q) i F (i, f (i))
i
Q(j)
Q P P Q
bigA_distr_bigA i∈I j∈J F (i, j) = f ∈J I i∈I F (i, f (i))
(* set_scope *) (* bool_scope *)
H
H set0 ∅ a \in A see ssrbool.v a∈A
A :|: B setU A∪B A \subset B see fintype.v A⊆B
a |: A [set a] :|: A {a} ∪ A [disjoint A & B] see fintype.v A∩B =∅
A :&: B setI A∩B
~: A setC A AC
A :\: B setD A B A\B
A :\ a A :\: [set a] A\{a}
f @^-1: A preimset f (mem A) f −1 (A)
f @: A imset f (mem A) f (A)
f @2: ( A , B ) imset2 f (mem A) (fun _ =>mem B) f (A, B)
setP A =i B <-> A = B
in_set0 x \in set0 = false
subset0 (A \subset set0) = (A == set0)
in_set1 (x \in [set a]) = (x == a)
in_setD1 (x \in A :\ b) = (x != b) && (x \in A)
in_setU (x \in A :|: B) = (x \in A) || (x \in B)
in_setC (x \in ~: A) = (x \notin A)
(NB: inE is a multi-rule corresponding to in_set0, in_set1, in_setD1, in_setU, in_setC, etc.)
setUC A :|: B = B :|: A
setIC A :&: B = B :&: A
setKI A :|: (B :&: A) = A
setCI ~: (A :&: B) = ~: A :|: ~: B
setCK involutive (@setC T)
setD0 A :\: set0 =A
cardsE #|[set x in pA]| = #|pA| (NB: cardE : #|A|= size (enum A) in fintype.v)
cards0 #|@set0 T| = 0 (NB: card0 : #|@pred0 T|=0 in fintype.v)
cards_eq0 (#|A| == 0) = (A == set0)
cardsU #|A :|: B| = #|A| + #|B| - #|A :&: B|
cardsT #|[set: T]| = #|T| (NB: cardT : #|T|= size (enum T) in fintype.v)
set0Pn reflect (exists x, x \in A) (A != set0)
subsetIl A :&: B \subset A
subsetUr B \subset A :|: B
subsetI (A \subset B :&: C) = (A \subset B) && (A \subset C)
setI_eq0 (A :&: B == set0) = [disjoint A & B]
imsetP reflect (exists2 x, in_mem x D & y = f x) (y \in imset f D)
card_imset injective f ->#|f @: D|= #|D|
Section Partitions
S
cover P PB∈P B
trivIset P B∈P |B| = |cover(P )|
see also bigop_doc.pdf
In case of emergency, you can use Coq in a web browser, just search for jsCoq
(“JavaScript Coq”) on the web. Maybe try https://coq.vercel.app/.
You can also install the Coq platform. It is a set of compatible packages for
Coq that is easy to install.
It is however much more convenient to install Coq from the source code on
your computer. You can find installation instructions online, e.g., installation
on Linux and Windows. (Please, PR on github if you find any error in these
installation notes.)
Coq is typically used through a customizable text editor. The most pop-
ular choice is Emacs with the Proof General extension (and possibly also the
Company-coq extension). It is arguably the best solution in terms of speed of
edition and integration with other tools, in particular in a Unix-like environment
such as Linux or MacOS.
CoqIDE is a text editor specific Coq. It is a popular choice for beginners,
some advanced users also manage to be productive with it. It comes with the
Coq platform.
Visual Studio Code is a more recent alternative. It might be a better choice
than Emacs on Windows thanks to a good interaction with WSL. It is however
still a bit less stable than Emacs, but definitely looks more modern.
103
104 APPENDIX B. COQ AND MATHCOMP INSTALLATION
List of Tables
105
106 LIST OF TABLES
List of Figures
107
Index
\o, 36 constructor, 23
^~, 18, 36 continuous, 59
trivIset, 56 Curry-Howard correspondence, 9
xget, 56
σ-algebra, 73 dependent pair, 29
dyadic interval, 84
algebra of sets, 73
attribute, 71 factory, 75
filter, 58
backward reasoning, 33 filterbase, 59
filtered type, 59
clear-switch, 20
forward reasoning, 33
coercion, 40
is_true, 40 generated σ-algebra, 75
nat_of_ord, 45 goal, 19
command
About, 21 implicit arguments, 21, 31
Check, 21 impredicative, 18
Context, 33 index, 27
Definition, 19 indicator function, 78
End, 33 integrable, 91
Fixpoint, 25 integral, 86
HB.factory, 75 intro-pattern, 24
HB.instance, 76
HB.mixin, 71 measurable function, 81
HB.structure, 71 measure, 78
Hypothesis, 33 additive measure, 77
Inductive, 23 Dirac measure, 78
Lemma, 19 Lebesgue measure, 81
Let, 33 mixin, 40, 71
Print, 21
Record, 39 neighborhood, 60
Search, 21 normed module, 62
Section, 33
Variable, 33 occurrence switch, 27
Variant, 23 open set, 60
108
INDEX 109
ring of sets, 73
scope, 23, 35
classical_set_scope, 55
ereal_set_scope, 69
see Table 3.1, 36
script, 14, 19
semi-σ-additive, 77
semiadditive, 77
semiring of sets, 72
sigma-type, 30, 71
simple function, 83, 84
simplification operation, 28
supremum, 56
tactic, 14, 20
apply, 21
case, 24
elim, 26
exact, 21
have, 33
left, 29
move, 20
near:, 63
near=>, 63
pose, 33
rewrite, 27
right, 29
set, 33
split, 29
terminating tactic, 21
tactical, 20
:, 20
;, 24
=>, 20
by, 32
topological space, 60