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 (**************************************************************************)
16 include "nat/minus.ma".
18 definition Zplus :Z \to Z \to Z \def
25 | (pos n) \Rightarrow (pos (pred ((S m)+(S n))))
27 match nat_compare m n with
28 [ LT \Rightarrow (neg (pred (n-m)))
30 | GT \Rightarrow (pos (pred (m-n)))] ]
35 match nat_compare m n with
36 [ LT \Rightarrow (pos (pred (n-m)))
38 | GT \Rightarrow (neg (pred (m-n)))]
39 | (neg n) \Rightarrow (neg (pred ((S m)+(S n))))] ].
41 (*CSC: the URI must disappear: there is a bug now *)
42 interpretation "integer plus" 'plus x y = (cic:/matita/Z/plus/Zplus.con x y).
44 theorem Zplus_z_OZ: \forall z:Z. z+OZ = z.
51 (* theorem symmetric_Zplus: symmetric Z Zplus. *)
53 theorem sym_Zplus : \forall x,y:Z. x+y = y+x.
54 intros.elim x.rewrite > Zplus_z_OZ.reflexivity.
55 elim y.simplify.reflexivity.
57 rewrite < plus_n_Sm. rewrite < plus_n_Sm.rewrite < sym_plus.reflexivity.
59 rewrite > nat_compare_n_m_m_n.
60 simplify.elim nat_compare.simplify.reflexivity.
61 simplify. reflexivity.
62 simplify. reflexivity.
63 elim y.simplify.reflexivity.
64 simplify.rewrite > nat_compare_n_m_m_n.
65 simplify.elim nat_compare.simplify.reflexivity.
66 simplify. reflexivity.
67 simplify. reflexivity.
68 simplify.rewrite < plus_n_Sm. rewrite < plus_n_Sm.rewrite < sym_plus.reflexivity.
71 theorem Zpred_Zplus_neg_O : \forall z:Z. Zpred z = (neg O)+z.
80 theorem Zsucc_Zplus_pos_O : \forall z:Z. Zsucc z = (pos O)+z.
89 theorem Zplus_pos_pos:
90 \forall n,m. (pos n)+(pos m) = (Zsucc (pos n))+(Zpred (pos m)).
96 simplify.rewrite < plus_n_Sm.
97 rewrite < plus_n_O.reflexivity.
98 simplify.rewrite < plus_n_Sm.
99 rewrite < plus_n_Sm.reflexivity.
102 theorem Zplus_pos_neg:
103 \forall n,m. (pos n)+(neg m) = (Zsucc (pos n))+(Zpred (neg m)).
107 theorem Zplus_neg_pos :
108 \forall n,m. (neg n)+(pos m) = (Zsucc (neg n))+(Zpred (pos m)).
111 simplify.reflexivity.
112 simplify.reflexivity.
114 simplify.reflexivity.
115 simplify.reflexivity.
118 theorem Zplus_neg_neg:
119 \forall n,m. (neg n)+(neg m) = (Zsucc (neg n))+(Zpred (neg m)).
122 simplify.reflexivity.
123 simplify.reflexivity.
125 simplify.rewrite > plus_n_Sm.reflexivity.
126 simplify.rewrite > plus_n_Sm.reflexivity.
129 theorem Zplus_Zsucc_Zpred:
130 \forall x,y. x+y = (Zsucc x)+(Zpred y).
133 simplify.reflexivity.
134 rewrite < Zsucc_Zplus_pos_O.rewrite > Zsucc_Zpred.reflexivity.
135 simplify.reflexivity.
137 simplify.reflexivity.
141 rewrite < sym_Zplus.rewrite < (sym_Zplus (Zpred OZ)).
142 rewrite < Zpred_Zplus_neg_O.rewrite > Zpred_Zsucc.simplify.reflexivity.
144 rewrite < Zplus_neg_neg.reflexivity.
147 theorem Zplus_Zsucc_pos_pos :
148 \forall n,m. (Zsucc (pos n))+(pos m) = Zsucc ((pos n)+(pos m)).
152 theorem Zplus_Zsucc_pos_neg:
153 \forall n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))).
156 (\lambda n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))))).intro.
158 simplify. reflexivity.
159 elim n2.simplify. reflexivity.
160 simplify. reflexivity.
162 simplify. reflexivity.
163 simplify.reflexivity.
165 rewrite < (Zplus_pos_neg ? m1).
169 theorem Zplus_Zsucc_neg_neg :
170 \forall n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m).
173 (\lambda n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m))).intro.
175 simplify. reflexivity.
176 elim n2.simplify. reflexivity.
177 simplify. reflexivity.
179 simplify. reflexivity.
180 simplify.reflexivity.
182 rewrite < (Zplus_neg_neg ? m1).
186 theorem Zplus_Zsucc_neg_pos:
187 \forall n,m. Zsucc (neg n)+(pos m) = Zsucc ((neg n)+(pos m)).
190 (\lambda n,m. Zsucc (neg n) + (pos m) = Zsucc (neg n + pos m))).
192 simplify. reflexivity.
193 elim n2.simplify. reflexivity.
194 simplify. reflexivity.
196 simplify. reflexivity.
197 simplify.reflexivity.
200 rewrite < (Zplus_neg_pos ? (S m1)).
204 theorem Zplus_Zsucc : \forall x,y:Z. (Zsucc x)+y = Zsucc (x+y).
207 simplify. reflexivity.
208 simplify.reflexivity.
209 rewrite < Zsucc_Zplus_pos_O.reflexivity.
211 rewrite < (sym_Zplus OZ).reflexivity.
212 apply Zplus_Zsucc_pos_pos.
213 apply Zplus_Zsucc_pos_neg.
215 rewrite < sym_Zplus.rewrite < (sym_Zplus OZ).simplify.reflexivity.
216 apply Zplus_Zsucc_neg_pos.
217 apply Zplus_Zsucc_neg_neg.
220 theorem Zplus_Zpred: \forall x,y:Z. (Zpred x)+y = Zpred (x+y).
222 cut (Zpred (x+y) = Zpred ((Zsucc (Zpred x))+y)).
224 rewrite > Zplus_Zsucc.
225 rewrite > Zpred_Zsucc.
227 rewrite > Zsucc_Zpred.
232 theorem associative_Zplus: associative Z Zplus.
233 change with (\forall x,y,z:Z. (x + y) + z = x + (y + z)).
236 simplify.reflexivity.
238 rewrite < Zsucc_Zplus_pos_O.rewrite < Zsucc_Zplus_pos_O.
239 rewrite > Zplus_Zsucc.reflexivity.
240 rewrite > (Zplus_Zsucc (pos n1)).rewrite > (Zplus_Zsucc (pos n1)).
241 rewrite > (Zplus_Zsucc ((pos n1)+y)).apply eq_f.assumption.
243 rewrite < (Zpred_Zplus_neg_O (y+z)).rewrite < (Zpred_Zplus_neg_O y).
244 rewrite < Zplus_Zpred.reflexivity.
245 rewrite > (Zplus_Zpred (neg n1)).rewrite > (Zplus_Zpred (neg n1)).
246 rewrite > (Zplus_Zpred ((neg n1)+y)).apply eq_f.assumption.
249 variant assoc_Zplus : \forall x,y,z:Z. (x+y)+z = x+(y+z)
250 \def associative_Zplus.
253 definition Zopp : Z \to Z \def
254 \lambda x:Z. match x with
256 | (pos n) \Rightarrow (neg n)
257 | (neg n) \Rightarrow (pos n) ].
259 (*CSC: the URI must disappear: there is a bug now *)
260 interpretation "integer unary minus" 'uminus x = (cic:/matita/Z/plus/Zopp.con x).
262 theorem eq_OZ_Zopp_OZ : OZ = (- OZ).
266 theorem Zopp_Zplus: \forall x,y:Z. -(x+y) = -x + -y.
269 simplify. reflexivity.
270 simplify. reflexivity.
271 simplify. reflexivity.
273 simplify. reflexivity.
274 simplify. reflexivity.
275 simplify. apply nat_compare_elim.
276 intro.simplify.reflexivity.
277 intro.simplify.reflexivity.
278 intro.simplify.reflexivity.
280 simplify. reflexivity.
281 simplify. apply nat_compare_elim.
282 intro.simplify.reflexivity.
283 intro.simplify.reflexivity.
284 intro.simplify.reflexivity.
285 simplify.reflexivity.
288 theorem Zopp_Zopp: \forall x:Z. --x = x.
290 reflexivity.reflexivity.reflexivity.
293 theorem Zplus_Zopp: \forall x:Z. x+ -x = OZ.
297 rewrite > nat_compare_n_n.
298 simplify.apply refl_eq.
300 rewrite > nat_compare_n_n.
301 simplify.apply refl_eq.
304 theorem injective_Zplus_l: \forall x:Z.injective Z Z (\lambda y.y+x).
305 intro.simplify.intros (z y).
306 rewrite < Zplus_z_OZ.
307 rewrite < (Zplus_z_OZ y).
308 rewrite < (Zplus_Zopp x).
309 rewrite < assoc_Zplus.
310 rewrite < assoc_Zplus.
312 [assumption|reflexivity]
315 theorem injective_Zplus_r: \forall x:Z.injective Z Z (\lambda y.x+y).
316 intro.simplify.intros (z y).
317 apply (injective_Zplus_l x).
324 definition Zminus : Z \to Z \to Z \def \lambda x,y:Z. x + (-y).
326 interpretation "integer minus" 'minus x y = (cic:/matita/Z/plus/Zminus.con x y).