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 include "Z/orders.ma".
16 include "nat/compare.ma".
18 (* boolean equality *)
19 definition eqZb : Z \to Z \to bool \def
25 | (pos q) \Rightarrow false
26 | (neg q) \Rightarrow false]
29 [ OZ \Rightarrow false
30 | (pos q) \Rightarrow eqb p q
31 | (neg q) \Rightarrow false]
34 [ OZ \Rightarrow false
35 | (pos q) \Rightarrow false
36 | (neg q) \Rightarrow eqb p q]].
41 [ true \Rightarrow x=y
42 | false \Rightarrow x \neq y].
47 simplify.apply not_eq_OZ_pos.
48 simplify.apply not_eq_OZ_neg.
50 simplify.unfold Not.intro.apply (not_eq_OZ_pos n).apply sym_eq.assumption.
51 simplify.apply eqb_elim.
52 intro.simplify.apply eq_f.assumption.
53 intro.simplify.unfold Not.intro.apply H.apply inj_pos.assumption.
54 simplify.apply not_eq_pos_neg.
56 simplify.unfold Not.intro.apply (not_eq_OZ_neg n).apply sym_eq.assumption.
57 simplify.unfold Not.intro.apply (not_eq_pos_neg n1 n).apply sym_eq.assumption.
58 simplify.apply eqb_elim.
59 intro.simplify.apply eq_f.assumption.
60 intro.simplify.unfold Not.intro.apply H.apply inj_neg.assumption.
63 theorem eqZb_elim: \forall x,y:Z.\forall P:bool \to Prop.
64 (x=y \to (P true)) \to (x \neq y \to (P false)) \to P (eqZb x y).
67 (match (eqZb x y) with
68 [ true \Rightarrow x=y
69 | false \Rightarrow x \neq y] \to P (eqZb x y)).
77 definition Z_compare : Z \to Z \to compare \def
83 | (pos m) \Rightarrow LT
84 | (neg m) \Rightarrow GT ]
88 | (pos m) \Rightarrow (nat_compare n m)
89 | (neg m) \Rightarrow GT]
93 | (pos m) \Rightarrow LT
94 | (neg m) \Rightarrow nat_compare m n ]].
96 theorem Z_compare_to_Prop :
97 \forall x,y:Z. match (Z_compare x y) with
98 [ LT \Rightarrow x < y
100 | GT \Rightarrow y < x].
104 simplify.apply refl_eq.
110 cut (match (nat_compare n n1) with
111 [ LT \Rightarrow n<n1
112 | EQ \Rightarrow n=n1
113 | GT \Rightarrow n1<n] \to
114 match (nat_compare n n1) with
115 [ LT \Rightarrow (S n) \leq n1
116 | EQ \Rightarrow pos n = pos n1
117 | GT \Rightarrow (S n1) \leq n]).
118 apply Hcut.apply nat_compare_to_Prop.
119 elim (nat_compare n n1).
121 simplify.apply eq_f.exact H.
128 cut (match (nat_compare n1 n) with
129 [ LT \Rightarrow n1<n
130 | EQ \Rightarrow n1=n
131 | GT \Rightarrow n<n1] \to
132 match (nat_compare n1 n) with
133 [ LT \Rightarrow (S n1) \leq n
134 | EQ \Rightarrow neg n = neg n1
135 | GT \Rightarrow (S n) \leq n1]).
136 apply Hcut. apply nat_compare_to_Prop.
137 elim (nat_compare n1 n).
139 simplify.apply eq_f.apply sym_eq.exact H.