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 "Z/orders.ma".
18 include "nat/compare.ma".
20 (* boolean equality *)
21 definition eqZb : Z \to Z \to bool \def
27 | (pos q) \Rightarrow false
28 | (neg q) \Rightarrow false]
31 [ OZ \Rightarrow false
32 | (pos q) \Rightarrow eqb p q
33 | (neg q) \Rightarrow false]
36 [ OZ \Rightarrow false
37 | (pos q) \Rightarrow false
38 | (neg q) \Rightarrow eqb p q]].
43 [ true \Rightarrow x=y
44 | false \Rightarrow x \neq y].
49 simplify.apply not_eq_OZ_pos.
50 simplify.apply not_eq_OZ_neg.
52 simplify.unfold Not.intro.apply (not_eq_OZ_pos n).apply sym_eq.assumption.
53 simplify.apply eqb_elim.
54 intro.simplify.apply eq_f.assumption.
55 intro.simplify.unfold Not.intro.apply H.apply inj_pos.assumption.
56 simplify.apply not_eq_pos_neg.
58 simplify.unfold Not.intro.apply (not_eq_OZ_neg n).apply sym_eq.assumption.
59 simplify.unfold Not.intro.apply (not_eq_pos_neg n1 n).apply sym_eq.assumption.
60 simplify.apply eqb_elim.
61 intro.simplify.apply eq_f.assumption.
62 intro.simplify.unfold Not.intro.apply H.apply inj_neg.assumption.
65 theorem eqZb_elim: \forall x,y:Z.\forall P:bool \to Prop.
66 (x=y \to (P true)) \to (x \neq y \to (P false)) \to P (eqZb x y).
69 (match (eqZb x y) with
70 [ true \Rightarrow x=y
71 | false \Rightarrow x \neq y] \to P (eqZb x y)).
79 definition Z_compare : Z \to Z \to compare \def
85 | (pos m) \Rightarrow LT
86 | (neg m) \Rightarrow GT ]
90 | (pos m) \Rightarrow (nat_compare n m)
91 | (neg m) \Rightarrow GT]
95 | (pos m) \Rightarrow LT
96 | (neg m) \Rightarrow nat_compare m n ]].
98 theorem Z_compare_to_Prop :
99 \forall x,y:Z. match (Z_compare x y) with
100 [ LT \Rightarrow x < y
102 | GT \Rightarrow y < x].
106 simplify.apply refl_eq.
112 cut (match (nat_compare n n1) with
113 [ LT \Rightarrow n<n1
114 | EQ \Rightarrow n=n1
115 | GT \Rightarrow n1<n] \to
116 match (nat_compare n n1) with
117 [ LT \Rightarrow (S n) \leq n1
118 | EQ \Rightarrow pos n = pos n1
119 | GT \Rightarrow (S n1) \leq n]).
120 apply Hcut.apply nat_compare_to_Prop.
121 elim (nat_compare n n1).
123 simplify.apply eq_f.exact H.
130 cut (match (nat_compare n1 n) with
131 [ LT \Rightarrow n1<n
132 | EQ \Rightarrow n1=n
133 | GT \Rightarrow n<n1] \to
134 match (nat_compare n1 n) with
135 [ LT \Rightarrow (S n1) \leq n
136 | EQ \Rightarrow neg n = neg n1
137 | GT \Rightarrow (S n) \leq n1]).
138 apply Hcut. apply nat_compare_to_Prop.
139 elim (nat_compare n1 n).
141 simplify.apply eq_f.apply sym_eq.exact H.