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 eq Z z OZ
55 |false \Rightarrow Not (eq Z 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. eq Z (Zpred (Zsucc z)) z.
91 intros.elim z.reflexivity.
97 theorem Zsucc_Zpred: \forall z:Z. eq 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 theorem Zplus_z_OZ: \forall z:Z. eq Z (Zplus z OZ) z.
129 simplify.reflexivity.
130 simplify.reflexivity.
131 simplify.reflexivity.
134 (* theorem symmetric_Zplus: symmetric Z Zplus. *)
136 theorem sym_Zplus : \forall x,y:Z. eq Z (Zplus x y) (Zplus y x).
137 intros.elim x.rewrite > Zplus_z_OZ.reflexivity.
138 elim y.simplify.reflexivity.
140 rewrite < sym_plus.reflexivity.
142 rewrite > nat_compare_n_m_m_n.
143 simplify.elim nat_compare ? ?.simplify.reflexivity.
144 simplify. reflexivity.
145 simplify. reflexivity.
146 elim y.simplify.reflexivity.
147 simplify.rewrite > nat_compare_n_m_m_n.
148 simplify.elim nat_compare ? ?.simplify.reflexivity.
149 simplify. reflexivity.
150 simplify. reflexivity.
151 simplify.rewrite < sym_plus.reflexivity.
154 theorem Zpred_Zplus_neg_O : \forall z:Z. eq Z (Zpred z) (Zplus (neg O) z).
156 simplify.reflexivity.
157 simplify.reflexivity.
158 elim n.simplify.reflexivity.
159 simplify.reflexivity.
162 theorem Zsucc_Zplus_pos_O : \forall z:Z. eq Z (Zsucc z) (Zplus (pos O) z).
164 simplify.reflexivity.
165 elim n.simplify.reflexivity.
166 simplify.reflexivity.
167 simplify.reflexivity.
170 theorem Zplus_pos_pos:
171 \forall n,m. eq Z (Zplus (pos n) (pos m)) (Zplus (Zsucc (pos n)) (Zpred (pos m))).
174 simplify.reflexivity.
175 simplify.reflexivity.
178 rewrite < plus_n_O.reflexivity.
180 rewrite < plus_n_Sm.reflexivity.
183 theorem Zplus_pos_neg:
184 \forall n,m. eq Z (Zplus (pos n) (neg m)) (Zplus (Zsucc (pos n)) (Zpred (neg m))).
188 theorem Zplus_neg_pos :
189 \forall n,m. eq Z (Zplus (neg n) (pos m)) (Zplus (Zsucc (neg n)) (Zpred (pos m))).
192 simplify.reflexivity.
193 simplify.reflexivity.
195 simplify.reflexivity.
196 simplify.reflexivity.
199 theorem Zplus_neg_neg:
200 \forall n,m. eq Z (Zplus (neg n) (neg m)) (Zplus (Zsucc (neg n)) (Zpred (neg m))).
203 simplify.reflexivity.
204 simplify.reflexivity.
206 simplify.rewrite < plus_n_Sm.reflexivity.
207 simplify.rewrite > plus_n_Sm.reflexivity.
210 theorem Zplus_Zsucc_Zpred:
211 \forall x,y. eq Z (Zplus x y) (Zplus (Zsucc x) (Zpred y)).
214 simplify.reflexivity.
215 simplify.reflexivity.
216 rewrite < Zsucc_Zplus_pos_O.
217 rewrite > Zsucc_Zpred.reflexivity.
218 elim y.rewrite < sym_Zplus.rewrite < sym_Zplus (Zpred OZ).
219 rewrite < Zpred_Zplus_neg_O.
220 rewrite > Zpred_Zsucc.
221 simplify.reflexivity.
222 rewrite < Zplus_neg_neg.reflexivity.
224 elim y.simplify.reflexivity.
229 theorem Zplus_Zsucc_pos_pos :
230 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (pos m)) (Zsucc (Zplus (pos n) (pos m))).
234 theorem Zplus_Zsucc_pos_neg:
235 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m))).
238 (\lambda n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m)))).intro.
240 simplify. reflexivity.
241 elim n2.simplify. reflexivity.
242 simplify. reflexivity.
244 simplify. reflexivity.
245 simplify.reflexivity.
247 rewrite < (Zplus_pos_neg ? m1).
251 theorem Zplus_Zsucc_neg_neg :
252 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m))).
255 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m)))).intro.
257 simplify. reflexivity.
258 elim n2.simplify. reflexivity.
259 simplify. reflexivity.
261 simplify. reflexivity.
262 simplify.reflexivity.
264 rewrite < (Zplus_neg_neg ? m1).
268 theorem Zplus_Zsucc_neg_pos:
269 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m))).
272 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m)))).
274 simplify. reflexivity.
275 elim n2.simplify. reflexivity.
276 simplify. reflexivity.
278 simplify. reflexivity.
279 simplify.reflexivity.
282 rewrite < (Zplus_neg_pos ? (S m1)).
286 theorem Zplus_Zsucc : \forall x,y:Z. eq Z (Zplus (Zsucc x) y) (Zsucc (Zplus x y)).
287 intros.elim x.elim y.
288 simplify. reflexivity.
289 rewrite < Zsucc_Zplus_pos_O.reflexivity.
290 simplify.reflexivity.
291 elim y.rewrite < sym_Zplus.rewrite < sym_Zplus OZ.simplify.reflexivity.
292 apply Zplus_Zsucc_neg_neg.
293 apply Zplus_Zsucc_neg_pos.
295 rewrite < sym_Zplus OZ.reflexivity.
296 apply Zplus_Zsucc_pos_neg.
297 apply Zplus_Zsucc_pos_pos.
300 theorem Zplus_Zpred: \forall x,y:Z. eq Z (Zplus (Zpred x) y) (Zpred (Zplus x y)).
302 cut eq Z (Zpred (Zplus x y)) (Zpred (Zplus (Zsucc (Zpred x)) y)).
304 rewrite > Zplus_Zsucc.
305 rewrite > Zpred_Zsucc.
307 rewrite > Zsucc_Zpred.
312 theorem associative_Zplus: associative Z Zplus.
313 change with \forall x,y,z:Z. eq Z (Zplus (Zplus x y) z) (Zplus x (Zplus y z)).
315 intros.elim x.simplify.reflexivity.
316 elim n.rewrite < (Zpred_Zplus_neg_O (Zplus y z)).
317 rewrite < (Zpred_Zplus_neg_O y).
318 rewrite < Zplus_Zpred.
320 rewrite > Zplus_Zpred (neg n1).
321 rewrite > Zplus_Zpred (neg n1).
322 rewrite > Zplus_Zpred (Zplus (neg n1) y).
323 apply eq_f.assumption.
324 elim n.rewrite < Zsucc_Zplus_pos_O.
325 rewrite < Zsucc_Zplus_pos_O.
326 rewrite > Zplus_Zsucc.
328 rewrite > Zplus_Zsucc (pos n1).
329 rewrite > Zplus_Zsucc (pos n1).
330 rewrite > Zplus_Zsucc (Zplus (pos n1) y).
331 apply eq_f.assumption.
334 variant assoc_Zplus : \forall x,y,z:Z. eq Z (Zplus (Zplus x y) z) (Zplus x (Zplus y z))
335 \def associative_Zplus.
338 definition Zopp : Z \to Z \def
339 \lambda x:Z. match x with
341 | (pos n) \Rightarrow (neg n)
342 | (neg n) \Rightarrow (pos n) ].
344 theorem Zplus_Zopp: \forall x:Z. (eq Z (Zplus x (Zopp x)) OZ).
348 rewrite > nat_compare_n_n.
349 simplify.apply refl_eq.
351 rewrite > nat_compare_n_n.
352 simplify.apply refl_eq.