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/".
17 alias id "nat" = "cic:/matita/nat/nat.ind#xpointer(1/1)".
18 alias id "O" = "cic:/matita/nat/nat.ind#xpointer(1/1/1)".
19 alias id "false" = "cic:/matita/bool/bool.ind#xpointer(1/1/2)".
20 alias id "true" = "cic:/matita/bool/bool.ind#xpointer(1/1/1)".
21 alias id "Not" = "cic:/matita/logic/Not.con".
22 alias id "eq" = "cic:/matita/equality/eq.ind#xpointer(1/1)".
23 alias id "if_then_else" = "cic:/matita/bool/if_then_else.con".
24 alias id "refl_equal" = "cic:/matita/equality/eq.ind#xpointer(1/1/1)".
25 alias id "False" = "cic:/matita/logic/False.ind#xpointer(1/1)".
26 alias id "True" = "cic:/matita/logic/True.ind#xpointer(1/1)".
27 alias id "sym_eq" = "cic:/matita/equality/sym_eq.con".
28 alias id "I" = "cic:/matita/logic/True.ind#xpointer(1/1/1)".
29 alias id "S" = "cic:/matita/nat/nat.ind#xpointer(1/1/2)".
30 alias id "LT" = "cic:/matita/compare/compare.ind#xpointer(1/1/1)".
31 alias id "minus" = "cic:/matita/nat/minus.con".
32 alias id "nat_compare" = "cic:/matita/nat/nat_compare.con".
33 alias id "plus" = "cic:/matita/nat/plus.con".
34 alias id "pred" = "cic:/matita/nat/pred.con".
35 alias id "sym_plus" = "cic:/matita/nat/sym_plus.con".
36 alias id "nat_compare_invert" = "cic:/matita/nat/nat_compare_invert.con".
37 alias id "plus_n_O" = "cic:/matita/nat/plus_n_O.con".
38 alias id "plus_n_Sm" = "cic:/matita/nat/plus_n_Sm.con".
39 alias id "nat_double_ind" = "cic:/matita/nat/nat_double_ind.con".
40 alias id "f_equal" = "cic:/matita/equality/f_equal.con".
42 inductive Z : Set \def
47 definition Z_of_nat \def
48 \lambda n. match n with
50 | (S n)\Rightarrow pos n].
54 definition neg_Z_of_nat \def
55 \lambda n. match n with
57 | (S n)\Rightarrow neg n].
63 | (pos n) \Rightarrow n
64 | (neg n) \Rightarrow n].
66 definition OZ_testb \def
70 | (pos n) \Rightarrow false
71 | (neg n) \Rightarrow false].
74 \forall z. if_then_else (OZ_testb z) (eq Z z OZ) (Not (eq Z z OZ)).
75 intros.elim z.simplify.reflexivity.
79 | (pos n) \Rightarrow False
80 | (neg n) \Rightarrow False].
81 apply Hcut.rewrite > H.simplify.exact I.
85 | (pos n) \Rightarrow False
86 | (neg n) \Rightarrow False].
87 apply Hcut. rewrite > H.simplify.exact I.
91 \lambda z. match z with
92 [ OZ \Rightarrow pos O
93 | (pos n) \Rightarrow pos (S n)
97 | (S p) \Rightarrow neg p]].
100 \lambda z. match z with
101 [ OZ \Rightarrow neg O
102 | (pos n) \Rightarrow
105 | (S p) \Rightarrow pos p]
106 | (neg n) \Rightarrow neg (S n)].
108 theorem Zpred_succ: \forall z:Z. eq Z (Zpred (Zsucc z)) z.
109 intros.elim z.reflexivity.
115 theorem Zsucc_pred: \forall z:Z. eq Z (Zsucc (Zpred z)) z.
116 intros.elim z.reflexivity.
122 let rec Zplus x y : Z \def
125 | (pos m) \Rightarrow
128 | (pos n) \Rightarrow (pos (S (plus m n)))
129 | (neg n) \Rightarrow
130 match nat_compare m n with
131 [ LT \Rightarrow (neg (pred (minus n m)))
133 | GT \Rightarrow (pos (pred (minus m n)))]]
134 | (neg m) \Rightarrow
137 | (pos n) \Rightarrow
138 match nat_compare m n with
139 [ LT \Rightarrow (pos (pred (minus n m)))
141 | GT \Rightarrow (neg (pred (minus m n)))]
142 | (neg n) \Rightarrow (neg (S (plus m n)))]].
144 theorem Zplus_z_O: \forall z:Z. eq Z (Zplus z OZ) z.
146 simplify.reflexivity.
147 simplify.reflexivity.
148 simplify.reflexivity.
151 theorem sym_Zplus : \forall x,y:Z. eq Z (Zplus x y) (Zplus y x).
152 intros.elim x.simplify.rewrite > Zplus_z_O y.reflexivity.
153 elim y.simplify.reflexivity.
155 rewrite < (sym_plus e e1).reflexivity.
157 rewrite > nat_compare_invert e e1.
158 simplify.elim nat_compare e1 e.simplify.reflexivity.
159 simplify. reflexivity.
160 simplify. reflexivity.
161 elim y.simplify.reflexivity.
162 simplify.rewrite > nat_compare_invert e e1.
163 simplify.elim nat_compare e1 e.simplify.reflexivity.
164 simplify. reflexivity.
165 simplify. reflexivity.
166 simplify.elim (sym_plus e1 e).reflexivity.
169 theorem Zpred_neg : \forall z:Z. eq Z (Zpred z) (Zplus (neg O) z).
171 simplify.reflexivity.
172 simplify.reflexivity.
173 elim e.simplify.reflexivity.
174 simplify.reflexivity.
177 theorem Zsucc_pos : \forall z:Z. eq Z (Zsucc z) (Zplus (pos O) z).
179 simplify.reflexivity.
180 elim e.simplify.reflexivity.
181 simplify.reflexivity.
182 simplify.reflexivity.
185 theorem Zplus_succ_pred_pp :
186 \forall n,m. eq Z (Zplus (pos n) (pos m)) (Zplus (Zsucc (pos n)) (Zpred (pos m))).
189 simplify.reflexivity.
190 simplify.reflexivity.
193 rewrite < plus_n_O e.reflexivity.
195 rewrite < plus_n_Sm e e1.reflexivity.
198 theorem Zplus_succ_pred_pn :
199 \forall n,m. eq Z (Zplus (pos n) (neg m)) (Zplus (Zsucc (pos n)) (Zpred (neg m))).
203 theorem Zplus_succ_pred_np :
204 \forall n,m. eq Z (Zplus (neg n) (pos m)) (Zplus (Zsucc (neg n)) (Zpred (pos m))).
207 simplify.reflexivity.
208 simplify.reflexivity.
210 simplify.reflexivity.
211 simplify.reflexivity.
214 theorem Zplus_succ_pred_nn:
215 \forall n,m. eq Z (Zplus (neg n) (neg m)) (Zplus (Zsucc (neg n)) (Zpred (neg m))).
218 simplify.reflexivity.
219 simplify.reflexivity.
221 simplify.rewrite < plus_n_Sm e O.reflexivity.
222 simplify.rewrite > plus_n_Sm e (S e1).reflexivity.
225 (*CSC: da qui in avanti rewrite ancora non utilizzata *)
226 theorem Zplus_succ_pred:
227 \forall x,y. eq Z (Zplus x y) (Zplus (Zsucc x) (Zpred y)).
230 simplify.reflexivity.
231 simplify.reflexivity.
232 elim (Zsucc_pos ?).elim (sym_eq ? ? ? (Zsucc_pred ?)).reflexivity.
233 elim y.elim sym_Zplus ? ?.elim sym_Zplus (Zpred OZ) ?.
234 elim (Zpred_neg ?).elim (sym_eq ? ? ? (Zpred_succ ?)).
235 simplify.reflexivity.
236 apply Zplus_succ_pred_nn.
237 apply Zplus_succ_pred_np.
238 elim y.simplify.reflexivity.
239 apply Zplus_succ_pred_pn.
240 apply Zplus_succ_pred_pp.
243 theorem Zsucc_plus_pp :
244 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (pos m)) (Zsucc (Zplus (pos n) (pos m))).
248 theorem Zsucc_plus_pn :
249 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m))).
252 (\lambda n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m)))).intro.
254 simplify. reflexivity.
255 elim e.simplify. reflexivity.
256 simplify. reflexivity.
258 simplify. reflexivity.
259 simplify.reflexivity.
261 elim (Zplus_succ_pred_pn ? m1).
265 theorem Zsucc_plus_nn :
266 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m))).
269 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m)))).intro.
271 simplify. reflexivity.
272 elim e.simplify. reflexivity.
273 simplify. reflexivity.
275 simplify. reflexivity.
276 simplify.reflexivity.
278 elim (Zplus_succ_pred_nn ? m1).
282 theorem Zsucc_plus_np :
283 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m))).
286 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m)))).
288 simplify. reflexivity.
289 elim e.simplify. reflexivity.
290 simplify. reflexivity.
292 simplify. reflexivity.
293 simplify.reflexivity.
296 elim (Zplus_succ_pred_np ? (S m1)).
301 theorem Zsucc_plus : \forall x,y:Z. eq Z (Zplus (Zsucc x) y) (Zsucc (Zplus x y)).
302 intros.elim x.elim y.
303 simplify. reflexivity.
304 elim (Zsucc_pos ?).reflexivity.
305 simplify.reflexivity.
306 elim y.elim sym_Zplus ? ?.elim sym_Zplus OZ ?.simplify.reflexivity.
310 elim (sym_Zplus OZ ?).reflexivity.
315 theorem Zpred_plus : \forall x,y:Z. eq Z (Zplus (Zpred x) y) (Zpred (Zplus x y)).
317 cut eq Z (Zpred (Zplus x y)) (Zpred (Zplus (Zsucc (Zpred x)) y)).
318 elim (sym_eq ? ? ? Hcut).
319 elim (sym_eq ? ? ? (Zsucc_plus ? ?)).
320 elim (sym_eq ? ? ? (Zpred_succ ?)).
322 elim (sym_eq ? ? ? (Zsucc_pred ?)).
326 theorem assoc_Zplus :
327 \forall x,y,z:Z. eq Z (Zplus x (Zplus y z)) (Zplus (Zplus x y) z).
328 intros.elim x.simplify.reflexivity.
329 elim e.elim (Zpred_neg (Zplus y z)).
331 elim (Zpred_plus ? ?).
333 elim (sym_eq ? ? ? (Zpred_plus (neg e1) ?)).
334 elim (sym_eq ? ? ? (Zpred_plus (neg e1) ?)).
335 elim (sym_eq ? ? ? (Zpred_plus (Zplus (neg e1) y) ?)).
336 apply f_equal.assumption.
337 elim e.elim (Zsucc_pos ?).
339 apply (sym_eq ? ? ? (Zsucc_plus ? ?)) .
340 elim (sym_eq ? ? ? (Zsucc_plus (pos e1) ?)).
341 elim (sym_eq ? ? ? (Zsucc_plus (pos e1) ?)).
342 elim (sym_eq ? ? ? (Zsucc_plus (Zplus (pos e1) y) ?)).
343 apply f_equal.assumption.