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/library_autobatch/Z/plus".
17 include "auto/Z/z.ma".
18 include "auto/nat/minus.ma".
20 definition Zplus :Z \to Z \to Z \def
27 | (pos n) \Rightarrow (pos (pred ((S m)+(S n))))
29 match nat_compare m n with
30 [ LT \Rightarrow (neg (pred (n-m)))
32 | GT \Rightarrow (pos (pred (m-n)))] ]
37 match nat_compare m n with
38 [ LT \Rightarrow (pos (pred (n-m)))
40 | GT \Rightarrow (neg (pred (m-n)))]
41 | (neg n) \Rightarrow (neg (pred ((S m)+(S n))))] ].
43 interpretation "integer plus" 'plus x y = (Zplus x y).
45 theorem Zplus_z_OZ: \forall z:Z. z+OZ = z.
48 (*simplify;reflexivity.*)
51 (* theorem symmetric_Zplus: symmetric Z Zplus. *)
53 theorem sym_Zplus : \forall x,y:Z. x+y = y+x.
57 (*rewrite > Zplus_z_OZ.
65 (*rewrite < plus_n_Sm.
70 rewrite > nat_compare_n_m_m_n.
72 elim nat_compare;autobatch
86 rewrite > nat_compare_n_m_m_n.
88 elim nat_compare;autobatch
98 (*rewrite < plus_n_Sm.
106 theorem Zpred_Zplus_neg_O : \forall z:Z. Zpred z = (neg O)+z.
123 theorem Zsucc_Zplus_pos_O : \forall z:Z. Zsucc z = (pos O)+z.
141 theorem Zplus_pos_pos:
142 \forall n,m. (pos n)+(pos m) = (Zsucc (pos n))+(Zpred (pos m)).
159 (*rewrite < plus_n_Sm.
166 theorem Zplus_pos_neg:
167 \forall n,m. (pos n)+(neg m) = (Zsucc (pos n))+(Zpred (neg m)).
172 theorem Zplus_neg_pos :
173 \forall n,m. (neg n)+(pos m) = (Zsucc (neg n))+(Zpred (pos m)).
191 theorem Zplus_neg_neg:
192 \forall n,m. (neg n)+(neg m) = (Zsucc (neg n))+(Zpred (neg m)).
209 (*rewrite > plus_n_Sm.
215 theorem Zplus_Zsucc_Zpred:
216 \forall x,y. x+y = (Zsucc x)+(Zpred y).
223 | rewrite < Zsucc_Zplus_pos_O.
224 rewrite > Zsucc_Zpred.
232 | apply Zplus_pos_pos
233 | apply Zplus_pos_neg
236 (*[ rewrite < sym_Zplus.
237 rewrite < (sym_Zplus (Zpred OZ)).
238 rewrite < Zpred_Zplus_neg_O.
239 rewrite > Zpred_Zsucc.
242 | apply Zplus_neg_pos
243 | rewrite < Zplus_neg_neg.
249 theorem Zplus_Zsucc_pos_pos :
250 \forall n,m. (Zsucc (pos n))+(pos m) = Zsucc ((pos n)+(pos m)).
255 theorem Zplus_Zsucc_pos_neg:
256 \forall n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))).
259 (\lambda n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m)))))
264 | elim n2; simplify; reflexivity
268 (*elim n1;simplify;reflexivity*)
270 rewrite < (Zplus_pos_neg ? m1).
276 theorem Zplus_Zsucc_neg_neg :
277 \forall n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m).
280 (\lambda n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m)))
286 | elim n2;simplify;reflexivity
290 (*elim n1;simplify;reflexivity*)
293 (*rewrite < (Zplus_neg_neg ? m1).
298 theorem Zplus_Zsucc_neg_pos:
299 \forall n,m. Zsucc (neg n)+(pos m) = Zsucc ((neg n)+(pos m)).
302 (\lambda n,m. Zsucc (neg n) + (pos m) = Zsucc (neg n + pos m)))
308 | elim n2;simplify;reflexivity
312 (*elim n1;simplify;reflexivity*)
316 rewrite < (Zplus_neg_pos ? (S m1)).
321 theorem Zplus_Zsucc : \forall x,y:Z. (Zsucc x)+y = Zsucc (x+y).
330 | rewrite < Zsucc_Zplus_pos_O.
334 (*[ rewrite < (sym_Zplus OZ).
336 | apply Zplus_Zsucc_pos_pos
337 | apply Zplus_Zsucc_pos_neg
340 (*[ rewrite < sym_Zplus.
341 rewrite < (sym_Zplus OZ).
344 | apply Zplus_Zsucc_neg_pos
345 | apply Zplus_Zsucc_neg_neg
350 theorem Zplus_Zpred: \forall x,y:Z. (Zpred x)+y = Zpred (x+y).
352 cut (Zpred (x+y) = Zpred ((Zsucc (Zpred x))+y));autobatch.
354 rewrite > Zplus_Zsucc.
355 rewrite > Zpred_Zsucc.
357 | rewrite > Zsucc_Zpred.
363 theorem associative_Zplus: associative Z Zplus.
364 change with (\forall x,y,z:Z. (x + y) + z = x + (y + z)).
372 [ rewrite < Zsucc_Zplus_pos_O.
374 (*rewrite < Zsucc_Zplus_pos_O.
375 rewrite > Zplus_Zsucc.
377 | rewrite > (Zplus_Zsucc (pos n1)).
378 rewrite > (Zplus_Zsucc (pos n1)).
380 (*rewrite > (Zplus_Zsucc ((pos n1)+y)).
385 [ rewrite < (Zpred_Zplus_neg_O (y+z)).
387 (*rewrite < (Zpred_Zplus_neg_O y).
388 rewrite < Zplus_Zpred.
390 | rewrite > (Zplus_Zpred (neg n1)).
391 rewrite > (Zplus_Zpred (neg n1)).
393 (*rewrite > (Zplus_Zpred ((neg n1)+y)).
400 variant assoc_Zplus : \forall x,y,z:Z. (x+y)+z = x+(y+z)
401 \def associative_Zplus.
404 definition Zopp : Z \to Z \def
405 \lambda x:Z. match x with
407 | (pos n) \Rightarrow (neg n)
408 | (neg n) \Rightarrow (pos n) ].
410 interpretation "integer unary minus" 'uminus x = (Zopp x).
412 theorem Zopp_Zplus: \forall x,y:Z. -(x+y) = -x + -y.
416 (*simplify;reflexivity*)
425 apply nat_compare_elim;
426 intro;autobatch (*simplify;reflexivity*)
433 apply nat_compare_elim;
435 (*simplify;reflexivity*)
443 theorem Zopp_Zopp: \forall x:Z. --x = x.
448 theorem Zplus_Zopp: \forall x:Z. x+ -x = OZ.
453 rewrite > nat_compare_n_n.
458 rewrite > nat_compare_n_n.
466 definition Zminus : Z \to Z \to Z \def \lambda x,y:Z. x + (-y).
468 interpretation "integer minus" 'minus x y = (Zminus x y).