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

« back to all changes in this revision

Viewing changes to theories/Numbers/Natural/Abstract/NDefOps.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: NDefOps.v 11674 2008-12-12 19:48:40Z letouzey $ i*)
 
12
 
 
13
Require Import Bool. (* To get the orb and negb function *)
 
14
Require Export NStrongRec.
 
15
 
 
16
Module NdefOpsPropFunct (Import NAxiomsMod : NAxiomsSig).
 
17
Module Export NStrongRecPropMod := NStrongRecPropFunct NAxiomsMod.
 
18
Open Local Scope NatScope.
 
19
 
 
20
(*****************************************************)
 
21
(**                   Addition                       *)
 
22
 
 
23
Definition def_add (x y : N) := recursion y (fun _ p => S p) x.
 
24
 
 
25
Infix Local "++" := def_add (at level 50, left associativity).
 
26
 
 
27
Add Morphism def_add with signature Neq ==> Neq ==> Neq as def_add_wd.
 
28
Proof.
 
29
unfold def_add.
 
30
intros x x' Exx' y y' Eyy'.
 
31
apply recursion_wd with (Aeq := Neq).
 
32
assumption.
 
33
unfold fun2_eq; intros _ _ _ p p' Epp'; now rewrite Epp'.
 
34
assumption.
 
35
Qed.
 
36
 
 
37
Theorem def_add_0_l : forall y : N, 0 ++ y == y.
 
38
Proof.
 
39
intro y. unfold def_add. now rewrite recursion_0.
 
40
Qed.
 
41
 
 
42
Theorem def_add_succ_l : forall x y : N, S x ++ y == S (x ++ y).
 
43
Proof.
 
44
intros x y; unfold def_add.
 
45
rewrite (@recursion_succ N Neq); try reflexivity.
 
46
unfold fun2_wd. intros _ _ _ m1 m2 H2. now rewrite H2.
 
47
Qed.
 
48
 
 
49
Theorem def_add_add : forall n m : N, n ++ m == n + m.
 
50
Proof.
 
51
intros n m; induct n.
 
52
now rewrite def_add_0_l, add_0_l.
 
53
intros n H. now rewrite def_add_succ_l, add_succ_l, H.
 
54
Qed.
 
55
 
 
56
(*****************************************************)
 
57
(**                  Multiplication                  *)
 
58
 
 
59
Definition def_mul (x y : N) := recursion 0 (fun _ p => p ++ x) y.
 
60
 
 
61
Infix Local "**" := def_mul (at level 40, left associativity).
 
62
 
 
63
Lemma def_mul_step_wd : forall x : N, fun2_wd Neq Neq Neq (fun _ p => def_add p x).
 
64
Proof.
 
65
unfold fun2_wd. intros. now apply def_add_wd.
 
66
Qed.
 
67
 
 
68
Lemma def_mul_step_equal :
 
69
  forall x x' : N, x == x' ->
 
