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

« back to all changes in this revision

Viewing changes to theories/Numbers/NumPrelude.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
(*                      Evgeny Makarov, INRIA, 2007                     *)
 
9
(************************************************************************)
 
10
 
 
11
(*i $Id: NumPrelude.v 11674 2008-12-12 19:48:40Z letouzey $ i*)
 
12
 
 
13
Require Export Setoid.
 
14
 
 
15
Set Implicit Arguments.
 
16
(*
 
17
Contents:
 
18
- Coercion from bool to Prop
 
19
- Extension of the tactics stepl and stepr
 
20
- Extentional properties of predicates, relations and functions
 
21
  (well-definedness and equality)
 
22
- Relations on cartesian product
 
23
- Miscellaneous
 
24
*)
 
25
 
 
26
(** Coercion from bool to Prop *)
 
27
 
 
28
(*Definition eq_bool := (@eq bool).*)
 
29
 
 
30
(*Inductive eq_true : bool -> Prop := is_eq_true : eq_true true.*)
 
31
(* This has been added to theories/Datatypes.v *)
 
32
(*Coercion eq_true : bool >-> Sortclass.*)
 
33
 
 
34
(*Theorem eq_true_unfold_pos : forall b : bool, b <-> b = true.
 
35
Proof.
 
36
intro b; split; intro H. now inversion H. now rewrite H.
 
37
Qed.
 
38
 
 
39
Theorem eq_true_unfold_neg : forall b : bool, ~ b <-> b = false.
 
40
Proof.
 
41
intros b; destruct b; simpl; rewrite eq_true_unfold_pos.
 
42
split; intro H; [elim (H (refl_equal true)) | discriminate H].
 
43
split; intro H; [reflexivity | discriminate].
 
44
Qed.
 
45
 
 
46
Theorem eq_true_or : forall b1 b2 : bool, b1 || b2 <-> b1 \/ b2.
 
47
Proof.
 
48
destruct b1; destruct b2; simpl; tauto.
 
49
Qed.
 
50
 
 
51
Theorem eq_true_and : forall b1 b2 : bool, b1 && b2 <-> b1 /\ b2.
 
52
Proof.
 
53
destruct b1; destruct b2; simpl; tauto.
 
54
Qed.
 
55
 
 
56
Theorem eq_true_neg : forall b : bool, negb b <-> ~ b.
 
57
Proof.
 
58
destruct b; simpl; rewrite eq_true_unfold_pos; rewrite eq_true_unfold_neg;
 
59
split; now intro.
 
60
Qed.
 
61
 
 
62
Theorem eq_true_iff : forall b1 b2 : bool, b1 = b2 <-> (b1 <-> b2).
 
63
Proof.
 
64
intros b1 b2; split; intro H.
 
65
now rewrite H.
 
66
destruct b1; destruct b2; simpl; try reflexivity.
 
67
apply -> eq_true_unfold_neg. rewrite H. now intro.
 
68
symmetry; apply -> eq_true_unfold_neg. rewrite <- H; now intro.
 
69
Qed.*)
 
70
 
 
71
(** Extension of the tactics stepl and stepr to make them
 
72
applicable to hypotheses *)
 
