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/z".
17 include "nat/compare.ma".
18 include "nat/minus.ma".
19 include "higher_order_defs/functions.ma".
21 inductive Z : Set \def
26 definition Z_of_nat \def
27 \lambda n. match n with
29 | (S n)\Rightarrow pos n].
33 definition neg_Z_of_nat \def
34 \lambda n. match n with
36 | (S n)\Rightarrow neg n].
42 | (pos n) \Rightarrow n
43 | (neg n) \Rightarrow n].
45 definition OZ_test \def
49 | (pos n) \Rightarrow false
50 | (neg n) \Rightarrow false].
52 theorem OZ_test_to_Prop :\forall z:Z.
54 [true \Rightarrow z=OZ
55 |false \Rightarrow \lnot (z=OZ)].
61 | (pos n) \Rightarrow False
62 | (neg n) \Rightarrow False].
63 apply Hcut.rewrite > H.simplify.exact I.
67 | (pos n) \Rightarrow False
68 | (neg n) \Rightarrow False].
69 apply Hcut. rewrite > H.simplify.exact I.
73 \lambda z. match z with
74 [ OZ \Rightarrow pos O
75 | (pos n) \Rightarrow pos (S n)
79 | (S p) \Rightarrow neg p]].
82 \lambda z. match z with
83 [ OZ \Rightarrow neg O
87 | (S p) \Rightarrow pos p]
88 | (neg n) \Rightarrow neg (S n)].
90 theorem Zpred_Zsucc: \forall z:Z. Zpred (Zsucc z) = z.
91 intros.elim z.reflexivity.
97 theorem Zsucc_Zpred: \forall z:Z. Zsucc (Zpred z) = z.
98 intros.elim z.reflexivity.
104 definition Zplus :Z \to Z \to Z \def
108 | (pos m) \Rightarrow
111 | (pos n) \Rightarrow (pos (S (plus m n)))
112 | (neg n) \Rightarrow
113 match nat_compare m n with
114 [ LT \Rightarrow (neg (pred (minus n m)))
116 | GT \Rightarrow (pos (pred (minus m n)))]]
117 | (neg m) \Rightarrow
120 | (pos n) \Rightarrow
121 match nat_compare m n with
122 [ LT \Rightarrow (pos (pred (minus n m)))
124 | GT \Rightarrow (neg (pred (minus m n)))]
125 | (neg n) \Rightarrow (neg (S (plus m n)))]].
127 (*CSC: the URI must disappear: there is a bug now *)
128 interpretation "integer plus" 'plus x y = (cic:/matita/Z/z/Zplus.con x y).
130 theorem Zplus_z_OZ: \forall z:Z. z+OZ = z.
132 simplify.reflexivity.
133 simplify.reflexivity.
134 simplify.reflexivity.
137 (* theorem symmetric_Zplus: symmetric Z Zplus. *)
139 theorem sym_Zplus : \forall x,y:Z. x+y = y+x.
140 intros.elim x.rewrite > Zplus_z_OZ.reflexivity.
141 elim y.simplify.reflexivity.
143 rewrite < sym_plus.reflexivity.
145 rewrite > nat_compare_n_m_m_n.
146 simplify.elim nat_compare ? ?.simplify.reflexivity.
147 simplify. reflexivity.
148 simplify. reflexivity.
149 elim y.simplify.reflexivity.
150 simplify.rewrite > nat_compare_n_m_m_n.
151 simplify.elim nat_compare ? ?.simplify.reflexivity.
152 simplify. reflexivity.
153 simplify. reflexivity.
154 simplify.rewrite < sym_plus.reflexivity.
157 theorem Zpred_Zplus_neg_O : \forall z:Z. Zpred z = (neg O)+z.
159 simplify.reflexivity.
160 simplify.reflexivity.
161 elim n.simplify.reflexivity.
162 simplify.reflexivity.
165 theorem Zsucc_Zplus_pos_O : \forall z:Z. Zsucc z = (pos O)+z.
167 simplify.reflexivity.
168 elim n.simplify.reflexivity.
169 simplify.reflexivity.
170 simplify.reflexivity.
173 theorem Zplus_pos_pos:
174 \forall n,m. (pos n)+(pos m) = (Zsucc (pos n))+(Zpred (pos m)).
177 simplify.reflexivity.
178 simplify.reflexivity.
181 rewrite < plus_n_O.reflexivity.
183 rewrite < plus_n_Sm.reflexivity.
186 theorem Zplus_pos_neg:
187 \forall n,m. (pos n)+(neg m) = (Zsucc (pos n))+(Zpred (neg m)).
191 theorem Zplus_neg_pos :
192 \forall n,m. (neg n)+(pos m) = (Zsucc (neg n))+(Zpred (pos m)).
195 simplify.reflexivity.
196 simplify.reflexivity.
198 simplify.reflexivity.
199 simplify.reflexivity.
202 theorem Zplus_neg_neg:
203 \forall n,m. (neg n)+(neg m) = (Zsucc (neg n))+(Zpred (neg m)).
206 simplify.reflexivity.
207 simplify.reflexivity.
209 simplify.rewrite < plus_n_Sm.reflexivity.
210 simplify.rewrite > plus_n_Sm.reflexivity.
213 theorem Zplus_Zsucc_Zpred:
214 \forall x,y. x+y = (Zsucc x)+(Zpred y).
217 simplify.reflexivity.
218 simplify.reflexivity.
219 rewrite < Zsucc_Zplus_pos_O.
220 rewrite > Zsucc_Zpred.reflexivity.
221 elim y.rewrite < sym_Zplus.rewrite < sym_Zplus (Zpred OZ).
222 rewrite < Zpred_Zplus_neg_O.
223 rewrite > Zpred_Zsucc.
224 simplify.reflexivity.
225 rewrite < Zplus_neg_neg.reflexivity.
227 elim y.simplify.reflexivity.
232 theorem Zplus_Zsucc_pos_pos :
233 \forall n,m. (Zsucc (pos n))+(pos m) = Zsucc ((pos n)+(pos m)).
237 theorem Zplus_Zsucc_pos_neg:
238 \forall n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m))).
241 (\lambda n,m. (Zsucc (pos n))+(neg m) = (Zsucc ((pos n)+(neg m)))).intro.
243 simplify. reflexivity.
244 elim n2.simplify. reflexivity.
245 simplify. reflexivity.
247 simplify. reflexivity.
248 simplify.reflexivity.
250 rewrite < (Zplus_pos_neg ? m1).
254 theorem Zplus_Zsucc_neg_neg :
255 \forall n,m. (Zsucc (neg n))+(neg m) = Zsucc ((neg n)+(neg m)).
258 (\lambda n,m. ((Zsucc (neg n))+(neg m)) = Zsucc ((neg n)+(neg m))).intro.
260 simplify. reflexivity.
261 elim n2.simplify. reflexivity.
262 simplify. reflexivity.
264 simplify. reflexivity.
265 simplify.reflexivity.
267 rewrite < (Zplus_neg_neg ? m1).
271 theorem Zplus_Zsucc_neg_pos:
272 \forall n,m. Zsucc (neg n)+(pos m) = Zsucc ((neg n)+(pos m)).
275 (\lambda n,m. (Zsucc (neg n))+(pos m) = Zsucc ((neg n)+(pos m))).
277 simplify. reflexivity.
278 elim n2.simplify. reflexivity.
279 simplify. reflexivity.
281 simplify. reflexivity.
282 simplify.reflexivity.
285 rewrite < (Zplus_neg_pos ? (S m1)).
289 theorem Zplus_Zsucc : \forall x,y:Z. (Zsucc x)+y = Zsucc (x+y).
290 intros.elim x.elim y.
291 simplify. reflexivity.
292 rewrite < Zsucc_Zplus_pos_O.reflexivity.
293 simplify.reflexivity.
294 elim y.rewrite < sym_Zplus.rewrite < sym_Zplus OZ.simplify.reflexivity.
295 apply Zplus_Zsucc_neg_neg.
296 apply Zplus_Zsucc_neg_pos.
298 rewrite < sym_Zplus OZ.reflexivity.
299 apply Zplus_Zsucc_pos_neg.
300 apply Zplus_Zsucc_pos_pos.
303 theorem Zplus_Zpred: \forall x,y:Z. (Zpred x)+y = Zpred (x+y).
305 cut Zpred (x+y) = Zpred ((Zsucc (Zpred x))+y).
307 rewrite > Zplus_Zsucc.
308 rewrite > Zpred_Zsucc.
310 rewrite > Zsucc_Zpred.
315 theorem associative_Zplus: associative Z Zplus.
316 change with \forall x,y,z:Z. (x + y) + z = x + (y + z).
318 intros.elim x.simplify.reflexivity.
319 elim n.rewrite < (Zpred_Zplus_neg_O (y+z)).
320 rewrite < (Zpred_Zplus_neg_O y).
321 rewrite < Zplus_Zpred.
323 rewrite > Zplus_Zpred (neg n1).
324 rewrite > Zplus_Zpred (neg n1).
325 rewrite > Zplus_Zpred ((neg n1)+y).
326 apply eq_f.assumption.
327 elim n.rewrite < Zsucc_Zplus_pos_O.
328 rewrite < Zsucc_Zplus_pos_O.
329 rewrite > Zplus_Zsucc.
331 rewrite > Zplus_Zsucc (pos n1).
332 rewrite > Zplus_Zsucc (pos n1).
333 rewrite > Zplus_Zsucc ((pos n1)+y).
334 apply eq_f.assumption.
337 variant assoc_Zplus : \forall x,y,z:Z. (x+y)+z = x+(y+z)
338 \def associative_Zplus.
341 definition Zopp : Z \to Z \def
342 \lambda x:Z. match x with
344 | (pos n) \Rightarrow (neg n)
345 | (neg n) \Rightarrow (pos n) ].
347 (*CSC: the URI must disappear: there is a bug now *)
348 interpretation "integer unary minus" 'uminus x = (cic:/matita/Z/z/Zopp.con x).
350 theorem Zplus_Zopp: \forall x:Z. x+ -x = OZ.
354 rewrite > nat_compare_n_n.
355 simplify.apply refl_eq.
357 rewrite > nat_compare_n_n.
358 simplify.apply refl_eq.