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
(************************************************************************)
9
(*i $Id: ZSigZAxioms.v 11282 2008-07-28 11:51:53Z msozeau $ i*)
11
Require Import ZArith.
12
Require Import ZAxioms.
15
(** * The interface [ZSig.ZType] implies the interface [ZAxiomsSig] *)
17
Module ZSig_ZAxioms (Z:ZType) <: ZAxiomsSig.
19
Delimit Scope IntScope with Int.
20
Bind Scope IntScope with Z.t.
21
Open Local Scope IntScope.
22
Notation "[ x ]" := (Z.to_Z x) : IntScope.
23
Infix "==" := Z.eq (at level 70) : IntScope.
24
Notation "0" := Z.zero : IntScope.
25
Infix "+" := Z.add : IntScope.
26
Infix "-" := Z.sub : IntScope.
27
Infix "*" := Z.mul : IntScope.
28
Notation "- x" := (Z.opp x) : IntScope.
31
Z.spec_0 Z.spec_1 Z.spec_add Z.spec_sub Z.spec_pred Z.spec_succ
32
Z.spec_mul Z.spec_opp Z.spec_of_Z : Zspec.
34
Ltac zsimpl := unfold Z.eq in *; autorewrite with Zspec.
36
Module Export NZOrdAxiomsMod <: NZOrdAxiomsSig.
37
Module Export NZAxiomsMod <: NZAxiomsSig.
40
Definition NZeq := Z.eq.
41
Definition NZ0 := Z.zero.
42
Definition NZsucc := Z.succ.
43
Definition NZpred := Z.pred.
44
Definition NZadd := Z.add.
45
Definition NZsub := Z.sub.
46
Definition NZmul := Z.mul.
48
Theorem NZeq_equiv : equiv Z.t Z.eq.
50
repeat split; repeat red; intros; auto; congruence.
54
reflexivity proved by (proj1 NZeq_equiv)
55
symmetry proved by (proj2 (proj2 NZeq_equiv))
56
transitivity proved by (proj1 (proj2 NZeq_equiv))
59
Add Morphism NZsucc with signature Z.eq ==> Z.eq as NZsucc_wd.
61
intros; zsimpl; f_equal; assumption.
64
Add Morphism NZpred with signature Z.eq ==> Z.eq as NZpred_wd.
66
intros; zsimpl; f_equal; assumption.
69
Add Morphism NZadd with signature Z.eq ==> Z.eq ==> Z.eq as NZadd_wd.
71
intros; zsimpl; f_equal; assumption.
74
Add Morphism NZsub with signature Z.eq ==> Z.eq ==> Z.eq as NZsub_wd.
76
intros; zsimpl; f_equal; assumption.
79
Add Morphism NZmul with signature Z.eq ==> Z.eq ==> Z.eq as NZmul_wd.
81
intros; zsimpl; f_equal; assumption.
84
Theorem NZpred_succ : forall n, Z.pred (Z.succ n) == n.
86
intros; zsimpl; auto with zarith.
91
Variable A : Z.t -> Prop.
92
Hypothesis A_wd : predicate_wd Z.eq A.
94
Hypothesis AS : forall n, A n <-> A (Z.succ n).
96
Add Morphism A with signature Z.eq ==> iff as A_morph.
97
Proof. apply A_wd. Qed.
99
Let B (z : Z) := A (Z.of_Z z).
104
rewrite <- (A_wd 0); auto.
108
Lemma BS : forall z : Z, B z -> B (z + 1).
111
unfold B in *. apply -> AS in H.
112
setoid_replace (Z.of_Z (z + 1)) with (Z.succ (Z.of_Z z)); auto.
116
Lemma BP : forall z : Z, B z -> B (z - 1).
119
unfold B in *. rewrite AS.
120
setoid_replace (Z.succ (Z.of_Z (z - 1))) with (Z.of_Z z); auto.
121
zsimpl; auto with zarith.
124
Lemma B_holds : forall z : Z, B z.
126
intros; destruct (Z_lt_le_dec 0 z).
127
apply natlike_ind; auto with zarith.
129
intros; apply BS; auto.
130
replace z with (-(-z))%Z in * by (auto with zarith).
131
remember (-z)%Z as z'.
132
pattern z'; apply natlike_ind.
134
intros; rewrite Zopp_succ; unfold Zpred; apply BP; auto.
135
subst z'; auto with zarith.
138
Theorem NZinduction : forall n, A n.
140
intro n. setoid_replace n with (Z.of_Z (Z.to_Z n)).
147
Theorem NZadd_0_l : forall n, 0 + n == n.
149
intros; zsimpl; auto with zarith.
152
Theorem NZadd_succ_l : forall n m, (Z.succ n) + m == Z.succ (n + m).
154
intros; zsimpl; auto with zarith.
157
Theorem NZsub_0_r : forall n, n - 0 == n.
159
intros; zsimpl; auto with zarith.
162
Theorem NZsub_succ_r : forall n m, n - (Z.succ m) == Z.pred (n - m).
164
intros; zsimpl; auto with zarith.
167
Theorem NZmul_0_l : forall n, 0 * n == 0.
169
intros; zsimpl; auto with zarith.
172
Theorem NZmul_succ_l : forall n m, (Z.succ n) * m == n * m + m.
174
intros; zsimpl; ring.
179
Definition NZlt := Z.lt.
180
Definition NZle := Z.le.
181
Definition NZmin := Z.min.
182
Definition NZmax := Z.max.
184
Infix "<=" := Z.le : IntScope.
185
Infix "<" := Z.lt : IntScope.
187
Lemma spec_compare_alt : forall x y, Z.compare x y = ([x] ?= [y])%Z.
189
intros; generalize (Z.spec_compare x y).
190
destruct (Z.compare x y); auto.
191
intros H; rewrite H; symmetry; apply Zcompare_refl.
194
Lemma spec_lt : forall x y, (x<y) <-> ([x]<[y])%Z.
196
intros; unfold Z.lt, Zlt; rewrite spec_compare_alt; intuition.
199
Lemma spec_le : forall x y, (x<=y) <-> ([x]<=[y])%Z.
201
intros; unfold Z.le, Zle; rewrite spec_compare_alt; intuition.
204
Lemma spec_min : forall x y, [Z.min x y] = Zmin [x] [y].
206
intros; unfold Z.min, Zmin.
207
rewrite spec_compare_alt; destruct Zcompare; auto.
210
Lemma spec_max : forall x y, [Z.max x y] = Zmax [x] [y].
212
intros; unfold Z.max, Zmax.
213
rewrite spec_compare_alt; destruct Zcompare; auto.
216
Add Morphism Z.compare with signature Z.eq ==> Z.eq ==> (@eq comparison) as compare_wd.
218
intros x x' Hx y y' Hy.
219
rewrite 2 spec_compare_alt; unfold Z.eq in *; rewrite Hx, Hy; intuition.
222
Add Morphism Z.lt with signature Z.eq ==> Z.eq ==> iff as NZlt_wd.
224
intros x x' Hx y y' Hy; unfold Z.lt; rewrite Hx, Hy; intuition.
227
Add Morphism Z.le with signature Z.eq ==> Z.eq ==> iff as NZle_wd.
229
intros x x' Hx y y' Hy; unfold Z.le; rewrite Hx, Hy; intuition.
232
Add Morphism Z.min with signature Z.eq ==> Z.eq ==> Z.eq as NZmin_wd.
234
intros; red; rewrite 2 spec_min; congruence.
237
Add Morphism Z.max with signature Z.eq ==> Z.eq ==> Z.eq as NZmax_wd.
239
intros; red; rewrite 2 spec_max; congruence.
242
Theorem NZlt_eq_cases : forall n m, n <= m <-> n < m \/ n == m.
245
unfold Z.eq; rewrite spec_lt, spec_le; omega.
248
Theorem NZlt_irrefl : forall n, ~ n < n.
250
intros; rewrite spec_lt; auto with zarith.
253
Theorem NZlt_succ_r : forall n m, n < (Z.succ m) <-> n <= m.
255
intros; rewrite spec_lt, spec_le, Z.spec_succ; omega.
258
Theorem NZmin_l : forall n m, n <= m -> Z.min n m == n.
260
intros n m; unfold Z.eq; rewrite spec_le, spec_min.
261
generalize (Zmin_spec [n] [m]); omega.
264
Theorem NZmin_r : forall n m, m <= n -> Z.min n m == m.
266
intros n m; unfold Z.eq; rewrite spec_le, spec_min.
267
generalize (Zmin_spec [n] [m]); omega.
270
Theorem NZmax_l : forall n m, m <= n -> Z.max n m == n.
272
intros n m; unfold Z.eq; rewrite spec_le, spec_max.
273
generalize (Zmax_spec [n] [m]); omega.
276
Theorem NZmax_r : forall n m, n <= m -> Z.max n m == m.
278
intros n m; unfold Z.eq; rewrite spec_le, spec_max.
279
generalize (Zmax_spec [n] [m]); omega.
284
Definition Zopp := Z.opp.
286
Add Morphism Z.opp with signature Z.eq ==> Z.eq as Zopp_wd.
288
intros; zsimpl; auto with zarith.
291
Theorem Zsucc_pred : forall n, Z.succ (Z.pred n) == n.
293
red; intros; zsimpl; auto with zarith.
296
Theorem Zopp_0 : - 0 == 0.
298
red; intros; zsimpl; auto with zarith.
301
Theorem Zopp_succ : forall n, - (Z.succ n) == Z.pred (- n).
303
intros; zsimpl; auto with zarith.