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 S_pred: \forall n:nat.lt O n \to eq nat n (S (pred n)).
82 intro.elim n.apply False_ind.exact not_le_Sn_O O H.
83 apply eq_f.apply pred_Sn.
86 theorem nat_compare_pred_pred:
87 \forall n,m:nat.lt O n \to lt O m \to
88 eq compare (nat_compare n m) (nat_compare (pred n) (pred m)).
90 apply lt_O_n_elim n H.
91 apply lt_O_n_elim m H1.
96 theorem nat_compare_to_Prop: \forall n,m:nat.
97 match (nat_compare n m) with
98 [ LT \Rightarrow n < m
100 | GT \Rightarrow m < n ].
102 apply nat_elim2 (\lambda n,m.match (nat_compare n m) with
103 [ LT \Rightarrow n < m
105 | GT \Rightarrow m < n ]).
106 intro.elim n1.simplify.reflexivity.
107 simplify.apply le_S_S.apply le_O_n.
108 intro.simplify.apply le_S_S. apply le_O_n.
109 intros 2.simplify.elim (nat_compare n1 m1).
110 simplify. apply le_S_S.apply H.
111 simplify. apply le_S_S.apply H.
112 simplify. apply eq_f. apply H.
115 theorem nat_compare_n_m_m_n: \forall n,m:nat.
116 nat_compare n m = compare_invert (nat_compare m n).
118 apply nat_elim2 (\lambda n,m. nat_compare n m = compare_invert (nat_compare m n)).
119 intros.elim n1.simplify.reflexivity.
120 simplify.reflexivity.
121 intro.elim n1.simplify.reflexivity.
122 simplify.reflexivity.
123 intros.simplify.elim H.reflexivity.
126 theorem nat_compare_elim : \forall n,m:nat. \forall P:compare \to Prop.
127 (n < m \to P LT) \to (n=m \to P EQ) \to (m < n \to P GT) \to
128 (P (nat_compare n m)).
130 cut match (nat_compare n m) with
131 [ LT \Rightarrow n < m
133 | GT \Rightarrow m < n] \to
134 (P (nat_compare n m)).
135 apply Hcut.apply nat_compare_to_Prop.
136 elim (nat_compare n m).