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 interpretation "integer plus" 'plus x y = (Zplus x y).
43 theorem eq_plus_Zplus: \forall n,m:nat. Z_of_nat (n+m) =
44 Z_of_nat n + Z_of_nat m.
48 [simplify.rewrite < plus_n_O.reflexivity
49 |simplify.reflexivity.
53 theorem Zplus_z_OZ: \forall z:Z. z+OZ = z.
60 (* theorem symmetric_Zplus: symmetric Z Zplus. *)
62 theorem sym_Zplus : \forall x,y:Z. x+y = y+x.
63 intros.elim x.rewrite > Zplus_z_OZ.reflexivity.
64 elim y.simplify.reflexivity.
66 rewrite < plus_n_Sm. rewrite < plus_n_Sm.rewrite < sym_plus.reflexivity.
68 rewrite > nat_compare_n_m_m_n.
69 simplify.elim nat_compare.simplify.reflexivity.
70 simplify. reflexivity.
71 simplify. reflexivity.
72 elim y.simplify.reflexivity.
73 simplify.rewrite > nat_compare_n_m_m_n.
74 simplify.elim nat_compare.simplify.reflexivity.
75 simplify. reflexivity.
76 simplify. reflexivity.
77 simplify.rewrite < plus_n_Sm. rewrite < plus_n_Sm.rewrite < sym_plus.reflexivity.
80 theorem Zpred_Zplus_neg_O : \forall z:Z. Zpred z = (neg O)+z.
89 theorem Zsucc_Zplus_pos_O : \forall z:Z. Zsucc z = (pos O)+z.
98 theorem Zplus_pos_pos:
99 \forall n,m. (pos n)+(pos m) = (Zsucc (pos n))+(Zpred (pos m)).
102 simplify.reflexivity.
103 simplify.reflexivity.
105 simplify.rewrite < plus_n_Sm.
106 rewrite < plus_n_O.reflexivity.
107 simplify.rewrite < plus_n_Sm.
108 rewrite < plus_n_Sm.reflexivity.
111 theorem Zplus_pos_neg:
112 \forall n,m. (pos n)+(neg m) = (Zsucc (pos n))+(Zpred (neg m)).
116 theorem Zplus_neg_pos :
117 \forall n,m. (neg n)+(pos m) = (Zsucc (neg n))+(Zpred (pos m)).
120 simplify.reflexivity.
121 simplify.reflexivity.
123 simplify.reflexivity.
124 simplify.reflexivity.
127 theorem Zplus_neg_neg:
128 \forall n,m. (neg n)+(neg m) = (Zsucc (neg n))+(Zpred (neg m)).
131 simplify.reflexivity.
132 simplify.reflexivity.
134 simplify.rewrite > plus_n_Sm.reflexivity.
135 simplify.rewrite > plus_n_Sm.reflexivity.
138 theorem Zplus_Zsucc_Zpred:
139 \forall x,y. x+y = (Zsucc x)+(Zpred y).
142 simplify.reflexivity.
143 rewrite < Zsucc_Zplus_pos_O.rewrite > Zsucc_Zpred.reflexivity.
144 simplify.reflexivity.
146 simplify.reflexivity.
150 rewrite < sym_Zplus.rewrite < (sym_Zplus (Zpred OZ)).
151 rewrite < Zpred_Zplus_neg_O.rewrite > Zpred_Zsucc.simplify.reflexivity.
153 rewrite < Zplus_neg_neg.reflexivity.
156 theorem Zplus_Zsucc_pos_pos :
157 \forall n,m. (Zsucc (pos n))+(pos m) = Zsucc ((pos n)+(pos m)).
161 theorem Zplus_Zsucc_pos_neg:
162 \forall n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))).
165 (\lambda n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))))).intro.
167 simplify. reflexivity.
168 elim n2.simplify. reflexivity.
169 simplify. reflexivity.
171 simplify. reflexivity.
172 simplify.reflexivity.
174 rewrite < (Zplus_pos_neg ? m1).
178 theorem Zplus_Zsucc_neg_neg :
179 \forall n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m).
182 (\lambda n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m))).intro.
184 simplify. reflexivity.
185 elim n2.simplify. reflexivity.
186 simplify. reflexivity.
188 simplify. reflexivity.
189 simplify.reflexivity.
191 rewrite < (Zplus_neg_neg ? m1).
195 theorem Zplus_Zsucc_neg_pos:
196 \forall n,m. Zsucc (neg n)+(pos m) = Zsucc ((neg n)+(pos m)).
199 (\lambda n,m. Zsucc (neg n) + (pos m) = Zsucc (neg n + pos m))).
201 simplify. reflexivity.
202 elim n2.simplify. reflexivity.
203 simplify. reflexivity.
205 simplify. reflexivity.
206 simplify.reflexivity.
209 rewrite < (Zplus_neg_pos ? (S m1)).
213 theorem Zplus_Zsucc : \forall x,y:Z. (Zsucc x)+y = Zsucc (x+y).
216 simplify. reflexivity.
217 simplify.reflexivity.
218 rewrite < Zsucc_Zplus_pos_O.reflexivity.
220 rewrite < (sym_Zplus OZ).reflexivity.
221 apply Zplus_Zsucc_pos_pos.
222 apply Zplus_Zsucc_pos_neg.
224 rewrite < sym_Zplus.rewrite < (sym_Zplus OZ).simplify.reflexivity.
225 apply Zplus_Zsucc_neg_pos.
226 apply Zplus_Zsucc_neg_neg.
229 theorem Zplus_Zpred: \forall x,y:Z. (Zpred x)+y = Zpred (x+y).
231 cut (Zpred (x+y) = Zpred ((Zsucc (Zpred x))+y)).
233 rewrite > Zplus_Zsucc.
234 rewrite > Zpred_Zsucc.
236 rewrite > Zsucc_Zpred.
241 theorem associative_Zplus: associative Z Zplus.
242 change with (\forall x,y,z:Z. (x + y) + z = x + (y + z)).
245 simplify.reflexivity.
247 rewrite < Zsucc_Zplus_pos_O.rewrite < Zsucc_Zplus_pos_O.
248 rewrite > Zplus_Zsucc.reflexivity.
249 rewrite > (Zplus_Zsucc (pos n1)).rewrite > (Zplus_Zsucc (pos n1)).
250 rewrite > (Zplus_Zsucc ((pos n1)+y)).apply eq_f.assumption.
252 rewrite < (Zpred_Zplus_neg_O (y+z)).rewrite < (Zpred_Zplus_neg_O y).
253 rewrite < Zplus_Zpred.reflexivity.
254 rewrite > (Zplus_Zpred (neg n1)).rewrite > (Zplus_Zpred (neg n1)).
255 rewrite > (Zplus_Zpred ((neg n1)+y)).apply eq_f.assumption.
258 variant assoc_Zplus : \forall x,y,z:Z. (x+y)+z = x+(y+z)
259 \def associative_Zplus.
262 definition Zopp : Z \to Z \def
263 \lambda x:Z. match x with
265 | (pos n) \Rightarrow (neg n)
266 | (neg n) \Rightarrow (pos n) ].
268 interpretation "integer unary minus" 'uminus x = (Zopp x).
270 theorem eq_OZ_Zopp_OZ : OZ = (- OZ).
274 theorem Zopp_Zplus: \forall x,y:Z. -(x+y) = -x + -y.
277 simplify. reflexivity.
278 simplify. reflexivity.
279 simplify. reflexivity.
281 simplify. reflexivity.
282 simplify. reflexivity.
283 simplify. apply nat_compare_elim.
284 intro.simplify.reflexivity.
285 intro.simplify.reflexivity.
286 intro.simplify.reflexivity.
288 simplify. reflexivity.
289 simplify. apply nat_compare_elim.
290 intro.simplify.reflexivity.
291 intro.simplify.reflexivity.
292 intro.simplify.reflexivity.
293 simplify.reflexivity.
296 theorem Zopp_Zopp: \forall x:Z. --x = x.
298 reflexivity.reflexivity.reflexivity.
301 theorem Zplus_Zopp: \forall x:Z. x+ -x = OZ.
305 rewrite > nat_compare_n_n.
306 simplify.apply refl_eq.
308 rewrite > nat_compare_n_n.
309 simplify.apply refl_eq.
312 theorem injective_Zplus_l: \forall x:Z.injective Z Z (\lambda y.y+x).
313 intro.simplify.intros (z y).
314 rewrite < Zplus_z_OZ.
315 rewrite < (Zplus_z_OZ y).
316 rewrite < (Zplus_Zopp x).
317 rewrite < assoc_Zplus.
318 rewrite < assoc_Zplus.
320 [assumption|reflexivity]
323 theorem injective_Zplus_r: \forall x:Z.injective Z Z (\lambda y.x+y).
324 intro.simplify.intros (z y).
325 apply (injective_Zplus_l x).
332 definition Zminus : Z \to Z \to Z \def \lambda x,y:Z. x + (-y).
334 interpretation "integer minus" 'minus x y = (Zminus x y).