]> matita.cs.unibo.it Git - helm.git/blobdiff - matita/matita/contribs/lambda_delta/ground_2/arith.ma
- we introduced the pointer_step rc in the perspective of proving
[helm.git] / matita / matita / contribs / lambda_delta / ground_2 / arith.ma
index c65a47bcc70b31c7649709157b5e7ac81493c280..8afc445b8f4343d68494ce3e774ebc8beb196c9c 100644 (file)
@@ -19,6 +19,9 @@ include "ground_2/star.ma".
 
 (* Equations ****************************************************************)
 
+lemma plus_n_2: ∀n. n + 2 = n + 1 + 1.
+// qed.
+
 lemma le_plus_minus: ∀m,n,p. p ≤ n → m + n - p = m + (n - p).
 /2 by plus_minus/ qed.
 
@@ -41,7 +44,7 @@ lemma arith_h1: ∀a1,a2,b,c1. c1 ≤ a1 → c1 ≤ b →
 #a1 #a2 #b #c1 #H1 #H2 >plus_minus // /2 width=1/
 qed.
 
-(* inversion & forward lemmas ***********************************************)
+(* Inversion & forward lemmas ***********************************************)
 
 axiom eq_nat_dec: ∀n1,n2:nat. Decidable (n1 = n2).
 
@@ -66,11 +69,59 @@ lemma false_lt_to_le: ∀x,y. (x < y → ⊥) → y ≤ x.
 #Hxy elim (H Hxy)
 qed-.
 
-(*
-lemma pippo: ∀x,y,z. x < z → y < z - x → x + y < z.
-/3 width=2/
-
-lemma le_or_ge: ∀m,n. m ≤ n ∨ n ≤ m.
-#m #n elim (lt_or_ge m n) /2 width=1/ /3 width=2/
+lemma le_plus_xySz_x_false: ∀y,z,x. x + y + S z ≤ x → ⊥.
+#y #z #x elim x -x
+[ #H lapply (le_n_O_to_eq … H) -H
+  <plus_n_Sm #H destruct
+| /3 width=1 by le_S_S_to_le/
+]
 qed-.
-*)
+
+lemma plus_xySz_x_false: ∀z,x,y. x + y + S z = x → ⊥.
+/2 width=4 by le_plus_xySz_x_false/ qed-.
+
+(* Iterators ****************************************************************)
+
+(* Note: see also: lib/arithemetcs/bigops.ma *)
+let rec iter (n:nat) (B:Type[0]) (op: B → B) (nil: B) ≝
+  match n with
+   [ O   ⇒ nil
+   | S k ⇒ op (iter k B op nil)
+   ].
+
+interpretation "iterated function" 'exp op n = (iter n ? op).
+
+lemma iter_SO: ∀B:Type[0]. ∀f:B→B. ∀b,l. f^(l+1) b = f (f^l b).
+#B #f #b #l >commutative_plus //
+qed.
+
+lemma iter_n_Sm: ∀B:Type[0]. ∀f:B→B. ∀b,l. f^l (f b) = f (f^l b).
+#B #f #b #l elim l -l normalize //
+qed.
+
+(* Trichotomy operator ******************************************************)
+
+(* Note: this is "if eqb n1 n2 then a2 else if leb n1 n2 then a1 else a3" *)
+let rec tri (A:Type[0]) n1 n2 a1 a2 a3 on n1 : A ≝
+  match n1 with 
+  [ O    ⇒ match n2 with [ O ⇒ a2 | S n2 ⇒ a1 ]
+  | S n1 ⇒ match n2 with [ O ⇒ a3 | S n2 ⇒ tri A n1 n2 a1 a2 a3 ]
+  ].
+
+lemma tri_lt: ∀A,a1,a2,a3,n2,n1. n1 < n2 → tri A n1 n2 a1 a2 a3 = a1.
+#A #a1 #a2 #a3 #n2 elim n2 -n2
+[ #n1 #H elim (lt_zero_false … H)
+| #n2 #IH #n1 elim n1 -n1 // /3 width=1/
+]
+qed.
+
+lemma tri_eq: ∀A,a1,a2,a3,n. tri A n n a1 a2 a3 = a2.
+#A #a1 #a2 #a3 #n elim n -n normalize //
+qed.
+
+lemma tri_gt: ∀A,a1,a2,a3,n1,n2. n2 < n1 → tri A n1 n2 a1 a2 a3 = a3.
+#A #a1 #a2 #a3 #n1 elim n1 -n1
+[ #n2 #H elim (lt_zero_false … H)
+| #n1 #IH #n2 elim n2 -n2 // /3 width=1/
+]
+qed.