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

« back to all changes in this revision

Viewing changes to theories/Numbers/Natural/SpecViaZ/NSigNAxioms.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: NSigNAxioms.v 11282 2008-07-28 11:51:53Z msozeau $ i*)
 
10
 
 
11
Require Import ZArith.
 
12
Require Import Nnat.
 
13
Require Import NAxioms.
 
14
Require Import NSig.
 
15
 
 
16
(** * The interface [NSig.NType] implies the interface [NAxiomsSig] *)
 
17
 
 
18
Module NSig_NAxioms (N:NType) <: NAxiomsSig.
 
19
 
 
20
Delimit Scope IntScope with Int.
 
21
Bind Scope IntScope with N.t.
 
22
Open Local Scope IntScope.
 
23
Notation "[ x ]" := (N.to_Z x) : IntScope.
 
24
Infix "=="  := N.eq (at level 70) : IntScope.
 
25
Notation "0" := N.zero : IntScope.
 
26
Infix "+" := N.add : IntScope.
 
27
Infix "-" := N.sub : IntScope.
 
28
Infix "*" := N.mul : IntScope.
 
29
 
 
30
Module Export NZOrdAxiomsMod <: NZOrdAxiomsSig.
 
31
Module Export NZAxiomsMod <: NZAxiomsSig.
 
32
 
 
33
Definition NZ := N.t.
 
34
Definition NZeq := N.eq.
 
35
Definition NZ0 := N.zero.
 
36
Definition NZsucc := N.succ.
 
37
Definition NZpred := N.pred.
 
38
Definition NZadd := N.add.
 
39
Definition NZsub := N.sub.
 
40
Definition NZmul := N.mul.
 
41
 
 
42
Theorem NZeq_equiv : equiv N.t N.eq.
 
43
Proof.
 
44
repeat split; repeat red; intros; auto; congruence.
 
45
Qed.
 
46
 
 
47
Add Relation N.t N.eq
 
48
 reflexivity proved by (proj1 NZeq_equiv)
 
49
 symmetry proved by (proj2 (proj2 NZeq_equiv))
 
50
 transitivity proved by (proj1 (proj2 NZeq_equiv))
 
51
 as NZeq_rel.
 
52
 
 
53
Add Morphism NZsucc with signature N.eq ==> N.eq as NZsucc_wd.
 
54
Proof.
 
55
unfold N.eq; intros; rewrite 2 N.spec_succ; f_equal; auto.
 
56
Qed.
 
57
 
 
58
Add Morphism NZpred with signature N.eq ==> N.eq as NZpred_wd.
 
59
Proof.
 
60
unfold N.eq; intros.
 
61
generalize (N.spec_pos y) (N.spec_pos x) (N.spec_eq_bool x 0).
 
62
destruct N.eq_bool; rewrite N.spec_0; intros.
 
63
rewrite 2 N.spec_pred0; congruence.
 
64
rewrite 2 N.spec_pred; f_equal; auto; try omega.
 
65
Qed.
 
66
 
 
67
Add Morphism NZadd with signature N.eq ==> N.eq ==> N.eq as NZadd_wd.
 
68
Proof.
 
69
unfold N.eq; intros; rewrite 2 N.spec_add; f_equal; auto.
 
70
Qed.
 
71
 
 
72
Add Morphism NZsub with signature N.eq ==> N.eq ==> N.eq as NZsub_wd.
 
73
Proof.
 
74
unfold N.eq; intros x x' Hx y y' Hy.
 
75
destruct (Z_lt_le_dec [x] [y]).
 
76
rewrite 2 N.spec_sub0; f_equal; congruence.
 
77
rewrite 2 N.spec_sub; f_equal; congruence.
 
78
Qed.
 
79
 
 
80
Add Morphism NZmul with signature N.eq ==> N.eq ==> N.eq as NZmul_wd.
 
81
Proof.
 
82
unfold N.eq; intros; rewrite 2 N.spec_mul; f_equal; auto.
 
83
Qed.
 
84
 
 
85
Theorem NZpred_succ : forall n, N.pred (N.succ n) == n.
 
86
Proof.
 
87
unfold N.eq; intros.
 
88
rewrite N.spec_pred; rewrite N.spec_succ.
 
89
omega.
 
90
generalize (N.spec_pos n); omega.
 
91
Qed.
 
