]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambda_delta/ground_2/arith.ma
f7f5e35c4ce10e08a684f7c6f8955530c9899f73
[helm.git] / matita / matita / contribs / lambda_delta / ground_2 / arith.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "arithmetics/nat.ma".
16 include "ground_2/star.ma".
17
18 (* ARITHMETICAL PROPERTIES **************************************************)
19
20 (* Equations ****************************************************************)
21
22 lemma plus_n_2: ∀n. n + 2 = n + 1 + 1.
23 // qed.
24
25 lemma le_plus_minus: ∀m,n,p. p ≤ n → m + n - p = m + (n - p).
26 /2 by plus_minus/ qed.
27
28 lemma le_plus_minus_comm: ∀n,m,p. p ≤ m → m + n - p = m - p + n.
29 /2 by plus_minus/ qed.
30
31 lemma arith_b1: ∀a,b,c1. c1 ≤ b → a - c1 - (b - c1) = a - b.
32 #a #b #c1 #H >minus_minus_comm >minus_le_minus_minus_comm //
33 qed.
34
35 lemma arith_b2: ∀a,b,c1,c2. c1 + c2 ≤ b → a - c1 - c2 - (b - c1 - c2) = a - b.
36 #a #b #c1 #c2 #H >minus_plus >minus_plus >minus_plus /2 width=1/
37 qed.
38
39 lemma arith_c1x: ∀x,a,b,c1. x + c1 + a - (b + c1) = x + a - b.
40 /3 by monotonic_le_minus_l, le_to_le_to_eq, le_n/ qed.
41
42 lemma arith_h1: ∀a1,a2,b,c1. c1 ≤ a1 → c1 ≤ b →
43                 a1 - c1 + a2 - (b - c1) = a1 + a2 - b.
44 #a1 #a2 #b #c1 #H1 #H2 >plus_minus // /2 width=1/
45 qed.
46
47 (* inversion & forward lemmas ***********************************************)
48
49 axiom eq_nat_dec: ∀n1,n2:nat. Decidable (n1 = n2).
50
51 axiom lt_dec: ∀n1,n2. Decidable (n1 < n2).
52
53 lemma lt_or_eq_or_gt: ∀m,n. ∨∨ m < n | n = m | n < m.
54 #m #n elim (lt_or_ge m n) /2 width=1/
55 #H elim H -m /2 width=1/
56 #m #Hm * #H /2 width=1/ /3 width=1/
57 qed-.
58
59 lemma lt_refl_false: ∀n. n < n → ⊥.
60 #n #H elim (lt_to_not_eq … H) -H /2 width=1/
61 qed-.
62
63 lemma lt_zero_false: ∀n. n < 0 → ⊥.
64 #n #H elim (lt_to_not_le … H) -H /2 width=1/
65 qed-.
66
67 lemma false_lt_to_le: ∀x,y. (x < y → ⊥) → y ≤ x.
68 #x #y #H elim (decidable_lt x y) /2 width=1/
69 #Hxy elim (H Hxy)
70 qed-.
71
72 lemma plus_xySz_x_false: ∀z,x,y. x + y + S z = x → ⊥.
73 #z #x elim x -x normalize
74 [ #y <plus_n_Sm #H destruct
75 | /3 width=2/
76 ]
77 qed-.
78
79 (* iterators ****************************************************************)
80
81 (* Note: see also: lib/arithemetcs/bigops.ma *)
82 let rec iter (n:nat) (B:Type[0]) (op: B → B) (nil: B) ≝
83   match n with
84    [ O   ⇒ nil
85    | S k ⇒ op (iter k B op nil)
86    ].
87
88 interpretation "iterated function" 'exp op n = (iter n ? op).
89
90 lemma iter_SO: ∀B:Type[0]. ∀f:B→B. ∀b,l. f^(l+1) b = f (f^l b).
91 #B #f #b #l >commutative_plus //
92 qed.
93
94 lemma iter_n_Sm: ∀B:Type[0]. ∀f:B→B. ∀b,l. f^l (f b) = f (f^l b).
95 #B #f #b #l elim l -l normalize //
96 qed.