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 "datatypes/bool.ma".
20 inductive Z : Set \def
25 definition Z_of_nat \def
26 \lambda n. match n with
28 | (S n)\Rightarrow pos n].
30 coercion cic:/matita/Z/z/Z_of_nat.con.
32 definition neg_Z_of_nat \def
33 \lambda n. match n with
35 | (S n)\Rightarrow neg n].
41 | (pos n) \Rightarrow n
42 | (neg n) \Rightarrow n].
44 definition OZ_test \def
48 | (pos n) \Rightarrow false
49 | (neg n) \Rightarrow false].
51 theorem OZ_test_to_Prop :\forall z:Z.
53 [true \Rightarrow z=OZ
54 |false \Rightarrow z \neq OZ].
57 simplify. unfold Not. intros (H).
59 simplify. unfold Not. intros (H).
64 theorem injective_pos: injective nat Z pos.
67 change with (abs (pos x) = abs (pos y)).
68 apply eq_f.assumption.
71 variant inj_pos : \forall n,m:nat. pos n = pos m \to n = m
74 theorem injective_neg: injective nat Z neg.
77 change with (abs (neg x) = abs (neg y)).
78 apply eq_f.assumption.
81 variant inj_neg : \forall n,m:nat. neg n = neg m \to n = m
84 theorem not_eq_OZ_pos: \forall n:nat. OZ \neq pos n.
85 unfold Not.intros (n H).
89 theorem not_eq_OZ_neg :\forall n:nat. OZ \neq neg n.
90 unfold Not.intros (n H).
94 theorem not_eq_pos_neg :\forall n,m:nat. pos n \neq neg m.
95 unfold Not.intros (n m H).
99 theorem decidable_eq_Z : \forall x,y:Z. decidable (x=y).
100 intros.unfold decidable.
104 (* goal: x=OZ y=OZ *)
107 right.apply not_eq_OZ_pos.
109 right.apply not_eq_OZ_neg.
112 (* goal: x=pos y=OZ *)
113 right.unfold Not.intro.
114 apply (not_eq_OZ_pos n). symmetry. assumption.
115 (* goal: x=pos y=pos *)
116 elim (decidable_eq_nat n n1:((n=n1) \lor ((n=n1) \to False))).
117 left.apply eq_f.assumption.
118 right.unfold Not.intros (H_inj).apply H. injection H_inj. assumption.
119 (* goal: x=pos y=neg *)
120 right.unfold Not.intro.apply (not_eq_pos_neg n n1). assumption.
123 (* goal: x=neg y=OZ *)
124 right.unfold Not.intro.
125 apply (not_eq_OZ_neg n). symmetry. assumption.
126 (* goal: x=neg y=pos *)
127 right. unfold Not.intro. apply (not_eq_pos_neg n1 n). symmetry. assumption.
128 (* goal: x=neg y=neg *)
129 elim (decidable_eq_nat n n1:((n=n1) \lor ((n=n1) \to False))).
130 left.apply eq_f.assumption.
131 right.unfold Not.intro.apply H.apply injective_neg.assumption.
134 (* end discrimination *)
136 definition Zsucc \def
137 \lambda z. match z with
138 [ OZ \Rightarrow pos O
139 | (pos n) \Rightarrow pos (S n)
140 | (neg n) \Rightarrow
143 | (S p) \Rightarrow neg p]].
145 definition Zpred \def
146 \lambda z. match z with
147 [ OZ \Rightarrow neg O
148 | (pos n) \Rightarrow
151 | (S p) \Rightarrow pos p]
152 | (neg n) \Rightarrow neg (S n)].
154 theorem Zpred_Zsucc: \forall z:Z. Zpred (Zsucc z) = z.
164 theorem Zsucc_Zpred: \forall z:Z. Zsucc (Zpred z) = z.