92
 
 
93
Definition N_of_Z z := N.of_N (Zabs_N z).
 
94
 
 
95
Section Induction.
 
96
 
 
97
Variable A : N.t -> Prop.
 
98
Hypothesis A_wd : predicate_wd N.eq A.
 
99
Hypothesis A0 : A 0.
 
100
Hypothesis AS : forall n, A n <-> A (N.succ n). 
 
101
 
 
102
Add Morphism A with signature N.eq ==> iff as A_morph.
 
103
Proof. apply A_wd. Qed.
 
104
 
 
105
Let B (z : Z) := A (N_of_Z z).
 
106
 
 
107
Lemma B0 : B 0.
 
108
Proof.
 
109
unfold B, N_of_Z; simpl.
 
110
rewrite <- (A_wd 0); auto.
 
111
red; rewrite N.spec_0, N.spec_of_N; auto.
 
112
Qed.
 
113
 
 
114
Lemma BS : forall z : Z, (0 <= z)%Z -> B z -> B (z + 1).
 
115
Proof.
 
116
intros z H1 H2.
 
117
unfold B in *. apply -> AS in H2.
 
118
setoid_replace (N_of_Z (z + 1)) with (N.succ (N_of_Z z)); auto.
 
119
unfold N.eq. rewrite N.spec_succ.
 
120
unfold N_of_Z.
 
121
rewrite 2 N.spec_of_N, 2 Z_of_N_abs, 2 Zabs_eq; auto with zarith.
 
122
Qed.
 
123
 
 
124
Lemma B_holds : forall z : Z, (0 <= z)%Z -> B z.
 
125
Proof.
 
126
exact (natlike_ind B B0 BS).
 
127
Qed.
 
128
 
 
129
Theorem NZinduction : forall n, A n.
 
130
Proof.
 
131
intro n. setoid_replace n with (N_of_Z (N.to_Z n)).
 
132
apply B_holds. apply N.spec_pos.
 
133
red; unfold N_of_Z.
 
134
rewrite N.spec_of_N, Z_of_N_abs, Zabs_eq; auto.
 
135
apply N.spec_pos.
 
136
Qed.
 
137
 
 
138
End Induction.
 
139
 
 
140
Theorem NZadd_0_l : forall n, 0 + n == n.
 
141
Proof.
 
142
intros; red; rewrite N.spec_add, N.spec_0; auto with zarith.
 
143
Qed.
 
144
 
 
145
Theorem NZadd_succ_l : forall n m, (N.succ n) + m == N.succ (n + m).
 
146
Proof.
 
147
intros; red; rewrite N.spec_add, 2 N.spec_succ, N.spec_add; auto with zarith.
 
148
Qed.
 
149
 
 
150
Theorem NZsub_0_r : forall n, n - 0 == n.
 
151
Proof.
 
152
intros; red; rewrite N.spec_sub; rewrite N.spec_0; auto with zarith.
 
153
apply N.spec_pos.
 
154
Qed.
 
155
 
 
156
Theorem NZsub_succ_r : forall n m, n - (N.succ m) == N.pred (n - m).
 
157
Proof.
 
158
intros; red.
 
159
destruct (Z_lt_le_dec [n] [N.succ m]) as [H|H].
 
160
rewrite N.spec_sub0; auto.
 
161
rewrite N.spec_succ in H.
 
162
rewrite N.spec_pred0; auto.
 
163
destruct (Z_eq_dec [n] [m]).
 
164
rewrite N.spec_sub; auto with zarith.
 
165
rewrite N.spec_sub0; auto with zarith.
 
166
 
 
167
rewrite N.spec_sub, N.spec_succ in *; auto.
 
168
rewrite N.spec_pred, N.spec_sub; auto with zarith.
 
169
rewrite N.spec_sub; auto with zarith.
 
170
Qed.
 
171
 
 
172
Theorem NZmul_0_l : forall n, 0 * n == 0.
 
173
Proof.
 
174
intros; red.
 
175
rewrite N.spec_mul, N.spec_0; auto with zarith.
 
176
Qed.
 
177
 
 
178
Theorem NZmul_succ_l : forall n m, (N.succ n) * m == n * m + m.
 
179
Proof.
 
180
intros; red.
 
181
rewrite N.spec_add, 2 N.spec_mul, N.spec_succ; ring.
 
182
Qed.
 
183
 
 
184
End NZAxiomsMod.
 