73
 
 
74
Tactic Notation "stepl" constr(t1') "in" hyp(H) :=
 
75
match (type of H) with
 
76
| ?R ?t1 ?t2 =>
 
77
  let H1 := fresh in
 
78
  cut (R t1' t2); [clear H; intro H | stepl t1; [assumption |]]
 
79
| _ => fail 1 ": the hypothesis" H "does not have the form (R t1 t2)"
 
80
end.
 
81
 
 
82
Tactic Notation "stepl" constr(t1') "in" hyp(H) "by" tactic(r) := stepl t1' in H; [| r].
 
83
 
 
84
Tactic Notation "stepr" constr(t2') "in" hyp(H) :=
 
85
match (type of H) with
 
86
| ?R ?t1 ?t2 =>
 
87
  let H1 := fresh in
 
88
  cut (R t1 t2'); [clear H; intro H | stepr t2; [assumption |]]
 
89
| _ => fail 1 ": the hypothesis" H "does not have the form (R t1 t2)"
 
90
end.
 
91
 
 
92
Tactic Notation "stepr" constr(t2') "in" hyp(H) "by" tactic(r) := stepr t2' in H; [| r].
 
93
 
 
94
(** Extentional properties of predicates, relations and functions *)
 
95
 
 
96
Definition predicate (A : Type) := A -> Prop.
 
97
 
 
98
Section ExtensionalProperties.
 
99
 
 
100
Variables A B C : Type.
 
101
Variable Aeq : relation A.
 
102
Variable Beq : relation B.
 
103
Variable Ceq : relation C.
 
104
 
 
105
(* "wd" stands for "well-defined" *)
 
106
 
 
107
Definition fun_wd (f : A -> B) := forall x y : A, Aeq x y -> Beq (f x) (f y).
 
108
 
 
109
Definition fun2_wd (f : A -> B -> C) :=
 
110
  forall x x' : A, Aeq x x' -> forall y y' : B, Beq y y' -> Ceq (f x y) (f x' y').
 
111
 
 
112
Definition fun_eq : relation (A -> B) :=
 
113
  fun f f' => forall x x' : A, Aeq x x' -> Beq (f x) (f' x').
 
114
 
 
115
(* Note that reflexivity of fun_eq means that every function
 
116
is well-defined w.r.t. Aeq and Beq, i.e.,
 
117
forall x x' : A, Aeq x x' -> Beq (f x) (f x') *)
 
118
 
 
119
Definition fun2_eq (f f' : A -> B -> C) :=
 
120
  forall x x' : A, Aeq x x' -> forall y y' : B, Beq y y' -> Ceq (f x y) (f' x' y').
 
121
 
 
122
End ExtensionalProperties.
 
123
 
 
124
(* The following definitions instantiate Beq or Ceq to iff; therefore, they
 
125
have to be outside the ExtensionalProperties section *)
 
126
 
 
127
Definition predicate_wd (A : Type) (Aeq : relation A) := fun_wd Aeq iff.
 
128
 
 
129
Definition relation_wd (A B : Type) (Aeq : relation A) (Beq : relation B) :=
 
130
  fun2_wd Aeq Beq iff.
 
131
 
 
132
Definition relations_eq (A B : Type) (R1 R2 : A -> B -> Prop) :=
 
133
  forall (x : A) (y : B), R1 x y <-> R2 x y.
 
134
 
 
135
Theorem relations_eq_equiv :
 
136
  forall (A B : Type), equiv (A -> B -> Prop) (@relations_eq A B).
 
137
Proof.
 
138
intros A B; unfold equiv. split; [| split];
 
139
unfold reflexive, symmetric, transitive, relations_eq.
 
140
reflexivity.
 
141
intros R1 R2 R3 H1 H2 x y; rewrite H1; apply H2.
 
142
now symmetry.
 
143
Qed.
 
144
 
 
145
Add Parametric Relation (A B : Type) : (A -> B -> Prop) (@relations_eq A B)
 
146
  reflexivity proved by (proj1 (relations_eq_equiv A B))
 
147
  symmetry proved by (proj2 (proj2 (relations_eq_equiv A B)))
 
148
  transitivity proved by (proj1 (proj2 (relations_eq_equiv A B)))
 
149
as relations_eq_rel.
 
150
 
 
151
Add Parametric Morphism (A : Type) : (@well_founded A) with signature (@relations_eq A A) ==> iff as well_founded_wd.
 
152
Proof.
 
153
unfold relations_eq, well_founded; intros R1 R2 H;
 
154
split; intros H1 a; induction (H1 a) as [x H2 H3]; constructor;
 
155
intros y H4; apply H3; [now apply <- H | now apply -> H].
 
156
Qed.
 
157
 
 
158
(* solve_predicate_wd solves the goal [predicate_wd P] for P consisting of
 
159
morhisms and quatifiers *)
 
160
 
 
161
Ltac solve_predicate_wd :=
 
162
unfold predicate_wd;
 
163
let x := fresh "x" in
 
164
let y := fresh "y" in
 
165
let H := fresh "H" in
 
166
  intros x y H; setoid_rewrite H; reflexivity.
 
167
 
 
168
(* solve_relation_wd solves the goal [relation_wd R] for R consisting of
 
169
morhisms and quatifiers *)
 
170
 
 
171
Ltac solve_relation_wd :=
 
172
unfold relation_wd, fun2_wd;
 
173
let x1 := fresh "x" in
 
174
let y1 := fresh "y" in
 
175
let H1 := fresh "H" in
 
176
let x2 := fresh "x" in
 
177
let y2 := fresh "y" in
 
178
let H2 := fresh "H" in
 
179
  intros x1 y1 H1 x2 y2 H2;
 
180
  rewrite H1; setoid_rewrite H2; reflexivity.
 
181
 
 
182
(* The following tactic uses solve_predicate_wd to solve the goals
 
183
relating to well-defidedness that are produced by applying induction.
 
184
We declare it to take the tactic that applies the induction theorem
 
185
and not the induction theorem itself because the tactic may, for
 
186
example, supply additional arguments, as does NZinduct_center in
 
187
NZBase.v *)
 
188
 
 
189
Ltac induction_maker n t :=
 
190
  try intros until n;
 
191
  pattern n; t; clear n;
 
192
  [solve_predicate_wd | ..].
 
193
 
 
194
(** Relations on cartesian product. Used in MiscFunct for defining
 
195
functions whose domain is a product of sets by primitive recursion *)
 
196
 
 
197
Section RelationOnProduct.
 
198
 
 
199
Variables A B : Set.
 
200
Variable Aeq : relation A.
 
201
Variable Beq : relation B.
 
202
 
 
203
Hypothesis EA_equiv : equiv A Aeq.
 
204
Hypothesis EB_equiv : equiv B Beq.
 
205
 
 
206
Definition prod_rel : relation (A * B) :=
 
207
  fun p1 p2 => Aeq (fst p1) (fst p2) /\ Beq (snd p1) (snd p2).
 
208
 
 
209
Lemma prod_rel_refl : reflexive (A * B) prod_rel.
 
210
Proof.
 
211
unfold reflexive, prod_rel.
 
212
destruct x; split; [apply (proj1 EA_equiv) | apply (proj1 EB_equiv)]; simpl.
 
213
Qed.
 
214
 
 
215
Lemma prod_rel_sym : symmetric (A * B) prod_rel.
 
216
Proof.
 
217
unfold symmetric, prod_rel.
 
218
destruct x; destruct y;
 
219
split; [apply (proj2 (proj2 EA_equiv)) | apply (proj2 (proj2 EB_equiv))]; simpl in *; tauto.
 
220
Qed.
 
221
 
 
222
Lemma prod_rel_trans : transitive (A * B) prod_rel.
 
223
Proof.
 
224
unfold transitive, prod_rel.
 
225
destruct x; destruct y; destruct z; simpl.
 
226
intros; split; [apply (proj1 (proj2 EA_equiv)) with (y := a0) |
 
227
apply (proj1 (proj2 EB_equiv)) with (y := b0)]; tauto.
 
228
Qed.
 
229
 
 
230
Theorem prod_rel_equiv : equiv (A * B) prod_rel.
 
231
Proof.
 
232
unfold equiv; split; [exact prod_rel_refl | split; [exact prod_rel_trans | exact prod_rel_sym]].
 
233
Qed.
 
234
 
 
235
End RelationOnProduct.
 
236
 
 
237
Implicit Arguments prod_rel [A B].
 
238
Implicit Arguments prod_rel_equiv [A B].
 
239
 
 
240
(** Miscellaneous *)
 
241
 
 
242
(*Definition comp_bool (x y : comparison) : bool :=
 
243
match x, y with
 
244
| Lt, Lt => true
 
245
| Eq, Eq => true
 
246
| Gt, Gt => true
 
247
| _, _   => false
 
248
end.
 
249
 
 
250
Theorem comp_bool_correct : forall x y : comparison,
 
251
  comp_bool x y <-> x = y.
 
252
Proof.
 
253
destruct x; destruct y; simpl; split; now intro.
 
254
Qed.*)
 
255
 
 
256
Lemma eq_equiv : forall A : Set, equiv A (@eq A).
 
257
Proof.
 
258
intro A; unfold equiv, reflexive, symmetric, transitive.
 
259
repeat split; [exact (@trans_eq A) | exact (@sym_eq A)].
 
260
(* It is interesting how the tactic split proves reflexivity *)
 
261
Qed.
 
262
 
 
263
(*Add Relation (fun A : Set => A) LE_Set
 
264
 reflexivity proved by (fun A : Set => (proj1 (eq_equiv A)))
 
265
 symmetry proved by (fun A : Set => (proj2 (proj2 (eq_equiv A))))
 
266
 transitivity proved by (fun A : Set => (proj1 (proj2 (eq_equiv A))))
 
267
as EA_rel.*)