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/compare".
17 include "datatypes/bool.ma".
18 include "datatypes/compare.ma".
19 include "Z/orders.ma".
20 include "nat/compare.ma".
22 (* boolean equality *)
23 definition eqZb : Z \to Z \to bool \def
29 | (pos q) \Rightarrow false
30 | (neg q) \Rightarrow false]
33 [ OZ \Rightarrow false
34 | (pos q) \Rightarrow eqb p q
35 | (neg q) \Rightarrow false]
38 [ OZ \Rightarrow false
39 | (pos q) \Rightarrow false
40 | (neg q) \Rightarrow eqb p q]].
45 [ true \Rightarrow x=y
46 | false \Rightarrow \lnot x=y].
51 simplify.apply not_eq_OZ_pos.
52 simplify.apply not_eq_OZ_neg.
54 simplify.intro.apply not_eq_OZ_pos n.apply sym_eq.assumption.
55 simplify.apply eqb_elim.
56 intro.simplify.apply eq_f.assumption.
57 intro.simplify.intro.apply H.apply inj_pos.assumption.
58 simplify.apply not_eq_pos_neg.
60 simplify.intro.apply not_eq_OZ_neg n.apply sym_eq.assumption.
61 simplify.intro.apply not_eq_pos_neg n1 n.apply sym_eq.assumption.
62 simplify.apply eqb_elim.
63 intro.simplify.apply eq_f.assumption.
64 intro.simplify.intro.apply H.apply inj_neg.assumption.
67 theorem eqZb_elim: \forall x,y:Z.\forall P:bool \to Prop.
68 (x=y \to (P true)) \to (\lnot x=y \to (P false)) \to P (eqZb x y).
72 [ true \Rightarrow x=y
73 | false \Rightarrow \lnot x=y] \to P (eqZb x y).
81 definition Z_compare : Z \to Z \to compare \def
87 | (pos m) \Rightarrow LT
88 | (neg m) \Rightarrow GT ]
92 | (pos m) \Rightarrow (nat_compare n m)
93 | (neg m) \Rightarrow GT]
97 | (pos m) \Rightarrow LT
98 | (neg m) \Rightarrow nat_compare m n ]].
100 theorem Z_compare_to_Prop :
101 \forall x,y:Z. match (Z_compare x y) with
102 [ LT \Rightarrow x < y
104 | GT \Rightarrow y < x].
108 simplify.apply refl_eq.
114 cut match (nat_compare n n1) with
115 [ LT \Rightarrow n<n1
116 | EQ \Rightarrow n=n1
117 | GT \Rightarrow n1<n] \to
118 match (nat_compare n n1) with
119 [ LT \Rightarrow (S n) \leq n1
120 | EQ \Rightarrow pos n = pos n1
121 | GT \Rightarrow (S n1) \leq n].
122 apply Hcut.apply nat_compare_to_Prop.
123 elim (nat_compare n n1).
125 simplify.apply eq_f.exact H.
132 cut match (nat_compare n1 n) with
133 [ LT \Rightarrow n1<n
134 | EQ \Rightarrow n1=n
135 | GT \Rightarrow n<n1] \to
136 match (nat_compare n1 n) with
137 [ LT \Rightarrow (S n1) \leq n
138 | EQ \Rightarrow neg n = neg n1
139 | GT \Rightarrow (S n) \leq n1].
140 apply Hcut. apply nat_compare_to_Prop.
141 elim (nat_compare n1 n).
143 simplify.apply eq_f.apply sym_eq.exact H.