185
 
 
186
Definition NZlt := N.lt.
 
187
Definition NZle := N.le.
 
188
Definition NZmin := N.min.
 
189
Definition NZmax := N.max.
 
190
 
 
191
Infix "<=" := N.le : IntScope.
 
192
Infix "<" := N.lt : IntScope.
 
193
 
 
194
Lemma spec_compare_alt : forall x y, N.compare x y = ([x] ?= [y])%Z.
 
195
Proof.
 
196
 intros; generalize (N.spec_compare x y).
 
197
 destruct (N.compare x y); auto.
 
198
 intros H; rewrite H; symmetry; apply Zcompare_refl.
 
199
Qed.
 
200
 
 
201
Lemma spec_lt : forall x y, (x<y) <-> ([x]<[y])%Z.
 
202
Proof.
 
203
 intros; unfold N.lt, Zlt; rewrite spec_compare_alt; intuition.
 
204
Qed.
 
205
 
 
206
Lemma spec_le : forall x y, (x<=y) <-> ([x]<=[y])%Z.
 
207
Proof.
 
208
 intros; unfold N.le, Zle; rewrite spec_compare_alt; intuition.
 
209
Qed.
 
210
 
 
211
Lemma spec_min : forall x y, [N.min x y] = Zmin [x] [y].
 
212
Proof.
 
213
 intros; unfold N.min, Zmin.
 
214
 rewrite spec_compare_alt; destruct Zcompare; auto.
 
215
Qed.
 
216
 
 
217
Lemma spec_max : forall x y, [N.max x y] = Zmax [x] [y].
 
218
Proof.
 
219
 intros; unfold N.max, Zmax.
 
220
 rewrite spec_compare_alt; destruct Zcompare; auto.
 
221
Qed.
 
222
 
 
223
Add Morphism N.compare with signature N.eq ==> N.eq ==> (@eq comparison) as compare_wd.
 
224
Proof. 
 
225
intros x x' Hx y y' Hy.
 
226
rewrite 2 spec_compare_alt. unfold N.eq in *. rewrite Hx, Hy; intuition.
 
227
Qed.
 
228
 
 
229
Add Morphism N.lt with signature N.eq ==> N.eq ==> iff as NZlt_wd.
 
230
Proof.
 
231
intros x x' Hx y y' Hy; unfold N.lt; rewrite Hx, Hy; intuition.
 
232
Qed.
 
233
 
 
234
Add Morphism N.le with signature N.eq ==> N.eq ==> iff as NZle_wd.
 
235
Proof.
 
236
intros x x' Hx y y' Hy; unfold N.le; rewrite Hx, Hy; intuition.
 
237
Qed.
 
238
 
 
239
Add Morphism N.min with signature N.eq ==> N.eq ==> N.eq as NZmin_wd.
 
240
Proof.
 
241
intros; red; rewrite 2 spec_min; congruence.
 
242
Qed.
 
243
 
 
244
Add Morphism N.max with signature N.eq ==> N.eq ==> N.eq as NZmax_wd.
 
245
Proof.
 
246
intros; red; rewrite 2 spec_max; congruence.
 
247
Qed.
 
248
 
 
249
Theorem NZlt_eq_cases : forall n m, n <= m <-> n < m \/ n == m.
 
250
Proof.
 
251
intros.
 
252
unfold N.eq; rewrite spec_lt, spec_le; omega.
 
253
Qed.
 
254
 
 
255
Theorem NZlt_irrefl : forall n, ~ n < n.
 
256
Proof.
 
257
intros; rewrite spec_lt; auto with zarith.
 
258
Qed.
 
259
 
 
260
Theorem NZlt_succ_r : forall n m, n < (N.succ m) <-> n <= m.
 
261
Proof.
 
262
intros; rewrite spec_lt, spec_le, N.spec_succ; omega.
 
263
Qed.
 
264
 
 
265
Theorem NZmin_l : forall n m, n <= m -> N.min n m == n.
 
266
Proof.
 
267
intros n m; unfold N.eq; rewrite spec_le, spec_min.
 
268
generalize (Zmin_spec [n] [m]); omega.
 
269
Qed.
 
270
 
 
271
Theorem NZmin_r : forall n m, m <= n -> N.min n m == m.
 
272
Proof.
 
273
intros n m; unfold N.eq; rewrite spec_le, spec_min.
 
