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.
80 | (pos n) \Rightarrow False
81 | (neg n) \Rightarrow False].
83 elim (sym_eq ? ? ? H).simplify.
88 | (pos n) \Rightarrow False
89 | (neg n) \Rightarrow False].
90 apply Hcut. elim (sym_eq ? ? ? H).simplify.exact I.
94 \lambda z. match z with
95 [ OZ \Rightarrow pos O
96 | (pos n) \Rightarrow pos (S n)
100 | (S p) \Rightarrow neg p]].
102 definition Zpred \def
103 \lambda z. match z with
104 [ OZ \Rightarrow neg O
105 | (pos n) \Rightarrow
108 | (S p) \Rightarrow pos p]
109 | (neg n) \Rightarrow neg (S n)].
111 theorem Zpred_succ: \forall z:Z. eq Z (Zpred (Zsucc z)) z.
112 intros.elim z.apply refl_equal.
113 elim e.apply refl_equal.
118 theorem Zsucc_pred: \forall z:Z. eq Z (Zsucc (Zpred z)) z.
119 intros.elim z.apply refl_equal.
121 elim e.apply refl_equal.
125 let rec Zplus x y : Z \def
128 | (pos m) \Rightarrow
131 | (pos n) \Rightarrow (pos (S (plus m n)))
132 | (neg n) \Rightarrow
133 match nat_compare m n with
134 [ LT \Rightarrow (neg (pred (minus n m)))
136 | GT \Rightarrow (pos (pred (minus m n)))]]
137 | (neg m) \Rightarrow
140 | (pos n) \Rightarrow
141 match nat_compare m n with
142 [ LT \Rightarrow (pos (pred (minus n m)))
144 | GT \Rightarrow (neg (pred (minus m n)))]
145 | (neg n) \Rightarrow (neg (S (plus m n)))]].
147 theorem Zplus_z_O: \forall z:Z. eq Z (Zplus z OZ) z.
149 simplify.apply refl_equal.
150 simplify.apply refl_equal.
151 simplify.apply refl_equal.
154 theorem sym_Zplus : \forall x,y:Z. eq Z (Zplus x y) (Zplus y x).
155 intros.elim x.simplify.elim (sym_eq ? ? ? (Zplus_z_O y)).apply refl_equal.
156 elim y.simplify.reflexivity.
158 elim (sym_plus e e1).apply refl_equal.
160 elim (sym_eq ? ? ?(nat_compare_invert e e1)).
161 simplify.elim nat_compare e1 e.simplify.apply refl_equal.
162 simplify. apply refl_equal.
163 simplify. apply refl_equal.
164 elim y.simplify.reflexivity.
165 simplify.elim (sym_eq ? ? ?(nat_compare_invert e e1)).
166 simplify.elim nat_compare e1 e.simplify.apply refl_equal.
167 simplify. apply refl_equal.
168 simplify. apply refl_equal.
169 simplify.elim (sym_plus e1 e).apply refl_equal.
172 theorem Zpred_neg : \forall z:Z. eq Z (Zpred z) (Zplus (neg O) z).
174 simplify.apply refl_equal.
175 simplify.apply refl_equal.
176 elim e.simplify.apply refl_equal.
177 simplify.apply refl_equal.
180 theorem Zsucc_pos : \forall z:Z. eq Z (Zsucc z) (Zplus (pos O) z).
182 simplify.apply refl_equal.
183 elim e.simplify.apply refl_equal.
184 simplify.apply refl_equal.
185 simplify.apply refl_equal.
188 theorem Zplus_succ_pred_pp :
189 \forall n,m. eq Z (Zplus (pos n) (pos m)) (Zplus (Zsucc (pos n)) (Zpred (pos m))).
192 simplify.apply refl_equal.
193 simplify.apply refl_equal.
196 elim (plus_n_O ?).apply refl_equal.
198 elim (plus_n_Sm ? ?).apply refl_equal.
201 theorem Zplus_succ_pred_pn :
202 \forall n,m. eq Z (Zplus (pos n) (neg m)) (Zplus (Zsucc (pos n)) (Zpred (neg m))).
203 intros.apply refl_equal.
206 theorem Zplus_succ_pred_np :
207 \forall n,m. eq Z (Zplus (neg n) (pos m)) (Zplus (Zsucc (neg n)) (Zpred (pos m))).
210 simplify.apply refl_equal.
211 simplify.apply refl_equal.
213 simplify.apply refl_equal.
214 simplify.apply refl_equal.
217 theorem Zplus_succ_pred_nn:
218 \forall n,m. eq Z (Zplus (neg n) (neg m)) (Zplus (Zsucc (neg n)) (Zpred (neg m))).
221 simplify.apply refl_equal.
222 simplify.apply refl_equal.
224 simplify.elim (plus_n_Sm ? ?).apply refl_equal.
225 simplify.elim (sym_eq ? ? ? (plus_n_Sm ? ?)).apply refl_equal.
228 theorem Zplus_succ_pred:
229 \forall x,y. eq Z (Zplus x y) (Zplus (Zsucc x) (Zpred y)).
232 simplify.apply refl_equal.
233 simplify.apply refl_equal.
234 elim (Zsucc_pos ?).elim (sym_eq ? ? ? (Zsucc_pred ?)).apply refl_equal.
235 elim y.elim sym_Zplus ? ?.elim sym_Zplus (Zpred OZ) ?.
236 elim (Zpred_neg ?).elim (sym_eq ? ? ? (Zpred_succ ?)).
237 simplify.apply refl_equal.
238 apply Zplus_succ_pred_nn.
239 apply Zplus_succ_pred_np.
240 elim y.simplify.apply refl_equal.
241 apply Zplus_succ_pred_pn.
242 apply Zplus_succ_pred_pp.
245 theorem Zsucc_plus_pp :
246 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (pos m)) (Zsucc (Zplus (pos n) (pos m))).
247 intros.apply refl_equal.
250 theorem Zsucc_plus_pn :
251 \forall n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m))).
254 (\lambda n,m. eq Z (Zplus (Zsucc (pos n)) (neg m)) (Zsucc (Zplus (pos n) (neg m)))).intro.
256 simplify. apply refl_equal.
257 elim e.simplify. apply refl_equal.
258 simplify. apply refl_equal.
260 simplify. apply refl_equal.
261 simplify.apply refl_equal.
263 elim (Zplus_succ_pred_pn ? m1).
264 elim H.apply refl_equal.
267 theorem Zsucc_plus_nn :
268 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m))).
271 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (neg m)) (Zsucc (Zplus (neg n) (neg m)))).intro.
273 simplify. apply refl_equal.
274 elim e.simplify. apply refl_equal.
275 simplify. apply refl_equal.
277 simplify. apply refl_equal.
278 simplify.apply refl_equal.
280 elim (Zplus_succ_pred_nn ? m1).
284 theorem Zsucc_plus_np :
285 \forall n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m))).
288 (\lambda n,m. eq Z (Zplus (Zsucc (neg n)) (pos m)) (Zsucc (Zplus (neg n) (pos m)))).
290 simplify. apply refl_equal.
291 elim e.simplify. apply refl_equal.
292 simplify. apply refl_equal.
294 simplify. apply refl_equal.
295 simplify.apply refl_equal.
298 elim (Zplus_succ_pred_np ? (S m1)).
303 theorem Zsucc_plus : \forall x,y:Z. eq Z (Zplus (Zsucc x) y) (Zsucc (Zplus x y)).
304 intros.elim x.elim y.
305 simplify. apply refl_equal.
306 elim (Zsucc_pos ?).apply refl_equal.
307 simplify.apply refl_equal.
308 elim y.elim sym_Zplus ? ?.elim sym_Zplus OZ ?.simplify.apply refl_equal.
312 elim (sym_Zplus OZ ?).apply refl_equal.
317 theorem Zpred_plus : \forall x,y:Z. eq Z (Zplus (Zpred x) y) (Zpred (Zplus x y)).
319 cut eq Z (Zpred (Zplus x y)) (Zpred (Zplus (Zsucc (Zpred x)) y)).
320 elim (sym_eq ? ? ? Hcut).
321 elim (sym_eq ? ? ? (Zsucc_plus ? ?)).
322 elim (sym_eq ? ? ? (Zpred_succ ?)).
324 elim (sym_eq ? ? ? (Zsucc_pred ?)).
328 theorem assoc_Zplus :
329 \forall x,y,z:Z. eq Z (Zplus x (Zplus y z)) (Zplus (Zplus x y) z).
330 intros.elim x.simplify.apply refl_equal.
331 elim e.elim (Zpred_neg (Zplus y z)).
333 elim (Zpred_plus ? ?).
335 elim (sym_eq ? ? ? (Zpred_plus (neg e1) ?)).
336 elim (sym_eq ? ? ? (Zpred_plus (neg e1) ?)).
337 elim (sym_eq ? ? ? (Zpred_plus (Zplus (neg e1) y) ?)).
338 apply f_equal.assumption.
339 elim e.elim (Zsucc_pos ?).
341 apply (sym_eq ? ? ? (Zsucc_plus ? ?)) .
342 elim (sym_eq ? ? ? (Zsucc_plus (pos e1) ?)).
343 elim (sym_eq ? ? ? (Zsucc_plus (pos e1) ?)).
344 elim (sym_eq ? ? ? (Zsucc_plus (Zplus (pos e1) y) ?)).
345 apply f_equal.assumption.