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/nat/compare".
17 include "nat/orders.ma".
18 include "datatypes/bool.ma".
19 include "datatypes/compare.ma".
27 | (S q) \Rightarrow leb p q]].
29 theorem leb_to_Prop: \forall n,m:nat.
31 [ true \Rightarrow (le n m)
32 | false \Rightarrow (Not (le n m))].
35 (\lambda n,m:nat.match (leb n m) with
36 [ true \Rightarrow (le n m)
37 | false \Rightarrow (Not (le n m))]).
38 simplify.exact le_O_n.
39 simplify.exact not_le_Sn_O.
40 intros 2.simplify.elim (leb n1 m1).
41 simplify.apply le_S_S.apply H.
42 simplify.intros.apply H.apply le_S_S_to_le.assumption.
45 theorem leb_elim: \forall n,m:nat. \forall P:bool \to Prop.
46 ((le n m) \to (P true)) \to ((Not (le n m)) \to (P false)) \to
51 [ true \Rightarrow (le n m)
52 | false \Rightarrow (Not (le n m))] \to (P (leb n m)).
53 apply Hcut.apply leb_to_Prop.
59 let rec nat_compare n m: compare \def
64 | (S q) \Rightarrow LT ]
68 | (S q) \Rightarrow nat_compare p q]].
70 theorem nat_compare_n_n: \forall n:nat.(eq compare (nat_compare n n) EQ).
76 theorem nat_compare_S_S: \forall n,m:nat.
77 eq compare (nat_compare n m) (nat_compare (S n) (S m)).
78 intros.simplify.reflexivity.
81 theorem nat_compare_to_Prop: \forall n,m:nat.
82 match (nat_compare n m) with
83 [ LT \Rightarrow (lt n m)
84 | EQ \Rightarrow (eq nat n m)
85 | GT \Rightarrow (lt m n) ].
87 apply nat_elim2 (\lambda n,m.match (nat_compare n m) with
88 [ LT \Rightarrow (lt n m)
89 | EQ \Rightarrow (eq nat n m)
90 | GT \Rightarrow (lt m n) ]).
91 intro.elim n1.simplify.reflexivity.
92 simplify.apply le_S_S.apply le_O_n.
93 intro.simplify.apply le_S_S. apply le_O_n.
94 intros 2.simplify.elim (nat_compare n1 m1).
95 simplify. apply le_S_S.apply H.
96 simplify. apply le_S_S.apply H.
97 simplify. apply eq_f. apply H.
100 theorem nat_compare_n_m_m_n: \forall n,m:nat.
101 eq compare (nat_compare n m) (compare_invert (nat_compare m n)).
103 apply nat_elim2 (\lambda n,m.eq compare (nat_compare n m) (compare_invert (nat_compare m n))).
104 intros.elim n1.simplify.reflexivity.
105 simplify.reflexivity.
106 intro.elim n1.simplify.reflexivity.
107 simplify.reflexivity.
108 intros.simplify.elim H.reflexivity.
111 theorem nat_compare_elim : \forall n,m:nat. \forall P:compare \to Prop.
112 ((lt n m) \to (P LT)) \to ((eq nat n m) \to (P EQ)) \to ((lt m n) \to (P GT)) \to
113 (P (nat_compare n m)).
115 cut match (nat_compare n m) with
116 [ LT \Rightarrow (lt n m)
117 | EQ \Rightarrow (eq nat n m)
118 | GT \Rightarrow (lt m n)] \to
119 (P (nat_compare n m)).
120 apply Hcut.apply nat_compare_to_Prop.
121 elim (nat_compare n m).