1
\chapter[The {\Coq} library]{The {\Coq} library\index{Theories}\label{Theories}}
3
The \Coq\ library is structured into two parts:
6
\item[The initial library:] it contains
7
elementary logical notions and data-types. It constitutes the
8
basic state of the system directly available when running
11
\item[The standard library:] general-purpose libraries containing
12
various developments of \Coq\ axiomatizations about sets, lists,
13
sorting, arithmetic, etc. This library comes with the system and its
14
modules are directly accessible through the \verb!Require! command
15
(see Section~\ref{Require});
18
In addition, user-provided libraries or developments are provided by
19
\Coq\ users' community. These libraries and developments are available
20
for download at \texttt{http://coq.inria.fr} (see
21
Section~\ref{Contributions}).
23
The chapter briefly reviews the \Coq\ libraries.
25
\section[The basic library]{The basic library\label{Prelude}}
27
This section lists the basic notions and results which are directly
28
available in the standard \Coq\ system\footnote{Most
29
of these constructions are defined in the
30
{\tt Prelude} module in directory {\tt theories/Init} at the {\Coq}
31
root directory; this includes the modules
39
Module {\tt Logic\_Type} also makes it in the initial state}.
41
\subsection[Notations]{Notations\label{Notations}}
43
This module defines the parsing and pretty-printing of many symbols
44
(infixes, prefixes, etc.). However, it does not assign a meaning to
45
these notations. The purpose of this is to define and fix once for all
46
the precedence and associativity of very common notations. The main
47
notations fixed in the initial state are listed on
48
Figure~\ref{init-notations}.
52
\begin{tabular}{|cll|}
54
Notation & Precedence & Associativity \\
56
\verb!_ <-> _! & 95 & no \\
57
\verb!_ \/ _! & 85 & right \\
58
\verb!_ /\ _! & 80 & right \\
59
\verb!~ _! & 75 & right \\
60
\verb!_ = _! & 70 & no \\
61
\verb!_ = _ = _! & 70 & no \\
62
\verb!_ = _ :> _! & 70 & no \\
63
\verb!_ <> _! & 70 & no \\
64
\verb!_ <> _ :> _! & 70 & no \\
65
\verb!_ < _! & 70 & no \\
66
\verb!_ > _! & 70 & no \\
67
\verb!_ <= _! & 70 & no \\
68
\verb!_ >= _! & 70 & no \\
69
\verb!_ < _ < _! & 70 & no \\
70
\verb!_ < _ <= _! & 70 & no \\
71
\verb!_ <= _ < _! & 70 & no \\
72
\verb!_ <= _ <= _! & 70 & no \\
73
\verb!_ + _! & 50 & left \\
74
\verb!_ || _! & 50 & left \\
75
\verb!_ - _! & 50 & left \\
76
\verb!_ * _! & 40 & left \\
77
\verb!_ && _! & 40 & left \\
78
\verb!_ / _! & 40 & left \\
79
\verb!- _! & 35 & right \\
80
\verb!/ _! & 35 & right \\
81
\verb!_ ^ _! & 30 & right \\
85
\caption{Notations in the initial state}
86
\label{init-notations}
89
\subsection[Logic]{Logic\label{Logic}}
94
{\form} & ::= & {\tt True} & ({\tt True})\\
95
& $|$ & {\tt False} & ({\tt False})\\
96
& $|$ & {\tt\char'176} {\form} & ({\tt not})\\
97
& $|$ & {\form} {\tt /$\backslash$} {\form} & ({\tt and})\\
98
& $|$ & {\form} {\tt $\backslash$/} {\form} & ({\tt or})\\
99
& $|$ & {\form} {\tt ->} {\form} & (\em{primitive implication})\\
100
& $|$ & {\form} {\tt <->} {\form} & ({\tt iff})\\
101
& $|$ & {\tt forall} {\ident} {\tt :} {\type} {\tt ,}
102
{\form} & (\em{primitive for all})\\
103
& $|$ & {\tt exists} {\ident} \zeroone{{\tt :} {\specif}} {\tt
104
,} {\form} & ({\tt ex})\\
105
& $|$ & {\tt exists2} {\ident} \zeroone{{\tt :} {\specif}} {\tt
106
,} {\form} {\tt \&} {\form} & ({\tt ex2})\\
107
& $|$ & {\term} {\tt =} {\term} & ({\tt eq})\\
108
& $|$ & {\term} {\tt =} {\term} {\tt :>} {\specif} & ({\tt eq})
111
\caption{Syntax of formulas}
112
\label{formulas-syntax}
115
The basic library of {\Coq} comes with the definitions of standard
116
(intuitionistic) logical connectives (they are defined as inductive
117
constructions). They are equipped with an appealing syntax enriching the
118
(subclass {\form}) of the syntactic class {\term}. The syntax
119
extension is shown on Figure~\ref{formulas-syntax}.
121
% The basic library of {\Coq} comes with the definitions of standard
122
% (intuitionistic) logical connectives (they are defined as inductive
123
% constructions). They are equipped with an appealing syntax enriching
124
% the (subclass {\form}) of the syntactic class {\term}. The syntax
125
% extension \footnote{This syntax is defined in module {\tt
126
% LogicSyntax}} is shown on Figure~\ref{formulas-syntax}.
128
\Rem Implication is not defined but primitive (it is a non-dependent
129
product of a proposition over another proposition). There is also a
130
primitive universal quantification (it is a dependent product over a
131
proposition). The primitive universal quantification allows both
132
first-order and higher-order quantification.
134
\subsubsection[Propositional Connectives]{Propositional Connectives\label{Connectives}
137
First, we find propositional calculus connectives:
148
Set Printing Depth 50.
151
Inductive True : Prop := I.
152
Inductive False : Prop := .
153
Definition not (A: Prop) := A -> False.
154
Inductive and (A B:Prop) : Prop := conj (_:A) (_:B).
156
Variables A B : Prop.
157
Theorem proj1 : A /\ B -> A.
158
Theorem proj2 : A /\ B -> B.
168
\ttindex{IF\_then\_else}
170
Inductive or (A B:Prop) : Prop :=
173
Definition iff (P Q:Prop) := (P -> Q) /\ (Q -> P).
174
Definition IF_then_else (P Q R:Prop) := P /\ Q \/ ~ P /\ R.
177
\subsubsection[Quantifiers]{Quantifiers\label{Quantifiers}
180
Then we find first-order quantifiers:
190
Definition all (A:Set) (P:A -> Prop) := forall x:A, P x.
191
Inductive ex (A: Set) (P:A -> Prop) : Prop :=
192
ex_intro (x:A) (_:P x).
193
Inductive ex2 (A:Set) (P Q:A -> Prop) : Prop :=
194
ex_intro2 (x:A) (_:P x) (_:Q x).
197
The following abbreviations are allowed:
199
\begin{tabular}[h]{|l|l|}
201
\verb+exists x:A, P+ & \verb+ex A (fun x:A => P)+ \\
202
\verb+exists x, P+ & \verb+ex _ (fun x => P)+ \\
203
\verb+exists2 x:A, P & Q+ & \verb+ex2 A (fun x:A => P) (fun x:A => Q)+ \\
204
\verb+exists2 x, P & Q+ & \verb+ex2 _ (fun x => P) (fun x => Q)+ \\
209
The type annotation ``\texttt{:A}'' can be omitted when \texttt{A} can be
210
synthesized by the system.
212
\subsubsection[Equality]{Equality\label{Equality}
215
Then, we find equality, defined as an inductive relation. That is,
216
given a type \verb:A: and an \verb:x: of type \verb:A:, the
217
predicate \verb:(eq A x): is the smallest one which contains \verb:x:.
218
This definition, due to Christine Paulin-Mohring, is equivalent to
219
define \verb:eq: as the smallest reflexive relation, and it is also
220
equivalent to Leibniz' equality.
223
\ttindex{refl\_equal}
226
Inductive eq (A:Type) (x:A) : A -> Prop :=
227
refl_equal : eq A x x.
230
\subsubsection[Lemmas]{Lemmas\label{PreludeLemmas}}
232
Finally, a few easy lemmas are provided.
237
Theorem absurd : forall A C:Prop, A -> ~ A -> C.
245
\ttindex{sym\_not\_eq}
248
Variables A B : Type.
251
Theorem sym_eq : x = y -> y = x.
252
Theorem trans_eq : x = y -> y = z -> x = z.
253
Theorem f_equal : x = y -> f x = f y.
254
Theorem sym_not_eq : x <> y -> y <> x.
265
\ttindex{eq\_rect\_r}
266
%Definition eq_rect: (A:Set)(x:A)(P:A->Type)(P x)->(y:A)(x=y)->(P y).
269
Definition eq_ind_r :
270
forall (A:Type) (x:A) (P:A -> Prop), P x -> forall y:A, y = x -> P y.
271
Definition eq_rec_r :
272
forall (A:Type) (x:A) (P:A -> Set), P x -> forall y:A, y = x -> P y.
273
Definition eq_rect_r :
274
forall (A:Type) (x:A) (P:A -> Type), P x -> forall y:A, y = x -> P y.
281
%Abort (for now predefined eq_rect)
283
Hint Immediate sym_eq sym_not_eq : core.
285
\ttindex{f\_equal$i$}
287
The theorem {\tt f\_equal} is extended to functions with two to five
288
arguments. The theorem are names {\tt f\_equal2}, {\tt f\_equal3},
289
{\tt f\_equal4} and {\tt f\_equal5}.
290
For instance {\tt f\_equal3} is defined the following way.
293
forall (A1 A2 A3 B:Type) (f:A1 -> A2 -> A3 -> B) (x1 y1:A1) (x2 y2:A2)
294
(x3 y3:A3), x1 = y1 -> x2 = y2 -> x3 = y3 -> f x1 x2 x3 = f y1 y2 y3.
300
\subsection[Datatypes]{Datatypes\label{Datatypes}
305
\begin{tabular}{rclr}
306
{\specif} & ::= & {\specif} {\tt *} {\specif} & ({\tt prod})\\
307
& $|$ & {\specif} {\tt +} {\specif} & ({\tt sum})\\
308
& $|$ & {\specif} {\tt + \{} {\specif} {\tt \}} & ({\tt sumor})\\
309
& $|$ & {\tt \{} {\specif} {\tt \} + \{} {\specif} {\tt \}} &
311
& $|$ & {\tt \{} {\ident} {\tt :} {\specif} {\tt |} {\form} {\tt \}}
313
& $|$ & {\tt \{} {\ident} {\tt :} {\specif} {\tt |} {\form} {\tt \&}
314
{\form} {\tt \}} & ({\tt sig2})\\
315
& $|$ & {\tt \{} {\ident} {\tt :} {\specif} {\tt \&} {\specif} {\tt
317
& $|$ & {\tt \{} {\ident} {\tt :} {\specif} {\tt \&} {\specif} {\tt
318
\&} {\specif} {\tt \}} & ({\tt sigT2})\\
320
{\term} & ::= & {\tt (} {\term} {\tt ,} {\term} {\tt )} & ({\tt pair})
323
\caption{Syntax of data-types and specifications}
324
\label{specif-syntax}
328
In the basic library, we find the definition\footnote{They are in {\tt
329
Datatypes.v}} of the basic data-types of programming, again
330
defined as inductive constructions over the sort \verb:Set:. Some of
331
them come with a special syntax shown on Figure~\ref{specif-syntax}.
333
\subsubsection[Programming]{Programming\label{Programming}
348
\ttindex{refl\_identity}}
351
Inductive unit : Set := tt.
352
Inductive bool : Set := true | false.
353
Inductive nat : Set := O | S (n:nat).
354
Inductive option (A:Set) : Set := Some (_:A) | None.
355
Inductive identity (A:Type) (a:A) : A -> Type :=
356
refl_identity : identity A a a.
359
Note that zero is the letter \verb:O:, and {\sl not} the numeral
362
The predicate {\tt identity} is logically
363
equivalent to equality but it lives in sort {\tt
364
Type}. It is mainly maintained for compatibility.
366
We then define the disjoint sum of \verb:A+B: of two sets \verb:A: and
367
\verb:B:, and their product \verb:A*B:.
381
Inductive sum (A B:Set) : Set := inl (_:A) | inr (_:B).
382
Inductive prod (A B:Set) : Set := pair (_:A) (_:B).
385
Definition fst (H: prod A B) := match H with
388
Definition snd (H: prod A B) := match H with
394
Some operations on {\tt bool} are also provided: {\tt andb} (with
395
infix notation {\tt \&\&}), {\tt orb} (with
396
infix notation {\tt ||}), {\tt xorb}, {\tt implb} and {\tt negb}.
398
\subsection{Specification}
400
The following notions\footnote{They are defined in module {\tt
401
Specif.v}} allow to build new data-types and specifications.
402
They are available with the syntax shown on
403
Figure~\ref{specif-syntax}.
405
For instance, given \verb|A:Type| and \verb|P:A->Prop|, the construct
406
\verb+{x:A | P x}+ (in abstract syntax \verb+(sig A P)+) is a
407
\verb:Type:. We may build elements of this set as \verb:(exist x p):
408
whenever we have a witness \verb|x:A| with its justification
411
From such a \verb:(exist x p): we may in turn extract its witness
412
\verb|x:A| (using an elimination construct such as \verb:match:) but
413
{\sl not} its justification, which stays hidden, like in an abstract
414
data-type. In technical terms, one says that \verb:sig: is a ``weak
415
(dependent) sum''. A variant \verb:sig2: with two predicates is also
418
\index{\{x:A "| (P x)\}}
426
Inductive sig (A:Set) (P:A -> Prop) : Set := exist (x:A) (_:P x).
427
Inductive sig2 (A:Set) (P Q:A -> Prop) : Set :=
428
exist2 (x:A) (_:P x) (_:Q x).
431
A ``strong (dependent) sum'' \verb+{x:A & P x}+ may be also defined,
432
when the predicate \verb:P: is now defined as a
433
constructor of types in \verb:Type:.
435
\ttindex{\{x:A \& (P x)\}}
445
Inductive sigT (A:Type) (P:A -> Type) : Type := existT (x:A) (_:P x).
448
Variable P : A -> Type.
449
Definition projT1 (H:sigT A P) := let (x, h) := H in x.
450
Definition projT2 (H:sigT A P) :=
451
match H return P (projT1 H) with
455
Inductive sigT2 (A: Type) (P Q:A -> Type) : Type :=
456
existT2 (x:A) (_:P x) (_:Q x).
459
A related non-dependent construct is the constructive sum
460
\verb"{A}+{B}" of two propositions \verb:A: and \verb:B:.
465
\ttindex{\{A\}+\{B\}}
468
Inductive sumbool (A B:Prop) : Set := left (_:A) | right (_:B).
471
This \verb"sumbool" construct may be used as a kind of indexed boolean
472
data-type. An intermediate between \verb"sumbool" and \verb"sum" is
473
the mixed \verb"sumor" which combines \verb"A:Set" and \verb"B:Prop"
474
in the \verb"Set" \verb"A+{B}".
481
Inductive sumor (A:Set) (B:Prop) : Set := inleft (_:A) | inright (_:B).
484
We may define variants of the axiom of choice, like in Martin-L�f's
485
Intuitionistic Type Theory.
488
\ttindex{bool\_choice}
492
forall (S S':Set) (R:S -> S' -> Prop),
493
(forall x:S, {y : S' | R x y}) ->
494
{f : S -> S' | forall z:S, R z (f z)}.
496
forall (S S':Set) (R:S -> S' -> Set),
497
(forall x:S, {y : S' & R x y}) ->
498
{f : S -> S' & forall z:S, R z (f z)}.
500
forall (S:Set) (R1 R2:S -> Prop),
501
(forall x:S, {R1 x} + {R2 x}) ->
503
forall x:S, f x = true /\ R1 x \/ f x = false /\ R2 x}.
511
The next construct builds a sum between a data-type \verb|A:Type| and
512
an exceptional value encoding errors:
519
Definition Exc := option.
520
Definition value := Some.
521
Definition error := None.
525
This module ends with theorems,
526
relating the sorts \verb:Set: or \verb:Type: and
527
\verb:Prop: in a way which is consistent with the realizability
529
\ttindex{False\_rect}
532
\ttindex{absurd\_set}
536
Definition except := False_rec.
537
Theorem absurd_set : forall (A:Prop) (C:Set), A -> ~ A -> C.
539
forall (A B:Prop) (P:Type), (A -> B -> P) -> A /\ B -> P.
546
\subsection{Basic Arithmetics}
548
The basic library includes a few elementary properties of natural
549
numbers, together with the definitions of predecessor, addition and
550
multiplication\footnote{This is in module {\tt Peano.v}}. It also
551
provides a scope {\tt nat\_scope} gathering standard notations for
552
common operations (+, *) and a decimal notation for numbers. That is he
553
can write \texttt{3} for \texttt{(S (S (S O)))}. This also works on
554
the left hand side of a \texttt{match} expression (see for example
555
section~\ref{refine-example}). This scope is opened by default.
557
%Remove the redefinition of nat
562
The following example is not part of the standard library, but it
563
shows the usage of the notations:
566
Fixpoint even (n:nat) : bool :=
585
\ttindex{plus\_n\_Sm}
588
\ttindex{mult\_n\_Sm}
591
Theorem eq_S : forall x y:nat, x = y -> S x = S y.
597
Definition pred (n:nat) : nat :=
602
Theorem pred_Sn : forall m:nat, m = pred (S m).
603
Theorem eq_add_S : forall n m:nat, S n = S m -> n = m.
604
Hint Immediate eq_add_S : core.
605
Theorem not_eq_S : forall n m:nat, n <> m -> S n <> S m.
611
Definition IsSucc (n:nat) : Prop :=
616
Theorem O_S : forall n:nat, 0 <> S n.
617
Theorem n_Sn : forall n:nat, n <> S n.
623
Fixpoint plus (n m:nat) {struct n} : nat :=
628
where "n + m" := (plus n m) : nat_scope.
629
Lemma plus_n_O : forall n:nat, n = n + 0.
630
Lemma plus_n_Sm : forall n m:nat, S (n + m) = n + S m.
636
Fixpoint mult (n m:nat) {struct n} : nat :=
641
where "n * m" := (mult n m) : nat_scope.
642
Lemma mult_n_O : forall n:nat, 0 = n * 0.
643
Lemma mult_n_Sm : forall n m:nat, n * m + n = n * (S m).
649
Finally, it gives the definition of the usual orderings \verb:le:,
650
\verb:lt:, \verb:ge:, and \verb:gt:.
659
Inductive le (n:nat) : nat -> Prop :=
661
| le_S : forall m:nat, n <= m -> n <= (S m).
662
where "n <= m" := (le n m) : nat_scope.
663
Definition lt (n m:nat) := S n <= m.
664
Definition ge (n m:nat) := m <= n.
665
Definition gt (n m:nat) := m < n.
668
Properties of these relations are not initially known, but may be
669
required by the user from modules \verb:Le: and \verb:Lt:. Finally,
670
\verb:Peano: gives some lemmas allowing pattern-matching, and a double
674
\ttindex{nat\_double\_ind}
678
forall (n:nat) (P:nat -> Prop), P 0 -> (forall m:nat, P (S m)) -> P n.
684
Theorem nat_double_ind :
685
forall R:nat -> nat -> Prop,
686
(forall n:nat, R 0 n) ->
687
(forall n:nat, R (S n) 0) ->
688
(forall n m:nat, R n m -> R (S n) (S m)) -> forall n m:nat, R n m.
694
\subsection{Well-founded recursion}
696
The basic library contains the basics of well-founded recursion and
697
well-founded induction\footnote{This is defined in module {\tt Wf.v}}.
698
\index{Well foundedness}
700
\index{Well founded induction}
704
\ttindex{well\_founded}
707
Section Well_founded.
709
Variable R : A -> A -> Prop.
710
Inductive Acc (x:A) : Prop :=
711
Acc_intro : (forall y:A, R y x -> Acc y) -> Acc x.
712
Lemma Acc_inv : Acc x -> forall y:A, R y x -> Acc y.
718
%% Acc_rect now primitively defined
720
%% Variable P : A -> Set.
723
%% (forall y:A, R y x -> Acc y) -> (forall y:A, R y x -> P y) -> P x.
724
%% Fixpoint Acc_rec (x:A) (a:Acc x) {struct a} : P x :=
726
%% (fun (y:A) (h:R y x) => Acc_rec y (Acc_inv x a y h)).
729
Definition well_founded := forall a:A, Acc a.
730
Hypothesis Rwf : well_founded.
731
Theorem well_founded_induction :
733
(forall x:A, (forall y:A, R y x -> P y) -> P x) -> forall a:A, P a.
734
Theorem well_founded_ind :
736
(forall x:A, (forall y:A, R y x -> P y) -> P x) -> forall a:A, P a.
741
The automatically generated scheme {\tt Acc\_rect}
742
can be used to define functions by fixpoints using
743
well-founded relations to justify termination. Assuming
744
extensionality of the functional used for the recursive call, the
745
fixpoint equation can be proved.
748
\ttindex{Fix\_F\_inv}
752
Variable P : A -> Type.
753
Variable F : forall x:A, (forall y:A, R y x -> P y) -> P x.
754
Fixpoint Fix_F (x:A) (r:Acc x) {struct r} : P x :=
755
F x (fun (y:A) (p:R y x) => Fix_F y (Acc_inv x r y p)).
756
Definition Fix (x:A) := Fix_F x (Rwf x).
758
forall (x:A) (f g:forall y:A, R y x -> P y),
759
(forall (y:A) (p:R y x), f y p = g y p) -> F x f = F x g.
761
forall (x:A) (r:Acc x),
762
F x (fun (y:A) (p:R y x) => Fix_F y (Acc_inv x r y p)) = Fix_F x r.
763
Lemma Fix_F_inv : forall (x:A) (r s:Acc x), Fix_F x r = Fix_F x s.
764
Lemma fix_eq : forall x:A, Fix x = F x (fun (y:A) (p:R y x) => Fix y).
774
\subsection{Accessing the {\Type} level}
776
The basic library includes the definitions\footnote{This is in module
777
{\tt Logic\_Type.v}} of the counterparts of some data-types and logical
778
quantifiers at the \verb:Type: level: negation, pair, and properties
788
Definition notT (A:Type) := A -> False.
789
Inductive prodT (A B:Type) : Type := pairT (_:A) (_:B).
792
At the end, it defines data-types at the {\Type} level.
796
A few tactics defined at the user level are provided in the initial
797
state\footnote{This is in module {\tt Tactics.v}}.
799
\section{The standard library}
803
The rest of the standard library is structured into the following
806
\begin{tabular}{lp{12cm}}
807
{\bf Logic} & Classical logic and dependent equality \\
808
{\bf Arith} & Basic Peano arithmetic \\
809
{\bf NArith} & Basic positive integer arithmetic \\
810
{\bf ZArith} & Basic relative integer arithmetic \\
811
{\bf Numbers} & Various approaches to natural, integer and cyclic numbers (currently axiomatically and on top of 2$^{31}$ binary words) \\
812
{\bf Bool} & Booleans (basic functions and results) \\
813
{\bf Lists} & Monomorphic and polymorphic lists (basic functions and
814
results), Streams (infinite sequences defined with co-inductive
816
{\bf Sets} & Sets (classical, constructive, finite, infinite, power set,
818
{\bf FSets} & Specification and implementations of finite sets and finite
819
maps (by lists and by AVL trees)\\
820
{\bf Reals} & Axiomatization of real numbers (classical, basic functions,
821
integer part, fractional part, limit, derivative, Cauchy
822
series, power series and results,...)\\
823
{\bf Relations} & Relations (definitions and basic results) \\
824
{\bf Sorting} & Sorted list (basic definitions and heapsort correctness) \\
825
{\bf Strings} & 8-bits characters and strings\\
826
{\bf Wellfounded} & Well-founded relations (basic results) \\
831
These directories belong to the initial load path of the system, and
832
the modules they provide are compiled at installation time. So they
833
are directly accessible with the command \verb!Require! (see
834
Chapter~\ref{Other-commands}).
836
The different modules of the \Coq\ standard library are described in the
837
additional document \verb!Library.dvi!. They are also accessible on the WWW
838
through the \Coq\ homepage
839
\footnote{\texttt{http://coq.inria.fr}}.
841
\subsection[Notations for integer arithmetics]{Notations for integer arithmetics\index{Arithmetical notations}}
843
On Figure~\ref{zarith-syntax} is described the syntax of expressions
844
for integer arithmetics. It is provided by requiring and opening the
845
module {\tt ZArith} and opening scope {\tt Z\_scope}.
860
\begin{tabular}{l|l|l|l}
861
Notation & Interpretation & Precedence & Associativity\\
863
\verb!_ < _! & {\tt Zlt} &&\\
864
\verb!x <= y! & {\tt Zle} &&\\
865
\verb!_ > _! & {\tt Zgt} &&\\
866
\verb!x >= y! & {\tt Zge} &&\\
867
\verb!x < y < z! & {\tt x < y \verb!/\! y < z} &&\\
868
\verb!x < y <= z! & {\tt x < y \verb!/\! y <= z} &&\\
869
\verb!x <= y < z! & {\tt x <= y \verb!/\! y < z} &&\\
870
\verb!x <= y <= z! & {\tt x <= y \verb!/\! y <= z} &&\\
871
\verb!_ ?= _! & {\tt Zcompare} & 70 & no\\
872
\verb!_ + _! & {\tt Zplus} &&\\
873
\verb!_ - _! & {\tt Zminus} &&\\
874
\verb!_ * _! & {\tt Zmult} &&\\
875
\verb!_ / _! & {\tt Zdiv} &&\\
876
\verb!_ mod _! & {\tt Zmod} & 40 & no \\
877
\verb!- _! & {\tt Zopp} &&\\
878
\verb!_ ^ _! & {\tt Zpower} &&\\
881
\label{zarith-syntax}
882
\caption{Definition of the scope for integer arithmetics ({\tt Z\_scope})}
885
Figure~\ref{zarith-syntax} shows the notations provided by {\tt
886
Z\_scope}. It specifies how notations are interpreted and, when not
887
already reserved, the precedence and associativity.
890
Require Import ZArith.
896
\subsection[Peano's arithmetic (\texttt{nat})]{Peano's arithmetic (\texttt{nat})\index{Peano's arithmetic}
897
\ttindex{nat\_scope}}
899
While in the initial state, many operations and predicates of Peano's
900
arithmetic are defined, further operations and results belong to other
901
modules. For instance, the decidability of the basic predicates are
902
defined here. This is provided by requiring the module {\tt Arith}.
904
Figure~\ref{nat-syntax} describes notation available in scope {\tt
910
Notation & Interpretation \\
912
\verb!_ < _! & {\tt lt} \\
913
\verb!x <= y! & {\tt le} \\
914
\verb!_ > _! & {\tt gt} \\
915
\verb!x >= y! & {\tt ge} \\
916
\verb!x < y < z! & {\tt x < y \verb!/\! y < z} \\
917
\verb!x < y <= z! & {\tt x < y \verb!/\! y <= z} \\
918
\verb!x <= y < z! & {\tt x <= y \verb!/\! y < z} \\
919
\verb!x <= y <= z! & {\tt x <= y \verb!/\! y <= z} \\
920
\verb!_ + _! & {\tt plus} \\
921
\verb!_ - _! & {\tt minus} \\
922
\verb!_ * _! & {\tt mult} \\
926
\caption{Definition of the scope for natural numbers ({\tt nat\_scope})}
929
\subsection{Real numbers library}
931
\subsubsection[Notations for real numbers]{Notations for real numbers\index{Notations for real numbers}}
933
This is provided by requiring and opening the module {\tt Reals} and
934
opening scope {\tt R\_scope}. This set of notations is very similar to
935
the notation for integer arithmetics. The inverse function was added.
939
Notation & Interpretation \\
941
\verb!_ < _! & {\tt Rlt} \\
942
\verb!x <= y! & {\tt Rle} \\
943
\verb!_ > _! & {\tt Rgt} \\
944
\verb!x >= y! & {\tt Rge} \\
945
\verb!x < y < z! & {\tt x < y \verb!/\! y < z} \\
946
\verb!x < y <= z! & {\tt x < y \verb!/\! y <= z} \\
947
\verb!x <= y < z! & {\tt x <= y \verb!/\! y < z} \\
948
\verb!x <= y <= z! & {\tt x <= y \verb!/\! y <= z} \\
949
\verb!_ + _! & {\tt Rplus} \\
950
\verb!_ - _! & {\tt Rminus} \\
951
\verb!_ * _! & {\tt Rmult} \\
952
\verb!_ / _! & {\tt Rdiv} \\
953
\verb!- _! & {\tt Ropp} \\
954
\verb!/ _! & {\tt Rinv} \\
955
\verb!_ ^ _! & {\tt pow} \\
959
\caption{Definition of the scope for real arithmetics ({\tt R\_scope})}
966
Require Import Reals.
972
\subsubsection{Some tactics}
974
In addition to the \verb|ring|, \verb|field| and \verb|fourier|
975
tactics (see Chapter~\ref{Tactics}) there are:
977
\item {\tt discrR} \tacindex{discrR}
979
Proves that a real integer constant $c_1$ is different from another
980
real integer constant $c_2$.
983
Require Import DiscrR.
995
\item {\tt split\_Rabs} allows to unfold {\tt Rabs} constant and splits
996
corresponding conjonctions.
997
\tacindex{split\_Rabs}
1000
Require Import SplitAbsolu.
1001
Goal forall x:R, x <= Rabs x.
1012
\item {\tt split\_Rmult} allows to split a condition that a product is
1013
non null into subgoals corresponding to the condition on each
1014
operand of the product.
1015
\tacindex{split\_Rmult}
1017
\begin{coq_example*}
1018
Require Import SplitRmult.
1019
Goal forall x y z:R, x * y * z <> 0.
1023
intros; split_Rmult.
1028
All this tactics has been written with the tactic language Ltac
1029
described in Chapter~\ref{TacticLanguage}. More details are available
1030
in document \url{http://coq.inria.fr/~desmettr/Reals.ps}.
1036
\subsection[List library]{List library\index{Notations for lists}
1045
\ttindex{fold\_left}
1046
\ttindex{fold\_right}}
1048
Some elementary operations on polymorphic lists are defined here. They
1049
can be accessed by requiring module {\tt List}.
1051
It defines the following notions:
1053
\begin{tabular}{l|l}
1055
{\tt length} & length \\
1056
{\tt head} & first element (with default) \\
1057
{\tt tail} & all but first element \\
1058
{\tt app} & concatenation \\
1059
{\tt rev} & reverse \\
1060
{\tt nth} & accessing $n$-th element (with default) \\
1061
{\tt map} & applying a function \\
1062
{\tt flat\_map} & applying a function returning lists \\
1063
{\tt fold\_left} & iterator (from head to tail) \\
1064
{\tt fold\_right} & iterator (from tail to head) \\
1069
Table show notations available when opening scope {\tt list\_scope}.
1073
\begin{tabular}{l|l|l|l}
1074
Notation & Interpretation & Precedence & Associativity\\
1076
\verb!_ ++ _! & {\tt app} & 60 & right \\
1077
\verb!_ :: _! & {\tt cons} & 60 & right \\
1081
\caption{Definition of the scope for lists ({\tt list\_scope})}
1085
\section[Users' contributions]{Users' contributions\index{Contributions}
1086
\label{Contributions}}
1088
Numerous users' contributions have been collected and are available at
1089
URL \url{coq.inria.fr/contribs/}. On this web page, you have a list
1090
of all contributions with informations (author, institution, quick
1091
description, etc.) and the possibility to download them one by one.
1092
There is a small search engine to look for keywords in all
1093
contributions. You will also find informations on how to submit a new
1096
The users' contributions may also be obtained by anonymous FTP from site
1097
\verb:ftp.inria.fr:, in directory \verb:INRIA/coq/: and
1098
searchable on-line at \url{http://coq.inria.fr/contribs-eng.html}
1100
% $Id: RefMan-lib.tex 11793 2009-01-17 11:39:48Z herbelin $
1102
%%% Local Variables:
1104
%%% TeX-master: "Reference-Manual"