70
    fun2_eq Neq Neq Neq (fun _ p => def_add p x) (fun x p => def_add p x').
 
71
Proof.
 
72
unfold fun2_eq; intros; apply def_add_wd; assumption.
 
73
Qed.
 
74
 
 
75
Add Morphism def_mul with signature Neq ==> Neq ==> Neq as def_mul_wd.
 
76
Proof.
 
77
unfold def_mul.
 
78
intros x x' Exx' y y' Eyy'.
 
79
apply recursion_wd with (Aeq := Neq).
 
80
reflexivity. apply def_mul_step_equal. assumption. assumption.
 
81
Qed.
 
82
 
 
83
Theorem def_mul_0_r : forall x : N, x ** 0 == 0.
 
84
Proof.
 
85
intro. unfold def_mul. now rewrite recursion_0.
 
86
Qed.
 
87
 
 
88
Theorem def_mul_succ_r : forall x y : N, x ** S y == x ** y ++ x.
 
89
Proof.
 
90
intros x y; unfold def_mul.
 
91
now rewrite (@recursion_succ N Neq); [| apply def_mul_step_wd |].
 
92
Qed.
 
93
 
 
94
Theorem def_mul_mul : forall n m : N, n ** m == n * m.
 
95
Proof.
 
96
intros n m; induct m.
 
97
now rewrite def_mul_0_r, mul_0_r.
 
98
intros m IH; now rewrite def_mul_succ_r, mul_succ_r, def_add_add, IH.
 
99
Qed.
 
100
 
 
101
(*****************************************************)
 
102
(**                     Order                        *)
 
103
 
 
104
Definition def_ltb (m : N) : N -> bool :=
 
105
recursion
 
106
  (if_zero false true)
 
107
  (fun _ f => fun n => recursion false (fun n' _ => f n') n)
 
108
  m.
 
109
 
 
110
Infix Local "<<" := def_ltb (at level 70, no associativity).
 
111
 
 
112
Lemma lt_base_wd : fun_wd Neq (@eq bool) (if_zero false true).
 
113
unfold fun_wd; intros; now apply if_zero_wd.
 
114
Qed.
 
115
 
 
116
Lemma lt_step_wd :
 
117
fun2_wd Neq (fun_eq Neq (@eq bool)) (fun_eq Neq (@eq bool))
 
118
  (fun _ f => fun n => recursion false (fun n' _ => f n') n).
 
119
Proof.
 
120
unfold fun2_wd, fun_eq.
 
121
intros x x' Exx' f f' Eff' y y' Eyy'.
 
122
apply recursion_wd with (Aeq := @eq bool).
 
123
reflexivity.
 
124
unfold fun2_eq; intros; now apply Eff'.
 
125
assumption.
 
126
Qed.
 
127
 
 
128
Lemma lt_curry_wd :
 
129
  forall m m' : N, m == m' -> fun_eq Neq (@eq bool) (def_ltb m) (def_ltb m').
 
130
Proof.
 
131
unfold def_ltb.
 
132
intros m m' Emm'.
 
133
apply recursion_wd with (Aeq := fun_eq Neq (@eq bool)).
 
134
apply lt_base_wd.
 
135
apply lt_step_wd.
 
136
assumption.
 
137
Qed.
 
138
 
 
139
Add Morphism def_ltb with signature Neq ==> Neq ==> (@eq bool) as def_ltb_wd.
 
140
Proof.
 
141
intros; now apply lt_curry_wd.
 
142
Qed.
 
143
 
 
144
Theorem def_ltb_base : forall n : N, 0 << n = if_zero false true n.
 
145
Proof.
 
146
intro n; unfold def_ltb; now rewrite recursion_0.
 
147
Qed.
 
148
 
 
149
Theorem def_ltb_step :
 
150
  forall m n : N, S m << n = recursion false (fun n' _ => m << n') n.
 
151
Proof.
 
152
intros m n; unfold def_ltb.
 
153
pose proof
 
154
  (@recursion_succ
 
155
    (N -> bool)
 
156
    (fun_eq Neq (@eq bool))
 
157
    (if_zero false true)
 
158
    (fun _ f => fun n => recursion false (fun n' _ => f n') n)
 
159
    lt_base_wd
 
160
    lt_step_wd
 
161
    m n n) as H.
 
162
now rewrite H.
 
163
Qed.
 
164
 
 
165
(* Above, we rewrite applications of function. Is it possible to rewrite
 
166
functions themselves, i.e., rewrite (recursion lt_base lt_step (S n)) to
 
167
lt_step n (recursion lt_base lt_step n)? *)
 
168
 
 
169
Theorem def_ltb_0 : forall n : N, n << 0 = false.
 
170
Proof.
 
171
cases n.
 
172
rewrite def_ltb_base; now rewrite if_zero_0.
 
173
intro n; rewrite def_ltb_step. now rewrite recursion_0.
 
174
Qed.
 
175
 
 
176
Theorem def_ltb_0_succ : forall n : N, 0 << S n = true.
 
177
Proof.
 
178
intro n; rewrite def_ltb_base; now rewrite if_zero_succ.
 
179
Qed.
 
180
 
 
181
Theorem succ_def_ltb_mono : forall n m : N, (S n << S m) = (n << m).
 
182
Proof.
 
183
intros n m.
 
184
rewrite def_ltb_step. rewrite (@recursion_succ bool (@eq bool)); try reflexivity.
 
185
unfold fun2_wd; intros; now apply def_ltb_wd.
 
186
Qed.
 
187
 
 
188
Theorem def_ltb_lt : forall n m : N, n << m = true <-> n < m.
 
189
Proof.
 
190
double_induct n m.
 
191
cases m.
 
192
rewrite def_ltb_0. split; intro H; [discriminate H | false_hyp H nlt_0_r].
 
193
intro n. rewrite def_ltb_0_succ. split; intro; [apply lt_0_succ | reflexivity].
 
194
intro n. rewrite def_ltb_0. split; intro H; [discriminate | false_hyp H nlt_0_r].
 
195
intros n m. rewrite succ_def_ltb_mono. now rewrite <- succ_lt_mono.
 
196
Qed.
 
197
 
 
198
(*
 
199
(*****************************************************)
 
200
(**                     Even                         *)
 
201
 
 
202
Definition even (x : N) := recursion true (fun _ p => negb p) x.
 
203
 
 
204
Lemma even_step_wd : fun2_wd Neq (@eq bool) (@eq bool) (fun x p => if p then false else true).
 
205
Proof.
 
206
unfold fun2_wd.
 
207
intros x x' Exx' b b' Ebb'.
 
208
unfold eq_bool; destruct b; destruct b'; now simpl.
 
209
Qed.
 
210
 
 
211
Add Morphism even with signature Neq ==> (@eq bool) as even_wd.
 
212
Proof.
 
213
unfold even; intros.
 
214
apply recursion_wd with (A := bool) (Aeq := (@eq bool)).
 
215
now unfold eq_bool.
 
216
unfold fun2_eq. intros _ _ _ b b' Ebb'. unfold eq_bool; destruct b; destruct b'; now simpl.
 
217
assumption.
 
218
Qed.
 
219
 
 
220
Theorem even_0 : even 0 = true.
 
221
Proof.
 
222
unfold even.
 
223
now rewrite recursion_0.
 
224
Qed.
 
225
 
 
226
Theorem even_succ : forall x : N, even (S x) = negb (even x).
 
227
Proof.
 
228
unfold even.
 
229
intro x; rewrite (recursion_succ (@eq bool)); try reflexivity.
 
230
unfold fun2_wd.
 
231
intros _ _ _ b b' Ebb'. destruct b; destruct b'; now simpl.
 
232
Qed.
 
233
 
 
234
(*****************************************************)
 
235
(**                Division by 2                     *)
 
236
 
 
237
Definition half_aux (x : N) : N * N :=
 
238
  recursion (0, 0) (fun _ p => let (x1, x2) := p in ((S x2, x1))) x.
 
239
 
 
240
Definition half (x : N) := snd (half_aux x).
 
241
 
 
242
Definition E2 := prod_rel Neq Neq.
 
243
 
 
244
Add Relation (prod N N) E2
 
245
reflexivity proved by (prod_rel_refl N N Neq Neq E_equiv E_equiv)
 
246
symmetry proved by (prod_rel_sym N N Neq Neq E_equiv E_equiv)
 
247
transitivity proved by (prod_rel_trans N N Neq Neq E_equiv E_equiv)
 
248
as E2_rel.
 
249
 
 
250
Lemma half_step_wd: fun2_wd Neq E2 E2 (fun _ p => let (x1, x2) := p in ((S x2, x1))).
 
251
Proof.
 
252
unfold fun2_wd, E2, prod_rel.
 
253
intros _ _ _ p1 p2 [H1 H2].
 
254
destruct p1; destruct p2; simpl in *.
 
255
now split; [rewrite H2 |].
 
256
Qed.
 
257
 
 
258
Add Morphism half with signature Neq ==> Neq as half_wd.
 
259
Proof.
 
260
unfold half.
 
261
assert (H: forall x y, x == y -> E2 (half_aux x) (half_aux y)).
 
262
intros x y Exy; unfold half_aux; apply recursion_wd with (Aeq := E2); unfold E2.
 
263
unfold E2.
 
264
unfold prod_rel; simpl; now split.
 
265
unfold fun2_eq, prod_rel; simpl.
 
266
intros _ _ _ p1 p2; destruct p1; destruct p2; simpl.
 
267
intros [H1 H2]; split; [rewrite H2 | assumption]. reflexivity. assumption.
 
268
unfold E2, prod_rel in H. intros x y Exy; apply H in Exy.
 
269
exact (proj2 Exy).
 
270
Qed.
 
271
 
 
272
(*****************************************************)
 
273
(**            Logarithm for the base 2              *)
 
274
 
 
275
Definition log (x : N) : N :=
 
276
strong_rec 0
 
277
           (fun x g =>
 
278
              if (e x 0) then 0
 
279
              else if (e x 1) then 0
 
280
              else S (g (half x)))
 
281
           x.
 
282
 
 
283
Add Morphism log with signature Neq ==> Neq as log_wd.
 
284
Proof.
 
285
intros x x' Exx'. unfold log.
 
286
apply strong_rec_wd with (Aeq := Neq); try (reflexivity || assumption).
 
287
unfold fun2_eq. intros y y' Eyy' g g' Egg'.
 
288
assert (H : e y 0 = e y' 0); [now apply e_wd|].
 
289
rewrite <- H; clear H.
 
290
assert (H : e y 1 = e y' 1); [now apply e_wd|].
 
291
rewrite <- H; clear H.
 
292
assert (H : S (g (half y)) == S (g' (half y')));
 
293
[apply succ_wd; apply Egg'; now apply half_wd|].
 
294
now destruct (e y 0); destruct (e y 1).
 
295
Qed.
 
296
*)
 
297
End NdefOpsPropFunct.
 
298