1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/tests/".
18 inductive True: Prop \def
21 inductive False: Prop \def .
23 definition Not: Prop \to Prop \def
24 \lambda A. (A \to False).
26 theorem absurd : \forall A,C:Prop. A \to Not A \to C.
30 inductive And (A,B:Prop) : Prop \def
31 conj : A \to B \to (And A B).
33 theorem proj1: \forall A,B:Prop. (And A B) \to A.
34 intros. elim H. assumption.
37 theorem proj2: \forall A,B:Prop. (And A B) \to A.
38 intros. elim H. assumption.
41 inductive Or (A,B:Prop) : Prop \def
42 or_introl : A \to (Or A B)
43 | or_intror : B \to (Or A B).
45 inductive ex (A:Type) (P:A \to Prop) : Prop \def
46 ex_intro: \forall x:A. P x \to ex A P.
48 inductive ex2 (A:Type) (P,Q:A \to Prop) : Prop \def
49 ex_intro2: \forall x:A. P x \to Q x \to ex2 A P Q.
51 inductive eq (A:Type) (x:A) : A \to Prop \def
52 refl_equal : eq A x x.
54 theorem sym_eq : \forall A:Type.\forall x,y:A. eq A x y \to eq A y x.
55 intros. elim H. apply refl_equal.
58 theorem trans_eq : \forall A:Type.
59 \forall x,y,z:A. eq A x y \to eq A y z \to eq A x z.
60 intros.elim H1.assumption.
63 theorem f_equal: \forall A,B:Type.\forall f:A\to B.
64 \forall x,y:A. eq A x y \to eq B (f x) (f y).
65 intros.elim H.apply refl_equal.
68 theorem f_equal2: \forall A,B,C:Type.\forall f:A\to B \to C.
69 \forall x1,x2:A. \forall y1,y2:B.
70 eq A x1 x2\to eq B y1 y2\to eq C (f x1 y1) (f x2 y2).
71 intros.elim H1.elim H.apply refl_equal.
74 inductive nat : Set \def
78 definition pred: nat \to nat \def
79 \lambda n:nat. match n with
81 | (S u) \Rightarrow u ].
83 theorem pred_Sn : \forall n:nat.
84 (eq nat n (pred (S n))).
85 intros.apply refl_equal.
88 theorem injective_S : \forall n,m:nat.
89 (eq nat (S n) (S m)) \to (eq nat n m).
90 intros.(elim (sym_eq ? ? ? (pred_Sn n))).(elim (sym_eq ? ? ? (pred_Sn m))).
91 apply f_equal. assumption.
94 theorem not_eq_S : \forall n,m:nat.
95 Not (eq nat n m) \to Not (eq nat (S n) (S m)).
96 intros. simplify.intros.
97 apply H.apply injective_S.assumption.
100 definition not_zero : nat \to Prop \def
103 [ O \Rightarrow False
104 | (S p) \Rightarrow True ].
106 theorem O_S : \forall n:nat. Not (eq nat O (S n)).
107 intros.simplify.intros.
108 cut (not_zero O).exact Hcut.elim (sym_eq ? ? ? H).
112 theorem n_Sn : \forall n:nat. Not (eq nat n (S n)).
113 intros.elim n.apply O_S.apply not_eq_S.assumption.
117 let rec plus n m \def
120 | (S p) \Rightarrow S (plus p m) ].
122 theorem plus_n_O: \forall n:nat. eq nat n (plus n O).
123 intros.elim n.simplify.apply refl_equal.simplify.apply f_equal.assumption.
126 theorem plus_n_Sm : \forall n,m:nat. eq nat (S (plus n m)) (plus n (S m)).
127 intros.elim n.simplify.apply refl_equal.simplify.apply f_equal.assumption.
130 theorem sym_plus: \forall n,m:nat. eq nat (plus n m) (plus m n).
131 intros.elim n.simplify.apply plus_n_O.
132 simplify.elim (sym_eq ? ? ? H).apply plus_n_Sm.
136 \forall n,m,p:nat. eq nat (plus (plus n m) p) (plus n (plus m p)).
137 intros.elim n.simplify.apply refl_equal.simplify.apply f_equal.assumption.
140 let rec times n m \def
143 | (S p) \Rightarrow (plus m (times p m)) ].
145 theorem times_n_O: \forall n:nat. eq nat O (times n O).
146 intros.elim n.simplify.apply refl_equal.simplify.assumption.
150 \forall n,m:nat. eq nat (plus n (times n m)) (times n (S m)).
151 intros.elim n.simplify.apply refl_equal.
152 simplify.apply f_equal.elim H.
153 apply trans_eq ? ? (plus (plus e m) (times e m)).apply sym_eq.
154 apply assoc_plus.apply trans_eq ? ? (plus (plus m e) (times e m)).
156 apply sym_plus.apply refl_equal.apply assoc_plus.
160 \forall n,m:nat. eq nat (times n m) (times m n).
161 intros.elim n.simplify.apply times_n_O.
162 simplify.elim (sym_eq ? ? ? H).apply times_n_Sm.
165 let rec minus n m \def
171 | (S q) \Rightarrow minus p q ]].
174 \forall n:nat.\forall P:nat \to Prop.
175 P O \to (\forall m:nat. P (S m)) \to P n.
176 intros.elim n.assumption.apply H1.
179 theorem nat_double_ind :
180 \forall R:nat \to nat \to Prop.
181 (\forall n:nat. R O n) \to
182 (\forall n:nat. R (S n) O) \to
183 (\forall n,m:nat. R n m \to R (S n) (S m)) \to \forall n,m:nat. R n m.
184 intros.cut \forall m:nat.R n m.apply Hcut.elim n.apply H.
185 apply nat_case m1.apply H1.intros.apply H2. apply H3.
188 inductive bool : Set \def
192 definition notn : bool \to bool \def
195 [ true \Rightarrow false
196 | false \Rightarrow true ].
198 definition andb : bool \to bool \to bool\def
202 match b2 with [true \Rightarrow true | false \Rightarrow false]
203 | false \Rightarrow false ].
205 definition orb : bool \to bool \to bool\def
209 match b2 with [true \Rightarrow true | false \Rightarrow false]
210 | false \Rightarrow false ].
212 definition if_then_else : bool \to Prop \to Prop \to Prop \def
213 \lambda b:bool.\lambda P,Q:Prop.
216 | false \Rightarrow Q].
218 inductive le (n:nat) : nat \to Prop \def
220 | le_S : \forall m:nat. le n m \to le n (S m).
222 theorem trans_le: \forall n,m,p:nat. le n m \to le m p \to le n p.
225 apply le_S.assumption.
228 theorem le_n_S: \forall n,m:nat. le n m \to le (S n) (S m).
230 apply le_n.apply le_S.assumption.
233 theorem le_O_n : \forall n:nat. le O n.
234 intros.elim n.apply le_n.apply le_S. assumption.
237 theorem le_n_Sn : \forall n:nat. le n (S n).
238 intros. apply le_S.apply le_n.
241 theorem le_pred_n : \forall n:nat. le (pred n) n.
242 intros.elim n.simplify.apply le_n.simplify.
246 theorem not_zero_le : \forall n,m:nat. (le (S n) m ) \to not_zero m.
247 intros.elim H.exact I.exact I.
250 theorem le_Sn_O: \forall n:nat. Not (le (S n) O).
251 intros.simplify.intros.apply not_zero_le ? O H.
254 theorem le_n_O_eq : \forall n:nat. (le n O) \to (eq nat O n).
255 intros.cut (le n O) \to (eq nat O n).apply Hcut. assumption.
256 elim n.apply refl_equal.apply False_ind.apply (le_Sn_O ? H2).
259 theorem le_S_n : \forall n,m:nat. le (S n) (S m) \to le n m.
260 intros.cut le (pred (S n)) (pred (S m)).exact Hcut.
261 elim H.apply le_n.apply trans_le ? (pred x).assumption.
265 theorem le_Sn_n : \forall n:nat. Not (le (S n) n).
266 intros.elim n.apply le_Sn_O.simplify.intros.
267 cut le (S e) e.apply H.assumption.apply le_S_n.assumption.
270 theorem le_antisym : \forall n,m:nat. (le n m) \to (le m n) \to (eq nat n m).
271 intros.cut (le n m) \to (le m n) \to (eq nat n m).exact Hcut H H1.
272 apply nat_double_ind (\lambda n,m.((le n m) \to (le m n) \to eq nat n m)).
274 apply le_n_O_eq.assumption.
275 intros.whd.intros.apply sym_eq.apply le_n_O_eq.assumption.
276 intros.whd.intros.apply f_equal.apply H2.
277 apply le_S_n.assumption.
278 apply le_S_n.assumption.
286 [ O \Rightarrow false
287 | (S q) \Rightarrow leb p q]].
289 theorem le_dec: \forall n,m:nat. if_then_else (leb n m) (le n m) (Not (le n m)).
291 apply (nat_double_ind
292 (\lambda n,m:nat.if_then_else (leb n m) (le n m) (Not (le n m))) ? ? ? n m).
293 simplify.intros.apply le_O_n.
294 simplify.exact le_Sn_O.
295 intros 2.simplify.elim (leb n1 m1).
296 simplify.apply le_n_S.apply H.
297 simplify.intros.apply H.apply le_S_n.assumption.
300 inductive Z : Set \def
305 definition Z_of_nat \def
306 \lambda n. match n with
308 | (S n)\Rightarrow pos n].
312 definition neg_Z_of_nat \def
313 \lambda n. match n with
315 | (S n)\Rightarrow neg n].
321 | (pos n) \Rightarrow n
322 | (neg n) \Rightarrow n].
324 definition OZ_testb \def
327 [ OZ \Rightarrow true
328 | (pos n) \Rightarrow false
329 | (neg n) \Rightarrow false].
332 \forall z. if_then_else (OZ_testb z) (eq Z z OZ) (Not (eq Z z OZ)).
333 intros.elim z.simplify.apply refl_equal.
336 [ OZ \Rightarrow True
337 | (pos n) \Rightarrow False
338 | (neg n) \Rightarrow False].
339 apply Hcut. elim (sym_eq ? ? ? H).simplify.exact I.
342 [ OZ \Rightarrow True
343 | (pos n) \Rightarrow False
344 | (neg n) \Rightarrow False].
345 apply Hcut. elim (sym_eq ? ? ? H).simplify.exact I.
348 definition Zsucc \def
349 \lambda z. match z with
350 [ OZ \Rightarrow pos O
351 | (pos n) \Rightarrow pos (S n)
352 | (neg n) \Rightarrow
355 | (S p) \Rightarrow neg p]].
357 definition Zpred \def
358 \lambda z. match z with
359 [ OZ \Rightarrow neg O
360 | (pos n) \Rightarrow
363 | (S p) \Rightarrow pos p]
364 | (neg n) \Rightarrow neg (S n)].
366 theorem Zpred_succ: \forall z:Z. eq Z (Zpred (Zsucc z)) z.
367 intros.elim z.apply refl_equal.
368 elim e.apply refl_equal.
373 theorem Zsucc_pred: \forall z:Z. eq Z (Zsucc (Zpred z)) z.
374 intros.elim z.apply refl_equal.
376 elim e.apply refl_equal.
380 inductive compare :Set \def
385 let rec nat_compare n m: compare \def
390 | (S q) \Rightarrow LT ]
394 | (S q) \Rightarrow nat_compare p q]].
396 definition compare_invert: compare \to compare \def
401 | GT \Rightarrow LT ].
403 theorem nat_compare_invert: \forall n,m:nat.
404 eq compare (nat_compare n m) (compare_invert (nat_compare m n)).
406 apply nat_double_ind (\lambda n,m.eq compare (nat_compare n m) (compare_invert (nat_compare m n))).
407 intros.elim n1.simplify.apply refl_equal.
408 simplify.apply refl_equal.
409 intro.elim n1.simplify.apply refl_equal.
410 simplify.apply refl_equal.
411 intros.simplify.elim H.apply refl_equal.
414 let rec Zplus x y : Z \def
417 | (pos m) \Rightarrow
420 | (pos n) \Rightarrow (pos (S (plus m n)))
421 | (neg n) \Rightarrow
422 match nat_compare m n with
423 [ LT \Rightarrow (neg (pred (minus n m)))
425 | GT \Rightarrow (pos (pred (minus m n)))]]
426 | (neg m) \Rightarrow
429 | (pos n) \Rightarrow
430 match nat_compare m n with
431 [ LT \Rightarrow (pos (pred (minus n m)))
433 | GT \Rightarrow (neg (pred (minus m n)))]
434 | (neg n) \Rightarrow (neg (S (plus m n)))]].
436 theorem Zplus_z_O: \forall z:Z. eq Z (Zplus z OZ) z.
438 simplify.apply refl_equal.
439 simplify.apply refl_equal.
440 simplify.apply refl_equal.
443 theorem sym_Zplus : \forall x,y:Z. eq Z (Zplus x y) (Zplus y x).
444 intros.elim x.simplify.elim (sym_eq ? ? ? (Zplus_z_O y)).apply refl_equal.
445 elim y.simplify.reflexivity.
446 simplify.elim (sym_plus e e1).apply refl_equal.
447 simplify.elim (sym_eq ? ? ?(nat_compare_invert e e1)).
448 simplify.elim nat_compare e1 e.simplify.apply refl_equal.
449 simplify. apply refl_equal.
450 simplify. apply refl_equal.
451 elim y.simplify.reflexivity.
452 simplify.elim (sym_eq ? ? ?(nat_compare_invert e e1)).
453 simplify.elim nat_compare e1 e.simplify.apply refl_equal.
454 simplify. apply refl_equal.
455 simplify. apply refl_equal.
456 simplify.elim (sym_plus e1 e).apply refl_equal.
459 theorem Zpred_neg : \forall z:Z. eq Z (Zpred z) (Zplus (neg O) z).
461 simplify.apply refl_equal.
462 simplify.apply refl_equal.
463 elim e.simplify.apply refl_equal.
464 simplify.apply refl_equal.
467 theorem Zsucc_pos : \forall z:Z. eq Z (Zsucc z) (Zplus (pos O) z).
469 simplify.apply refl_equal.
470 elim e.simplify.apply refl_equal.
471 simplify.apply refl_equal.
472 simplify.apply refl_equal.
475 theorem Zplus_succ_pred_pp :
476 \forall n,m. eq Z (Zplus (pos n) (pos m)) (Zplus (Zsucc (pos n)) (Zpred (pos m))).
479 simplify.apply refl_equal.
480 simplify.apply refl_equal.
482 simplify.elim (plus_n_O ?).apply refl_equal.
483 simplify.elim (plus_n_Sm ? ?).apply refl_equal.
486 theorem Zplus_succ_pred_pn :
487 \forall n,m. eq Z (Zplus (pos n) (neg m)) (Zplus (Zsucc (pos n)) (Zpred (neg m))).
488 intros.apply refl_equal.
491 theorem Zplus_succ_pred_np :
492 \forall n,m. eq Z (Zplus (neg n) (pos m)) (Zplus (Zsucc (neg n)) (Zpred (pos m))).
495 simplify.apply refl_equal.
496 simplify.apply refl_equal.
498 simplify.apply refl_equal.
499 simplify.apply refl_equal.
502 theorem Zplus_succ_pred_nn:
503 \forall n,m. eq Z (Zplus (neg n) (neg m)) (Zplus (Zsucc (neg n)) (Zpred (neg m))).
506 simplify.apply refl_equal.
507 simplify.apply refl_equal.
509 simplify.elim (plus_n_Sm ? ?).apply refl_equal.
510 simplify.elim (sym_eq ? ? ? (plus_n_Sm ? ?)).apply refl_equal.
513 theorem Zplus_succ_pred:
514 \forall x,y. eq Z (Zplus x y) (Zplus (Zsucc x) (Zpred y)).
517 simplify.apply refl_equal.
518 simplify.apply refl_equal.
519 elim (Zsucc_pos ?).elim (sym_eq ? ? ? (Zsucc_pred ?)).apply refl_equal.
520 elim y.elim sym_Zplus ? ?.elim sym_Zplus (Zpred OZ) ?.
521 elim (Zpred_neg ?).elim (sym_eq ? ? ? (Zpred_succ ?)).
522 simplify.apply refl_equal.
523 apply Zplus_succ_pred_nn.
524 apply Zplus_succ_pred_np.
525 elim y.simplify.apply refl_equal.
526 apply Zplus_succ_pred_pn.
527 apply Zplus_succ_pred_pp.
530 theorem Zsucc_plus_pp :
531 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (pos m)) (Zsucc (Zplus (pos n) (pos m))).
532 intros.apply refl_equal.
535 theorem Zsucc_plus_pn :
536 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m))).
539 (\lambda n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m)))).intro.
541 simplify. apply refl_equal.
542 elim e.simplify. apply refl_equal.
543 simplify. apply refl_equal.
545 simplify. apply refl_equal.
546 simplify.apply refl_equal.
548 elim (Zplus_succ_pred_pn ? m1).
549 elim H.apply refl_equal.
552 theorem Zsucc_plus_nn :
553 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m))).
556 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m)))).intro.
558 simplify. apply refl_equal.
559 elim e.simplify. apply refl_equal.
560 simplify. apply refl_equal.
562 simplify. apply refl_equal.
563 simplify.apply refl_equal.
565 elim (Zplus_succ_pred_nn ? m1).
569 theorem Zsucc_plus_np :
570 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m))).
573 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m)))).
575 simplify. apply refl_equal.
576 elim e.simplify. apply refl_equal.
577 simplify. apply refl_equal.
579 simplify. apply refl_equal.
580 simplify.apply refl_equal.
583 elim (Zplus_succ_pred_np ? (S m1)).
588 theorem Zsucc_plus : \forall x,y:Z. eq Z (Zplus (Zsucc x) y) (Zsucc (Zplus x y)).
589 intros.elim x.elim y.
590 simplify. apply refl_equal.
591 elim (Zsucc_pos ?).apply refl_equal.
592 simplify.apply refl_equal.
593 elim y.elim sym_Zplus ? ?.elim sym_Zplus OZ ?.simplify.apply refl_equal.
597 elim (sym_Zplus OZ ?).apply refl_equal.
602 theorem Zpred_plus : \forall x,y:Z. eq Z (Zplus (Zpred x) y) (Zpred (Zplus x y)).
604 cut eq Z (Zpred (Zplus x y)) (Zpred (Zplus (Zsucc (Zpred x)) y)).
605 elim (sym_eq ? ? ? Hcut).
606 elim (sym_eq ? ? ? (Zsucc_plus ? ?)).
607 elim (sym_eq ? ? ? (Zpred_succ ?)).
609 elim (sym_eq ? ? ? (Zsucc_pred ?)).
613 theorem assoc_Zplus :
614 \forall x,y,z:Z. eq Z (Zplus x (Zplus y z)) (Zplus (Zplus x y) z).
615 intros.elim x.simplify.apply refl_equal.
616 elim e.elim (Zpred_neg (Zplus y z)).
618 elim (Zpred_plus ? ?).
620 elim (sym_eq ? ? ? (Zpred_plus (neg e1) ?)).
621 elim (sym_eq ? ? ? (Zpred_plus (neg e1) ?)).
622 elim (sym_eq ? ? ? (Zpred_plus (Zplus (neg e1) y) ?)).
623 apply f_equal.assumption.
624 elim e.elim (Zsucc_pos ?).
626 apply (sym_eq ? ? ? (Zsucc_plus ? ?)) .
627 elim (sym_eq ? ? ? (Zsucc_plus (pos e1) ?)).
628 elim (sym_eq ? ? ? (Zsucc_plus (pos e1) ?)).
629 elim (sym_eq ? ? ? (Zsucc_plus (Zplus (pos e1) y) ?)).
630 apply f_equal.assumption.