1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "arithmetics/nat.ma".
16 include "Ground_2/star.ma".
18 (* ARITHMETICAL PROPERTIES **************************************************)
20 (* equations ****************************************************************)
22 lemma plus_plus_comm_23: ∀x,y,z. x + y + z = x + z + y.
25 lemma le_plus_minus: ∀m,n,p. p ≤ n → m + n - p = m + (n - p).
26 /2 by plus_minus/ qed.
28 lemma le_plus_minus_comm: ∀n,m,p. p ≤ m → m + n - p = m - p + n.
29 /2 by plus_minus/ qed.
31 lemma minus_le_minus_minus_comm: ∀b,c,a. c ≤ b → a - (b - c) = a + c - b.
33 [ #c #a #H >(le_n_O_to_eq … H) -H //
34 | #b #IHb #c elim c -c //
36 lapply (le_S_S_to_le … Hcb) -Hcb #Hcb
37 <plus_n_Sm normalize /2 width=1/
41 lemma minus_minus_comm: ∀a,b,c. a - b - c = a - c - b.
42 /3 by monotonic_le_minus_l, le_to_le_to_eq/ qed.
44 lemma arith_b1: ∀a,b,c1. c1 ≤ b → a - c1 - (b - c1) = a - b.
45 #a #b #c1 #H >minus_plus @eq_f2 /2 width=1/
48 lemma arith_b2: ∀a,b,c1,c2. c1 + c2 ≤ b → a - c1 - c2 - (b - c1 - c2) = a - b.
49 #a #b #c1 #c2 #H >minus_plus >minus_plus >minus_plus /2 width=1/
52 lemma arith_c1x: ∀x,a,b,c1. x + c1 + a - (b + c1) = x + a - b.
53 /3 by monotonic_le_minus_l, le_to_le_to_eq, le_n/ qed.
55 lemma arith_h1: ∀a1,a2,b,c1. c1 ≤ a1 → c1 ≤ b →
56 a1 - c1 + a2 - (b - c1) = a1 + a2 - b.
57 #a1 #a2 #b #c1 #H1 #H2 >plus_minus // /2 width=1/
60 (* inversion & forward lemmas ***********************************************)
62 axiom eq_nat_dec: ∀n1,n2:nat. Decidable (n1 = n2).
64 axiom lt_dec: ∀n1,n2. Decidable (n1 < n2).
66 lemma lt_or_ge: ∀m,n. m < n ∨ n ≤ m.
67 #m #n elim (decidable_lt m n) /2 width=1/ /3 width=1/
70 lemma lt_or_eq_or_gt: ∀m,n. ∨∨ m < n | n = m | n < m.
73 | #m #IHm * /2 width=1/
74 #n elim (IHm n) -IHm #H
75 [ @or3_intro0 | @or3_intro1 destruct | @or3_intro2 ] // /2 width=1/ (**) (* /3 width=1/ is slow *)
78 lemma le_inv_plus_plus_r: ∀x,y,z. x + z ≤ y + z → x ≤ y.
79 /2 by le_plus_to_le/ qed-.
81 lemma le_inv_plus_l: ∀x,y,z. x + y ≤ z → x ≤ z - y ∧ y ≤ z.
84 lemma lt_refl_false: ∀n. n < n → False.
85 #n #H elim (lt_to_not_eq … H) -H /2 width=1/
88 lemma lt_zero_false: ∀n. n < 0 → False.
89 #n #H elim (lt_to_not_le … H) -H /2 width=1/
92 lemma plus_S_eq_O_false: ∀n,m. n + S m = 0 → False.
93 #n #m <plus_n_Sm #H destruct
96 lemma plus_lt_false: ∀m,n. m + n < m → False.
97 #m #n #H1 lapply (le_plus_n_r n m) #H2
98 lapply (le_to_lt_to_lt … H2 H1) -H2 -H1 #H
99 elim (lt_refl_false … H)
102 lemma false_lt_to_le: ∀x,y. (x < y → False) → y ≤ x.
103 #x #y #H elim (decidable_lt x y) /2 width=1/
107 lemma le_fwd_plus_plus_ge: ∀m1,m2. m2 ≤ m1 → ∀n1,n2. m1 + n1 ≤ m2 + n2 → n1 ≤ n2.
108 #m1 #m2 #H elim H -m1
110 | #m1 #_ #IHm1 #n1 #n2 #H @IHm1 /2 width=3/
114 (* backward lemmas **********************************************************)
116 lemma monotonic_lt_minus_l: ∀p,q,n. n ≤ q → q < p → q - n < p - n.
118 @lt_plus_to_minus_r <plus_minus_m_m //.
121 (* unstable *****************************************************************)
123 lemma arith2: ∀j,i,e,d. d + e ≤ i → d ≤ i - e + j.
124 #j #i #e #d #H lapply (le_plus_to_minus_r … H) -H /2 width=3/
127 lemma arith5: ∀a,b1,b2,c1. c1 ≤ b1 → c1 ≤ a → a < b1 + b2 → a - c1 < b1 - c1 + b2.
128 #a #b1 #b2 #c1 #H1 #H2 #H3
129 >plus_minus // @monotonic_lt_minus_l //
132 lemma arith10: ∀a,b,c,d,e. a ≤ b → c + (a - d - e) ≤ c + (b - d - e).
134 >minus_plus >minus_plus @monotonic_le_plus_r @monotonic_le_minus_l //
137 (* remove *******************************************************************)
139 lemma minus_plus_comm: ∀a,b,c. a - b - c = a - (c + b).
142 lemma plus_S_le_to_pos: ∀n,m,p. n + S m ≤ p → 0 < p.
143 /2 by ltn_to_ltO/ qed.
145 lemma minus_le: ∀m,n. m - n ≤ m.
146 /2 by monotonic_le_minus_l/ qed.
148 lemma le_O_to_eq_O: ∀n. n ≤ 0 → n = 0.
149 /2 by le_n_O_to_eq/ qed.
151 lemma lt_to_le: ∀a,b. a < b → a ≤ b.
152 /2 by le_plus_b/ qed.
154 lemma le_to_lt_or_eq: ∀m,n. m ≤ n → m < n ∨ m = n.
155 /2 by le_to_or_lt_eq/ qed.
157 lemma plus_le_weak: ∀m,n,p. m + n ≤ p → n ≤ p.
158 /2 by le_plus_b/ qed.
160 lemma plus_le_minus: ∀a,b,c. a + b ≤ c → a ≤ c - b.
161 /2 by le_plus_to_minus_r/ qed.
163 lemma lt_plus_minus: ∀i,u,d. u ≤ i → i < d + u → i - u < d.
164 /2 by monotonic_lt_minus_l/ qed.
166 lemma arith_a2: ∀a,c1,c2. c1 + c2 ≤ a → a - c1 - c2 + (c1 + c2) = a.
167 /2 by plus_minus/ qed.
169 lemma arith_c1: ∀a,b,c1. a + c1 - (b + c1) = a - b.
172 lemma arith_d1: ∀a,b,c1. c1 ≤ b → a + c1 + (b - c1) = a + b.
173 /2 by plus_minus/ qed.
175 lemma arith_e2: ∀a,c1,c2. a ≤ c1 → c1 + c2 - (c1 - a + c2) = a.
176 /2 by minus_le_minus_minus_comm/ qed.
178 lemma arith_f1: ∀a,b,c1. a + b ≤ c1 → c1 - (c1 - a - b) = a + b.
179 /2 by minus_le_minus_minus_comm/
182 lemma arith_g1: ∀a,b,c1. c1 ≤ b → a - (b - c1) - c1 = a - b.
185 lemma arith_i2: ∀a,c1,c2. c1 + c2 ≤ a → c1 + c2 + (a - c1 - c2) = a.
186 /2 by plus_minus_m_m/ qed.
188 lemma arith_z1: ∀a,b,c1. a + c1 - b - c1 = a - b.
191 lemma arith1: ∀n,h,m,p. n + h + m ≤ p + h → n + m ≤ p.
192 /2 by le_plus_to_le/ qed.
194 lemma arith3: ∀a1,a2,b,c1. a1 + a2 ≤ b → a1 + c1 + a2 ≤ b + c1.
195 /2 by le_minus_to_plus/ qed.
197 lemma arith4: ∀h,d,e1,e2. d ≤ e1 + e2 → d + h ≤ e1 + h + e2.
200 lemma arith8: ∀a,b. a < a + b + 1.
203 lemma arith9: ∀a,b,c. c < a + (b + c + 1) + 1.
206 (* backward form of le_inv_plus_l *)
207 lemma P2: ∀x,y,z. x ≤ z - y → y ≤ z → x + y ≤ z.
208 /2 by le_minus_to_plus_r/ qed.