~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to theories/Init/Logic.v

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(************************************************************************)
 
2
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
 
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
 
4
(*   \VV/  **************************************************************)
 
5
(*    //   *      This file is distributed under the terms of the       *)
 
6
(*         *       GNU Lesser General Public License Version 2.1        *)
 
7
(************************************************************************)
 
8
 
 
9
(*i $Id: Logic.v 11735 2009-01-02 17:22:31Z herbelin $ i*)
 
10
 
 
11
Set Implicit Arguments.
 
12
 
 
13
Require Import Notations.
 
14
 
 
15
(** * Propositional connectives *)
 
16
 
 
17
(** [True] is the always true proposition *)
 
18
Inductive True : Prop :=
 
19
  I : True.
 
20
 
 
21
(** [False] is the always false proposition *)
 
22
Inductive False : Prop :=.
 
23
 
 
24
(** [not A], written [~A], is the negation of [A] *)
 
25
Definition not (A:Prop) := A -> False.
 
26
 
 
27
Notation "~ x" := (not x) : type_scope.
 
28
 
 
29
Hint Unfold not: core.
 
30
 
 
31
  (** [and A B], written [A /\ B], is the conjunction of [A] and [B]
 
32
 
 
33
      [conj p q] is a proof of [A /\ B] as soon as
 
34
      [p] is a proof of [A] and [q] a proof of [B]
 
35
 
 
36
      [proj1] and [proj2] are first and second projections of a conjunction *)
 
37
 
 
38
Inductive and (A B:Prop) : Prop :=
 
39
  conj : A -> B -> A /\ B
 
40
 
 
41
where "A /\ B" := (and A B) : type_scope.
 
42
 
 
43
Section Conjunction.
 
44
 
 
45
  Variables A B : Prop.
 
46
 
 
47
  Theorem proj1 : A /\ B -> A.
 
48
  Proof.
 
49
    destruct 1; trivial.
 
50
  Qed.
 
51
 
 
52
  Theorem proj2 : A /\ B -> B.
 
53
  Proof.
 
54
    destruct 1; trivial.
 
55
  Qed.
 
56
 
 
57
End Conjunction.
 
58
 
 
59
(** [or A B], written [A \/ B], is the disjunction of [A] and [B] *)
 
60
 
 
61
Inductive or (A B:Prop) : Prop :=
 
62
  | or_introl : A -> A \/ B
 
63
  | or_intror : B -> A \/ B
 
64
 
 
65
where "A \/ B" := (or A B) : type_scope.
 
66
 
 
67
(** [iff A B], written [A <-> B], expresses the equivalence of [A] and [B] *)
 
68
 
 
69
Definition iff (A B:Prop) := (A -> B) /\ (B -> A).
 
70
 
 
71
Notation "A <-> B" := (iff A B) : type_scope.
 
72
 
 
73
Section Equivalence.
 
74
 
 
75
Theorem iff_refl : forall A:Prop, A <-> A.
 
76
  Proof.
 
77
    split; auto.
 
78
  Qed.
 
79
 
 
80
Theorem iff_trans : forall A B C:Prop, (A <-> B) -> (B <-> C) -> (A <-> C).
 
81
  Proof.
 
82
    intros A B C [H1 H2] [H3 H4]; split; auto.
 
83
  Qed.
 
84
 
 
85
Theorem iff_sym : forall A B:Prop, (A <-> B) -> (B <-> A).
 
86
  Proof.
 
87
    intros A B [H1 H2]; split; auto.
 
88
  Qed.
 
89
 
 
90
End Equivalence.
 
91
 
 
92
Hint Unfold iff: extcore.
 
93
 
 
94
(** Some equivalences *)
 
95
 
 
96
Theorem neg_false : forall A : Prop, ~ A <-> (A <-> False).
 
97
Proof.
 
98
intro A; unfold not; split.
 
99
intro H; split; [exact H | intro H1; elim H1].
 
100
intros [H _]; exact H.
 
101
Qed.
 
102
 
 
103
Theorem and_cancel_l : forall A B C : Prop,
 
104
  (B -> A) -> (C -> A) -> ((A /\ B <-> A /\ C) <-> (B <-> C)).
 
105
Proof.
 
106
intros; tauto.
 
107
Qed.
 
108
 
 
109
Theorem and_cancel_r : forall A B C : Prop,
 
110
  (B -> A) -> (C -> A) -> ((B /\ A <-> C /\ A) <-> (B <-> C)).
 
111
Proof.
 
112
intros; tauto.
 
113
Qed.
 
114
 
 
115
Theorem or_cancel_l : forall A B C : Prop,
 
116
  (B -> ~ A) -> (C -> ~ A) -> ((A \/ B <-> A \/ C) <-> (B <-> C)).
 
117
Proof.
 
118
intros; tauto.
 
119
Qed.
 
120
 
 
121
Theorem or_cancel_r : forall A B C : Prop,
 
122
  (B -> ~ A) -> (C -> ~ A) -> ((B \/ A <-> C \/ A) <-> (B <-> C)).
 
123
Proof.
 
124
intros; tauto.
 
125
Qed.
 
126
 
 
127
(** Backward direction of the equivalences above does not need assumptions *)
 
128
 
 
129
Theorem and_iff_compat_l : forall A B C : Prop,
 
130
  (B <-> C) -> (A /\ B <-> A /\ C).
 
131
Proof.
 
132
intros; tauto.
 
133
Qed.
 
134
 
 
135
Theorem and_iff_compat_r : forall A B C : Prop,
 
136
  (B <-> C) -> (B /\ A <-> C /\ A).
 
137
Proof.
 
138
intros; tauto.
 
139
Qed.
 
140
 
 
141
Theorem or_iff_compat_l : forall A B C : Prop,
 
142
  (B <-> C) -> (A \/ B <-> A \/ C).
 
143
Proof.
 
144
intros; tauto.
 
145
Qed.
 
146
 
 
147
Theorem or_iff_compat_r : forall A B C : Prop,
 
148
  (B <-> C) -> (B \/ A <-> C \/ A).
 
149
Proof.
 
150
intros; tauto.
 
151
Qed.
 
152
 
 
153
Lemma iff_and : forall A B : Prop, (A <-> B) -> (A -> B) /\ (B -> A).
 
154
Proof.
 
155
intros A B []; split; trivial.
 
156
Qed.
 
157
 
 
158
Lemma iff_to_and : forall A B : Prop, (A <-> B) <-> (A -> B) /\ (B -> A).
 
159
Proof.
 
160
intros; tauto.
 
161
Qed.
 
162
 
 
163
(** [(IF_then_else P Q R)], written [IF P then Q else R] denotes
 
164
    either [P] and [Q], or [~P] and [Q] *)
 
165
 
 
166
Definition IF_then_else (P Q R:Prop) := P /\ Q \/ ~ P /\ R.
 
167
 
 
168
Notation "'IF' c1 'then' c2 'else' c3" := (IF_then_else c1 c2 c3)
 
169
  (at level 200, right associativity) : type_scope.
 
170
 
 
171
(** * First-order quantifiers *)
 
172
 
 
173
(** [ex P], or simply [exists x, P x], or also [exists x:A, P x],
 
174
    expresses the existence of an [x] of some type [A] in [Set] which
 
175
    satisfies the predicate [P].  This is existential quantification.
 
176
 
 
177
    [ex2 P Q], or simply [exists2 x, P x & Q x], or also
 
178
    [exists2 x:A, P x & Q x], expresses the existence of an [x] of
 
179
    type [A] which satisfies both predicates [P] and [Q].
 
180
 
 
181
    Universal quantification is primitively written [forall x:A, Q]. By
 
182
    symmetry with existential quantification, the construction [all P]
 
183
    is provided too.
 
184
*)
 
185
 
 
186
(** Remark: [exists x, Q] denotes [ex (fun x => Q)] so that [exists x,
 
187
   P x] is in fact equivalent to [ex (fun x => P x)] which may be not
 
188
   convertible to [ex P] if [P] is not itself an abstraction *)
 
189
 
 
190
 
 
191
Inductive ex (A:Type) (P:A -> Prop) : Prop :=
 
192
  ex_intro : forall x:A, P x -> ex (A:=A) P.
 
193
 
 
194
Inductive ex2 (A:Type) (P Q:A -> Prop) : Prop :=
 
195
  ex_intro2 : forall x:A, P x -> Q x -> ex2 (A:=A) P Q.
 
196
 
 
197
Definition all (A:Type) (P:A -> Prop) := forall x:A, P x.
 
198
 
 
199
(* Rule order is important to give printing priority to fully typed exists *)
 
200
 
 
201
Notation "'exists' x , p" := (ex (fun x => p))
 
202
  (at level 200, x ident, right associativity) : type_scope.
 
203
Notation "'exists' x : t , p" := (ex (fun x:t => p))
 
204
  (at level 200, x ident, right associativity,
 
205
    format "'[' 'exists'  '/  ' x  :  t ,  '/  ' p ']'")
 
206
  : type_scope.
 
207
 
 
208
Notation "'exists2' x , p & q" := (ex2 (fun x => p) (fun x => q))
 
209
  (at level 200, x ident, p at level 200, right associativity) : type_scope.
 
210
Notation "'exists2' x : t , p & q" := (ex2 (fun x:t => p) (fun x:t => q))
 
211
  (at level 200, x ident, t at level 200, p at level 200, right associativity,
 
212
    format "'[' 'exists2'  '/  ' x  :  t ,  '/  ' '[' p  &  '/' q ']' ']'")
 
213
  : type_scope.
 
214
 
 
215
(** Derived rules for universal quantification *)
 
216
 
 
217
Section universal_quantification.
 
218
 
 
219
  Variable A : Type.
 
220
  Variable P : A -> Prop.
 
221
 
 
222
  Theorem inst : forall x:A, all (fun x => P x) -> P x.
 
223
  Proof.
 
224
    unfold all in |- *; auto.
 
225
  Qed.
 
226
 
 
227
  Theorem gen : forall (B:Prop) (f:forall y:A, B -> P y), B -> all P.
 
228
  Proof.
 
229
    red in |- *; auto.
 
230
  Qed.
 
231
 
 
232
End universal_quantification.
 
233
 
 
234
(** * Equality *)
 
235
 
 
236
(** [eq x y], or simply [x=y] expresses the equality of [x] and
 
237
    [y]. Both [x] and [y] must belong to the same type [A].
 
238
    The definition is inductive and states the reflexivity of the equality.
 
239
    The others properties (symmetry, transitivity, replacement of
 
240
    equals by equals) are proved below. The type of [x] and [y] can be
 
241
    made explicit using the notation [x = y :> A]. This is Leibniz equality
 
242
    as it expresses that [x] and [y] are equal iff every property on
 
243
    [A] which is true of [x] is also true of [y] *)
 
244
 
 
245
Inductive eq (A:Type) (x:A) : A -> Prop :=
 
246
    refl_equal : x = x :>A
 
247
 
 
248
where "x = y :> A" := (@eq A x y) : type_scope.
 
249
 
 
250
Notation "x = y" := (x = y :>_) : type_scope.
 
251
Notation "x <> y  :> T" := (~ x = y :>T) : type_scope.
 
252
Notation "x <> y" := (x <> y :>_) : type_scope.
 
253
 
 
254
Implicit Arguments eq_ind [A].
 
255
Implicit Arguments eq_rec [A].
 
256
Implicit Arguments eq_rect [A].
 
257
 
 
258
Hint Resolve I conj or_introl or_intror refl_equal: core.
 
259
Hint Resolve ex_intro ex_intro2: core.
 
260
 
 
261
Section Logic_lemmas.
 
262
 
 
263
  Theorem absurd : forall A C:Prop, A -> ~ A -> C.
 
264
  Proof.
 
265
    unfold not in |- *; intros A C h1 h2.
 
266
    destruct (h2 h1).
 
267
  Qed.
 
268
 
 
269
  Section equality.
 
270
    Variables A B : Type.
 
271
    Variable f : A -> B.
 
272
    Variables x y z : A.
 
273
 
 
274
    Theorem sym_eq : x = y -> y = x.
 
275
    Proof.
 
276
      destruct 1; trivial.
 
277
    Defined.
 
278
    Opaque sym_eq.
 
279
 
 
280
    Theorem trans_eq : x = y -> y = z -> x = z.
 
281
    Proof.
 
282
      destruct 2; trivial.
 
283
    Defined.
 
284
    Opaque trans_eq.
 
285
 
 
286
    Theorem f_equal : x = y -> f x = f y.
 
287
    Proof.
 
288
      destruct 1; trivial.
 
289
    Defined.
 
290
    Opaque f_equal.
 
291
 
 
292
    Theorem sym_not_eq : x <> y -> y <> x.
 
293
    Proof.
 
294
      red in |- *; intros h1 h2; apply h1; destruct h2; trivial.
 
295
    Qed.
 
296
 
 
297
    Definition sym_equal := sym_eq.
 
298
    Definition sym_not_equal := sym_not_eq.
 
299
    Definition trans_equal := trans_eq.
 
300
 
 
301
  End equality.
 
302
 
 
303
  Definition eq_ind_r :
 
304
    forall (A:Type) (x:A) (P:A -> Prop), P x -> forall y:A, y = x -> P y.
 
305
    intros A x P H y H0; elim sym_eq with (1 := H0); assumption.
 
306
  Defined.
 
307
 
 
308
  Definition eq_rec_r :
 
309
    forall (A:Type) (x:A) (P:A -> Set), P x -> forall y:A, y = x -> P y.
 
310
    intros A x P H y H0; elim sym_eq with (1 := H0); assumption.
 
311
  Defined.
 
312
 
 
313
  Definition eq_rect_r :
 
314
    forall (A:Type) (x:A) (P:A -> Type), P x -> forall y:A, y = x -> P y.
 
315
    intros A x P H y H0; elim sym_eq with (1 := H0); assumption.
 
316
  Defined.
 
317
End Logic_lemmas.
 
318
 
 
319
Theorem f_equal2 :
 
320
  forall (A1 A2 B:Type) (f:A1 -> A2 -> B) (x1 y1:A1)
 
321
    (x2 y2:A2), x1 = y1 -> x2 = y2 -> f x1 x2 = f y1 y2.
 
322
Proof.
 
323
  destruct 1; destruct 1; reflexivity.
 
324
Qed.
 
325
 
 
326
Theorem f_equal3 :
 
327
  forall (A1 A2 A3 B:Type) (f:A1 -> A2 -> A3 -> B) (x1 y1:A1)
 
328
    (x2 y2:A2) (x3 y3:A3),
 
329
    x1 = y1 -> x2 = y2 -> x3 = y3 -> f x1 x2 x3 = f y1 y2 y3.
 
330
Proof.
 
331
  destruct 1; destruct 1; destruct 1; reflexivity.
 
332
Qed.
 
333
 
 
334
Theorem f_equal4 :
 
335
  forall (A1 A2 A3 A4 B:Type) (f:A1 -> A2 -> A3 -> A4 -> B)
 
336
    (x1 y1:A1) (x2 y2:A2) (x3 y3:A3) (x4 y4:A4),
 
337
    x1 = y1 -> x2 = y2 -> x3 = y3 -> x4 = y4 -> f x1 x2 x3 x4 = f y1 y2 y3 y4.
 
338
Proof.
 
339
  destruct 1; destruct 1; destruct 1; destruct 1; reflexivity.
 
340
Qed.
 
341
 
 
342
Theorem f_equal5 :
 
343
  forall (A1 A2 A3 A4 A5 B:Type) (f:A1 -> A2 -> A3 -> A4 -> A5 -> B)
 
344
    (x1 y1:A1) (x2 y2:A2) (x3 y3:A3) (x4 y4:A4) (x5 y5:A5),
 
345
    x1 = y1 ->
 
346
    x2 = y2 ->
 
347
    x3 = y3 -> x4 = y4 -> x5 = y5 -> f x1 x2 x3 x4 x5 = f y1 y2 y3 y4 y5.
 
348
Proof.
 
349
  destruct 1; destruct 1; destruct 1; destruct 1; destruct 1; reflexivity.
 
350
Qed.
 
351
 
 
352
Hint Immediate sym_eq sym_not_eq: core.
 
353
 
 
354
(** Basic definitions about relations and properties *)
 
355
 
 
356
Definition subrelation (A B : Type) (R R' : A->B->Prop) :=
 
357
  forall x y, R x y -> R' x y.
 
358
 
 
359
Definition unique (A : Type) (P : A->Prop) (x:A) :=
 
360
  P x /\ forall (x':A), P x' -> x=x'.
 
361
 
 
362
Definition uniqueness (A:Type) (P:A->Prop) := forall x y, P x -> P y -> x = y.
 
363
 
 
364
(** Unique existence *)
 
365
 
 
366
Notation "'exists' ! x , P" := (ex (unique (fun x => P)))
 
367
  (at level 200, x ident, right associativity,
 
368
    format "'[' 'exists' !  '/  ' x ,  '/  ' P ']'") : type_scope.
 
369
Notation "'exists' ! x : A , P" :=
 
370
  (ex (unique (fun x:A => P)))
 
371
  (at level 200, x ident, right associativity,
 
372
    format "'[' 'exists' !  '/  ' x  :  A ,  '/  ' P ']'") : type_scope.
 
373
 
 
374
Lemma unique_existence : forall (A:Type) (P:A->Prop),
 
375
  ((exists x, P x) /\ uniqueness P) <-> (exists! x, P x).
 
376
Proof.
 
377
  intros A P; split.
 
378
  intros ((x,Hx),Huni); exists x; red; auto.
 
379
  intros (x,(Hx,Huni)); split.
 
380
  exists x; assumption.
 
381
  intros x' x'' Hx' Hx''; transitivity x.
 
382
  symmetry; auto.
 
383
  auto.
 
384
Qed.
 
385
 
 
386
(** * Being inhabited *)
 
387
 
 
388
(** The predicate [inhabited] can be used in different contexts. If [A] is
 
389
    thought as a type, [inhabited A] states that [A] is inhabited. If [A] is
 
390
    thought as a computationally relevant proposition, then
 
391
    [inhabited A] weakens [A] so as to hide its computational meaning.
 
392
    The so-weakened proof remains computationally relevant but only in
 
393
    a propositional context.
 
394
*)
 
395
 
 
396
Inductive inhabited (A:Type) : Prop := inhabits : A -> inhabited A.
 
397
 
 
398
Hint Resolve inhabits: core.
 
399
 
 
400
Lemma exists_inhabited : forall (A:Type) (P:A->Prop),
 
401
  (exists x, P x) -> inhabited A.
 
402
Proof.
 
403
  destruct 1; auto.
 
404
Qed.
 
405
 
 
406
(** Declaration of stepl and stepr for eq and iff *)
 
407
 
 
408
Lemma eq_stepl : forall (A : Type) (x y z : A), x = y -> x = z -> z = y.
 
409
Proof.
 
410
intros A x y z H1 H2. rewrite <- H2; exact H1.
 
411
Qed.
 
412
 
 
413
Declare Left Step eq_stepl.
 
414
Declare Right Step trans_eq.
 
415
 
 
416
Lemma iff_stepl : forall A B C : Prop, (A <-> B) -> (A <-> C) -> (C <-> B).
 
417
Proof.
 
418
intros; tauto.
 
419
Qed.
 
420
 
 
421
Declare Left Step iff_stepl.
 
422
Declare Right Step iff_trans.