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/".
19 inductive Z : Set \def
24 definition Z_of_nat \def
25 \lambda n. match n with
27 | (S n)\Rightarrow pos n].
31 definition neg_Z_of_nat \def
32 \lambda n. match n with
34 | (S n)\Rightarrow neg n].
40 | (pos n) \Rightarrow n
41 | (neg n) \Rightarrow n].
43 definition OZ_testb \def
47 | (pos n) \Rightarrow false
48 | (neg n) \Rightarrow false].
51 \forall z. if_then_else (OZ_testb z) (eq Z z OZ) (Not (eq Z z OZ)).
52 intros.elim z.simplify.reflexivity.
56 | (pos n) \Rightarrow False
57 | (neg n) \Rightarrow False].
58 apply Hcut.rewrite > H.simplify.exact I.
62 | (pos n) \Rightarrow False
63 | (neg n) \Rightarrow False].
64 apply Hcut. rewrite > H.simplify.exact I.
68 \lambda z. match z with
69 [ OZ \Rightarrow pos O
70 | (pos n) \Rightarrow pos (S n)
74 | (S p) \Rightarrow neg p]].
77 \lambda z. match z with
78 [ OZ \Rightarrow neg O
82 | (S p) \Rightarrow pos p]
83 | (neg n) \Rightarrow neg (S n)].
85 theorem Zpred_succ: \forall z:Z. eq Z (Zpred (Zsucc z)) z.
86 intros.elim z.reflexivity.
92 theorem Zsucc_pred: \forall z:Z. eq Z (Zsucc (Zpred z)) z.
93 intros.elim z.reflexivity.
99 let rec Zplus x y : Z \def
102 | (pos m) \Rightarrow
105 | (pos n) \Rightarrow (pos (S (plus m n)))
106 | (neg n) \Rightarrow
107 match nat_compare m n with
108 [ LT \Rightarrow (neg (pred (minus n m)))
110 | GT \Rightarrow (pos (pred (minus m n)))]]
111 | (neg m) \Rightarrow
114 | (pos n) \Rightarrow
115 match nat_compare m n with
116 [ LT \Rightarrow (pos (pred (minus n m)))
118 | GT \Rightarrow (neg (pred (minus m n)))]
119 | (neg n) \Rightarrow (neg (S (plus m n)))]].
121 theorem Zplus_z_O: \forall z:Z. eq Z (Zplus z OZ) z.
123 simplify.reflexivity.
124 simplify.reflexivity.
125 simplify.reflexivity.
128 theorem sym_Zplus : \forall x,y:Z. eq Z (Zplus x y) (Zplus y x).
129 intros.elim x.simplify.rewrite > Zplus_z_O.reflexivity.
130 elim y.simplify.reflexivity.
132 rewrite < sym_plus.reflexivity.
134 rewrite > nat_compare_invert.
135 simplify.elim nat_compare ? ?.simplify.reflexivity.
136 simplify. reflexivity.
137 simplify. reflexivity.
138 elim y.simplify.reflexivity.
139 simplify.rewrite > nat_compare_invert.
140 simplify.elim nat_compare ? ?.simplify.reflexivity.
141 simplify. reflexivity.
142 simplify. reflexivity.
143 simplify.elim (sym_plus ? ?).reflexivity.
146 theorem Zpred_neg : \forall z:Z. eq Z (Zpred z) (Zplus (neg O) z).
148 simplify.reflexivity.
149 simplify.reflexivity.
150 elim e2.simplify.reflexivity.
151 simplify.reflexivity.
154 theorem Zsucc_pos : \forall z:Z. eq Z (Zsucc z) (Zplus (pos O) z).
156 simplify.reflexivity.
157 elim e1.simplify.reflexivity.
158 simplify.reflexivity.
159 simplify.reflexivity.
162 theorem Zplus_succ_pred_pp :
163 \forall n,m. eq Z (Zplus (pos n) (pos m)) (Zplus (Zsucc (pos n)) (Zpred (pos m))).
166 simplify.reflexivity.
167 simplify.reflexivity.
170 rewrite < plus_n_O.reflexivity.
172 rewrite < plus_n_Sm.reflexivity.
175 theorem Zplus_succ_pred_pn :
176 \forall n,m. eq Z (Zplus (pos n) (neg m)) (Zplus (Zsucc (pos n)) (Zpred (neg m))).
180 theorem Zplus_succ_pred_np :
181 \forall n,m. eq Z (Zplus (neg n) (pos m)) (Zplus (Zsucc (neg n)) (Zpred (pos m))).
184 simplify.reflexivity.
185 simplify.reflexivity.
187 simplify.reflexivity.
188 simplify.reflexivity.
191 theorem Zplus_succ_pred_nn:
192 \forall n,m. eq Z (Zplus (neg n) (neg m)) (Zplus (Zsucc (neg n)) (Zpred (neg m))).
195 simplify.reflexivity.
196 simplify.reflexivity.
198 simplify.rewrite < plus_n_Sm.reflexivity.
199 simplify.rewrite > plus_n_Sm.reflexivity.
202 theorem Zplus_succ_pred:
203 \forall x,y. eq Z (Zplus x y) (Zplus (Zsucc x) (Zpred y)).
206 simplify.reflexivity.
207 simplify.reflexivity.
208 rewrite < Zsucc_pos.rewrite > Zsucc_pred.reflexivity.
209 elim y.rewrite < sym_Zplus.rewrite < sym_Zplus (Zpred OZ).
210 rewrite < Zpred_neg.rewrite > Zpred_succ.
211 simplify.reflexivity.
212 rewrite < Zplus_succ_pred_nn.reflexivity.
213 apply Zplus_succ_pred_np.
214 elim y.simplify.reflexivity.
215 apply Zplus_succ_pred_pn.
216 apply Zplus_succ_pred_pp.
219 theorem Zsucc_plus_pp :
220 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (pos m)) (Zsucc (Zplus (pos n) (pos m))).
224 theorem Zsucc_plus_pn :
225 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m))).
228 (\lambda n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m)))).intro.
230 simplify. reflexivity.
231 elim e1.simplify. reflexivity.
232 simplify. reflexivity.
234 simplify. reflexivity.
235 simplify.reflexivity.
237 rewrite < (Zplus_succ_pred_pn ? m1).
241 theorem Zsucc_plus_nn :
242 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m))).
245 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m)))).intro.
247 simplify. reflexivity.
248 elim e1.simplify. reflexivity.
249 simplify. reflexivity.
251 simplify. reflexivity.
252 simplify.reflexivity.
254 rewrite < (Zplus_succ_pred_nn ? m1).
258 theorem Zsucc_plus_np :
259 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m))).
262 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m)))).
264 simplify. reflexivity.
265 elim e1.simplify. reflexivity.
266 simplify. reflexivity.
268 simplify. reflexivity.
269 simplify.reflexivity.
272 rewrite < (Zplus_succ_pred_np ? (S m1)).
277 theorem Zsucc_plus : \forall x,y:Z. eq Z (Zplus (Zsucc x) y) (Zsucc (Zplus x y)).
278 intros.elim x.elim y.
279 simplify. reflexivity.
280 rewrite < Zsucc_pos.reflexivity.
281 simplify.reflexivity.
282 elim y.rewrite < sym_Zplus.rewrite < sym_Zplus OZ.simplify.reflexivity.
286 rewrite < sym_Zplus OZ.reflexivity.
291 theorem Zpred_plus : \forall x,y:Z. eq Z (Zplus (Zpred x) y) (Zpred (Zplus x y)).
293 cut eq Z (Zpred (Zplus x y)) (Zpred (Zplus (Zsucc (Zpred x)) y)).
295 rewrite > Zsucc_plus.
296 rewrite > Zpred_succ.
298 rewrite > Zsucc_pred.
302 theorem assoc_Zplus :
303 \forall x,y,z:Z. eq Z (Zplus x (Zplus y z)) (Zplus (Zplus x y) z).
304 intros.elim x.simplify.reflexivity.
305 elim e1.rewrite < (Zpred_neg (Zplus y z)).
306 rewrite < (Zpred_neg y).
307 rewrite < Zpred_plus.
309 rewrite > Zpred_plus (neg e).
310 rewrite > Zpred_plus (neg e).
311 rewrite > Zpred_plus (Zplus (neg e) y).
312 apply f_equal.assumption.
313 elim e2.rewrite < Zsucc_pos.
315 rewrite > Zsucc_plus.
317 rewrite > Zsucc_plus (pos e1).
318 rewrite > Zsucc_plus (pos e1).
319 rewrite > Zsucc_plus (Zplus (pos e1) y).
320 apply f_equal.assumption.