Debian Codegraph @

test-suite/interactive/ParalITP_smallproofs.v

raw
1 (* This program is free software; you can redistribute it and/or *)
2 (* modify it under the terms of the GNU Lesser General Public License *)
3 (* as published by the Free Software Foundation; either version 2.1 *)
4 (* of the License, or (at your option) any later version. *)
5 (* *)
6 (* This program is distributed in the hope that it will be useful, *)
7 (* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
8 (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
9 (* GNU General Public License for more details. *)
10 (* *)
11 (* You should have received a copy of the GNU Lesser General Public *)
12 (* License along with this program; if not, write to the Free *)
13 (* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
14 (* 02110-1301 USA *)
15
16
17 (** This file includes random facts about Integers (and natural numbers) which are not found in the standard library. Some of the lemma here are not used in the QArith development but are rather useful.
18 *)
19
20 Require Export ZArith.
21 Require Export ZArithRing.
22
23 Tactic Notation "ElimCompare" constr(c) constr(d) := elim_compare c d.
24
25 Ltac Flip :=
26 apply Zgt_lt || apply Zlt_gt || apply Zle_ge || apply Zge_le; assumption.
27
28 Ltac Falsum :=
29 try intro; apply False_ind;
30 repeat
31 match goal with
32 | id1:(~ ?X1) |- ?X2 =>
33 (apply id1; assumption || reflexivity) || clear id1
34 end.
35
36
37 Ltac Step_l a :=
38 match goal with
39 | |- (?X1 < ?X2)%Z => replace X1 with a; [ idtac | try ring ]
40 end.
41
42 Ltac Step_r a :=
43 match goal with
44 | |- (?X1 < ?X2)%Z => replace X2 with a; [ idtac | try ring ]
45 end.
46
47 Ltac CaseEq formula :=
48 generalize (refl_equal formula); pattern formula at -1 in |- *;
49 case formula.
50
51
52 Lemma pair_1 : forall (A B : Set) (H : A * B), H = pair (fst H) (snd H).
53 Proof.
54 intros.
55 case H.
56 intros.
57 simpl in |- *.
58 reflexivity.
59 Qed.
60
61 Lemma pair_2 :
62 forall (A B : Set) (H1 H2 : A * B),
63 fst H1 = fst H2 -> snd H1 = snd H2 -> H1 = H2.
64 Proof.
65 intros A B H1 H2.
66 case H1.
67 case H2.
68 simpl in |- *.
69 intros.
70 rewrite H.
71 rewrite H0.
72 reflexivity.
73 Qed.
74
75
76 Section projection.
77 Variable A : Set.
78 Variable P : A -> Prop.
79
80 Definition projP1 (H : sig P) := let (x, h) := H in x.
81 Definition projP2 (H : sig P) :=
82 let (x, h) as H return (P (projP1 H)) := H in h.
83 End projection.
84
85
86 (*###########################################################################*)
87 (* Declaring some relations on natural numbers for stepl and stepr tactics. *)
88 (*###########################################################################*)
89
90 Lemma le_stepl: forall x y z, le x y -> x=z -> le z y.
91 Proof.
92 intros x y z H_le H_eq; subst z; trivial.
93 Qed.
94
95 Lemma le_stepr: forall x y z, le x y -> y=z -> le x z.
96 Proof.
97 intros x y z H_le H_eq; subst z; trivial.
98 Qed.
99
100 Lemma lt_stepl: forall x y z, lt x y -> x=z -> lt z y.
101 Proof.
102 intros x y z H_lt H_eq; subst z; trivial.
103 Qed.
104
105 Lemma lt_stepr: forall x y z, lt x y -> y=z -> lt x z.
106 Proof.
107 intros x y z H_lt H_eq; subst z; trivial.
108 Qed.
109
110 Lemma neq_stepl:forall (x y z:nat), x<>y -> x=z -> z<>y.
111 Proof.
112 intros x y z H_lt H_eq; subst; assumption.
113 Qed.
114
115 Lemma neq_stepr:forall (x y z:nat), x<>y -> y=z -> x<>z.
116 Proof.
117 intros x y z H_lt H_eq; subst; assumption.
118 Qed.
119
120
121 Declare Left Step le_stepl.
122 Declare Right Step le_stepr.
123 Declare Left Step lt_stepl.
124 Declare Right Step lt_stepr.
125 Declare Left Step neq_stepl.
126 Declare Right Step neq_stepr.
127
128 (*###########################################################################*)
129 (** Some random facts about natural numbers, positive numbers and integers *)
130 (*###########################################################################*)
131
132
133 Lemma not_O_S : forall n : nat, n <> 0 -> {p : nat | n = S p}.
134 Proof.
135 intros [| np] Hn; [ exists 0; apply False_ind; apply Hn | exists np ];
136 reflexivity.
137 Qed.
138
139
140 Lemma lt_minus_neq : forall m n : nat, m < n -> n - m <> 0.
141 Proof.
142 intros.
143 lia.
144 Qed.
145
146 Lemma lt_minus_eq_0 : forall m n : nat, m < n -> m - n = 0.
147 Proof.
148 intros.
149 lia.
150 Qed.
151
152 Lemma le_plus_Sn_1_SSn : forall n : nat, S n + 1 <= S (S n).
153 Proof.
154 intros.
155 lia.
156 Qed.
157
158 Lemma le_plus_O_l : forall p q : nat, p + q <= 0 -> p = 0.
159 Proof.
160 intros; lia.
161 Qed.
162
163 Lemma le_plus_O_r : forall p q : nat, p + q <= 0 -> q = 0.
164 Proof.
165 intros; lia.
166 Qed.
167
168 Lemma minus_pred : forall m n : nat, 0 < n -> pred m - pred n = m - n.
169 Proof.
170 intros.
171 lia.
172 Qed.
173
174
175 (*###########################################################################*)
176 (* Declaring some relations on integers for stepl and stepr tactics. *)
177 (*###########################################################################*)
178
179 Lemma Zle_stepl: forall x y z, (x<=y)%Z -> x=z -> (z<=y)%Z.
180 Proof.
181 intros x y z H_le H_eq; subst z; trivial.
182 Qed.
183
184 Lemma Zle_stepr: forall x y z, (x<=y)%Z -> y=z -> (x<=z)%Z.
185 Proof.
186 intros x y z H_le H_eq; subst z; trivial.
187 Qed.
188
189 Lemma Zlt_stepl: forall x y z, (x<y)%Z -> x=z -> (z<y)%Z.
190 Proof.
191 intros x y z H_lt H_eq; subst z; trivial.
192 Qed.
193
194 Lemma Zlt_stepr: forall x y z, (x<y)%Z -> y=z -> (x<z)%Z.
195 Proof.
196 intros x y z H_lt H_eq; subst z; trivial.
197 Qed.
198
199 Lemma Zneq_stepl:forall (x y z:Z), (x<>y)%Z -> x=z -> (z<>y)%Z.
200 Proof.
201 intros x y z H_lt H_eq; subst; assumption.
202 Qed.
203
204 Lemma Zneq_stepr:forall (x y z:Z), (x<>y)%Z -> y=z -> (x<>z)%Z.
205 Proof.
206 intros x y z H_lt H_eq; subst; assumption.
207 Qed.
208
209 Declare Left Step Zle_stepl.
210 Declare Right Step Zle_stepr.
211 Declare Left Step Zlt_stepl.
212 Declare Right Step Zlt_stepr.
213 Declare Left Step Zneq_stepl.
214 Declare Right Step Zneq_stepr.
215
216
217 (*###########################################################################*)
218 (** Informative case analysis *)
219 (*###########################################################################*)
220
221 Lemma Zlt_cotrans :
222 forall x y : Z, (x < y)%Z -> forall z : Z, {(x < z)%Z} + {(z < y)%Z}.
223 Proof.
224 intros.
225 case (Z_lt_ge_dec x z).
226 intro.
227 left.
228 assumption.
229 intro.
230 right.
231 apply Zle_lt_trans with (m := x).
232 apply Zge_le.
233 assumption.
234 assumption.
235 Qed.
236
237 Lemma Zlt_cotrans_pos :
238 forall x y : Z, (0 < x + y)%Z -> {(0 < x)%Z} + {(0 < y)%Z}.
239 Proof.
240 intros.
241 case (Zlt_cotrans 0 (x + y) H x).
242 intro.
243 left.
244 assumption.
245 intro.
246 right.
247 apply Zplus_lt_reg_l with (p := x).
248 rewrite Zplus_0_r.
249 assumption.
250 Qed.
251
252
253 Lemma Zlt_cotrans_neg :
254 forall x y : Z, (x + y < 0)%Z -> {(x < 0)%Z} + {(y < 0)%Z}.
255 Proof.
256 intros x y H; case (Zlt_cotrans (x + y) 0 H x); intro Hxy;
257 [ right; apply Zplus_lt_reg_l with (p := x); rewrite Zplus_0_r | left ];
258 assumption.
259 Qed.
260
261
262
263 Lemma not_Zeq_inf : forall x y : Z, x <> y -> {(x < y)%Z} + {(y < x)%Z}.
264 Proof.
265 intros.
266 case Z_lt_ge_dec with x y.
267 intro.
268 left.
269 assumption.
270 intro H0.
271 generalize (Zge_le _ _ H0).
272 intro.
273 case (Z_le_lt_eq_dec _ _ H1).
274 intro.
275 right.
276 assumption.
277 intro.
278 apply False_rec.
279 apply H.
280 symmetry in |- *.
281 assumption.
282 Qed.
283
284 Lemma Z_dec : forall x y : Z, {(x < y)%Z} + {(x > y)%Z} + {x = y}.
285 Proof.
286 intros.
287 case (Z_lt_ge_dec x y).
288 intro H.
289 left.
290 left.
291 assumption.
292 intro H.
293 generalize (Zge_le _ _ H).
294 intro H0.
295 case (Z_le_lt_eq_dec y x H0).
296 intro H1.
297 left.
298 right.
299 apply Zlt_gt.
300 assumption.
301 intro.
302 right.
303 symmetry in |- *.
304 assumption.
305 Qed.
306
307
308 Lemma Z_dec' : forall x y : Z, {(x < y)%Z} + {(y < x)%Z} + {x = y}.
309 Proof.
310 intros x y.
311 case (Z_eq_dec x y); intro H;
312 [ right; assumption | left; apply (not_Zeq_inf _ _ H) ].
313 Qed.
314
315 Lemma Z_lt_le_dec : forall x y : Z, {(x < y)%Z} + {(y <= x)%Z}.
316 Proof.
317 intros.
318 case (Z_lt_ge_dec x y).
319 intro.
320 left.
321 assumption.
322 intro.
323 right.
324 apply Zge_le.
325 assumption.
326 Qed.
327
328 Lemma Z_le_lt_dec : forall x y : Z, {(x <= y)%Z} + {(y < x)%Z}.
329 Proof.
330 intros; case (Z_lt_le_dec y x); [ right | left ]; assumption.
331 Qed.
332
333 Lemma Z_lt_lt_S_eq_dec :
334 forall x y : Z, (x < y)%Z -> {(x + 1 < y)%Z} + {(x + 1)%Z = y}.
335 Proof.
336 intros.
337 generalize (Zlt_le_succ _ _ H).
338 unfold Zsucc in |- *.
339 apply Z_le_lt_eq_dec.
340 Qed.
341
342 Lemma quadro_leq_inf :
343 forall a b c d : Z,
344 {(c <= a)%Z /\ (d <= b)%Z} + {~ ((c <= a)%Z /\ (d <= b)%Z)}.
345 Proof.
346 intros.
347 case (Z_lt_le_dec a c).
348 intro z.
349 right.
350 intro.
351 elim H.
352 intros.
353 generalize z.
354 apply Zle_not_lt.
355 assumption.
356 intro.
357 case (Z_lt_le_dec b d).
358 intro z0.
359 right.
360 intro.
361 elim H.
362 intros.
363 generalize z0.
364 apply Zle_not_lt.
365 assumption.
366 intro.
367 left.
368 split.
369 assumption.
370 assumption.
371 Qed.
372
373 (*###########################################################################*)
374 (** General auxiliary lemmata *)
375 (*###########################################################################*)
376
377 Lemma Zminus_eq : forall x y : Z, (x - y)%Z = 0%Z -> x = y.
378 Proof.
379 intros.
380 apply Zplus_reg_l with (- y)%Z.
381 rewrite Zplus_opp_l.
382 unfold Zminus in H.
383 rewrite Zplus_comm.
384 assumption.
385 Qed.
386
387 Lemma Zlt_minus : forall a b : Z, (b < a)%Z -> (0 < a - b)%Z.
388 Proof.
389 intros a b.
390 intros.
391 apply Zplus_lt_reg_l with b.
392 unfold Zminus in |- *.
393 rewrite (Zplus_comm a).
394 rewrite (Zplus_assoc b (- b)).
395 rewrite Zplus_opp_r.
396 simpl in |- *.
397 rewrite <- Zplus_0_r_reverse.
398 assumption.
399 Qed.
400
401
402 Lemma Zle_minus : forall a b : Z, (b <= a)%Z -> (0 <= a - b)%Z.
403 Proof.
404 intros a b.
405 intros.
406 apply Zplus_le_reg_l with b.
407 unfold Zminus in |- *.
408 rewrite (Zplus_comm a).
409 rewrite (Zplus_assoc b (- b)).
410 rewrite Zplus_opp_r.
411 simpl in |- *.
412 rewrite <- Zplus_0_r_reverse.
413 assumption.
414 Qed.
415
416 Lemma Zlt_plus_plus :
417 forall m n p q : Z, (m < n)%Z -> (p < q)%Z -> (m + p < n + q)%Z.
418 Proof.
419 intros.
420 apply Zlt_trans with (m := (n + p)%Z).
421 rewrite Zplus_comm.
422 rewrite Zplus_comm with (n := n).
423 apply Zplus_lt_compat_l.
424 assumption.
425 apply Zplus_lt_compat_l.
426 assumption.
427 Qed.
428
429 Lemma Zgt_plus_plus :
430 forall m n p q : Z, (m > n)%Z -> (p > q)%Z -> (m + p > n + q)%Z.
431 intros.
432 apply Zgt_trans with (m := (n + p)%Z).
433 rewrite Zplus_comm.
434 rewrite Zplus_comm with (n := n).
435 apply Zplus_gt_compat_l.
436 assumption.
437 apply Zplus_gt_compat_l.
438 assumption.
439 Qed.
440
441 Lemma Zle_lt_plus_plus :
442 forall m n p q : Z, (m <= n)%Z -> (p < q)%Z -> (m + p < n + q)%Z.
443 Proof.
444 intros.
445 case (Zle_lt_or_eq m n).
446 assumption.
447 intro.
448 apply Zlt_plus_plus.
449 assumption.
450 assumption.
451 intro.
452 rewrite H1.
453 apply Zplus_lt_compat_l.
454 assumption.
455 Qed.
456
457 Lemma Zge_gt_plus_plus :
458 forall m n p q : Z, (m >= n)%Z -> (p > q)%Z -> (m + p > n + q)%Z.
459 Proof.
460 intros.
461 case (Zle_lt_or_eq n m).
462 apply Zge_le.
463 assumption.
464 intro.
465 apply Zgt_plus_plus.
466 apply Zlt_gt.
467 assumption.
468 assumption.
469 intro.
470 rewrite H1.
471 apply Zplus_gt_compat_l.
472 assumption.
473 Qed.
474
475 Lemma Zgt_ge_plus_plus :
476 forall m n p q : Z, (m > n)%Z -> (p >= q)%Z -> (m + p > n + q)%Z.
477 Proof.
478 intros.
479 rewrite Zplus_comm.
480 replace (n + q)%Z with (q + n)%Z.
481 apply Zge_gt_plus_plus.
482 assumption.
483 assumption.
484 apply Zplus_comm.
485 Qed.
486
487 Lemma Zlt_resp_pos : forall x y : Z, (0 < x)%Z -> (0 < y)%Z -> (0 < x + y)%Z.
488 Proof.
489 intros.
490 rewrite <- Zplus_0_r with 0%Z.
491 apply Zlt_plus_plus; assumption.
492 Qed.
493
494
495 Lemma Zle_resp_neg :
496 forall x y : Z, (x <= 0)%Z -> (y <= 0)%Z -> (x + y <= 0)%Z.
497 Proof.
498 intros.
499 rewrite <- Zplus_0_r with 0%Z.
500 apply Zplus_le_compat; assumption.
501 Qed.
502
503
504 Lemma Zlt_pos_opp : forall x : Z, (0 < x)%Z -> (- x < 0)%Z.
505 Proof.
506 intros.
507 apply Zplus_lt_reg_l with x.
508 rewrite Zplus_opp_r.
509 rewrite Zplus_0_r.
510 assumption.
511 Qed.
512
513 Lemma Zlt_neg_opp : forall x : Z, (x < 0)%Z -> (0 < - x)%Z.
514 Proof.
515 intros.
516 apply Zplus_lt_reg_l with x.
517 rewrite Zplus_opp_r.
518 rewrite Zplus_0_r.
519 assumption.
520 Qed.
521
522
523 Lemma Zle_neg_opp : forall x : Z, (x <= 0)%Z -> (0 <= - x)%Z.
524 Proof.
525 intros.
526 apply Zplus_le_reg_l with x.
527 rewrite Zplus_opp_r.
528 rewrite Zplus_0_r.
529 assumption.
530 Qed.
531
532 Lemma Zle_pos_opp : forall x : Z, (0 <= x)%Z -> (- x <= 0)%Z.
533 Proof.
534 intros.
535 apply Zplus_le_reg_l with x.
536 rewrite Zplus_opp_r.
537 rewrite Zplus_0_r.
538 assumption.
539 Qed.
540
541
542 Lemma Zge_opp : forall x y : Z, (x <= y)%Z -> (- x >= - y)%Z.
543 Proof.
544 intros.
545 apply Zle_ge.
546 apply Zplus_le_reg_l with (p := (x + y)%Z).
547 ring_simplify (x + y + - y)%Z (x + y + - x)%Z.
548 assumption.
549 Qed.
550
551
552
553 (* Omega can't solve this *)
554 Lemma Zmult_pos_pos : forall x y : Z, (0 < x)%Z -> (0 < y)%Z -> (0 < x * y)%Z.
555 Proof.
556 intros [| px| px] [| py| py] Hx Hy; trivial || constructor.
557 Qed.
558
559 Lemma Zmult_neg_neg : forall x y : Z, (x < 0)%Z -> (y < 0)%Z -> (0 < x * y)%Z.
560 Proof.
561 intros [| px| px] [| py| py] Hx Hy; trivial || constructor.
562 Qed.
563
564 Lemma Zmult_neg_pos : forall x y : Z, (x < 0)%Z -> (0 < y)%Z -> (x * y < 0)%Z.
565 Proof.
566 intros [| px| px] [| py| py] Hx Hy; trivial || constructor.
567 Qed.
568
569 Lemma Zmult_pos_neg : forall x y : Z, (0 < x)%Z -> (y < 0)%Z -> (x * y < 0)%Z.
570 Proof.
571 intros [| px| px] [| py| py] Hx Hy; trivial || constructor.
572 Qed.
573
574
575
576 Hint Resolve Zmult_pos_pos Zmult_neg_neg Zmult_neg_pos Zmult_pos_neg: zarith.
577
578
579 Lemma Zle_reg_mult_l :
580 forall x y a : Z, (0 < a)%Z -> (x <= y)%Z -> (a * x <= a * y)%Z.
581 Proof.
582 intros.
583 apply Zplus_le_reg_l with (p := (- a * x)%Z).
584 ring_simplify (- a * x + a * x)%Z.
585 replace (- a * x + a * y)%Z with ((y - x) * a)%Z.
586 apply Zmult_gt_0_le_0_compat.
587 apply Zlt_gt.
588 assumption.
589 unfold Zminus in |- *.
590 apply Zle_left.
591 assumption.
592 ring.
593 Qed.
594
595 Lemma Zsimpl_plus_l_dep :
596 forall x y m n : Z, (x + m)%Z = (y + n)%Z -> x = y -> m = n.
597 Proof.
598 intros.
599 apply Zplus_reg_l with x.
600 rewrite <- H0 in H.
601 assumption.
602 Qed.
603
604
605 Lemma Zsimpl_plus_r_dep :
606 forall x y m n : Z, (m + x)%Z = (n + y)%Z -> x = y -> m = n.
607 Proof.
608 intros.
609 apply Zplus_reg_l with x.
610 rewrite Zplus_comm.
611 rewrite Zplus_comm with x n.
612 rewrite <- H0 in H.
613 assumption.
614 Qed.
615
616 Lemma Zmult_simpl :
617 forall n m p q : Z, n = m -> p = q -> (n * p)%Z = (m * q)%Z.
618 Proof.
619 intros.
620 rewrite H.
621 rewrite H0.
622 reflexivity.
623 Qed.
624
625 Lemma Zsimpl_mult_l :
626 forall n m p : Z, n <> 0%Z -> (n * m)%Z = (n * p)%Z -> m = p.
627 Proof.
628 intros.
629 apply Zplus_reg_l with (n := (- p)%Z).
630 replace (- p + p)%Z with 0%Z.
631 apply Zmult_integral_l with (n := n).
632 assumption.
633 replace ((- p + m) * n)%Z with (n * m + - (n * p))%Z.
634 apply Zegal_left.
635 assumption.
636 ring.
637 ring.
638 Qed.
639
640 Lemma Zlt_reg_mult_l :
641 forall x y z : Z, (x > 0)%Z -> (y < z)%Z -> (x * y < x * z)%Z. (*QA*)
642 Proof.
643 intros.
644 case (Zcompare_Gt_spec x 0).
645 unfold Zgt in H.
646 assumption.
647 intros.
648 cut (x = Zpos x0).
649 intro.
650 rewrite H2.
651 unfold Zlt in H0.
652 unfold Zlt in |- *.
653 cut ((Zpos x0 * y ?= Zpos x0 * z)%Z = (y ?= z)%Z).
654 intro.
655 exact (trans_eq H3 H0).
656 apply Zcompare_mult_compat.
657 cut (x = (x + - (0))%Z).
658 intro.
659 exact (trans_eq H2 H1).
660 simpl in |- *.
661 apply (sym_eq (A:=Z)).
662 exact (Zplus_0_r x).
663 Qed.
664
665
666 Lemma Zlt_opp : forall x y : Z, (x < y)%Z -> (- x > - y)%Z. (*QA*)
667 Proof.
668 intros.
669 red in |- *.
670 apply sym_eq.
671 cut (Datatypes.Gt = (y ?= x)%Z).
672 intro.
673 cut ((y ?= x)%Z = (- x ?= - y)%Z).
674 intro.
675 exact (trans_eq H0 H1).
676 exact (Zcompare_opp y x).
677 apply sym_eq.
678 exact (Zlt_gt x y H).
679 Qed.
680
681
682 Lemma Zlt_conv_mult_l :
683 forall x y z : Z, (x < 0)%Z -> (y < z)%Z -> (x * y > x * z)%Z. (*QA*)
684 Proof.
685 intros.
686 cut (- x > 0)%Z.
687 intro.
688 cut (- x * y < - x * z)%Z.
689 intro.
690 cut (- (- x * y) > - (- x * z))%Z.
691 intro.
692 cut (- - (x * y) > - - (x * z))%Z.
693 intro.
694 cut ((- - (x * y))%Z = (x * y)%Z).
695 intro.
696 rewrite H5 in H4.
697 cut ((- - (x * z))%Z = (x * z)%Z).
698 intro.
699 rewrite H6 in H4.
700 assumption.
701 exact (Zopp_involutive (x * z)).
702 exact (Zopp_involutive (x * y)).
703 cut ((- (- x * y))%Z = (- - (x * y))%Z).
704 intro.
705 rewrite H4 in H3.
706 cut ((- (- x * z))%Z = (- - (x * z))%Z).
707 intro.
708 rewrite H5 in H3.
709 assumption.
710 cut ((- x * z)%Z = (- (x * z))%Z).
711 intro.
712 exact (f_equal Zopp H5).
713 exact (Zopp_mult_distr_l_reverse x z).
714 cut ((- x * y)%Z = (- (x * y))%Z).
715 intro.
716 exact (f_equal Zopp H4).
717 exact (Zopp_mult_distr_l_reverse x y).
718 exact (Zlt_opp (- x * y) (- x * z) H2).
719 exact (Zlt_reg_mult_l (- x) y z H1 H0).
720 exact (Zlt_opp x 0 H).
721 Qed.
722
723 Lemma Zgt_not_eq : forall x y : Z, (x > y)%Z -> x <> y. (*QA*)
724 Proof.
725 intros.
726 cut (y < x)%Z.
727 intro.
728 cut (y <> x).
729 intro.
730 red in |- *.
731 intros.
732 cut (y = x).
733 intros.
734 apply H1.
735 assumption.
736 exact (sym_eq H2).
737 exact (Zorder.Zlt_not_eq y x H0).
738 exact (Zgt_lt x y H).
739 Qed.
740
741 Lemma Zmult_resp_nonzero :
742 forall x y : Z, x <> 0%Z -> y <> 0%Z -> (x * y)%Z <> 0%Z.
743 Proof.
744 intros x y Hx Hy Hxy.
745 apply Hx.
746 apply Zmult_integral_l with y; assumption.
747 Qed.
748
749
750 Lemma Zopp_app : forall y : Z, y <> 0%Z -> (- y)%Z <> 0%Z.
751 Proof.
752 intros.
753 intro.
754 apply H.
755 apply Zplus_reg_l with (- y)%Z.
756 rewrite Zplus_opp_l.
757 rewrite H0.
758 simpl in |- *.
759 reflexivity.
760 Qed.
761
762
763 Lemma Zle_neq_Zlt : forall a b : Z, (a <= b)%Z -> b <> a -> (a < b)%Z.
764 Proof.
765 intros a b H H0.
766 case (Z_le_lt_eq_dec _ _ H); trivial.
767 intro; apply False_ind; apply H0; symmetry in |- *; assumption.
768 Qed.
769
770 Lemma not_Zle_lt : forall x y : Z, ~ (y <= x)%Z -> (x < y)%Z.
771 Proof.
772 intros; apply Zgt_lt; apply Znot_le_gt; assumption.
773 Qed.
774
775 Lemma not_Zlt : forall x y : Z, ~ (y < x)%Z -> (x <= y)%Z.
776 Proof.
777 intros x y H1 H2; apply H1; apply Zgt_lt; assumption.
778 Qed.
779
780
781 Lemma Zmult_absorb :
782 forall x y z : Z, x <> 0%Z -> (x * y)%Z = (x * z)%Z -> y = z. (*QA*)
783 Proof.
784 intros.
785 case (dec_eq y z).
786 intro.
787 assumption.
788 intro.
789 case (not_Zeq y z).
790 assumption.
791 intro.
792 case (not_Zeq x 0).
793 assumption.
794 intro.
795 apply False_ind.
796 cut (x * y > x * z)%Z.
797 intro.
798 cut ((x * y)%Z <> (x * z)%Z).
799 intro.
800 apply H5.
801 assumption.
802 exact (Zgt_not_eq (x * y) (x * z) H4).
803 exact (Zlt_conv_mult_l x y z H3 H2).
804 intro.
805 apply False_ind.
806 cut (x * y < x * z)%Z.
807 intro.
808 cut ((x * y)%Z <> (x * z)%Z).
809 intro.
810 apply H5.
811 assumption.
812 exact (Zorder.Zlt_not_eq (x * y) (x * z) H4).
813 cut (x > 0)%Z.
814 intro.
815 exact (Zlt_reg_mult_l x y z H4 H2).
816 exact (Zlt_gt 0 x H3).
817 intro.
818 apply False_ind.
819 cut (x * z < x * y)%Z.
820 intro.
821 cut ((x * z)%Z <> (x * y)%Z).
822 intro.
823 apply H4.
824 apply (sym_eq (A:=Z)).
825 assumption.
826 exact (Zorder.Zlt_not_eq (x * z) (x * y) H3).
827 apply False_ind.
828 case (not_Zeq x 0).
829 assumption.
830 intro.
831 cut (x * z > x * y)%Z.
832 intro.
833 cut ((x * z)%Z <> (x * y)%Z).
834 intro.
835 apply H5.
836 apply (sym_eq (A:=Z)).
837 assumption.
838 exact (Zgt_not_eq (x * z) (x * y) H4).
839 exact (Zlt_conv_mult_l x z y H3 H2).
840 intro.
841 cut (x * z < x * y)%Z.
842 intro.
843 cut ((x * z)%Z <> (x * y)%Z).
844 intro.
845 apply H5.
846 apply (sym_eq (A:=Z)).
847 assumption.
848 exact (Zorder.Zlt_not_eq (x * z) (x * y) H4).
849 cut (x > 0)%Z.
850 intro.
851 exact (Zlt_reg_mult_l x z y H4 H2).
852 exact (Zlt_gt 0 x H3).
853 Qed.
854
855 Lemma Zlt_mult_mult :
856 forall a b c d : Z,
857 (0 < a)%Z -> (0 < d)%Z -> (a < b)%Z -> (c < d)%Z -> (a * c < b * d)%Z.
858 Proof.
859 intros.
860 apply Zlt_trans with (a * d)%Z.
861 apply Zlt_reg_mult_l.
862 Flip.
863 assumption.
864 rewrite Zmult_comm.
865 rewrite Zmult_comm with b d.
866 apply Zlt_reg_mult_l.
867 Flip.
868 assumption.
869 Qed.
870
871 Lemma Zgt_mult_conv_absorb_l :
872 forall a x y : Z, (a < 0)%Z -> (a * x > a * y)%Z -> (x < y)%Z. (*QC*)
873 Proof.
874 intros.
875 case (dec_eq x y).
876 intro.
877 apply False_ind.
878 rewrite H1 in H0.
879 cut ((a * y)%Z = (a * y)%Z).
880 change ((a * y)%Z <> (a * y)%Z) in |- *.
881 apply Zgt_not_eq.
882 assumption.
883 trivial.
884
885 intro.
886 case (not_Zeq x y H1).
887 trivial.
888
889 intro.
890 apply False_ind.
891 cut (a * y > a * x)%Z.
892 apply Zgt_asym with (m := (a * y)%Z) (n := (a * x)%Z).
893 assumption.
894 apply Zlt_conv_mult_l.
895 assumption.
896 assumption.
897 Qed.
898
899 Lemma Zgt_mult_reg_absorb_l :
900 forall a x y : Z, (a > 0)%Z -> (a * x > a * y)%Z -> (x > y)%Z. (*QC*)
901 Proof.
902 intros.
903 cut (- - a > - - (0))%Z.
904 intro.
905 cut (- a < - (0))%Z.
906 simpl in |- *.
907 intro.
908 replace x with (- - x)%Z.
909 replace y with (- - y)%Z.
910 apply Zlt_opp.
911 apply Zgt_mult_conv_absorb_l with (a := (- a)%Z) (x := (- x)%Z).
912 assumption.
913 rewrite Zmult_opp_opp.
914 rewrite Zmult_opp_opp.
915 assumption.
916 apply Zopp_involutive.
917 apply Zopp_involutive.
918 apply Zgt_lt.
919 apply Zlt_opp.
920 apply Zgt_lt.
921 assumption.
922 simpl in |- *.
923 rewrite Zopp_involutive.
924 assumption.
925 Qed.
926
927 Lemma Zopp_Zlt : forall x y : Z, (y < x)%Z -> (- x < - y)%Z.
928 Proof.
929 intros x y Hyx.
930 apply Zgt_mult_conv_absorb_l with (a := (-1)%Z).
931 constructor.
932 replace (-1 * - y)%Z with y.
933 replace (-1 * - x)%Z with x.
934 Flip.
935 ring.
936 ring.
937 Qed.
938
939
940 Lemma Zmin_cancel_Zlt : forall x y : Z, (- x < - y)%Z -> (y < x)%Z.
941 Proof.
942 intros.
943 apply Zgt_mult_conv_absorb_l with (a := (-1)%Z).
944 constructor.
945 replace (-1 * y)%Z with (- y)%Z.
946 replace (-1 * x)%Z with (- x)%Z.
947 apply Zlt_gt.
948 assumption.
949 ring.
950 ring.
951 Qed.
952
953
954 Lemma Zmult_cancel_Zle :
955 forall a x y : Z, (a < 0)%Z -> (a * x <= a * y)%Z -> (y <= x)%Z.
956 Proof.
957 intros.
958 case (Z_le_gt_dec y x).
959 trivial.
960 intro.
961 apply False_ind.
962 apply (Zlt_irrefl (a * x)).
963 apply Zle_lt_trans with (m := (a * y)%Z).
964 assumption.
965 apply Zgt_lt.
966 apply Zlt_conv_mult_l.
967 assumption.
968 apply Zgt_lt.
969 assumption.
970 Qed.
971
972 Lemma Zlt_mult_cancel_l :
973 forall x y z : Z, (0 < x)%Z -> (x * y < x * z)%Z -> (y < z)%Z.
974 Proof.
975 intros.
976 apply Zgt_lt.
977 apply Zgt_mult_reg_absorb_l with x.
978 apply Zlt_gt.
979 assumption.
980 apply Zlt_gt.
981 assumption.
982 Qed.
983
984
985 Lemma Zmin_cancel_Zle : forall x y : Z, (- x <= - y)%Z -> (y <= x)%Z.
986 Proof.
987 intros.
988 apply Zmult_cancel_Zle with (a := (-1)%Z).
989 constructor.
990 replace (-1 * y)%Z with (- y)%Z.
991 replace (-1 * x)%Z with (- x)%Z.
992 assumption.
993 ring.
994 ring.
995 Qed.
996
997
998
999 Lemma Zmult_resp_Zle :
1000 forall a x y : Z, (0 < a)%Z -> (a * y <= a * x)%Z -> (y <= x)%Z.
1001 Proof.
1002 intros.
1003 case (Z_le_gt_dec y x).
1004 trivial.
1005 intro.
1006 apply False_ind.
1007 apply (Zlt_irrefl (a * y)).
1008 apply Zle_lt_trans with (m := (a * x)%Z).
1009 assumption.
1010 apply Zlt_reg_mult_l.
1011 apply Zlt_gt.
1012 assumption.
1013 apply Zgt_lt.
1014 assumption.
1015 Qed.
1016
1017 Lemma Zopp_Zle : forall x y : Z, (y <= x)%Z -> (- x <= - y)%Z.
1018 Proof.
1019 intros.
1020 apply Zmult_cancel_Zle with (a := (-1)%Z).
1021 constructor.
1022 replace (-1 * - y)%Z with y.
1023 replace (-1 * - x)%Z with x.
1024 assumption.
1025 clear y H; ring.
1026 clear x H; ring.
1027 Qed.
1028
1029
1030 Lemma Zle_lt_eq_S : forall x y : Z, (x <= y)%Z -> (y < x + 1)%Z -> y = x.
1031 Proof.
1032 intros.
1033 case (Z_le_lt_eq_dec x y H).
1034 intro H1.
1035 apply False_ind.
1036 generalize (Zlt_le_succ x y H1).
1037 intro.
1038 apply (Zlt_not_le y (x + 1) H0).
1039 replace (x + 1)%Z with (Zsucc x).
1040 assumption.
1041 reflexivity.
1042 intro H1.
1043 symmetry in |- *.
1044 assumption.
1045 Qed.
1046
1047 Lemma Zlt_le_eq_S :
1048 forall x y : Z, (x < y)%Z -> (y <= x + 1)%Z -> y = (x + 1)%Z.
1049 Proof.
1050 intros.
1051 case (Z_le_lt_eq_dec y (x + 1) H0).
1052 intro H1.
1053 apply False_ind.
1054 generalize (Zlt_le_succ x y H).
1055 intro.
1056 apply (Zlt_not_le y (x + 1) H1).
1057 replace (x + 1)%Z with (Zsucc x).
1058 assumption.
1059 reflexivity.
1060 trivial.
1061 Qed.
1062
1063
1064 Lemma double_not_equal_zero :
1065 forall c d : Z, ~ (c = 0%Z /\ d = 0%Z) -> c <> d \/ c <> 0%Z.
1066 Proof.
1067 intros.
1068 case (Z_zerop c).
1069 intro.
1070 rewrite e.
1071 left.
1072 apply sym_not_eq.
1073 intro.
1074 apply H; repeat split; assumption.
1075 intro; right; assumption.
1076 Qed.
1077
1078 Lemma triple_not_equal_zero :
1079 forall a b c : Z,
1080 ~ (a = 0%Z /\ b = 0%Z /\ c = 0%Z) -> a <> 0%Z \/ b <> 0%Z \/ c <> 0%Z.
1081 Proof.
1082 intros a b c H; case (Z_zerop a); intro Ha;
1083 [ case (Z_zerop b); intro Hb;
1084 [ case (Z_zerop c); intro Hc;
1085 [ apply False_ind; apply H; repeat split | right; right ]
1086 | right; left ]
1087 | left ]; assumption.
1088 Qed.
1089
1090 Lemma mediant_1 :
1091 forall m n m' n' : Z, (m' * n < m * n')%Z -> ((m + m') * n < m * (n + n'))%Z.
1092 Proof.
1093 intros.
1094 rewrite Zmult_plus_distr_r.
1095 rewrite Zmult_plus_distr_l.
1096 apply Zplus_lt_compat_l.
1097 assumption.
1098 Qed.
1099
1100 Lemma mediant_2 :
1101 forall m n m' n' : Z,
1102 (m' * n < m * n')%Z -> (m' * (n + n') < (m + m') * n')%Z.
1103 Proof.
1104 intros.
1105 rewrite Zmult_plus_distr_l.
1106 rewrite Zmult_plus_distr_r.
1107 apply Zplus_lt_compat_r.
1108 assumption.
1109 Qed.
1110
1111
1112 Lemma mediant_3 :
1113 forall a b m n m' n' : Z,
1114 (0 <= a * m + b * n)%Z ->
1115 (0 <= a * m' + b * n')%Z -> (0 <= a * (m + m') + b * (n + n'))%Z.
1116 Proof.
1117 intros.
1118 replace (a * (m + m') + b * (n + n'))%Z with
1119 (a * m + b * n + (a * m' + b * n'))%Z.
1120 apply Zplus_le_0_compat.
1121 assumption.
1122 assumption.
1123 ring.
1124 Qed.
1125
1126 Lemma fraction_lt_trans :
1127 forall a b c d e f : Z,
1128 (0 < b)%Z ->
1129 (0 < d)%Z ->
1130 (0 < f)%Z -> (a * d < c * b)%Z -> (c * f < e * d)%Z -> (a * f < e * b)%Z.
1131 Proof.
1132 intros.
1133 apply Zgt_lt.
1134 apply Zgt_mult_reg_absorb_l with d.
1135 Flip.
1136 apply Zgt_trans with (c * b * f)%Z.
1137 replace (d * (e * b))%Z with (b * (e * d))%Z.
1138 replace (c * b * f)%Z with (b * (c * f))%Z.
1139 apply Zlt_gt.
1140 apply Zlt_reg_mult_l.
1141 Flip.
1142 assumption.
1143 ring.
1144 ring.
1145 replace (c * b * f)%Z with (f * (c * b))%Z.
1146 replace (d * (a * f))%Z with (f * (a * d))%Z.
1147 apply Zlt_gt.
1148 apply Zlt_reg_mult_l.
1149 Flip.
1150 assumption.
1151 ring.
1152 ring.
1153 Qed.
1154
1155
1156 Lemma square_pos : forall a : Z, a <> 0%Z -> (0 < a * a)%Z.
1157 Proof.
1158 intros [| p| p]; intros; [ Falsum | constructor | constructor ].
1159 Qed.
1160
1161 Hint Resolve square_pos: zarith.
1162
1163 (*###########################################################################*)
1164 (** Properties of positive numbers, mapping between Z and nat *)
1165 (*###########################################################################*)
1166
1167
1168 Definition Z2positive (z : Z) :=
1169 match z with
1170 | Zpos p => p
1171 | Zneg p => p
1172 | Z0 => 1%positive
1173 end.
1174
1175
1176 Lemma ZL9 : forall p : positive, Z_of_nat (nat_of_P p) = Zpos p. (*QF*)
1177 Proof.
1178 intro.
1179 cut (exists h : nat, nat_of_P p = S h).
1180 intro.
1181 case H.
1182 intros.
1183 unfold Z_of_nat in |- *.
1184 rewrite H0.
1185
1186 apply f_equal with (A := positive) (B := Z) (f := Zpos).
1187 cut (P_of_succ_nat (nat_of_P p) = P_of_succ_nat (S x)).
1188 intro.
1189 rewrite P_of_succ_nat_o_nat_of_P_eq_succ in H1.
1190 cut (Ppred (Psucc p) = Ppred (P_of_succ_nat (S x))).
1191 intro.
1192 rewrite Ppred_succ in H2.
1193 simpl in H2.
1194 rewrite Ppred_succ in H2.
1195 apply sym_eq.
1196 assumption.
1197 apply f_equal with (A := positive) (B := positive) (f := Ppred).
1198 assumption.
1199 apply f_equal with (f := P_of_succ_nat).
1200 assumption.
1201 apply ZL4.
1202 Qed.
1203
1204 Coercion Z_of_nat : nat >-> Z.
1205
1206 Lemma ZERO_lt_POS : forall p : positive, (0 < Zpos p)%Z.
1207 Proof.
1208 intros.
1209 constructor.
1210 Qed.
1211
1212
1213 Lemma POS_neq_ZERO : forall p : positive, Zpos p <> 0%Z.
1214 Proof.
1215 intros.
1216 apply sym_not_eq.
1217 apply Zorder.Zlt_not_eq.
1218 apply ZERO_lt_POS.
1219 Qed.
1220
1221 Lemma NEG_neq_ZERO : forall p : positive, Zneg p <> 0%Z.
1222 Proof.
1223 intros.
1224 apply Zorder.Zlt_not_eq.
1225 unfold Zlt in |- *.
1226 constructor.
1227 Qed.
1228
1229
1230 Lemma POS_resp_eq : forall p0 p1 : positive, Zpos p0 = Zpos p1 -> p0 = p1.
1231 Proof.
1232 intros.
1233 injection H.
1234 trivial.
1235 Qed.
1236
1237 Lemma nat_nat_pos : forall m n : nat, ((m + 1) * (n + 1) > 0)%Z. (*QF*)
1238 Proof.
1239 intros.
1240 apply Zlt_gt.
1241 cut (Z_of_nat m + 1 > 0)%Z.
1242 intro.
1243 cut (0 < Z_of_nat n + 1)%Z.
1244 intro.
1245 cut ((Z_of_nat m + 1) * 0 < (Z_of_nat m + 1) * (Z_of_nat n + 1))%Z.
1246 rewrite Zmult_0_r.
1247 intro.
1248 assumption.
1249
1250 apply Zlt_reg_mult_l.
1251 assumption.
1252 assumption.
1253 change (0 < Zsucc (Z_of_nat n))%Z in |- *.
1254 apply Zle_lt_succ.
1255 change (Z_of_nat 0 <= Z_of_nat n)%Z in |- *.
1256 apply Znat.inj_le.
1257 apply le_O_n.
1258 apply Zlt_gt.
1259 change (0 < Zsucc (Z_of_nat m))%Z in |- *.
1260 apply Zle_lt_succ.
1261 change (Z_of_nat 0 <= Z_of_nat m)%Z in |- *.
1262 apply Znat.inj_le.
1263 apply le_O_n.
1264 Qed.
1265
1266
1267 Theorem S_predn : forall m : nat, m <> 0 -> S (pred m) = m. (*QF*)
1268 Proof.
1269 intros.
1270 case (O_or_S m).
1271 intro.
1272 case s.
1273 intros.
1274 rewrite <- e.
1275 rewrite <- pred_Sn with (n := x).
1276 trivial.
1277 intro.
1278 apply False_ind.
1279 apply H.
1280 apply sym_eq.
1281 assumption.
1282 Qed.
1283
1284 Lemma absolu_1 : forall x : Z, Zabs_nat x = 0 -> x = 0%Z. (*QF*)
1285 Proof.
1286 intros.
1287 case (dec_eq x 0).
1288 intro.
1289 assumption.
1290 intro.
1291 apply False_ind.
1292 cut ((x < 0)%Z \/ (x > 0)%Z).
1293 intro.
1294 ElimCompare x 0%Z.
1295 intro.
1296 cut (x = 0%Z).
1297 assumption.
1298 cut ((x ?= 0)%Z = Datatypes.Eq -> x = 0%Z).
1299 intro.
1300 apply H3.
1301 assumption.
1302 apply proj1 with (B := x = 0%Z -> (x ?= 0)%Z = Datatypes.Eq).
1303 change ((x ?= 0)%Z = Datatypes.Eq <-> x = 0%Z) in |- *.
1304 apply Zcompare_Eq_iff_eq.
1305
1306 (***)
1307 intro.
1308 cut (exists h : nat, Zabs_nat x = S h).
1309 intro.
1310 case H3.
1311 rewrite H.
1312 exact O_S.
1313
1314 change (x < 0)%Z in H2.
1315 cut (0 > x)%Z.
1316 intro.
1317 cut (exists p : positive, (0 + - x)%Z = Zpos p).
1318 simpl in |- *.
1319 intro.
1320 case H4.
1321 intros.
1322 cut (exists q : positive, x = Zneg q).
1323 intro.
1324 case H6.
1325 intros.
1326 rewrite H7.
1327 unfold Zabs_nat in |- *.
1328 generalize x1.
1329 exact ZL4.
1330 cut (x = (- Zpos x0)%Z).
1331 simpl in |- *.
1332 intro.
1333 exists x0.
1334 assumption.
1335 cut ((- - x)%Z = x).
1336 intro.
1337 rewrite <- H6.
1338 exact (f_equal Zopp H5).
1339 apply Zopp_involutive.
1340 apply Zcompare_Gt_spec.
1341 assumption.
1342 apply Zlt_gt.
1343 assumption.
1344
1345 (***)
1346 intro.
1347 cut (exists h : nat, Zabs_nat x = S h).
1348 intro.
1349 case H3.
1350 rewrite H.
1351 exact O_S.
1352
1353 cut (exists p : positive, (x + - (0))%Z = Zpos p).
1354 simpl in |- *.
1355 rewrite Zplus_0_r.
1356 intro.
1357 case H3.
1358 intros.
1359 rewrite H4.
1360 unfold Zabs_nat in |- *.
1361 generalize x0.
1362 exact ZL4.
1363 apply Zcompare_Gt_spec.
1364 assumption.
1365
1366 (***)
1367 cut ((x < 0)%Z \/ (0 < x)%Z).
1368 intro.
1369 apply
1370 or_ind with (A := (x < 0)%Z) (B := (0 < x)%Z) (P := (x < 0)%Z \/ (x > 0)%Z).
1371 intro.
1372 left.
1373 assumption.
1374 intro.
1375 right.
1376 apply Zlt_gt.
1377 assumption.
1378 assumption.
1379 apply not_Zeq.
1380 assumption.
1381 Qed.
1382
1383 Lemma absolu_2 : forall x : Z, x <> 0%Z -> Zabs_nat x <> 0. (*QF*)
1384 Proof.
1385 intros.
1386 intro.
1387 apply H.
1388 apply absolu_1.
1389 assumption.
1390 Qed.
1391
1392
1393
1394
1395 Lemma absolu_inject_nat : forall n : nat, Zabs_nat (Z_of_nat n) = n.
1396 Proof.
1397 simple induction n; simpl in |- *.
1398 reflexivity.
1399 intros.
1400 apply nat_of_P_o_P_of_succ_nat_eq_succ.
1401 Qed.
1402
1403
1404 Lemma eq_inj : forall m n : nat, m = n :>Z -> m = n.
1405 Proof.
1406 intros.
1407 generalize (f_equal Zabs_nat H).
1408 intro.
1409 rewrite (absolu_inject_nat m) in H0.
1410 rewrite (absolu_inject_nat n) in H0.
1411 assumption.
1412 Qed.
1413
1414 Lemma lt_inj : forall m n : nat, (m < n)%Z -> m < n.
1415 Proof.
1416 intros.
1417 lia.
1418 Qed.
1419
1420 Lemma le_inj : forall m n : nat, (m <= n)%Z -> m <= n.
1421 Proof.
1422 intros.
1423 lia.
1424 Qed.
1425
1426
1427 Lemma inject_nat_S_inf : forall x : Z, (0 < x)%Z -> {n : nat | x = S n}.
1428 Proof.
1429 intros [| p| p] Hp; try discriminate Hp.
1430 exists (pred (nat_of_P p)).
1431 rewrite S_predn.
1432 symmetry in |- *; apply ZL9.
1433 clear Hp;
1434 apply sym_not_equal; apply lt_O_neq; apply lt_O_nat_of_P.
1435 Qed.
1436
1437
1438
1439 Lemma le_absolu :
1440 forall x y : Z,
1441 (0 <= x)%Z -> (0 <= y)%Z -> (x <= y)%Z -> Zabs_nat x <= Zabs_nat y.
1442 Proof.
1443 intros [| x| x] [| y| y] Hx Hy Hxy;
1444 apply le_O_n ||
1445 (try
1446 match goal with
1447 | id1:(0 <= Zneg _)%Z |- _ =>
1448 apply False_ind; apply id1; constructor
1449 | id1:(Zpos _ <= 0)%Z |- _ =>
1450 apply False_ind; apply id1; constructor
1451 | id1:(Zpos _ <= Zneg _)%Z |- _ =>
1452 apply False_ind; apply id1; constructor
1453 end).
1454 simpl in |- *.
1455 apply le_inj.
1456 do 2 rewrite ZL9.
1457 assumption.
1458 Qed.
1459
1460 Lemma lt_absolu :
1461 forall x y : Z,
1462 (0 <= x)%Z -> (0 <= y)%Z -> (x < y)%Z -> Zabs_nat x < Zabs_nat y.
1463 Proof.
1464 intros [| x| x] [| y| y] Hx Hy Hxy; inversion Hxy;
1465 try
1466 match goal with
1467 | id1:(0 <= Zneg _)%Z |- _ =>
1468 apply False_ind; apply id1; constructor
1469 | id1:(Zpos _ <= 0)%Z |- _ =>
1470 apply False_ind; apply id1; constructor
1471 | id1:(Zpos _ <= Zneg _)%Z |- _ =>
1472 apply False_ind; apply id1; constructor
1473 end; simpl in |- *; apply lt_inj; repeat rewrite ZL9;
1474 assumption.
1475 Qed.
1476
1477 Lemma absolu_plus :
1478 forall x y : Z,
1479 (0 <= x)%Z -> (0 <= y)%Z -> Zabs_nat (x + y) = Zabs_nat x + Zabs_nat y.
1480 Proof.
1481 intros [| x| x] [| y| y] Hx Hy; trivial;
1482 try
1483 match goal with
1484 | id1:(0 <= Zneg _)%Z |- _ =>
1485 apply False_ind; apply id1; constructor
1486 | id1:(Zpos _ <= 0)%Z |- _ =>
1487 apply False_ind; apply id1; constructor
1488 | id1:(Zpos _ <= Zneg _)%Z |- _ =>
1489 apply False_ind; apply id1; constructor
1490 end.
1491 rewrite <- BinInt.Zpos_plus_distr.
1492 unfold Zabs_nat in |- *.
1493 apply nat_of_P_plus_morphism.
1494 Qed.
1495
1496 Lemma pred_absolu :
1497 forall x : Z, (0 < x)%Z -> pred (Zabs_nat x) = Zabs_nat (x - 1).
1498 Proof.
1499 intros x Hx.
1500 generalize (Z_lt_lt_S_eq_dec 0 x Hx); simpl in |- *; intros [H1| H1];
1501 [ replace (Zabs_nat x) with (Zabs_nat (x - 1 + 1));
1502 [ idtac | apply f_equal with Z; auto with zarith ];
1503 rewrite absolu_plus;
1504 [ unfold Zabs_nat at 2, nat_of_P, Piter_op in |- *; lia
1505 | auto with zarith
1506 | intro; discriminate ]
1507 | rewrite <- H1; reflexivity ].
1508 Qed.
1509
1510 Definition pred_nat : forall (x : Z) (Hx : (0 < x)%Z), nat.
1511 intros [| px| px] Hx; try abstract (discriminate Hx).
1512 exact (pred (nat_of_P px)).
1513 Defined.
1514
1515 Lemma pred_nat_equal :
1516 forall (x : Z) (Hx1 Hx2 : (0 < x)%Z), pred_nat x Hx1 = pred_nat x Hx2.
1517 Proof.
1518 intros [| px| px] Hx1 Hx2; try (discriminate Hx1); trivial.
1519 Qed.
1520
1521 Let pred_nat_unfolded_subproof px :
1522 Pos.to_nat px <> 0.
1523 Proof.
1524 apply sym_not_equal; apply lt_O_neq; apply lt_O_nat_of_P.
1525 Qed.
1526
1527 Lemma pred_nat_unfolded :
1528 forall (x : Z) (Hx : (0 < x)%Z), x = S (pred_nat x Hx).
1529 Proof.
1530 intros [| px| px] Hx; try discriminate Hx.
1531 unfold pred_nat in |- *.
1532 rewrite S_predn.
1533 symmetry in |- *; apply ZL9.
1534 clear Hx; apply pred_nat_unfolded_subproof.
1535 Qed.
1536
1537 Lemma absolu_pred_nat :
1538 forall (m : Z) (Hm : (0 < m)%Z), S (pred_nat m Hm) = Zabs_nat m.
1539 Proof.
1540 intros [| px| px] Hx; try discriminate Hx.
1541 unfold pred_nat in |- *.
1542 rewrite S_predn.
1543 reflexivity.
1544 apply pred_nat_unfolded_subproof.
1545 Qed.
1546
1547 Lemma pred_nat_absolu :
1548 forall (m : Z) (Hm : (0 < m)%Z), pred_nat m Hm = Zabs_nat (m - 1).
1549 Proof.
1550 intros [| px| px] Hx; try discriminate Hx.
1551 unfold pred_nat in |- *.
1552 rewrite <- pred_absolu; reflexivity || assumption.
1553 Qed.
1554
1555 Lemma minus_pred_nat :
1556 forall (n m : Z) (Hn : (0 < n)%Z) (Hm : (0 < m)%Z) (Hnm : (0 < n - m)%Z),
1557 S (pred_nat n Hn) - S (pred_nat m Hm) = S (pred_nat (n - m) Hnm).
1558 Proof.
1559 intros.
1560 simpl in |- *.
1561 destruct n; try discriminate Hn.
1562 destruct m; try discriminate Hm.
1563 unfold pred_nat at 1 2 in |- *.
1564 rewrite minus_pred; try apply lt_O_nat_of_P.
1565 apply eq_inj.
1566 rewrite <- pred_nat_unfolded.
1567 rewrite Znat.inj_minus1.
1568 repeat rewrite ZL9.
1569 reflexivity.
1570 apply le_inj.
1571 apply Zlt_le_weak.
1572 repeat rewrite ZL9.
1573 apply Zlt_O_minus_lt.
1574 assumption.
1575 Qed.
1576
1577
1578 (*###########################################################################*)
1579 (** Properties of Zsgn *)
1580 (*###########################################################################*)
1581
1582
1583 Lemma Zsgn_1 :
1584 forall x : Z, {Zsgn x = 0%Z} + {Zsgn x = 1%Z} + {Zsgn x = (-1)%Z}. (*QF*)
1585 Proof.
1586 intros.
1587 case x.
1588 left.
1589 left.
1590 unfold Zsgn in |- *.
1591 reflexivity.
1592 intro.
1593 simpl in |- *.
1594 left.
1595 right.
1596 reflexivity.
1597 intro.
1598 right.
1599 simpl in |- *.
1600 reflexivity.
1601 Qed.
1602
1603
1604 Lemma Zsgn_2 : forall x : Z, Zsgn x = 0%Z -> x = 0%Z. (*QF*)
1605 Proof.
1606 intros [| p1| p1]; simpl in |- *; intro H; constructor || discriminate H.
1607 Qed.
1608
1609
1610 Lemma Zsgn_3 : forall x : Z, x <> 0%Z -> Zsgn x <> 0%Z. (*QF*)
1611 Proof.
1612 intro.
1613 case x.
1614 intros.
1615 apply False_ind.
1616 apply H.
1617 reflexivity.
1618 intros.
1619 simpl in |- *.
1620 discriminate.
1621 intros.
1622 simpl in |- *.
1623 discriminate.
1624 Qed.
1625
1626
1627
1628
1629 Theorem Zsgn_4 : forall a : Z, a = (Zsgn a * Zabs_nat a)%Z. (*QF*)
1630 Proof.
1631 intro.
1632 case a.
1633 simpl in |- *.
1634 reflexivity.
1635 intro.
1636 unfold Zsgn in |- *.
1637 unfold Zabs_nat in |- *.
1638 rewrite Zmult_1_l.
1639 symmetry in |- *.
1640 apply ZL9.
1641 intros.
1642 unfold Zsgn in |- *.
1643 unfold Zabs_nat in |- *.
1644 rewrite ZL9.
1645 constructor.
1646 Qed.
1647
1648
1649 Theorem Zsgn_5 :
1650 forall a b x y : Z,
1651 x <> 0%Z ->
1652 y <> 0%Z ->
1653 (Zsgn a * x)%Z = (Zsgn b * y)%Z -> (Zsgn a * y)%Z = (Zsgn b * x)%Z. (*QF*)
1654 Proof.
1655 intros a b x y H H0.
1656 case a.
1657
1658 case b.
1659 simpl in |- *.
1660 trivial.
1661
1662 intro.
1663 unfold Zsgn in |- *.
1664 intro.
1665 rewrite Zmult_1_l in H1.
1666 simpl in H1.
1667 apply False_ind.
1668 apply H0.
1669 symmetry in |- *.
1670 assumption.
1671 intro.
1672 unfold Zsgn in |- *.
1673 intro.
1674 apply False_ind.
1675 apply H0.
1676 apply Zopp_inj.
1677 simpl in |- *.
1678 transitivity (-1 * y)%Z.
1679 constructor.
1680 transitivity (0 * x)%Z.
1681 symmetry in |- *.
1682 assumption.
1683 simpl in |- *.
1684 reflexivity.
1685 intro.
1686 unfold Zsgn at 1 in |- *.
1687 unfold Zsgn at 2 in |- *.
1688 intro.
1689 transitivity y.
1690 rewrite Zmult_1_l.
1691 reflexivity.
1692 transitivity (Zsgn b * (Zsgn b * y))%Z.
1693 case (Zsgn_1 b).
1694 intro.
1695 case s.
1696 intro.
1697 apply False_ind.
1698 apply H.
1699 rewrite e in H1.
1700 change ((1 * x)%Z = 0%Z) in H1.
1701 rewrite Zmult_1_l in H1.
1702 assumption.
1703 intro.
1704 rewrite e.
1705 rewrite Zmult_1_l.
1706 rewrite Zmult_1_l.
1707 reflexivity.
1708 intro.
1709 rewrite e.
1710 ring.
1711 rewrite Zmult_1_l in H1.
1712 rewrite H1.
1713 reflexivity.
1714 intro.
1715 unfold Zsgn at 1 in |- *.
1716 unfold Zsgn at 2 in |- *.
1717 intro.
1718 transitivity (Zsgn b * (-1 * (Zsgn b * y)))%Z.
1719 case (Zsgn_1 b).
1720 intros.
1721 case s.
1722 intro.
1723 apply False_ind.
1724 apply H.
1725 apply Zopp_inj.
1726 transitivity (-1 * x)%Z.
1727 ring.
1728 unfold Zopp in |- *.
1729 rewrite e in H1.
1730 transitivity (0 * y)%Z.
1731 assumption.
1732 simpl in |- *.
1733 reflexivity.
1734 intro.
1735 rewrite e.
1736 ring.
1737 intro.
1738 rewrite e.
1739 ring.
1740 rewrite <- H1.
1741 ring.
1742 Qed.
1743
1744 Lemma Zsgn_6 : forall x : Z, x = 0%Z -> Zsgn x = 0%Z.
1745 Proof.
1746 intros.
1747 rewrite H.
1748 simpl in |- *.
1749 reflexivity.
1750 Qed.
1751
1752
1753 Lemma Zsgn_7 : forall x : Z, (x > 0)%Z -> Zsgn x = 1%Z.
1754 Proof.
1755 intro.
1756 case x.
1757 intro.
1758 apply False_ind.
1759 apply (Zlt_irrefl 0).
1760 Flip.
1761 intros.
1762 simpl in |- *.
1763 reflexivity.
1764 intros.
1765 apply False_ind.
1766 apply (Zlt_irrefl (Zneg p)).
1767 apply Zlt_trans with 0%Z.
1768 constructor.
1769 Flip.
1770 Qed.
1771
1772
1773 Lemma Zsgn_7' : forall x : Z, (0 < x)%Z -> Zsgn x = 1%Z.
1774 Proof.
1775 intros; apply Zsgn_7; Flip.
1776 Qed.
1777
1778
1779 Lemma Zsgn_8 : forall x : Z, (x < 0)%Z -> Zsgn x = (-1)%Z.
1780 Proof.
1781 intro.
1782 case x.
1783 intro.
1784 apply False_ind.
1785 apply (Zlt_irrefl 0).
1786 assumption.
1787 intros.
1788 apply False_ind.
1789 apply (Zlt_irrefl 0).
1790 apply Zlt_trans with (Zpos p).
1791 constructor.
1792 assumption.
1793 intros.
1794 simpl in |- *.
1795 reflexivity.
1796 Qed.
1797
1798 Lemma Zsgn_9 : forall x : Z, Zsgn x = 1%Z -> (0 < x)%Z.
1799 Proof.
1800 intro.
1801 case x.
1802 intro.
1803 apply False_ind.
1804 simpl in H.
1805 discriminate.
1806 intros.
1807 constructor.
1808 intros.
1809 apply False_ind.
1810 discriminate.
1811 Qed.
1812
1813 Lemma Zsgn_10 : forall x : Z, Zsgn x = (-1)%Z -> (x < 0)%Z.
1814 Proof.
1815 intro.
1816 case x.
1817 intro.
1818 apply False_ind.
1819 discriminate.
1820 intros.
1821 apply False_ind.
1822 discriminate.
1823 intros.
1824 constructor.
1825 Qed.
1826
1827 Lemma Zsgn_11 : forall x : Z, (Zsgn x < 0)%Z -> (x < 0)%Z.
1828 Proof.
1829 intros.
1830 apply Zsgn_10.
1831 case (Zsgn_1 x).
1832 intro.
1833 apply False_ind.
1834 case s.
1835 intro.
1836 generalize (Zorder.Zlt_not_eq _ _ H).
1837 intro.
1838 apply (H0 e).
1839 intro.
1840 rewrite e in H.
1841 generalize (Zorder.Zlt_not_eq _ _ H).
1842 intro.
1843 discriminate.
1844 trivial.
1845 Qed.
1846
1847 Lemma Zsgn_12 : forall x : Z, (0 < Zsgn x)%Z -> (0 < x)%Z.
1848 Proof.
1849 intros.
1850 apply Zsgn_9.
1851 case (Zsgn_1 x).
1852 intro.
1853 case s.
1854 intro.
1855 generalize (Zorder.Zlt_not_eq _ _ H).
1856 intro.
1857 generalize (sym_eq e).
1858 intro.
1859 apply False_ind.
1860 apply (H0 H1).
1861 trivial.
1862 intro.
1863 rewrite e in H.
1864 generalize (Zorder.Zlt_not_eq _ _ H).
1865 intro.
1866 apply False_ind.
1867 discriminate.
1868 Qed.
1869
1870 Lemma Zsgn_13 : forall x : Z, (0 <= Zsgn x)%Z -> (0 <= x)%Z.
1871 Proof.
1872 intros.
1873 case (Z_le_lt_eq_dec 0 (Zsgn x) H).
1874 intro.
1875 apply Zlt_le_weak.
1876 apply Zsgn_12.
1877 assumption.
1878 intro.
1879 assert (x = 0%Z).
1880 apply Zsgn_2.
1881 symmetry in |- *.
1882 assumption.
1883 rewrite H0.
1884 apply Zle_refl.
1885 Qed.
1886
1887 Lemma Zsgn_14 : forall x : Z, (Zsgn x <= 0)%Z -> (x <= 0)%Z.
1888 Proof.
1889 intros.
1890 case (Z_le_lt_eq_dec (Zsgn x) 0 H).
1891 intro.
1892 apply Zlt_le_weak.
1893 apply Zsgn_11.
1894 assumption.
1895 intro.
1896 assert (x = 0%Z).
1897 apply Zsgn_2.
1898 assumption.
1899 rewrite H0.
1900 apply Zle_refl.
1901 Qed.
1902
1903 Lemma Zsgn_15 : forall x y : Z, Zsgn (x * y) = (Zsgn x * Zsgn y)%Z.
1904 Proof.
1905 intros [y| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *; constructor.
1906 Qed.
1907
1908 Lemma Zsgn_16 :
1909 forall x y : Z,
1910 Zsgn (x * y) = 1%Z -> {(0 < x)%Z /\ (0 < y)%Z} + {(x < 0)%Z /\ (y < 0)%Z}.
1911 Proof.
1912 intros [y| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *; intro H;
1913 try discriminate H; [ left | right ]; repeat split.
1914 Qed.
1915
1916 Lemma Zsgn_17 :
1917 forall x y : Z,
1918 Zsgn (x * y) = (-1)%Z -> {(0 < x)%Z /\ (y < 0)%Z} + {(x < 0)%Z /\ (0 < y)%Z}.
1919 Proof.
1920 intros [y| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *; intro H;
1921 try discriminate H; [ left | right ]; repeat split.
1922 Qed.
1923
1924 Lemma Zsgn_18 : forall x y : Z, Zsgn (x * y) = 0%Z -> {x = 0%Z} + {y = 0%Z}.
1925 Proof.
1926 intros [y| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *; intro H;
1927 try discriminate H; [ left | right | right ]; constructor.
1928 Qed.
1929
1930
1931
1932 Lemma Zsgn_19 : forall x y : Z, (0 < Zsgn x + Zsgn y)%Z -> (0 < x + y)%Z.
1933 Proof.
1934 Proof.
1935 intros [y| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *; intro H;
1936 discriminate H || (constructor || apply Zsgn_12; assumption).
1937 Qed.
1938
1939 Lemma Zsgn_20 : forall x y : Z, (Zsgn x + Zsgn y < 0)%Z -> (x + y < 0)%Z.
1940 Proof.
1941 Proof.
1942 intros [y| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *; intro H;
1943 discriminate H || (constructor || apply Zsgn_11; assumption).
1944 Qed.
1945
1946
1947 Lemma Zsgn_21 : forall x y : Z, (0 < Zsgn x + Zsgn y)%Z -> (0 <= x)%Z.
1948 Proof.
1949 intros [y| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *; intros H H0;
1950 discriminate H || discriminate H0.
1951 Qed.
1952
1953 Lemma Zsgn_22 : forall x y : Z, (Zsgn x + Zsgn y < 0)%Z -> (x <= 0)%Z.
1954 Proof.
1955 Proof.
1956 intros [y| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *; intros H H0;
1957 discriminate H || discriminate H0.
1958 Qed.
1959
1960 Lemma Zsgn_23 : forall x y : Z, (0 < Zsgn x + Zsgn y)%Z -> (0 <= y)%Z.
1961 Proof.
1962 intros [[| p2| p2]| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *;
1963 intros H H0; discriminate H || discriminate H0.
1964 Qed.
1965
1966 Lemma Zsgn_24 : forall x y : Z, (Zsgn x + Zsgn y < 0)%Z -> (y <= 0)%Z.
1967 Proof.
1968 intros [[| p2| p2]| p1 [| p2| p2]| p1 [| p2| p2]]; simpl in |- *;
1969 intros H H0; discriminate H || discriminate H0.
1970 Qed.
1971
1972 Lemma Zsgn_25 : forall x : Z, Zsgn (- x) = (- Zsgn x)%Z.
1973 Proof.
1974 intros [| p1| p1]; simpl in |- *; reflexivity.
1975 Qed.
1976
1977
1978 Lemma Zsgn_26 : forall x : Z, (0 < x)%Z -> (0 < Zsgn x)%Z.
1979 Proof.
1980 intros [| p| p] Hp; trivial.
1981 Qed.
1982
1983 Lemma Zsgn_27 : forall x : Z, (x < 0)%Z -> (Zsgn x < 0)%Z.
1984 Proof.
1985 intros [| p| p] Hp; trivial.
1986 Qed.
1987
1988 Hint Resolve Zsgn_1 Zsgn_2 Zsgn_3 Zsgn_4 Zsgn_5 Zsgn_6 Zsgn_7 Zsgn_7' Zsgn_8
1989 Zsgn_9 Zsgn_10 Zsgn_11 Zsgn_12 Zsgn_13 Zsgn_14 Zsgn_15 Zsgn_16 Zsgn_17
1990 Zsgn_18 Zsgn_19 Zsgn_20 Zsgn_21 Zsgn_22 Zsgn_23 Zsgn_24 Zsgn_25 Zsgn_26
1991 Zsgn_27: zarith.
1992
1993 (*###########################################################################*)
1994 (** Properties of Zabs *)
1995 (*###########################################################################*)
1996
1997 Lemma Zabs_1 : forall z p : Z, (Zabs z < p)%Z -> (z < p)%Z /\ (- p < z)%Z.
1998 Proof.
1999 intros z p.
2000 case z.
2001 intros.
2002 simpl in H.
2003 split.
2004 assumption.
2005 apply Zgt_mult_conv_absorb_l with (a := (-1)%Z).
2006 replace (-1)%Z with (Zpred 0).
2007 apply Zlt_pred.
2008 simpl; trivial.
2009 ring_simplify (-1 * - p)%Z (-1 * 0)%Z.
2010 apply Zlt_gt.
2011 assumption.
2012
2013 intros.
2014 simpl in H.
2015 split.
2016 assumption.
2017 apply Zlt_trans with (m := 0%Z).
2018 apply Zgt_mult_conv_absorb_l with (a := (-1)%Z).
2019 replace (-1)%Z with (Zpred 0).
2020 apply Zlt_pred.
2021 simpl; trivial.
2022 ring_simplify (-1 * - p)%Z (-1 * 0)%Z.
2023 apply Zlt_gt.
2024 apply Zlt_trans with (m := Zpos p0).
2025 constructor.
2026 assumption.
2027 constructor.
2028
2029 intros.
2030 simpl in H.
2031 split.
2032 apply Zlt_trans with (m := Zpos p0).
2033 constructor.
2034 assumption.
2035
2036 apply Zgt_mult_conv_absorb_l with (a := (-1)%Z).
2037 replace (-1)%Z with (Zpred 0).
2038 apply Zlt_pred.
2039 simpl;trivial.
2040 ring_simplify (-1 * - p)%Z.
2041 replace (-1 * Zneg p0)%Z with (- Zneg p0)%Z.
2042 replace (- Zneg p0)%Z with (Zpos p0).
2043 apply Zlt_gt.
2044 assumption.
2045 symmetry in |- *.
2046 apply Zopp_neg.
2047 rewrite Zopp_mult_distr_l_reverse with (n := 1%Z).
2048 simpl in |- *.
2049 constructor.
2050 Qed.
2051
2052
2053 Lemma Zabs_2 : forall z p : Z, (Zabs z > p)%Z -> (z > p)%Z \/ (- p > z)%Z.
2054 Proof.
2055 intros z p.
2056 case z.
2057 intros.
2058 simpl in H.
2059 left.
2060 assumption.
2061
2062 intros.
2063 simpl in H.
2064 left.
2065 assumption.
2066
2067 intros.
2068 simpl in H.
2069 right.
2070 apply Zlt_gt.
2071 apply Zgt_mult_conv_absorb_l with (a := (-1)%Z).
2072 constructor.
2073 ring_simplify (-1 * - p)%Z.
2074 replace (-1 * Zneg p0)%Z with (Zpos p0).
2075 assumption.
2076 reflexivity.
2077 Qed.
2078
2079 Lemma Zabs_3 : forall z p : Z, (z < p)%Z /\ (- p < z)%Z -> (Zabs z < p)%Z.
2080 Proof.
2081 intros z p.
2082 case z.
2083 intro.
2084 simpl in |- *.
2085 elim H.
2086 intros.
2087 assumption.
2088
2089 intros.
2090 elim H.
2091 intros.
2092 simpl in |- *.
2093 assumption.
2094
2095 intros.
2096 elim H.
2097 intros.
2098 simpl in |- *.
2099 apply Zgt_mult_conv_absorb_l with (a := (-1)%Z).
2100 constructor.
2101 replace (-1 * Zpos p0)%Z with (Zneg p0).
2102 replace (-1 * p)%Z with (- p)%Z.
2103 apply Zlt_gt.
2104 assumption.
2105 ring.
2106 simpl in |- *.
2107 reflexivity.
2108 Qed.
2109
2110 Lemma Zabs_4 : forall z p : Z, (Zabs z < p)%Z -> (- p < z < p)%Z.
2111 Proof.
2112 intros.
2113 split.
2114 apply proj2 with (A := (z < p)%Z).
2115 apply Zabs_1.
2116 assumption.
2117 apply proj1 with (B := (- p < z)%Z).
2118 apply Zabs_1.
2119 assumption.
2120 Qed.
2121
2122
2123 Lemma Zabs_5 : forall z p : Z, (Zabs z <= p)%Z -> (- p <= z <= p)%Z.
2124 Proof.
2125 intros.
2126 split.
2127 replace (- p)%Z with (Zsucc (- Zsucc p)).
2128 apply Zlt_le_succ.
2129 apply proj2 with (A := (z < Zsucc p)%Z).
2130 apply Zabs_1.
2131 apply Zle_lt_succ.
2132 assumption.
2133 unfold Zsucc in |- *.
2134 ring.
2135 apply Zlt_succ_le.
2136 apply proj1 with (B := (- Zsucc p < z)%Z).
2137 apply Zabs_1.
2138 apply Zle_lt_succ.
2139 assumption.
2140 Qed.
2141
2142 Lemma Zabs_6 : forall z p : Z, (Zabs z <= p)%Z -> (z <= p)%Z.
2143 Proof.
2144 intros.
2145 apply proj2 with (A := (- p <= z)%Z).
2146 apply Zabs_5.
2147 assumption.
2148 Qed.
2149
2150 Lemma Zabs_7 : forall z p : Z, (Zabs z <= p)%Z -> (- p <= z)%Z.
2151 Proof.
2152 intros.
2153 apply proj1 with (B := (z <= p)%Z).
2154 apply Zabs_5.
2155 assumption.
2156 Qed.
2157
2158 Lemma Zabs_8 : forall z p : Z, (- p <= z <= p)%Z -> (Zabs z <= p)%Z.
2159 Proof.
2160 intros.
2161 apply Zlt_succ_le.
2162 apply Zabs_3.
2163 elim H.
2164 intros.
2165 split.
2166 apply Zle_lt_succ.
2167 assumption.
2168 apply Zlt_le_trans with (m := (- p)%Z).
2169 apply Zgt_lt.
2170 apply Zlt_opp.
2171 apply Zlt_succ.
2172 assumption.
2173 Qed.
2174
2175 Lemma Zabs_min : forall z : Z, Zabs z = Zabs (- z).
2176 Proof.
2177 intro.
2178 case z.
2179 simpl in |- *.
2180 reflexivity.
2181 intro.
2182 simpl in |- *.
2183 reflexivity.
2184 intro.
2185 simpl in |- *.
2186 reflexivity.
2187 Qed.
2188
2189 Lemma Zabs_9 :
2190 forall z p : Z, (0 <= p)%Z -> (p < z)%Z \/ (z < - p)%Z -> (p < Zabs z)%Z.
2191 Proof.
2192 intros.
2193 case H0.
2194 intro.
2195 replace (Zabs z) with z.
2196 assumption.
2197 symmetry in |- *.
2198 apply Zabs_eq.
2199 apply Zlt_le_weak.
2200 apply Zle_lt_trans with (m := p).
2201 assumption.
2202 assumption.
2203 intro.
2204 cut (Zabs z = (- z)%Z).
2205 intro.
2206 rewrite H2.
2207 apply Zmin_cancel_Zlt.
2208 ring_simplify (- - z)%Z.
2209 assumption.
2210 rewrite Zabs_min.
2211 apply Zabs_eq.
2212 apply Zlt_le_weak.
2213 apply Zle_lt_trans with (m := p).
2214 assumption.
2215 apply Zmin_cancel_Zlt.
2216 ring_simplify (- - z)%Z.
2217 assumption.
2218 Qed.
2219
2220 Lemma Zabs_10 : forall z : Z, (0 <= Zabs z)%Z.
2221 Proof.
2222 intro.
2223 case (Z_zerop z).
2224 intro.
2225 rewrite e.
2226 simpl in |- *.
2227 apply Zle_refl.
2228 intro.
2229 case (not_Zeq z 0 n).
2230 intro.
2231 apply Zlt_le_weak.
2232 apply Zabs_9.
2233 apply Zle_refl.
2234 simpl in |- *.
2235 right.
2236 assumption.
2237 intro.
2238 apply Zlt_le_weak.
2239 apply Zabs_9.
2240 apply Zle_refl.
2241 simpl in |- *.
2242 left.
2243 assumption.
2244 Qed.
2245
2246 Lemma Zabs_11 : forall z : Z, z <> 0%Z -> (0 < Zabs z)%Z.
2247 Proof.
2248 intros.
2249 apply Zabs_9.
2250 apply Zle_refl.
2251 simpl in |- *.
2252 apply not_Zeq.
2253 intro.
2254 apply H.
2255 symmetry in |- *.
2256 assumption.
2257 Qed.
2258
2259 Lemma Zabs_12 : forall z m : Z, (m < Zabs z)%Z -> {(m < z)%Z} + {(z < - m)%Z}.
2260 Proof.
2261 intros [| p| p] m; simpl in |- *; intros H;
2262 [ left | left | right; apply Zmin_cancel_Zlt; rewrite Zopp_involutive ];
2263 assumption.
2264 Qed.
2265
2266 Lemma Zabs_mult : forall z p : Z, Zabs (z * p) = (Zabs z * Zabs p)%Z.
2267 Proof.
2268 intros.
2269 case z.
2270 simpl in |- *.
2271 reflexivity.
2272 case p.
2273 simpl in |- *.
2274 reflexivity.
2275 intros.
2276 simpl in |- *.
2277 reflexivity.
2278 intros.
2279 simpl in |- *.
2280 reflexivity.
2281 case p.
2282 intro.
2283 simpl in |- *.
2284 reflexivity.
2285 intros.
2286 simpl in |- *.
2287 reflexivity.
2288 intros.
2289 simpl in |- *.
2290 reflexivity.
2291 Qed.
2292
2293 Lemma Zabs_plus : forall z p : Z, (Zabs (z + p) <= Zabs z + Zabs p)%Z.
2294 Proof.
2295 intros.
2296 case z.
2297 simpl in |- *.
2298 apply Zle_refl.
2299 case p.
2300 intro.
2301 simpl in |- *.
2302 apply Zle_refl.
2303 intros.
2304 simpl in |- *.
2305 apply Zle_refl.
2306 intros.
2307 unfold Zabs at 2 in |- *.
2308 unfold Zabs at 2 in |- *.
2309 apply Zabs_8.
2310 split.
2311 apply Zplus_le_reg_l with (Zpos p1 - Zneg p0)%Z.
2312 replace (Zpos p1 - Zneg p0 + - (Zpos p1 + Zpos p0))%Z with
2313 (- (Zpos p0 + Zneg p0))%Z.
2314 replace (Zpos p1 - Zneg p0 + (Zpos p1 + Zneg p0))%Z with (2 * Zpos p1)%Z.
2315 replace (- (Zpos p0 + Zneg p0))%Z with 0%Z.
2316 apply Zmult_gt_0_le_0_compat.
2317 constructor.
2318 apply Zlt_le_weak.
2319 constructor.
2320 rewrite <- Zopp_neg with p0.
2321 ring.
2322 ring.
2323 ring.
2324 apply Zplus_le_compat.
2325 apply Zle_refl.
2326 apply Zlt_le_weak.
2327 constructor.
2328
2329 case p.
2330 simpl in |- *.
2331 intro.
2332 apply Zle_refl.
2333 intros.
2334 unfold Zabs at 2 in |- *.
2335 unfold Zabs at 2 in |- *.
2336 apply Zabs_8.
2337 split.
2338 apply Zplus_le_reg_l with (Zpos p1 + Zneg p0)%Z.
2339 replace (Zpos p1 + Zneg p0 + - (Zpos p1 + Zpos p0))%Z with
2340 (Zneg p0 - Zpos p0)%Z.
2341 replace (Zpos p1 + Zneg p0 + (Zneg p1 + Zpos p0))%Z with 0%Z.
2342 apply Zplus_le_reg_l with (Zpos p0).
2343 replace (Zpos p0 + (Zneg p0 - Zpos p0))%Z with (Zneg p0).
2344 simpl in |- *.
2345 apply Zlt_le_weak.
2346 constructor.
2347 ring.
2348 replace (Zpos p1 + Zneg p0 + (Zneg p1 + Zpos p0))%Z with
2349 (Zpos p1 + Zneg p1 + (Zpos p0 + Zneg p0))%Z.
2350 replace 0%Z with (0 + 0)%Z.
2351 apply Zplus_eq_compat.
2352 rewrite <- Zopp_neg with p1.
2353 ring.
2354 rewrite <- Zopp_neg with p0.
2355 ring.
2356 simpl in |- *.
2357 constructor.
2358 ring.
2359 ring.
2360 apply Zplus_le_compat.
2361 apply Zlt_le_weak.
2362 constructor.
2363 apply Zle_refl.
2364 intros.
2365 simpl in |- *.
2366 apply Zle_refl.
2367 Qed.
2368
2369 Lemma Zabs_neg : forall z : Z, (z <= 0)%Z -> Zabs z = (- z)%Z.
2370 Proof.
2371 intro.
2372 case z.
2373 simpl in |- *.
2374 intro.
2375 reflexivity.
2376 intros.
2377 apply False_ind.
2378 apply H.
2379 simpl in |- *.
2380 reflexivity.
2381 intros.
2382 simpl in |- *.
2383 reflexivity.
2384 Qed.
2385
2386 Lemma Zle_Zabs: forall z, (z <= Zabs z)%Z.
2387 Proof.
2388 intros [|z|z]; simpl; auto with zarith; apply Zle_neg_pos.
2389 Qed.
2390
2391 Hint Resolve Zabs_1 Zabs_2 Zabs_3 Zabs_4 Zabs_5 Zabs_6 Zabs_7 Zabs_8 Zabs_9
2392 Zabs_10 Zabs_11 Zabs_12 Zabs_min Zabs_neg Zabs_mult Zabs_plus Zle_Zabs: zarith.
2393
2394
2395 (*###########################################################################*)
2396 (** Induction on Z *)
2397 (*###########################################################################*)
2398
2399 Lemma Zind :
2400 forall (P : Z -> Prop) (p : Z),
2401 P p ->
2402 (forall q : Z, (p <= q)%Z -> P q -> P (q + 1)%Z) ->
2403 forall q : Z, (p <= q)%Z -> P q.
2404 Proof.
2405 intros P p.
2406 intro.
2407 intro.
2408 cut (forall q : Z, (p <= q)%Z -> exists k : nat, q = (p + k)%Z).
2409 intro.
2410 cut (forall k : nat, P (p + k)%Z).
2411 intro.
2412 intros.
2413 cut (exists k : nat, q = (p + Z_of_nat k)%Z).
2414 intro.
2415 case H4.
2416 intros.
2417 rewrite H5.
2418 apply H2.
2419 apply H1.
2420 assumption.
2421 intro.
2422 induction k as [| k Hreck].
2423 simpl in |- *.
2424 ring_simplify (p + 0)%Z.
2425 assumption.
2426 replace (p + Z_of_nat (S k))%Z with (p + k + 1)%Z.
2427 apply H0.
2428 apply Zplus_le_reg_l with (p := (- p)%Z).
2429 replace (- p + p)%Z with (Z_of_nat 0).
2430 ring_simplify (- p + (p + Z_of_nat k))%Z.
2431 apply Znat.inj_le.
2432 apply le_O_n.
2433 ring_simplify; auto with arith.
2434 assumption.
2435 rewrite (Znat.inj_S k).
2436 unfold Zsucc in |- *.
2437 ring.
2438 intros.
2439 cut (exists k : nat, (q - p)%Z = Z_of_nat k).
2440 intro.
2441 case H2.
2442 intro k.
2443 intros.
2444 exists k.
2445 apply Zplus_reg_l with (n := (- p)%Z).
2446 replace (- p + q)%Z with (q - p)%Z.
2447 rewrite H3.
2448 ring.
2449 ring.
2450 apply Z_of_nat_complete.
2451 unfold Zminus in |- *.
2452 apply Zle_left.
2453 assumption.
2454 Qed.
2455
2456 Lemma Zrec :
2457 forall (P : Z -> Set) (p : Z),
2458 P p ->
2459 (forall q : Z, (p <= q)%Z -> P q -> P (q + 1)%Z) ->
2460 forall q : Z, (p <= q)%Z -> P q.
2461 Proof.
2462 intros F p.
2463 intro.
2464 intro.
2465 cut (forall q : Z, (p <= q)%Z -> {k : nat | q = (p + k)%Z}).
2466 intro.
2467 cut (forall k : nat, F (p + k)%Z).
2468 intro.
2469 intros.
2470 cut {k : nat | q = (p + Z_of_nat k)%Z}.
2471 intro.
2472 case H4.
2473 intros.
2474 rewrite e.
2475 apply H2.
2476 apply H1.
2477 assumption.
2478 intro.
2479 induction k as [| k Hreck].
2480 simpl in |- *.
2481 rewrite Zplus_0_r.
2482 assumption.
2483 replace (p + Z_of_nat (S k))%Z with (p + k + 1)%Z.
2484 apply H0.
2485 apply Zplus_le_reg_l with (p := (- p)%Z).
2486 replace (- p + p)%Z with (Z_of_nat 0).
2487 replace (- p + (p + Z_of_nat k))%Z with (Z_of_nat k).
2488 apply Znat.inj_le.
2489 apply le_O_n.
2490 rewrite Zplus_assoc; rewrite Zplus_opp_l; reflexivity.
2491 rewrite Zplus_opp_l; reflexivity.
2492 assumption.
2493 rewrite (Znat.inj_S k).
2494 unfold Zsucc in |- *.
2495 apply Zplus_assoc_reverse.
2496 intros.
2497 cut {k : nat | (q - p)%Z = Z_of_nat k}.
2498 intro H2.
2499 case H2.
2500 intro k.
2501 intros.
2502 exists k.
2503 apply Zplus_reg_l with (n := (- p)%Z).
2504 replace (- p + q)%Z with (q - p)%Z.
2505 rewrite e.
2506 rewrite Zplus_assoc; rewrite Zplus_opp_l; reflexivity.
2507 unfold Zminus in |- *.
2508 apply Zplus_comm.
2509 apply Z_of_nat_complete_inf.
2510 unfold Zminus in |- *.
2511 apply Zle_left.
2512 assumption.
2513 Qed.
2514
2515 Lemma Zrec_down :
2516 forall (P : Z -> Set) (p : Z),
2517 P p ->
2518 (forall q : Z, (q <= p)%Z -> P q -> P (q - 1)%Z) ->
2519 forall q : Z, (q <= p)%Z -> P q.
2520 Proof.
2521 intros F p.
2522 intro.
2523 intro.
2524 cut (forall q : Z, (q <= p)%Z -> {k : nat | q = (p - k)%Z}).
2525 intro.
2526 cut (forall k : nat, F (p - k)%Z).
2527 intro.
2528 intros.
2529 cut {k : nat | q = (p - Z_of_nat k)%Z}.
2530 intro.
2531 case H4.
2532 intros.
2533 rewrite e.
2534 apply H2.
2535 apply H1.
2536 assumption.
2537 intro.
2538 induction k as [| k Hreck].
2539 simpl in |- *.
2540 replace (p - 0)%Z with p.
2541 assumption.
2542 unfold Zminus in |- *.
2543 unfold Zopp in |- *.
2544 rewrite Zplus_0_r; reflexivity.
2545 replace (p - Z_of_nat (S k))%Z with (p - k - 1)%Z.
2546 apply H0.
2547 apply Zplus_le_reg_l with (p := (- p)%Z).
2548 replace (- p + p)%Z with (- Z_of_nat 0)%Z.
2549 replace (- p + (p - Z_of_nat k))%Z with (- Z_of_nat k)%Z.
2550 apply Zge_le.
2551 apply Zge_opp.
2552 apply Znat.inj_le.
2553 apply le_O_n.
2554 unfold Zminus in |- *; rewrite Zplus_assoc; rewrite Zplus_opp_l; reflexivity.
2555 rewrite Zplus_opp_l; reflexivity.
2556 assumption.
2557 rewrite (Znat.inj_S k).
2558 unfold Zsucc in |- *.
2559 unfold Zminus at 1 2 in |- *.
2560 rewrite Zplus_assoc_reverse.
2561 rewrite <- Zopp_plus_distr.
2562 reflexivity.
2563 intros.
2564 cut {k : nat | (p - q)%Z = Z_of_nat k}.
2565 intro.
2566 case H2.
2567 intro k.
2568 intros.
2569 exists k.
2570 apply Zopp_inj.
2571 apply Zplus_reg_l with (n := p).
2572 replace (p + - (p - Z_of_nat k))%Z with (Z_of_nat k).
2573 rewrite <- e.
2574 reflexivity.
2575 unfold Zminus in |- *.
2576 rewrite Zopp_plus_distr.
2577 rewrite Zplus_assoc.
2578 rewrite Zplus_opp_r.
2579 rewrite Zopp_involutive.
2580 reflexivity.
2581 apply Z_of_nat_complete_inf.
2582 unfold Zminus in |- *.
2583 apply Zle_left.
2584 assumption.
2585 Qed.
2586
2587 Lemma Zind_down :
2588 forall (P : Z -> Prop) (p : Z),
2589 P p ->
2590 (forall q : Z, (q <= p)%Z -> P q -> P (q - 1)%Z) ->
2591 forall q : Z, (q <= p)%Z -> P q.
2592 Proof.
2593 intros F p.
2594 intro.
2595 intro.
2596 cut (forall q : Z, (q <= p)%Z -> exists k : nat, q = (p - k)%Z).
2597 intro.
2598 cut (forall k : nat, F (p - k)%Z).
2599 intro.
2600 intros.
2601 cut (exists k : nat, q = (p - Z_of_nat k)%Z).
2602 intro.
2603 case H4.
2604 intros x e.
2605 rewrite e.
2606 apply H2.
2607 apply H1.
2608 assumption.
2609 intro.
2610 induction k as [| k Hreck].
2611 simpl in |- *.
2612 replace (p - 0)%Z with p.
2613 assumption.
2614 ring.
2615 replace (p - Z_of_nat (S k))%Z with (p - k - 1)%Z.
2616 apply H0.
2617 apply Zplus_le_reg_l with (p := (- p)%Z).
2618 replace (- p + p)%Z with (- Z_of_nat 0)%Z.
2619 replace (- p + (p - Z_of_nat k))%Z with (- Z_of_nat k)%Z.
2620 apply Zge_le.
2621 apply Zge_opp.
2622 apply Znat.inj_le.
2623 apply le_O_n.
2624 ring.
2625 ring_simplify; auto with arith.
2626 assumption.
2627 rewrite (Znat.inj_S k).
2628 unfold Zsucc in |- *.
2629 ring.
2630 intros.
2631 cut (exists k : nat, (p - q)%Z = Z_of_nat k).
2632 intro.
2633 case H2.
2634 intro k.
2635 intros.
2636 exists k.
2637 apply Zopp_inj.
2638 apply Zplus_reg_l with (n := p).
2639 replace (p + - (p - Z_of_nat k))%Z with (Z_of_nat k).
2640 rewrite <- H3.
2641 ring.
2642 ring.
2643 apply Z_of_nat_complete.
2644 unfold Zminus in |- *.
2645 apply Zle_left.
2646 assumption.
2647 Qed.
2648
2649 Lemma Zrec_wf :
2650 forall (P : Z -> Set) (p : Z),
2651 (forall q : Z, (forall r : Z, (p <= r < q)%Z -> P r) -> P q) ->
2652 forall q : Z, (p <= q)%Z -> P q.
2653 Proof.
2654 intros P p WF_ind_step q Hq.
2655 cut (forall x : Z, (p <= x)%Z -> forall y : Z, (p <= y < x)%Z -> P y).
2656 intro.
2657 apply (H (Zsucc q)).
2658 apply Zle_le_succ.
2659 assumption.
2660
2661 split; [ assumption | exact (Zlt_succ q) ].
2662
2663 intros x0 Hx0; generalize Hx0; pattern x0 in |- *.
2664 apply Zrec with (p := p).
2665 intros.
2666 absurd (p <= p)%Z.
2667 apply Zgt_not_le.
2668 apply Zgt_le_trans with (m := y).
2669 apply Zlt_gt.
2670 elim H.
2671 intros.
2672 assumption.
2673 elim H.
2674 intros.
2675 assumption.
2676 apply Zle_refl.
2677
2678 intros.
2679 apply WF_ind_step.
2680 intros.
2681 apply (H0 H).
2682 split.
2683 elim H2.
2684 intros.
2685 assumption.
2686 apply Zlt_le_trans with y.
2687 elim H2.
2688 intros.
2689 assumption.
2690 apply Zgt_succ_le.
2691 apply Zlt_gt.
2692 elim H1.
2693 intros.
2694 unfold Zsucc in |- *.
2695 assumption.
2696 assumption.
2697 Qed.
2698
2699 Lemma Zrec_wf2 :
2700 forall (q : Z) (P : Z -> Set) (p : Z),
2701 (forall q : Z, (forall r : Z, (p <= r < q)%Z -> P r) -> P q) ->
2702 (p <= q)%Z -> P q.
2703 Proof.
2704 intros.
2705 apply Zrec_wf with (p := p).
2706 assumption.
2707 assumption.
2708 Qed.
2709
2710 Lemma Zrec_wf_double :
2711 forall (P : Z -> Z -> Set) (p0 q0 : Z),
2712 (forall n m : Z,
2713 (forall p q : Z, (q0 <= q)%Z -> (p0 <= p < n)%Z -> P p q) ->
2714 (forall p : Z, (q0 <= p < m)%Z -> P n p) -> P n m) ->
2715 forall p q : Z, (q0 <= q)%Z -> (p0 <= p)%Z -> P p q.
2716 Proof.
2717 intros P p0 q0 Hrec p.
2718 intros.
2719 generalize q H.
2720 pattern p in |- *.
2721 apply Zrec_wf with (p := p0).
2722 intros p1 H1.
2723 intros.
2724 pattern q1 in |- *.
2725 apply Zrec_wf with (p := q0).
2726 intros q2 H3.
2727 apply Hrec.
2728 intros.
2729 apply H1.
2730 assumption.
2731 assumption.
2732 intros.
2733 apply H3.
2734 assumption.
2735 assumption.
2736 assumption.
2737 Qed.
2738
2739 Lemma Zind_wf :
2740 forall (P : Z -> Prop) (p : Z),
2741 (forall q : Z, (forall r : Z, (p <= r < q)%Z -> P r) -> P q) ->
2742 forall q : Z, (p <= q)%Z -> P q.
2743 Proof.
2744 intros P p WF_ind_step q Hq.
2745 cut (forall x : Z, (p <= x)%Z -> forall y : Z, (p <= y < x)%Z -> P y).
2746 intro.
2747 apply (H (Zsucc q)).
2748 apply Zle_le_succ.
2749 assumption.
2750
2751 split; [ assumption | exact (Zlt_succ q) ].
2752
2753 intros x0 Hx0; generalize Hx0; pattern x0 in |- *.
2754 apply Zind with (p := p).
2755 intros.
2756 absurd (p <= p)%Z.
2757 apply Zgt_not_le.
2758 apply Zgt_le_trans with (m := y).
2759 apply Zlt_gt.
2760 elim H.
2761 intros.
2762 assumption.
2763 elim H.
2764 intros.
2765 assumption.
2766 apply Zle_refl.
2767
2768 intros.
2769 apply WF_ind_step.
2770 intros.
2771 apply (H0 H).
2772 split.
2773 elim H2.
2774 intros.
2775 assumption.
2776 apply Zlt_le_trans with y.
2777 elim H2.
2778 intros.
2779 assumption.
2780 apply Zgt_succ_le.
2781 apply Zlt_gt.
2782 elim H1.
2783 intros.
2784 unfold Zsucc in |- *.
2785 assumption.
2786 assumption.
2787 Qed.
2788
2789 Lemma Zind_wf2 :
2790 forall (q : Z) (P : Z -> Prop) (p : Z),
2791 (forall q : Z, (forall r : Z, (p <= r < q)%Z -> P r) -> P q) ->
2792 (p <= q)%Z -> P q.
2793 Proof.
2794 intros.
2795 apply Zind_wf with (p := p).
2796 assumption.
2797 assumption.
2798 Qed.
2799
2800 Lemma Zind_wf_double :
2801 forall (P : Z -> Z -> Prop) (p0 q0 : Z),
2802 (forall n m : Z,
2803 (forall p q : Z, (q0 <= q)%Z -> (p0 <= p < n)%Z -> P p q) ->
2804 (forall p : Z, (q0 <= p < m)%Z -> P n p) -> P n m) ->
2805 forall p q : Z, (q0 <= q)%Z -> (p0 <= p)%Z -> P p q.
2806 Proof.
2807 intros P p0 q0 Hrec p.
2808 intros.
2809 generalize q H.
2810 pattern p in |- *.
2811 apply Zind_wf with (p := p0).
2812 intros p1 H1.
2813 intros.
2814 pattern q1 in |- *.
2815 apply Zind_wf with (p := q0).
2816 intros q2 H3.
2817 apply Hrec.
2818 intros.
2819 apply H1.
2820 assumption.
2821 assumption.
2822 intros.
2823 apply H3.
2824 assumption.
2825 assumption.
2826 assumption.
2827 Qed.
2828
2829 (*###########################################################################*)
2830 (** Properties of Zmax *)
2831 (*###########################################################################*)
2832
2833 Definition Zmax (n m : Z) := (n + m - Zmin n m)%Z.
2834
2835 Lemma ZmaxSS : forall n m : Z, (Zmax n m + 1)%Z = Zmax (n + 1) (m + 1).
2836 Proof.
2837 intros.
2838 unfold Zmax in |- *.
2839 replace (Zmin (n + 1) (m + 1)) with (Zmin n m + 1)%Z.
2840 ring.
2841 symmetry in |- *.
2842 change (Zmin (Zsucc n) (Zsucc m) = Zsucc (Zmin n m)) in |- *.
2843 symmetry in |- *.
2844 apply Zmin_SS.
2845 Qed.
2846
2847 Lemma Zle_max_l : forall n m : Z, (n <= Zmax n m)%Z.
2848 Proof.
2849 intros.
2850 unfold Zmax in |- *.
2851 apply Zplus_le_reg_l with (p := (- n + Zmin n m)%Z).
2852 ring_simplify (- n + Zmin n m + n)%Z.
2853 ring_simplify (- n + Zmin n m + (n + m - Zmin n m))%Z.
2854 apply Zle_min_r.
2855 Qed.
2856
2857 Lemma Zle_max_r : forall n m : Z, (m <= Zmax n m)%Z.
2858 Proof.
2859 intros.
2860 unfold Zmax in |- *.
2861 apply Zplus_le_reg_l with (p := (- m + Zmin n m)%Z).
2862 ring_simplify (- m + Zmin n m + m)%Z.
2863 ring_simplify (- m + Zmin n m + (n + m - Zmin n m))%Z.
2864 apply Zle_min_l.
2865 Qed.
2866
2867
2868 Lemma Zmin_or_informative : forall n m : Z, {Zmin n m = n} + {Zmin n m = m}.
2869 Proof.
2870 intros.
2871 case (Z_lt_ge_dec n m).
2872 unfold Zmin in |- *.
2873 unfold Zlt in |- *.
2874 intro z.
2875 rewrite z.
2876 left.
2877 reflexivity.
2878 intro.
2879 cut ({(n > m)%Z} + {n = m :>Z}).
2880 intro.
2881 case H.
2882 intros z0.
2883 unfold Zmin in |- *.
2884 unfold Zgt in z0.
2885 rewrite z0.
2886 right.
2887 reflexivity.
2888 intro.
2889 rewrite e.
2890 right.
2891 apply Zmin_n_n.
2892 cut ({(m < n)%Z} + {m = n :>Z}).
2893 intro.
2894 elim H.
2895 intro.
2896 left.
2897 apply Zlt_gt.
2898 assumption.
2899 intro.
2900 right.
2901 symmetry in |- *.
2902 assumption.
2903 apply Z_le_lt_eq_dec.
2904 apply Zge_le.
2905 assumption.
2906 Qed.
2907
2908 Lemma Zmax_case : forall (n m : Z) (P : Z -> Set), P n -> P m -> P (Zmax n m).
2909 Proof.
2910 intros.
2911 unfold Zmax in |- *.
2912 case Zmin_or_informative with (n := n) (m := m).
2913 intro.
2914 rewrite e.
2915 cut ((n + m - n)%Z = m).
2916 intro.
2917 rewrite H1.
2918 assumption.
2919 ring.
2920 intro.
2921 rewrite e.
2922 cut ((n + m - m)%Z = n).
2923 intro.
2924 rewrite H1.
2925 assumption.
2926 ring.
2927 Qed.
2928
2929 Lemma Zmax_or_informative : forall n m : Z, {Zmax n m = n} + {Zmax n m = m}.
2930 Proof.
2931 intros.
2932 unfold Zmax in |- *.
2933 case Zmin_or_informative with (n := n) (m := m).
2934 intro.
2935 rewrite e.
2936 right.
2937 ring.
2938 intro.
2939 rewrite e.
2940 left.
2941 ring.
2942 Qed.
2943
2944 Lemma Zmax_n_n : forall n : Z, Zmax n n = n.
2945 Proof.
2946 intros.
2947 unfold Zmax in |- *.
2948 rewrite (Zmin_n_n n).
2949 ring.
2950 Qed.
2951
2952 Hint Resolve ZmaxSS Zle_max_r Zle_max_l Zmax_n_n: zarith.
2953
2954 (*###########################################################################*)
2955 (** Properties of Arity *)
2956 (*###########################################################################*)
2957
2958 Lemma Zeven_S : forall x : Z, Zeven.Zodd x -> Zeven.Zeven (x + 1).
2959 Proof.
2960 exact Zeven.Zeven_Sn.
2961 Qed.
2962
2963 Lemma Zeven_pred : forall x : Z, Zeven.Zodd x -> Zeven.Zeven (x - 1).
2964 Proof.
2965 exact Zeven.Zeven_pred.
2966 Qed.
2967
2968 (* This lemma used to be useful since it was mentioned with an unnecessary premise
2969 `x>=0` as Z_modulo_2 in ZArith, but the ZArith version has been fixed. *)
2970
2971 Definition Z_modulo_2_always :
2972 forall x : Z, {y : Z | x = (2 * y)%Z} + {y : Z | x = (2 * y + 1)%Z} :=
2973 Zeven.Z_modulo_2.
2974
2975 (*###########################################################################*)
2976 (** Properties of Zdiv *)
2977 (*###########################################################################*)
2978
2979 Lemma Z_div_mod_eq_2 :
2980 forall a b : Z, (0 < b)%Z -> (b * (a / b))%Z = (a - a mod b)%Z.
2981 Proof.
2982 intros.
2983 apply Zplus_minus_eq.
2984 rewrite Zplus_comm.
2985 apply Z_div_mod_eq.
2986 Flip.
2987 Qed.
2988
2989 Lemma Z_div_le :
2990 forall a b c : Z, (0 < c)%Z -> (b <= a)%Z -> (b / c <= a / c)%Z.
2991 Proof.
2992 intros.
2993 apply Zge_le.
2994 apply Z_div_ge; Flip; assumption.
2995 Qed.
2996
2997 Lemma Z_div_nonneg :
2998 forall a b : Z, (0 < b)%Z -> (0 <= a)%Z -> (0 <= a / b)%Z.
2999 Proof.
3000 intros.
3001 apply Zge_le.
3002 apply Z_div_ge0; Flip; assumption.
3003 Qed.
3004
3005 Lemma Z_div_neg : forall a b : Z, (0 < b)%Z -> (a < 0)%Z -> (a / b < 0)%Z.
3006 Proof.
3007 intros.
3008 rewrite (Z_div_mod_eq a b) in H0.
3009 elim (Z_mod_lt a b).
3010 intros H1 _.
3011 apply Znot_ge_lt.
3012 intro.
3013 apply (Zlt_not_le (b * (a / b) + a mod b) 0 H0).
3014 apply Zplus_le_0_compat.
3015 apply Zmult_le_0_compat.
3016 apply Zlt_le_weak; assumption.
3017 Flip.
3018 assumption.
3019 Flip.
3020 Flip.
3021 Qed.
3022
3023 Hint Resolve Z_div_mod_eq_2 Z_div_le Z_div_nonneg Z_div_neg: zarith.
3024
3025 (*###########################################################################*)
3026 (** Properties of Zpower *)
3027 (*###########################################################################*)
3028
3029 Lemma Zpower_1 : forall a : Z, (a ^ 1)%Z = a.
3030 Proof.
3031 intros; unfold Zpower in |- *; unfold Zpower_pos in |- *; simpl in |- *;
3032 auto with zarith.
3033 Qed.
3034
3035 Lemma Zpower_2 : forall a : Z, (a ^ 2)%Z = (a * a)%Z.
3036 Proof.
3037 intros; unfold Zpower in |- *; unfold Zpower_pos in |- *; simpl in |- *;
3038 ring.
3039 Qed.
3040
3041 Hint Resolve Zpower_1 Zpower_2: zarith.