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 n \leq m
32 | false \Rightarrow \lnot (n \leq m)].
35 (\lambda n,m:nat.match (leb n m) with
36 [ true \Rightarrow n \leq m
37 | false \Rightarrow \lnot (n \leq 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 (n \leq m \to (P true)) \to (\not (n \leq m) \to (P false)) \to
51 [ true \Rightarrow n \leq m
52 | false \Rightarrow \lnot (n \leq 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. nat_compare n n = EQ.
76 theorem nat_compare_S_S: \forall n,m:nat.
77 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 n < m
85 | GT \Rightarrow m < n ].
87 apply nat_elim2 (\lambda n,m.match (nat_compare n m) with
88 [ LT \Rightarrow n < m
90 | GT \Rightarrow 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 nat_compare n m = compare_invert (nat_compare m n).
103 apply nat_elim2 (\lambda n,m. 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 (n < m \to P LT) \to (n=m \to P EQ) \to (m < n \to P GT) \to
113 (P (nat_compare n m)).
115 cut match (nat_compare n m) with
116 [ LT \Rightarrow n < m
118 | GT \Rightarrow m < n] \to
119 (P (nat_compare n m)).
120 apply Hcut.apply nat_compare_to_Prop.
121 elim (nat_compare n m).