X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fmatita%2Flibrary%2Fnat%2Fcompare.ma;h=e20d824df5ae105129599fda2b93beac3a23fcfb;hb=30b7e65d641fe7243c4f36ed448f56360a1c5e1c;hp=60a9d4194c2dc5b3dbf47936260f9763d4bf577d;hpb=3eff4cc36820df9faddb3cb16390717851db499c;p=helm.git diff --git a/helm/matita/library/nat/compare.ma b/helm/matita/library/nat/compare.ma index 60a9d4194..e20d824df 100644 --- a/helm/matita/library/nat/compare.ma +++ b/helm/matita/library/nat/compare.ma @@ -1,5 +1,5 @@ (**************************************************************************) -(* ___ *) +(* ___ *) (* ||M|| *) (* ||A|| A project by Andrea Asperti *) (* ||T|| *) @@ -14,9 +14,55 @@ set "baseuri" "cic:/matita/nat/compare". -include "nat/orders.ma". include "datatypes/bool.ma". include "datatypes/compare.ma". +include "nat/orders.ma". + +let rec eqb n m \def +match n with + [ O \Rightarrow + match m with + [ O \Rightarrow true + | (S q) \Rightarrow false] + | (S p) \Rightarrow + match m with + [ O \Rightarrow false + | (S q) \Rightarrow eqb p q]]. + +theorem eqb_to_Prop: \forall n,m:nat. +match (eqb n m) with +[ true \Rightarrow n = m +| false \Rightarrow \lnot (n = m)]. +intros. +apply nat_elim2 +(\lambda n,m:nat.match (eqb n m) with +[ true \Rightarrow n = m +| false \Rightarrow \lnot (n = m)]). +intro.elim n1. +simplify.reflexivity. +simplify.apply not_eq_O_S. +intro. +simplify. +intro. apply not_eq_O_S n1.apply sym_eq.assumption. +intros.simplify. +generalize in match H. +elim (eqb n1 m1). +simplify.apply eq_f.apply H1. +simplify.intro.apply H1.apply inj_S.assumption. +qed. + +theorem eqb_elim : \forall n,m:nat.\forall P:bool \to Prop. +(n=m \to (P true)) \to (\lnot n=m \to (P false)) \to (P (eqb n m)). +intros. +cut +match (eqb n m) with +[ true \Rightarrow n = m +| false \Rightarrow \lnot (n = m)] \to (P (eqb n m)). +apply Hcut.apply eqb_to_Prop. +elim eqb n m. +apply (H H2). +apply (H1 H2). +qed. let rec leb n m \def match n with @@ -43,7 +89,7 @@ simplify.intros.apply H.apply le_S_S_to_le.assumption. qed. theorem leb_elim: \forall n,m:nat. \forall P:bool \to Prop. -(n \leq m \to (P true)) \to (\not (n \leq m) \to (P false)) \to +(n \leq m \to (P true)) \to (\lnot (n \leq m) \to (P false)) \to P (leb n m). intros. cut @@ -78,6 +124,21 @@ nat_compare n m = nat_compare (S n) (S m). intros.simplify.reflexivity. qed. +theorem S_pred: \forall n:nat.lt O n \to eq nat n (S (pred n)). +intro.elim n.apply False_ind.exact not_le_Sn_O O H. +apply eq_f.apply pred_Sn. +qed. + +theorem nat_compare_pred_pred: +\forall n,m:nat.lt O n \to lt O m \to +eq compare (nat_compare n m) (nat_compare (pred n) (pred m)). +intros. +apply lt_O_n_elim n H. +apply lt_O_n_elim m H1. +intros. +simplify.reflexivity. +qed. + theorem nat_compare_to_Prop: \forall n,m:nat. match (nat_compare n m) with [ LT \Rightarrow n < m @@ -93,8 +154,8 @@ simplify.apply le_S_S.apply le_O_n. intro.simplify.apply le_S_S. apply le_O_n. intros 2.simplify.elim (nat_compare n1 m1). simplify. apply le_S_S.apply H. -simplify. apply le_S_S.apply H. simplify. apply eq_f. apply H. +simplify. apply le_S_S.apply H. qed. theorem nat_compare_n_m_m_n: \forall n,m:nat. @@ -120,6 +181,6 @@ cut match (nat_compare n m) with apply Hcut.apply nat_compare_to_Prop. elim (nat_compare n m). apply (H H3). -apply (H2 H3). apply (H1 H3). +apply (H2 H3). qed.