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 (*CSC: the URI must disappear: there is a bug now *)
44 interpretation "integer plus" 'plus x y = (cic:/matita/library_autobatch/Z/plus/Zplus.con x y).
46 theorem Zplus_z_OZ: \forall z:Z. z+OZ = z.
49 (*simplify;reflexivity.*)
52 (* theorem symmetric_Zplus: symmetric Z Zplus. *)
54 theorem sym_Zplus : \forall x,y:Z. x+y = y+x.
58 (*rewrite > Zplus_z_OZ.
66 (*rewrite < plus_n_Sm.
71 rewrite > nat_compare_n_m_m_n.
73 elim nat_compare;autobatch
87 rewrite > nat_compare_n_m_m_n.
89 elim nat_compare;autobatch
99 (*rewrite < plus_n_Sm.
107 theorem Zpred_Zplus_neg_O : \forall z:Z. Zpred z = (neg O)+z.
124 theorem Zsucc_Zplus_pos_O : \forall z:Z. Zsucc z = (pos O)+z.
142 theorem Zplus_pos_pos:
143 \forall n,m. (pos n)+(pos m) = (Zsucc (pos n))+(Zpred (pos m)).
160 (*rewrite < plus_n_Sm.
167 theorem Zplus_pos_neg:
168 \forall n,m. (pos n)+(neg m) = (Zsucc (pos n))+(Zpred (neg m)).
173 theorem Zplus_neg_pos :
174 \forall n,m. (neg n)+(pos m) = (Zsucc (neg n))+(Zpred (pos m)).
192 theorem Zplus_neg_neg:
193 \forall n,m. (neg n)+(neg m) = (Zsucc (neg n))+(Zpred (neg m)).
210 (*rewrite > plus_n_Sm.
216 theorem Zplus_Zsucc_Zpred:
217 \forall x,y. x+y = (Zsucc x)+(Zpred y).
224 | rewrite < Zsucc_Zplus_pos_O.
225 rewrite > Zsucc_Zpred.
233 | apply Zplus_pos_pos
234 | apply Zplus_pos_neg
237 (*[ rewrite < sym_Zplus.
238 rewrite < (sym_Zplus (Zpred OZ)).
239 rewrite < Zpred_Zplus_neg_O.
240 rewrite > Zpred_Zsucc.
243 | apply Zplus_neg_pos
244 | rewrite < Zplus_neg_neg.
250 theorem Zplus_Zsucc_pos_pos :
251 \forall n,m. (Zsucc (pos n))+(pos m) = Zsucc ((pos n)+(pos m)).
256 theorem Zplus_Zsucc_pos_neg:
257 \forall n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))).
260 (\lambda n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m)))))
265 | elim n2; simplify; reflexivity
269 (*elim n1;simplify;reflexivity*)
271 rewrite < (Zplus_pos_neg ? m1).
277 theorem Zplus_Zsucc_neg_neg :
278 \forall n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m).
281 (\lambda n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m)))
287 | elim n2;simplify;reflexivity
291 (*elim n1;simplify;reflexivity*)
294 (*rewrite < (Zplus_neg_neg ? m1).
299 theorem Zplus_Zsucc_neg_pos:
300 \forall n,m. Zsucc (neg n)+(pos m) = Zsucc ((neg n)+(pos m)).
303 (\lambda n,m. Zsucc (neg n) + (pos m) = Zsucc (neg n + pos m)))
309 | elim n2;simplify;reflexivity
313 (*elim n1;simplify;reflexivity*)
317 rewrite < (Zplus_neg_pos ? (S m1)).
322 theorem Zplus_Zsucc : \forall x,y:Z. (Zsucc x)+y = Zsucc (x+y).
331 | rewrite < Zsucc_Zplus_pos_O.
335 (*[ rewrite < (sym_Zplus OZ).
337 | apply Zplus_Zsucc_pos_pos
338 | apply Zplus_Zsucc_pos_neg
341 (*[ rewrite < sym_Zplus.
342 rewrite < (sym_Zplus OZ).
345 | apply Zplus_Zsucc_neg_pos
346 | apply Zplus_Zsucc_neg_neg
351 theorem Zplus_Zpred: \forall x,y:Z. (Zpred x)+y = Zpred (x+y).
353 cut (Zpred (x+y) = Zpred ((Zsucc (Zpred x))+y));autobatch.
355 rewrite > Zplus_Zsucc.
356 rewrite > Zpred_Zsucc.
358 | rewrite > Zsucc_Zpred.
364 theorem associative_Zplus: associative Z Zplus.
365 change with (\forall x,y,z:Z. (x + y) + z = x + (y + z)).
373 [ rewrite < Zsucc_Zplus_pos_O.
375 (*rewrite < Zsucc_Zplus_pos_O.
376 rewrite > Zplus_Zsucc.
378 | rewrite > (Zplus_Zsucc (pos n1)).
379 rewrite > (Zplus_Zsucc (pos n1)).
381 (*rewrite > (Zplus_Zsucc ((pos n1)+y)).
386 [ rewrite < (Zpred_Zplus_neg_O (y+z)).
388 (*rewrite < (Zpred_Zplus_neg_O y).
389 rewrite < Zplus_Zpred.
391 | rewrite > (Zplus_Zpred (neg n1)).
392 rewrite > (Zplus_Zpred (neg n1)).
394 (*rewrite > (Zplus_Zpred ((neg n1)+y)).
401 variant assoc_Zplus : \forall x,y,z:Z. (x+y)+z = x+(y+z)
402 \def associative_Zplus.
405 definition Zopp : Z \to Z \def
406 \lambda x:Z. match x with
408 | (pos n) \Rightarrow (neg n)
409 | (neg n) \Rightarrow (pos n) ].
411 (*CSC: the URI must disappear: there is a bug now *)
412 interpretation "integer unary minus" 'uminus x = (cic:/matita/library_autobatch/Z/plus/Zopp.con x).
414 theorem Zopp_Zplus: \forall x,y:Z. -(x+y) = -x + -y.
418 (*simplify;reflexivity*)
427 apply nat_compare_elim;
428 intro;autobatch (*simplify;reflexivity*)
435 apply nat_compare_elim;
437 (*simplify;reflexivity*)
445 theorem Zopp_Zopp: \forall x:Z. --x = x.
450 theorem Zplus_Zopp: \forall x:Z. x+ -x = OZ.
455 rewrite > nat_compare_n_n.
460 rewrite > nat_compare_n_n.
468 definition Zminus : Z \to Z \to Z \def \lambda x,y:Z. x + (-y).
470 interpretation "integer minus" 'minus x y = (cic:/matita/library_autobatch/Z/plus/Zminus.con x y).