274
generalize (Zmin_spec [n] [m]); omega.
 
275
Qed.
 
276
 
 
277
Theorem NZmax_l : forall n m, m <= n -> N.max n m == n.
 
278
Proof.
 
279
intros n m; unfold N.eq; rewrite spec_le, spec_max.
 
280
generalize (Zmax_spec [n] [m]); omega.
 
281
Qed.
 
282
 
 
283
Theorem NZmax_r : forall n m, n <= m -> N.max n m == m.
 
284
Proof.
 
285
intros n m; unfold N.eq; rewrite spec_le, spec_max.
 
286
generalize (Zmax_spec [n] [m]); omega.
 
287
Qed.
 
288
 
 
289
End NZOrdAxiomsMod.
 
290
 
 
291
Theorem pred_0 : N.pred 0 == 0.
 
292
Proof.
 
293
red; rewrite N.spec_pred0; rewrite N.spec_0; auto.
 
294
Qed.
 
295
 
 
296
Definition recursion (A : Type) (a : A) (f : N.t -> A -> A) (n : N.t) :=
 
297
  Nrect (fun _ => A) a (fun n a => f (N.of_N n) a) (N.to_N n).
 
298
Implicit Arguments recursion [A].
 
299
 
 
300
Theorem recursion_wd :
 
301
forall (A : Type) (Aeq : relation A),
 
302
  forall a a' : A, Aeq a a' ->
 
303
    forall f f' : N.t -> A -> A, fun2_eq N.eq Aeq Aeq f f' ->
 
304
      forall x x' : N.t, x == x' ->
 
305
        Aeq (recursion a f x) (recursion a' f' x').
 
306
Proof.
 
307
unfold fun2_wd, N.eq, fun2_eq.
 
308
intros A Aeq a a' Eaa' f f' Eff' x x' Exx'.
 
309
unfold recursion.
 
310
unfold N.to_N.
 
311
rewrite <- Exx'; clear x' Exx'.
 
312
replace (Zabs_N [x]) with (N_of_nat (Zabs_nat [x])).
 
313
induction (Zabs_nat [x]).
 
314
simpl; auto.
 
315
rewrite N_of_S, 2 Nrect_step; auto.
 
316
destruct [x]; simpl; auto.
 
317
change (nat_of_P p) with (nat_of_N (Npos p)); apply N_of_nat_of_N.
 
318
change (nat_of_P p) with (nat_of_N (Npos p)); apply N_of_nat_of_N.
 
319
Qed.
 
320
 
 
321
Theorem recursion_0 :
 
322
  forall (A : Type) (a : A) (f : N.t -> A -> A), recursion a f 0 = a.
 
323
Proof.
 
324
intros A a f; unfold recursion, N.to_N; rewrite N.spec_0; simpl; auto.
 
325
Qed.
 
326
 
 
327
Theorem recursion_succ :
 
328
  forall (A : Type) (Aeq : relation A) (a : A) (f : N.t -> A -> A),
 
329
    Aeq a a -> fun2_wd N.eq Aeq Aeq f ->
 
330
      forall n, Aeq (recursion a f (N.succ n)) (f n (recursion a f n)).
 
331
Proof.
 
332
unfold N.eq, recursion, fun2_wd; intros A Aeq a f EAaa f_wd n.
 
333
replace (N.to_N (N.succ n)) with (Nsucc (N.to_N n)).
 
334
rewrite Nrect_step.
 
335
apply f_wd; auto.
 
336
unfold N.to_N.
 
337
rewrite N.spec_of_N, Z_of_N_abs, Zabs_eq; auto.
 
338
 apply N.spec_pos.
 
339
 
 
340
fold (recursion a f n).
 
341
apply recursion_wd; auto.
 
342
red; auto.
 
343
red; auto.
 
344
unfold N.to_N.
 
345
 
 
346
rewrite N.spec_succ.
 
347
change ([n]+1)%Z with (Zsucc [n]).
 
348
apply Z_of_N_eq_rev.
 
349
rewrite Z_of_N_succ.
 
350
rewrite 2 Z_of_N_abs.
 
351
rewrite 2 Zabs_eq; auto.
 
352
generalize (N.spec_pos n); auto with zarith.
 
353
apply N.spec_pos; auto.
 
354
Qed.
 
355
 
 
356
End NSig_NAxioms.