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/Z/plus".
18 include "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/Z/plus/Zplus.con x y).
46 theorem Zplus_z_OZ: \forall z:Z. z+OZ = z.
53 (* theorem symmetric_Zplus: symmetric Z Zplus. *)
55 theorem sym_Zplus : \forall x,y:Z. x+y = y+x.
56 intros.elim x.rewrite > Zplus_z_OZ.reflexivity.
57 elim y.simplify.reflexivity.
59 rewrite < plus_n_Sm. rewrite < plus_n_Sm.rewrite < sym_plus.reflexivity.
61 rewrite > nat_compare_n_m_m_n.
62 simplify.elim nat_compare.simplify.reflexivity.
63 simplify. reflexivity.
64 simplify. reflexivity.
65 elim y.simplify.reflexivity.
66 simplify.rewrite > nat_compare_n_m_m_n.
67 simplify.elim nat_compare.simplify.reflexivity.
68 simplify. reflexivity.
69 simplify. reflexivity.
70 simplify.rewrite < plus_n_Sm. rewrite < plus_n_Sm.rewrite < sym_plus.reflexivity.
73 theorem Zpred_Zplus_neg_O : \forall z:Z. Zpred z = (neg O)+z.
82 theorem Zsucc_Zplus_pos_O : \forall z:Z. Zsucc z = (pos O)+z.
91 theorem Zplus_pos_pos:
92 \forall n,m. (pos n)+(pos m) = (Zsucc (pos n))+(Zpred (pos m)).
98 simplify.rewrite < plus_n_Sm.
99 rewrite < plus_n_O.reflexivity.
100 simplify.rewrite < plus_n_Sm.
101 rewrite < plus_n_Sm.reflexivity.
104 theorem Zplus_pos_neg:
105 \forall n,m. (pos n)+(neg m) = (Zsucc (pos n))+(Zpred (neg m)).
109 theorem Zplus_neg_pos :
110 \forall n,m. (neg n)+(pos m) = (Zsucc (neg n))+(Zpred (pos m)).
113 simplify.reflexivity.
114 simplify.reflexivity.
116 simplify.reflexivity.
117 simplify.reflexivity.
120 theorem Zplus_neg_neg:
121 \forall n,m. (neg n)+(neg m) = (Zsucc (neg n))+(Zpred (neg m)).
124 simplify.reflexivity.
125 simplify.reflexivity.
127 simplify.rewrite > plus_n_Sm.reflexivity.
128 simplify.rewrite > plus_n_Sm.reflexivity.
131 theorem Zplus_Zsucc_Zpred:
132 \forall x,y. x+y = (Zsucc x)+(Zpred y).
135 simplify.reflexivity.
136 rewrite < Zsucc_Zplus_pos_O.rewrite > Zsucc_Zpred.reflexivity.
137 simplify.reflexivity.
139 simplify.reflexivity.
143 rewrite < sym_Zplus.rewrite < (sym_Zplus (Zpred OZ)).
144 rewrite < Zpred_Zplus_neg_O.rewrite > Zpred_Zsucc.simplify.reflexivity.
146 rewrite < Zplus_neg_neg.reflexivity.
149 theorem Zplus_Zsucc_pos_pos :
150 \forall n,m. (Zsucc (pos n))+(pos m) = Zsucc ((pos n)+(pos m)).
154 theorem Zplus_Zsucc_pos_neg:
155 \forall n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))).
158 (\lambda n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))))).intro.
160 simplify. reflexivity.
161 elim n2.simplify. reflexivity.
162 simplify. reflexivity.
164 simplify. reflexivity.
165 simplify.reflexivity.
167 rewrite < (Zplus_pos_neg ? m1).
171 theorem Zplus_Zsucc_neg_neg :
172 \forall n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m).
175 (\lambda n,m. Zsucc (neg n) + neg m = Zsucc (neg n + neg m))).intro.
177 simplify. reflexivity.
178 elim n2.simplify. reflexivity.
179 simplify. reflexivity.
181 simplify. reflexivity.
182 simplify.reflexivity.
184 rewrite < (Zplus_neg_neg ? m1).
188 theorem Zplus_Zsucc_neg_pos:
189 \forall n,m. Zsucc (neg n)+(pos m) = Zsucc ((neg n)+(pos m)).
192 (\lambda n,m. Zsucc (neg n) + (pos m) = Zsucc (neg n + pos m))).
194 simplify. reflexivity.
195 elim n2.simplify. reflexivity.
196 simplify. reflexivity.
198 simplify. reflexivity.
199 simplify.reflexivity.
202 rewrite < (Zplus_neg_pos ? (S m1)).
206 theorem Zplus_Zsucc : \forall x,y:Z. (Zsucc x)+y = Zsucc (x+y).
209 simplify. reflexivity.
210 simplify.reflexivity.
211 rewrite < Zsucc_Zplus_pos_O.reflexivity.
213 rewrite < (sym_Zplus OZ).reflexivity.
214 apply Zplus_Zsucc_pos_pos.
215 apply Zplus_Zsucc_pos_neg.
217 rewrite < sym_Zplus.rewrite < (sym_Zplus OZ).simplify.reflexivity.
218 apply Zplus_Zsucc_neg_pos.
219 apply Zplus_Zsucc_neg_neg.
222 theorem Zplus_Zpred: \forall x,y:Z. (Zpred x)+y = Zpred (x+y).
224 cut (Zpred (x+y) = Zpred ((Zsucc (Zpred x))+y)).
226 rewrite > Zplus_Zsucc.
227 rewrite > Zpred_Zsucc.
229 rewrite > Zsucc_Zpred.
234 theorem associative_Zplus: associative Z Zplus.
235 change with (\forall x,y,z:Z. (x + y) + z = x + (y + z)).
238 simplify.reflexivity.
240 rewrite < Zsucc_Zplus_pos_O.rewrite < Zsucc_Zplus_pos_O.
241 rewrite > Zplus_Zsucc.reflexivity.
242 rewrite > (Zplus_Zsucc (pos n1)).rewrite > (Zplus_Zsucc (pos n1)).
243 rewrite > (Zplus_Zsucc ((pos n1)+y)).apply eq_f.assumption.
245 rewrite < (Zpred_Zplus_neg_O (y+z)).rewrite < (Zpred_Zplus_neg_O y).
246 rewrite < Zplus_Zpred.reflexivity.
247 rewrite > (Zplus_Zpred (neg n1)).rewrite > (Zplus_Zpred (neg n1)).
248 rewrite > (Zplus_Zpred ((neg n1)+y)).apply eq_f.assumption.
251 variant assoc_Zplus : \forall x,y,z:Z. (x+y)+z = x+(y+z)
252 \def associative_Zplus.
255 definition Zopp : Z \to Z \def
256 \lambda x:Z. match x with
258 | (pos n) \Rightarrow (neg n)
259 | (neg n) \Rightarrow (pos n) ].
261 (*CSC: the URI must disappear: there is a bug now *)
262 interpretation "integer unary minus" 'uminus x = (cic:/matita/Z/plus/Zopp.con x).
264 theorem Zopp_Zplus: \forall x,y:Z. -(x+y) = -x + -y.
267 simplify. reflexivity.
268 simplify. reflexivity.
269 simplify. reflexivity.
271 simplify. reflexivity.
272 simplify. reflexivity.
273 simplify. apply nat_compare_elim.
274 intro.simplify.reflexivity.
275 intro.simplify.reflexivity.
276 intro.simplify.reflexivity.
278 simplify. reflexivity.
279 simplify. apply nat_compare_elim.
280 intro.simplify.reflexivity.
281 intro.simplify.reflexivity.
282 intro.simplify.reflexivity.
283 simplify.reflexivity.
286 theorem Zopp_Zopp: \forall x:Z. --x = x.
288 reflexivity.reflexivity.reflexivity.
291 theorem Zplus_Zopp: \forall x:Z. x+ -x = OZ.
295 rewrite > nat_compare_n_n.
296 simplify.apply refl_eq.
298 rewrite > nat_compare_n_n.
299 simplify.apply refl_eq.