]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground_2/lib/arith.ma
advances on append allow to complete the long awaited "big tree" theorem by closing...
[helm.git] / matita / matita / contribs / lambdadelta / ground_2 / lib / 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/lib/star.ma".
17
18 (* ARITHMETICAL PROPERTIES **************************************************)
19
20 (* Equations ****************************************************************)
21
22 (* Note: uses minus_minus_comm, minus_plus_m_m, commutative_plus, plus_minus *)
23 lemma plus_minus_minus_be: ∀x,y,z. y ≤ z → z ≤ x → (x - z) + (z - y) = x - y.
24 #x #z #y #Hzy #Hyx >plus_minus // >commutative_plus >plus_minus //
25 qed-.
26
27 fact plus_minus_minus_be_aux: ∀i,x,y,z. y ≤ z → z ≤ x → i = z - y → x - z + i = x - y.
28 /2 width=1 by plus_minus_minus_be/ qed-.
29
30 lemma plus_n_2: ∀n. n + 2 = n + 1 + 1.
31 // qed.
32
33 lemma le_plus_minus: ∀m,n,p. p ≤ n → m + n - p = m + (n - p).
34 /2 by plus_minus/ qed.
35
36 lemma le_plus_minus_comm: ∀n,m,p. p ≤ m → m + n - p = m - p + n.
37 /2 by plus_minus/ qed.
38
39 lemma minus_minus_comm3: ∀n,x,y,z. n-x-y-z = n-y-z-x.
40 // qed.
41
42 lemma arith_b1: ∀a,b,c1. c1 ≤ b → a - c1 - (b - c1) = a - b.
43 #a #b #c1 #H >minus_minus_comm >minus_le_minus_minus_comm //
44 qed.
45
46 lemma arith_b2: ∀a,b,c1,c2. c1 + c2 ≤ b → a - c1 - c2 - (b - c1 - c2) = a - b.
47 #a #b #c1 #c2 #H >minus_plus >minus_plus >minus_plus /2 width=1 by arith_b1/
48 qed.
49
50 lemma arith_c1x: ∀x,a,b,c1. x + c1 + a - (b + c1) = x + a - b.
51 /3 by monotonic_le_minus_l, le_to_le_to_eq, le_n/ qed.
52
53 lemma arith_h1: ∀a1,a2,b,c1. c1 ≤ a1 → c1 ≤ b →
54                 a1 - c1 + a2 - (b - c1) = a1 + a2 - b.
55 #a1 #a2 #b #c1 #H1 #H2 >plus_minus /2 width=1 by arith_b2/
56 qed.
57
58 lemma arith_i: ∀x,y,z. y < x → x+z-y-1 = x-y-1+z.
59 /2 width=1 by plus_minus/ qed-.
60
61 (* Properties ***************************************************************)
62
63 axiom eq_nat_dec: ∀n1,n2:nat. Decidable (n1 = n2).
64
65 axiom lt_dec: ∀n1,n2. Decidable (n1 < n2).
66
67 lemma lt_or_eq_or_gt: ∀m,n. ∨∨ m < n | n = m | n < m.
68 #m #n elim (lt_or_ge m n) /2 width=1 by or3_intro0/
69 #H elim H -m /2 width=1 by or3_intro1/
70 #m #Hm * /3 width=1 by not_le_to_lt, le_S_S, or3_intro2/
71 qed-.
72
73 fact le_repl_sn_conf_aux: ∀x,y,z:nat. x ≤ z → x = y → y ≤ z.
74 // qed-.
75
76 fact le_repl_sn_trans_aux: ∀x,y,z:nat. x ≤ z → y = x → y ≤ z.
77 // qed-.
78
79 lemma monotonic_le_minus_l2: ∀x1,x2,y,z. x1 ≤ x2 → x1 - y - z ≤ x2 - y - z.
80 /3 width=1 by monotonic_le_minus_l/ qed.
81
82 (* Note: this might interfere with nat.ma *)
83 lemma monotonic_lt_pred: ∀m,n. m < n → O < m → pred m < pred n.
84 #m #n #Hmn #Hm whd >(S_pred … Hm)
85 @le_S_S_to_le >S_pred /2 width=3 by transitive_lt/
86 qed.
87
88 lemma arith_j: ∀x,y,z. x-y-1 ≤ x-(y-z)-1.
89 /3 width=1 by monotonic_le_minus_l, monotonic_le_minus_r/ qed.
90
91 lemma arith_k_sn: ∀z,x,y,n. z < x → x+n ≤ y → x-z-1+n ≤ y-z-1.
92 #z #x #y #n #Hzx #Hxny
93 >plus_minus [2: /2 width=1 by monotonic_le_minus_r/ ]
94 >plus_minus [2: /2 width=1 by lt_to_le/ ]
95 /2 width=1 by monotonic_le_minus_l2/
96 qed.
97
98 lemma arith_k_dx: ∀z,x,y,n. z < x → y ≤ x+n → y-z-1 ≤ x-z-1+n.
99 #z #x #y #n #Hzx #Hyxn
100 >plus_minus [2: /2 width=1 by monotonic_le_minus_r/ ]
101 >plus_minus [2: /2 width=1 by lt_to_le/ ]
102 /2 width=1 by monotonic_le_minus_l2/
103 qed.
104
105 (* Inversion & forward lemmas ***********************************************)
106
107 lemma lt_plus_SO_to_le: ∀x,y. x < y + 1 → x ≤ y.
108 /2 width=1 by monotonic_pred/ qed-.
109
110 lemma lt_refl_false: ∀n. n < n → ⊥.
111 #n #H elim (lt_to_not_eq … H) -H /2 width=1 by/
112 qed-.
113
114 lemma lt_zero_false: ∀n. n < 0 → ⊥.
115 #n #H elim (lt_to_not_le … H) -H /2 width=1 by/
116 qed-.
117
118 lemma false_lt_to_le: ∀x,y. (x < y → ⊥) → y ≤ x.
119 #x #y #H elim (decidable_lt x y) /2 width=1 by not_lt_to_le/
120 #Hxy elim (H Hxy)
121 qed-.
122
123 lemma pred_inv_refl: ∀m. pred m = m → m = 0.
124 * // normalize #m #H elim (lt_refl_false m) //
125 qed-.
126
127 lemma le_plus_xSy_O_false: ∀x,y. x + S y ≤ 0 → ⊥.
128 #x #y #H lapply (le_n_O_to_eq … H) -H <plus_n_Sm #H destruct
129 qed-.
130
131 lemma le_plus_xySz_x_false: ∀y,z,x. x + y + S z ≤ x → ⊥.
132 #y #z #x elim x -x /3 width=1 by le_S_S_to_le/
133 #H elim (le_plus_xSy_O_false … H)
134 qed-.
135
136 lemma plus_xySz_x_false: ∀z,x,y. x + y + S z = x → ⊥.
137 /2 width=4 by le_plus_xySz_x_false/ qed-.
138
139 lemma plus_xSy_x_false: ∀y,x. x + S y = x → ⊥.
140 /2 width=4 by plus_xySz_x_false/ qed-.
141
142 (* Iterators ****************************************************************)
143
144 (* Note: see also: lib/arithemetcs/bigops.ma *)
145 let rec iter (n:nat) (B:Type[0]) (op: B → B) (nil: B) ≝
146   match n with
147    [ O   ⇒ nil
148    | S k ⇒ op (iter k B op nil)
149    ].
150
151 interpretation "iterated function" 'exp op n = (iter n ? op).
152
153 lemma iter_SO: ∀B:Type[0]. ∀f:B→B. ∀b,l. f^(l+1) b = f (f^l b).
154 #B #f #b #l >commutative_plus //
155 qed.
156
157 lemma iter_n_Sm: ∀B:Type[0]. ∀f:B→B. ∀b,l. f^l (f b) = f (f^l b).
158 #B #f #b #l elim l -l normalize //
159 qed.
160
161 lemma iter_plus: ∀B:Type[0]. ∀f:B→B. ∀b,l1,l2. f^(l1+l2) b = f^l1 (f^l2 b).
162 #B #f #b #l1 elim l1 -l1 normalize //
163 qed.
164
165 (* Trichotomy operator ******************************************************)
166
167 (* Note: this is "if eqb n1 n2 then a2 else if leb n1 n2 then a1 else a3" *)
168 let rec tri (A:Type[0]) n1 n2 a1 a2 a3 on n1 : A ≝
169   match n1 with
170   [ O    ⇒ match n2 with [ O ⇒ a2 | S n2 ⇒ a1 ]
171   | S n1 ⇒ match n2 with [ O ⇒ a3 | S n2 ⇒ tri A n1 n2 a1 a2 a3 ]
172   ].
173
174 lemma tri_lt: ∀A,a1,a2,a3,n2,n1. n1 < n2 → tri A n1 n2 a1 a2 a3 = a1.
175 #A #a1 #a2 #a3 #n2 elim n2 -n2
176 [ #n1 #H elim (lt_zero_false … H)
177 | #n2 #IH #n1 elim n1 -n1 /3 width=1 by monotonic_lt_pred/
178 ]
179 qed.
180
181 lemma tri_eq: ∀A,a1,a2,a3,n. tri A n n a1 a2 a3 = a2.
182 #A #a1 #a2 #a3 #n elim n -n normalize //
183 qed.
184
185 lemma tri_gt: ∀A,a1,a2,a3,n1,n2. n2 < n1 → tri A n1 n2 a1 a2 a3 = a3.
186 #A #a1 #a2 #a3 #n1 elim n1 -n1
187 [ #n2 #H elim (lt_zero_false … H)
188 | #n1 #IH #n2 elim n2 -n2 /3 width=1 by monotonic_lt_pred/
189 ]
190 qed.