author | wenzelm |
Thu, 22 Oct 1998 20:15:26 +0200 | |
changeset 5732 | 8712391bbf3d |
parent 5654 | 8b872d546b9e |
child 5758 | 27a2b36efd95 |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/Arith.ML |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
4736 | 4 |
Copyright 1998 University of Cambridge |
923 | 5 |
|
6 |
Proofs about elementary arithmetic: addition, multiplication, etc. |
|
3234 | 7 |
Some from the Hoare example from Norbert Galm |
923 | 8 |
*) |
9 |
||
10 |
(*** Basic rewrite rules for the arithmetic operators ***) |
|
11 |
||
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3842
diff
changeset
|
12 |
|
923 | 13 |
(** Difference **) |
14 |
||
4732 | 15 |
qed_goal "diff_0_eq_0" thy |
923 | 16 |
"0 - n = 0" |
3339 | 17 |
(fn _ => [induct_tac "n" 1, ALLGOALS Asm_simp_tac]); |
923 | 18 |
|
5429 | 19 |
(*Must simplify BEFORE the induction! (Else we get a critical pair) |
923 | 20 |
Suc(m) - Suc(n) rewrites to pred(Suc(m) - n) *) |
4732 | 21 |
qed_goal "diff_Suc_Suc" thy |
923 | 22 |
"Suc(m) - Suc(n) = m - n" |
23 |
(fn _ => |
|
3339 | 24 |
[Simp_tac 1, induct_tac "n" 1, ALLGOALS Asm_simp_tac]); |
923 | 25 |
|
2682
13cdbf95ed92
minor changes due to new primrec definitions for +,-,*
pusch
parents:
2498
diff
changeset
|
26 |
Addsimps [diff_0_eq_0, diff_Suc_Suc]; |
923 | 27 |
|
4360 | 28 |
(* Could be (and is, below) generalized in various ways; |
29 |
However, none of the generalizations are currently in the simpset, |
|
30 |
and I dread to think what happens if I put them in *) |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
31 |
Goal "0 < n ==> Suc(n-1) = n"; |
5183 | 32 |
by (asm_simp_tac (simpset() addsplits [nat.split]) 1); |
4360 | 33 |
qed "Suc_pred"; |
34 |
Addsimps [Suc_pred]; |
|
35 |
||
36 |
Delsimps [diff_Suc]; |
|
37 |
||
923 | 38 |
|
39 |
(**** Inductive properties of the operators ****) |
|
40 |
||
41 |
(*** Addition ***) |
|
42 |
||
4732 | 43 |
qed_goal "add_0_right" thy "m + 0 = m" |
3339 | 44 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 45 |
|
4732 | 46 |
qed_goal "add_Suc_right" thy "m + Suc(n) = Suc(m+n)" |
3339 | 47 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 48 |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
49 |
Addsimps [add_0_right,add_Suc_right]; |
923 | 50 |
|
51 |
(*Associative law for addition*) |
|
4732 | 52 |
qed_goal "add_assoc" thy "(m + n) + k = m + ((n + k)::nat)" |
3339 | 53 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 54 |
|
55 |
(*Commutative law for addition*) |
|
4732 | 56 |
qed_goal "add_commute" thy "m + n = n + (m::nat)" |
3339 | 57 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 58 |
|
4732 | 59 |
qed_goal "add_left_commute" thy "x+(y+z)=y+((x+z)::nat)" |
923 | 60 |
(fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1, |
61 |
rtac (add_commute RS arg_cong) 1]); |
|
62 |
||
63 |
(*Addition is an AC-operator*) |
|
64 |
val add_ac = [add_assoc, add_commute, add_left_commute]; |
|
65 |
||
5429 | 66 |
Goal "(k + m = k + n) = (m=(n::nat))"; |
3339 | 67 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
68 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
69 |
by (Asm_simp_tac 1); |
923 | 70 |
qed "add_left_cancel"; |
71 |
||
5429 | 72 |
Goal "(m + k = n + k) = (m=(n::nat))"; |
3339 | 73 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
74 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
75 |
by (Asm_simp_tac 1); |
923 | 76 |
qed "add_right_cancel"; |
77 |
||
5429 | 78 |
Goal "(k + m <= k + n) = (m<=(n::nat))"; |
3339 | 79 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
80 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
81 |
by (Asm_simp_tac 1); |
923 | 82 |
qed "add_left_cancel_le"; |
83 |
||
5429 | 84 |
Goal "(k + m < k + n) = (m<(n::nat))"; |
3339 | 85 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
86 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
87 |
by (Asm_simp_tac 1); |
923 | 88 |
qed "add_left_cancel_less"; |
89 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
90 |
Addsimps [add_left_cancel, add_right_cancel, |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
91 |
add_left_cancel_le, add_left_cancel_less]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
92 |
|
3339 | 93 |
(** Reasoning about m+0=0, etc. **) |
94 |
||
5069 | 95 |
Goal "(m+n = 0) = (m=0 & n=0)"; |
5598 | 96 |
by (exhaust_tac "m" 1); |
97 |
by (Auto_tac); |
|
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
98 |
qed "add_is_0"; |
4360 | 99 |
AddIffs [add_is_0]; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
100 |
|
5598 | 101 |
Goal "(0 = m+n) = (m=0 & n=0)"; |
102 |
by (exhaust_tac "m" 1); |
|
103 |
by (Auto_tac); |
|
104 |
qed "zero_is_add"; |
|
105 |
AddIffs [zero_is_add]; |
|
106 |
||
107 |
Goal "(m+n=1) = (m=1 & n=0 | m=0 & n=1)"; |
|
108 |
by(exhaust_tac "m" 1); |
|
109 |
by(Auto_tac); |
|
110 |
qed "add_is_1"; |
|
111 |
||
112 |
Goal "(1=m+n) = (m=1 & n=0 | m=0 & n=1)"; |
|
113 |
by(exhaust_tac "m" 1); |
|
114 |
by(Auto_tac); |
|
115 |
qed "one_is_add"; |
|
116 |
||
5069 | 117 |
Goal "(0<m+n) = (0<m | 0<n)"; |
4423 | 118 |
by (simp_tac (simpset() delsimps [neq0_conv] addsimps [neq0_conv RS sym]) 1); |
4360 | 119 |
qed "add_gr_0"; |
120 |
AddIffs [add_gr_0]; |
|
121 |
||
122 |
(* FIXME: really needed?? *) |
|
5069 | 123 |
Goal "((m+n)-1 = 0) = (m=0 & n-1 = 0 | m-1 = 0 & n=0)"; |
4360 | 124 |
by (exhaust_tac "m" 1); |
4089 | 125 |
by (ALLGOALS (fast_tac (claset() addss (simpset())))); |
3293 | 126 |
qed "pred_add_is_0"; |
127 |
Addsimps [pred_add_is_0]; |
|
128 |
||
5429 | 129 |
(* Could be generalized, eg to "k<n ==> m+(n-(Suc k)) = (m+n)-(Suc k)" *) |
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
130 |
Goal "0<n ==> m + (n-1) = (m+n)-1"; |
4360 | 131 |
by (exhaust_tac "m" 1); |
132 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_Suc] |
|
5183 | 133 |
addsplits [nat.split]))); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
134 |
qed "add_pred"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
135 |
Addsimps [add_pred]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
136 |
|
5429 | 137 |
Goal "m + n = m ==> n = 0"; |
5078 | 138 |
by (dtac (add_0_right RS ssubst) 1); |
139 |
by (asm_full_simp_tac (simpset() addsimps [add_assoc] |
|
140 |
delsimps [add_0_right]) 1); |
|
141 |
qed "add_eq_self_zero"; |
|
142 |
||
1626 | 143 |
|
923 | 144 |
(**** Additional theorems about "less than" ****) |
145 |
||
5078 | 146 |
(*Deleted less_natE; instead use less_eq_Suc_add RS exE*) |
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
147 |
Goal "m<n --> (? k. n=Suc(m+k))"; |
3339 | 148 |
by (induct_tac "n" 1); |
5604 | 149 |
by (ALLGOALS (simp_tac (simpset() addsimps [order_le_less]))); |
4089 | 150 |
by (blast_tac (claset() addSEs [less_SucE] |
5497 | 151 |
addSIs [add_0_right RS sym, add_Suc_right RS sym]) 1); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1475
diff
changeset
|
152 |
qed_spec_mp "less_eq_Suc_add"; |
923 | 153 |
|
5069 | 154 |
Goal "n <= ((m + n)::nat)"; |
3339 | 155 |
by (induct_tac "m" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
156 |
by (ALLGOALS Simp_tac); |
923 | 157 |
qed "le_add2"; |
158 |
||
5069 | 159 |
Goal "n <= ((n + m)::nat)"; |
4089 | 160 |
by (simp_tac (simpset() addsimps add_ac) 1); |
923 | 161 |
by (rtac le_add2 1); |
162 |
qed "le_add1"; |
|
163 |
||
164 |
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); |
|
165 |
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); |
|
166 |
||
5429 | 167 |
Goal "(m<n) = (? k. n=Suc(m+k))"; |
168 |
by (blast_tac (claset() addSIs [less_add_Suc1, less_eq_Suc_add]) 1); |
|
169 |
qed "less_iff_Suc_add"; |
|
170 |
||
171 |
||
923 | 172 |
(*"i <= j ==> i <= j+m"*) |
173 |
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); |
|
174 |
||
175 |
(*"i <= j ==> i <= m+j"*) |
|
176 |
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); |
|
177 |
||
178 |
(*"i < j ==> i < j+m"*) |
|
179 |
bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); |
|
180 |
||
181 |
(*"i < j ==> i < m+j"*) |
|
182 |
bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); |
|
183 |
||
5654 | 184 |
Goal "i+j < (k::nat) --> i<k"; |
3339 | 185 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
186 |
by (ALLGOALS Asm_simp_tac); |
5654 | 187 |
qed_spec_mp "add_lessD1"; |
1152 | 188 |
|
5429 | 189 |
Goal "~ (i+j < (i::nat))"; |
3457 | 190 |
by (rtac notI 1); |
191 |
by (etac (add_lessD1 RS less_irrefl) 1); |
|
3234 | 192 |
qed "not_add_less1"; |
193 |
||
5429 | 194 |
Goal "~ (j+i < (i::nat))"; |
4089 | 195 |
by (simp_tac (simpset() addsimps [add_commute, not_add_less1]) 1); |
3234 | 196 |
qed "not_add_less2"; |
197 |
AddIffs [not_add_less1, not_add_less2]; |
|
198 |
||
5069 | 199 |
Goal "m+k<=n --> m<=(n::nat)"; |
3339 | 200 |
by (induct_tac "k" 1); |
5497 | 201 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps le_simps))); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1475
diff
changeset
|
202 |
qed_spec_mp "add_leD1"; |
923 | 203 |
|
5429 | 204 |
Goal "m+k<=n ==> k<=(n::nat)"; |
4089 | 205 |
by (full_simp_tac (simpset() addsimps [add_commute]) 1); |
2498 | 206 |
by (etac add_leD1 1); |
207 |
qed_spec_mp "add_leD2"; |
|
208 |
||
5429 | 209 |
Goal "m+k<=n ==> m<=n & k<=(n::nat)"; |
4089 | 210 |
by (blast_tac (claset() addDs [add_leD1, add_leD2]) 1); |
2498 | 211 |
bind_thm ("add_leE", result() RS conjE); |
212 |
||
5429 | 213 |
(*needs !!k for add_ac to work*) |
214 |
Goal "!!k:: nat. [| k<l; m+l = k+n |] ==> m<n"; |
|
5497 | 215 |
by (auto_tac (claset(), |
216 |
simpset() delsimps [add_Suc_right] |
|
5537 | 217 |
addsimps [less_iff_Suc_add, |
218 |
add_Suc_right RS sym] @ add_ac)); |
|
923 | 219 |
qed "less_add_eq_less"; |
220 |
||
221 |
||
1713 | 222 |
(*** Monotonicity of Addition ***) |
923 | 223 |
|
224 |
(*strict, in 1st argument*) |
|
5429 | 225 |
Goal "i < j ==> i + k < j + (k::nat)"; |
3339 | 226 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
227 |
by (ALLGOALS Asm_simp_tac); |
923 | 228 |
qed "add_less_mono1"; |
229 |
||
230 |
(*strict, in both arguments*) |
|
5429 | 231 |
Goal "[|i < j; k < l|] ==> i + k < j + (l::nat)"; |
923 | 232 |
by (rtac (add_less_mono1 RS less_trans) 1); |
1198 | 233 |
by (REPEAT (assume_tac 1)); |
3339 | 234 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
235 |
by (ALLGOALS Asm_simp_tac); |
923 | 236 |
qed "add_less_mono"; |
237 |
||
238 |
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) |
|
5316 | 239 |
val [lt_mono,le] = Goal |
1465 | 240 |
"[| !!i j::nat. i<j ==> f(i) < f(j); \ |
241 |
\ i <= j \ |
|
923 | 242 |
\ |] ==> f(i) <= (f(j)::nat)"; |
243 |
by (cut_facts_tac [le] 1); |
|
5604 | 244 |
by (asm_full_simp_tac (simpset() addsimps [order_le_less]) 1); |
4089 | 245 |
by (blast_tac (claset() addSIs [lt_mono]) 1); |
923 | 246 |
qed "less_mono_imp_le_mono"; |
247 |
||
248 |
(*non-strict, in 1st argument*) |
|
5429 | 249 |
Goal "i<=j ==> i + k <= j + (k::nat)"; |
3842 | 250 |
by (res_inst_tac [("f", "%j. j+k")] less_mono_imp_le_mono 1); |
1552 | 251 |
by (etac add_less_mono1 1); |
923 | 252 |
by (assume_tac 1); |
253 |
qed "add_le_mono1"; |
|
254 |
||
255 |
(*non-strict, in both arguments*) |
|
5429 | 256 |
Goal "[|i<=j; k<=l |] ==> i + k <= j + (l::nat)"; |
923 | 257 |
by (etac (add_le_mono1 RS le_trans) 1); |
4089 | 258 |
by (simp_tac (simpset() addsimps [add_commute]) 1); |
923 | 259 |
qed "add_le_mono"; |
1713 | 260 |
|
3234 | 261 |
|
262 |
(*** Multiplication ***) |
|
263 |
||
264 |
(*right annihilation in product*) |
|
4732 | 265 |
qed_goal "mult_0_right" thy "m * 0 = 0" |
3339 | 266 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 267 |
|
3293 | 268 |
(*right successor law for multiplication*) |
4732 | 269 |
qed_goal "mult_Suc_right" thy "m * Suc(n) = m + (m * n)" |
3339 | 270 |
(fn _ => [induct_tac "m" 1, |
4089 | 271 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 272 |
|
3293 | 273 |
Addsimps [mult_0_right, mult_Suc_right]; |
3234 | 274 |
|
5069 | 275 |
Goal "1 * n = n"; |
3234 | 276 |
by (Asm_simp_tac 1); |
277 |
qed "mult_1"; |
|
278 |
||
5069 | 279 |
Goal "n * 1 = n"; |
3234 | 280 |
by (Asm_simp_tac 1); |
281 |
qed "mult_1_right"; |
|
282 |
||
283 |
(*Commutative law for multiplication*) |
|
4732 | 284 |
qed_goal "mult_commute" thy "m * n = n * (m::nat)" |
3339 | 285 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 286 |
|
287 |
(*addition distributes over multiplication*) |
|
4732 | 288 |
qed_goal "add_mult_distrib" thy "(m + n)*k = (m*k) + ((n*k)::nat)" |
3339 | 289 |
(fn _ => [induct_tac "m" 1, |
4089 | 290 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 291 |
|
4732 | 292 |
qed_goal "add_mult_distrib2" thy "k*(m + n) = (k*m) + ((k*n)::nat)" |
3339 | 293 |
(fn _ => [induct_tac "m" 1, |
4089 | 294 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 295 |
|
296 |
(*Associative law for multiplication*) |
|
4732 | 297 |
qed_goal "mult_assoc" thy "(m * n) * k = m * ((n * k)::nat)" |
3339 | 298 |
(fn _ => [induct_tac "m" 1, |
4089 | 299 |
ALLGOALS (asm_simp_tac (simpset() addsimps [add_mult_distrib]))]); |
3234 | 300 |
|
4732 | 301 |
qed_goal "mult_left_commute" thy "x*(y*z) = y*((x*z)::nat)" |
3234 | 302 |
(fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1, |
303 |
rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]); |
|
304 |
||
305 |
val mult_ac = [mult_assoc,mult_commute,mult_left_commute]; |
|
306 |
||
5069 | 307 |
Goal "(m*n = 0) = (m=0 | n=0)"; |
3339 | 308 |
by (induct_tac "m" 1); |
309 |
by (induct_tac "n" 2); |
|
3293 | 310 |
by (ALLGOALS Asm_simp_tac); |
311 |
qed "mult_is_0"; |
|
312 |
Addsimps [mult_is_0]; |
|
313 |
||
5429 | 314 |
Goal "m <= m*(m::nat)"; |
4158 | 315 |
by (induct_tac "m" 1); |
316 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_assoc RS sym]))); |
|
317 |
by (etac (le_add2 RSN (2,le_trans)) 1); |
|
318 |
qed "le_square"; |
|
319 |
||
3234 | 320 |
|
321 |
(*** Difference ***) |
|
322 |
||
323 |
||
4732 | 324 |
qed_goal "diff_self_eq_0" thy "m - m = 0" |
3339 | 325 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 326 |
Addsimps [diff_self_eq_0]; |
327 |
||
328 |
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) |
|
5069 | 329 |
Goal "~ m<n --> n+(m-n) = (m::nat)"; |
3234 | 330 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
3352 | 331 |
by (ALLGOALS Asm_simp_tac); |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
332 |
qed_spec_mp "add_diff_inverse"; |
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
333 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
334 |
Goal "n<=m ==> n+(m-n) = (m::nat)"; |
4089 | 335 |
by (asm_simp_tac (simpset() addsimps [add_diff_inverse, not_less_iff_le]) 1); |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
336 |
qed "le_add_diff_inverse"; |
3234 | 337 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
338 |
Goal "n<=m ==> (m-n)+n = (m::nat)"; |
4089 | 339 |
by (asm_simp_tac (simpset() addsimps [le_add_diff_inverse, add_commute]) 1); |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
340 |
qed "le_add_diff_inverse2"; |
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
341 |
|
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
342 |
Addsimps [le_add_diff_inverse, le_add_diff_inverse2]; |
3234 | 343 |
|
344 |
||
345 |
(*** More results about difference ***) |
|
346 |
||
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
347 |
Goal "n <= m ==> Suc(m)-n = Suc(m-n)"; |
5316 | 348 |
by (etac rev_mp 1); |
3352 | 349 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
350 |
by (ALLGOALS Asm_simp_tac); |
|
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
351 |
qed "Suc_diff_le"; |
3352 | 352 |
|
5429 | 353 |
Goal "n<=(l::nat) --> Suc l - n + m = Suc (l - n + m)"; |
354 |
by (res_inst_tac [("m","n"),("n","l")] diff_induct 1); |
|
355 |
by (ALLGOALS Asm_simp_tac); |
|
356 |
qed_spec_mp "Suc_diff_add_le"; |
|
357 |
||
5069 | 358 |
Goal "m - n < Suc(m)"; |
3234 | 359 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
360 |
by (etac less_SucE 3); |
|
4089 | 361 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq]))); |
3234 | 362 |
qed "diff_less_Suc"; |
363 |
||
5429 | 364 |
Goal "m - n <= (m::nat)"; |
3234 | 365 |
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); |
366 |
by (ALLGOALS Asm_simp_tac); |
|
367 |
qed "diff_le_self"; |
|
3903
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
368 |
Addsimps [diff_le_self]; |
3234 | 369 |
|
4732 | 370 |
(* j<k ==> j-n < k *) |
371 |
bind_thm ("less_imp_diff_less", diff_le_self RS le_less_trans); |
|
372 |
||
5069 | 373 |
Goal "!!i::nat. i-j-k = i - (j+k)"; |
3352 | 374 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
375 |
by (ALLGOALS Asm_simp_tac); |
|
376 |
qed "diff_diff_left"; |
|
377 |
||
5069 | 378 |
Goal "(Suc m - n) - Suc k = m - n - k"; |
4423 | 379 |
by (simp_tac (simpset() addsimps [diff_diff_left]) 1); |
4736 | 380 |
qed "Suc_diff_diff"; |
381 |
Addsimps [Suc_diff_diff]; |
|
4360 | 382 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
383 |
Goal "0<n ==> n - Suc i < n"; |
5183 | 384 |
by (exhaust_tac "n" 1); |
4732 | 385 |
by Safe_tac; |
5497 | 386 |
by (asm_simp_tac (simpset() addsimps le_simps) 1); |
4732 | 387 |
qed "diff_Suc_less"; |
388 |
Addsimps [diff_Suc_less]; |
|
389 |
||
5329 | 390 |
Goal "i<n ==> n - Suc i < n - i"; |
391 |
by (exhaust_tac "n" 1); |
|
5497 | 392 |
by (auto_tac (claset(), |
5537 | 393 |
simpset() addsimps [Suc_diff_le]@le_simps)); |
5329 | 394 |
qed "diff_Suc_less_diff"; |
395 |
||
3396 | 396 |
(*This and the next few suggested by Florian Kammueller*) |
5069 | 397 |
Goal "!!i::nat. i-j-k = i-k-j"; |
4089 | 398 |
by (simp_tac (simpset() addsimps [diff_diff_left, add_commute]) 1); |
3352 | 399 |
qed "diff_commute"; |
400 |
||
5429 | 401 |
Goal "k<=j --> j<=i --> i - (j - k) = i - j + (k::nat)"; |
3352 | 402 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
403 |
by (ALLGOALS Asm_simp_tac); |
|
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
404 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1); |
3352 | 405 |
qed_spec_mp "diff_diff_right"; |
406 |
||
5429 | 407 |
Goal "k <= (j::nat) --> (i + j) - k = i + (j - k)"; |
3352 | 408 |
by (res_inst_tac [("m","j"),("n","k")] diff_induct 1); |
409 |
by (ALLGOALS Asm_simp_tac); |
|
410 |
qed_spec_mp "diff_add_assoc"; |
|
411 |
||
5429 | 412 |
Goal "k <= (j::nat) --> (j + i) - k = i + (j - k)"; |
4732 | 413 |
by (asm_simp_tac (simpset() addsimps [add_commute, diff_add_assoc]) 1); |
414 |
qed_spec_mp "diff_add_assoc2"; |
|
415 |
||
5429 | 416 |
Goal "(n+m) - n = (m::nat)"; |
3339 | 417 |
by (induct_tac "n" 1); |
3234 | 418 |
by (ALLGOALS Asm_simp_tac); |
419 |
qed "diff_add_inverse"; |
|
420 |
Addsimps [diff_add_inverse]; |
|
421 |
||
5429 | 422 |
Goal "(m+n) - n = (m::nat)"; |
4089 | 423 |
by (simp_tac (simpset() addsimps [diff_add_assoc]) 1); |
3234 | 424 |
qed "diff_add_inverse2"; |
425 |
Addsimps [diff_add_inverse2]; |
|
426 |
||
5429 | 427 |
Goal "i <= (j::nat) ==> (j-i=k) = (j=k+i)"; |
3724 | 428 |
by Safe_tac; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
429 |
by (ALLGOALS Asm_simp_tac); |
3366 | 430 |
qed "le_imp_diff_is_add"; |
431 |
||
5356 | 432 |
Goal "(m-n = 0) = (m <= n)"; |
3234 | 433 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
5497 | 434 |
by (ALLGOALS Asm_simp_tac); |
5356 | 435 |
qed "diff_is_0_eq"; |
436 |
Addsimps [diff_is_0_eq RS iffD2]; |
|
3234 | 437 |
|
5316 | 438 |
Goal "m-n = 0 --> n-m = 0 --> m=n"; |
3234 | 439 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
440 |
by (REPEAT(Simp_tac 1 THEN TRY(atac 1))); |
|
441 |
qed_spec_mp "diffs0_imp_equal"; |
|
442 |
||
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
443 |
Goal "(0<n-m) = (m<n)"; |
3234 | 444 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
3352 | 445 |
by (ALLGOALS Asm_simp_tac); |
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
446 |
qed "zero_less_diff"; |
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
447 |
Addsimps [zero_less_diff]; |
3234 | 448 |
|
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
449 |
Goal "i < j ==> ? k. 0<k & i+k = j"; |
5078 | 450 |
by (res_inst_tac [("x","j - i")] exI 1); |
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
451 |
by (asm_simp_tac (simpset() addsimps [add_diff_inverse, less_not_sym]) 1); |
5078 | 452 |
qed "less_imp_add_positive"; |
453 |
||
5069 | 454 |
Goal "Suc(m)-n = (if m<n then 0 else Suc(m-n))"; |
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
455 |
by (simp_tac (simpset() addsimps [leI, Suc_le_eq, Suc_diff_le]) 1); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
456 |
qed "if_Suc_diff_le"; |
3234 | 457 |
|
5069 | 458 |
Goal "Suc(m)-n <= Suc(m-n)"; |
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
459 |
by (simp_tac (simpset() addsimps [if_Suc_diff_le]) 1); |
4672
9d55bc687e1e
New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents:
4423
diff
changeset
|
460 |
qed "diff_Suc_le_Suc_diff"; |
9d55bc687e1e
New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents:
4423
diff
changeset
|
461 |
|
5069 | 462 |
Goal "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)"; |
3234 | 463 |
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); |
3718 | 464 |
by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac)); |
3234 | 465 |
qed "zero_induct_lemma"; |
466 |
||
5316 | 467 |
val prems = Goal "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; |
3234 | 468 |
by (rtac (diff_self_eq_0 RS subst) 1); |
469 |
by (rtac (zero_induct_lemma RS mp RS mp) 1); |
|
470 |
by (REPEAT (ares_tac ([impI,allI]@prems) 1)); |
|
471 |
qed "zero_induct"; |
|
472 |
||
5429 | 473 |
Goal "(k+m) - (k+n) = m - (n::nat)"; |
3339 | 474 |
by (induct_tac "k" 1); |
3234 | 475 |
by (ALLGOALS Asm_simp_tac); |
476 |
qed "diff_cancel"; |
|
477 |
Addsimps [diff_cancel]; |
|
478 |
||
5429 | 479 |
Goal "(m+k) - (n+k) = m - (n::nat)"; |
3234 | 480 |
val add_commute_k = read_instantiate [("n","k")] add_commute; |
5537 | 481 |
by (asm_simp_tac (simpset() addsimps [add_commute_k]) 1); |
3234 | 482 |
qed "diff_cancel2"; |
483 |
Addsimps [diff_cancel2]; |
|
484 |
||
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
485 |
(*From Clemens Ballarin, proof by lcp*) |
5429 | 486 |
Goal "[| k<=n; n<=m |] ==> (m-k) - (n-k) = m-(n::nat)"; |
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
487 |
by (REPEAT (etac rev_mp 1)); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
488 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
489 |
by (ALLGOALS Asm_simp_tac); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
490 |
(*a confluence problem*) |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
491 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1); |
3234 | 492 |
qed "diff_right_cancel"; |
493 |
||
5429 | 494 |
Goal "n - (n+m) = 0"; |
3339 | 495 |
by (induct_tac "n" 1); |
3234 | 496 |
by (ALLGOALS Asm_simp_tac); |
497 |
qed "diff_add_0"; |
|
498 |
Addsimps [diff_add_0]; |
|
499 |
||
5409 | 500 |
|
3234 | 501 |
(** Difference distributes over multiplication **) |
502 |
||
5069 | 503 |
Goal "!!m::nat. (m - n) * k = (m * k) - (n * k)"; |
3234 | 504 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
505 |
by (ALLGOALS Asm_simp_tac); |
|
506 |
qed "diff_mult_distrib" ; |
|
507 |
||
5069 | 508 |
Goal "!!m::nat. k * (m - n) = (k * m) - (k * n)"; |
3234 | 509 |
val mult_commute_k = read_instantiate [("m","k")] mult_commute; |
4089 | 510 |
by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1); |
3234 | 511 |
qed "diff_mult_distrib2" ; |
512 |
(*NOT added as rewrites, since sometimes they are used from right-to-left*) |
|
513 |
||
514 |
||
1713 | 515 |
(*** Monotonicity of Multiplication ***) |
516 |
||
5429 | 517 |
Goal "i <= (j::nat) ==> i*k<=j*k"; |
3339 | 518 |
by (induct_tac "k" 1); |
4089 | 519 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_le_mono]))); |
1713 | 520 |
qed "mult_le_mono1"; |
521 |
||
522 |
(*<=monotonicity, BOTH arguments*) |
|
5429 | 523 |
Goal "[| i <= (j::nat); k <= l |] ==> i*k <= j*l"; |
2007 | 524 |
by (etac (mult_le_mono1 RS le_trans) 1); |
1713 | 525 |
by (rtac le_trans 1); |
2007 | 526 |
by (stac mult_commute 2); |
527 |
by (etac mult_le_mono1 2); |
|
4089 | 528 |
by (simp_tac (simpset() addsimps [mult_commute]) 1); |
1713 | 529 |
qed "mult_le_mono"; |
530 |
||
531 |
(*strict, in 1st argument; proof is by induction on k>0*) |
|
5429 | 532 |
Goal "[| i<j; 0<k |] ==> k*i < k*j"; |
5078 | 533 |
by (eres_inst_tac [("m1","0")] (less_eq_Suc_add RS exE) 1); |
1713 | 534 |
by (Asm_simp_tac 1); |
3339 | 535 |
by (induct_tac "x" 1); |
4089 | 536 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_less_mono]))); |
1713 | 537 |
qed "mult_less_mono2"; |
538 |
||
5429 | 539 |
Goal "[| i<j; 0<k |] ==> i*k < j*k"; |
3457 | 540 |
by (dtac mult_less_mono2 1); |
4089 | 541 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute]))); |
3234 | 542 |
qed "mult_less_mono1"; |
543 |
||
5069 | 544 |
Goal "(0 < m*n) = (0<m & 0<n)"; |
3339 | 545 |
by (induct_tac "m" 1); |
546 |
by (induct_tac "n" 2); |
|
1713 | 547 |
by (ALLGOALS Asm_simp_tac); |
548 |
qed "zero_less_mult_iff"; |
|
4356 | 549 |
Addsimps [zero_less_mult_iff]; |
1713 | 550 |
|
5069 | 551 |
Goal "(m*n = 1) = (m=1 & n=1)"; |
3339 | 552 |
by (induct_tac "m" 1); |
1795 | 553 |
by (Simp_tac 1); |
3339 | 554 |
by (induct_tac "n" 1); |
1795 | 555 |
by (Simp_tac 1); |
4089 | 556 |
by (fast_tac (claset() addss simpset()) 1); |
1795 | 557 |
qed "mult_eq_1_iff"; |
4356 | 558 |
Addsimps [mult_eq_1_iff]; |
1795 | 559 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
560 |
Goal "0<k ==> (m*k < n*k) = (m<n)"; |
4089 | 561 |
by (safe_tac (claset() addSIs [mult_less_mono1])); |
3234 | 562 |
by (cut_facts_tac [less_linear] 1); |
4389 | 563 |
by (blast_tac (claset() addIs [mult_less_mono1] addEs [less_asym]) 1); |
3234 | 564 |
qed "mult_less_cancel2"; |
565 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
566 |
Goal "0<k ==> (k*m < k*n) = (m<n)"; |
3457 | 567 |
by (dtac mult_less_cancel2 1); |
4089 | 568 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 569 |
qed "mult_less_cancel1"; |
570 |
Addsimps [mult_less_cancel1, mult_less_cancel2]; |
|
571 |
||
5069 | 572 |
Goal "(Suc k * m < Suc k * n) = (m < n)"; |
4423 | 573 |
by (rtac mult_less_cancel1 1); |
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
574 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
575 |
qed "Suc_mult_less_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
576 |
|
5069 | 577 |
Goalw [le_def] "(Suc k * m <= Suc k * n) = (m <= n)"; |
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
578 |
by (simp_tac (simpset_of HOL.thy) 1); |
4423 | 579 |
by (rtac Suc_mult_less_cancel1 1); |
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
580 |
qed "Suc_mult_le_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
581 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
582 |
Goal "0<k ==> (m*k = n*k) = (m=n)"; |
3234 | 583 |
by (cut_facts_tac [less_linear] 1); |
3724 | 584 |
by Safe_tac; |
3457 | 585 |
by (assume_tac 2); |
3234 | 586 |
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac)); |
587 |
by (ALLGOALS Asm_full_simp_tac); |
|
588 |
qed "mult_cancel2"; |
|
589 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
590 |
Goal "0<k ==> (k*m = k*n) = (m=n)"; |
3457 | 591 |
by (dtac mult_cancel2 1); |
4089 | 592 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 593 |
qed "mult_cancel1"; |
594 |
Addsimps [mult_cancel1, mult_cancel2]; |
|
595 |
||
5069 | 596 |
Goal "(Suc k * m = Suc k * n) = (m = n)"; |
4423 | 597 |
by (rtac mult_cancel1 1); |
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
598 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
599 |
qed "Suc_mult_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
600 |
|
3234 | 601 |
|
1795 | 602 |
(** Lemma for gcd **) |
603 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
604 |
Goal "m = m*n ==> n=1 | m=0"; |
1795 | 605 |
by (dtac sym 1); |
606 |
by (rtac disjCI 1); |
|
607 |
by (rtac nat_less_cases 1 THEN assume_tac 2); |
|
4089 | 608 |
by (fast_tac (claset() addSEs [less_SucE] addss simpset()) 1); |
4356 | 609 |
by (best_tac (claset() addDs [mult_less_mono2] addss simpset()) 1); |
1795 | 610 |
qed "mult_eq_self_implies_10"; |
611 |
||
612 |
||
4736 | 613 |
(*** Subtraction laws -- mostly from Clemens Ballarin ***) |
3234 | 614 |
|
5429 | 615 |
Goal "[| a < (b::nat); c <= a |] ==> a-c < b-c"; |
3234 | 616 |
by (subgoal_tac "c+(a-c) < c+(b-c)" 1); |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
617 |
by (Full_simp_tac 1); |
3234 | 618 |
by (subgoal_tac "c <= b" 1); |
4089 | 619 |
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 2); |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
620 |
by (Asm_simp_tac 1); |
3234 | 621 |
qed "diff_less_mono"; |
622 |
||
5429 | 623 |
Goal "a+b < (c::nat) ==> a < c-b"; |
3457 | 624 |
by (dtac diff_less_mono 1); |
625 |
by (rtac le_add2 1); |
|
3234 | 626 |
by (Asm_full_simp_tac 1); |
627 |
qed "add_less_imp_less_diff"; |
|
628 |
||
5427 | 629 |
Goal "(i < j-k) = (i+k < (j::nat))"; |
5497 | 630 |
by (rtac iffI 1); |
631 |
by (case_tac "k <= j" 1); |
|
632 |
by (dtac le_add_diff_inverse2 1); |
|
633 |
by (dres_inst_tac [("k","k")] add_less_mono1 1); |
|
634 |
by (Asm_full_simp_tac 1); |
|
635 |
by (rotate_tac 1 1); |
|
636 |
by (asm_full_simp_tac (simpset() addSolver cut_trans_tac) 1); |
|
637 |
by (etac add_less_imp_less_diff 1); |
|
5427 | 638 |
qed "less_diff_conv"; |
639 |
||
5497 | 640 |
Goal "(j-k <= (i::nat)) = (j <= i+k)"; |
641 |
by (simp_tac (simpset() addsimps [less_diff_conv, le_def]) 1); |
|
5485 | 642 |
qed "le_diff_conv"; |
643 |
||
5497 | 644 |
Goal "k <= j ==> (i <= j-k) = (i+k <= (j::nat))"; |
645 |
by (asm_full_simp_tac |
|
646 |
(simpset() delsimps [less_Suc_eq_le] |
|
647 |
addsimps [less_Suc_eq_le RS sym, less_diff_conv, |
|
648 |
Suc_diff_le RS sym]) 1); |
|
649 |
qed "le_diff_conv2"; |
|
650 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
651 |
Goal "Suc i <= n ==> Suc (n - Suc i) = n - i"; |
5497 | 652 |
by (asm_full_simp_tac (simpset() addsimps [Suc_diff_le RS sym]) 1); |
3234 | 653 |
qed "Suc_diff_Suc"; |
654 |
||
5429 | 655 |
Goal "i <= (n::nat) ==> n - (n - i) = i"; |
3903
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
656 |
by (etac rev_mp 1); |
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
657 |
by (res_inst_tac [("m","n"),("n","i")] diff_induct 1); |
4089 | 658 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Suc_diff_le]))); |
3234 | 659 |
qed "diff_diff_cancel"; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
660 |
Addsimps [diff_diff_cancel]; |
3234 | 661 |
|
5429 | 662 |
Goal "k <= (n::nat) ==> m <= n + m - k"; |
3457 | 663 |
by (etac rev_mp 1); |
3234 | 664 |
by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1); |
665 |
by (Simp_tac 1); |
|
5497 | 666 |
by (simp_tac (simpset() addsimps [le_add2, less_imp_le]) 1); |
3234 | 667 |
by (Simp_tac 1); |
668 |
qed "le_add_diff"; |
|
669 |
||
5429 | 670 |
Goal "0<k ==> j<i --> j+k-i < k"; |
4736 | 671 |
by (res_inst_tac [("m","j"),("n","i")] diff_induct 1); |
672 |
by (ALLGOALS Asm_simp_tac); |
|
673 |
qed_spec_mp "add_diff_less"; |
|
674 |
||
3234 | 675 |
|
5356 | 676 |
Goal "m-1 < n ==> m <= n"; |
677 |
by (exhaust_tac "m" 1); |
|
678 |
by (auto_tac (claset(), simpset() addsimps [Suc_le_eq])); |
|
679 |
qed "pred_less_imp_le"; |
|
680 |
||
681 |
Goal "j<=i ==> i - j < Suc i - j"; |
|
682 |
by (REPEAT (etac rev_mp 1)); |
|
683 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
|
684 |
by Auto_tac; |
|
685 |
qed "diff_less_Suc_diff"; |
|
686 |
||
687 |
Goal "i - j <= Suc i - j"; |
|
688 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
|
689 |
by Auto_tac; |
|
690 |
qed "diff_le_Suc_diff"; |
|
691 |
AddIffs [diff_le_Suc_diff]; |
|
692 |
||
693 |
Goal "n - Suc i <= n - i"; |
|
694 |
by (case_tac "i<n" 1); |
|
5497 | 695 |
by (dtac diff_Suc_less_diff 1); |
5604 | 696 |
by (auto_tac (claset(), simpset() addsimps [less_imp_le, leI])); |
5356 | 697 |
qed "diff_Suc_le_diff"; |
698 |
AddIffs [diff_Suc_le_diff]; |
|
699 |
||
5409 | 700 |
Goal "0 < n ==> (m <= n-1) = (m<n)"; |
701 |
by (exhaust_tac "n" 1); |
|
5497 | 702 |
by (auto_tac (claset(), simpset() addsimps le_simps)); |
5409 | 703 |
qed "le_pred_eq"; |
704 |
||
705 |
Goal "0 < n ==> (m-1 < n) = (m<=n)"; |
|
706 |
by (exhaust_tac "m" 1); |
|
707 |
by (auto_tac (claset(), simpset() addsimps [Suc_le_eq])); |
|
708 |
qed "less_pred_eq"; |
|
709 |
||
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
710 |
(*In ordinary notation: if 0<n and n<=m then m-n < m *) |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
711 |
Goal "[| 0<n; ~ m<n |] ==> m - n < m"; |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
712 |
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
713 |
by (Blast_tac 1); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
714 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
715 |
by (ALLGOALS(asm_simp_tac(simpset() addsimps [diff_less_Suc]))); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
716 |
qed "diff_less"; |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
717 |
|
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
718 |
Goal "[| 0<n; n<=m |] ==> m - n < m"; |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
719 |
by (asm_simp_tac (simpset() addsimps [diff_less, not_less_iff_le]) 1); |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
720 |
qed "le_diff_less"; |
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
721 |
|
5356 | 722 |
|
4732 | 723 |
|
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
724 |
(** (Anti)Monotonicity of subtraction -- by Stefan Merz **) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
725 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
726 |
(* Monotonicity of subtraction in first argument *) |
5429 | 727 |
Goal "m <= (n::nat) --> (m-l) <= (n-l)"; |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
728 |
by (induct_tac "n" 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
729 |
by (Simp_tac 1); |
4089 | 730 |
by (simp_tac (simpset() addsimps [le_Suc_eq]) 1); |
4732 | 731 |
by (blast_tac (claset() addIs [diff_le_Suc_diff, le_trans]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
732 |
qed_spec_mp "diff_le_mono"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
733 |
|
5429 | 734 |
Goal "m <= (n::nat) ==> (l-n) <= (l-m)"; |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
735 |
by (induct_tac "l" 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
736 |
by (Simp_tac 1); |
5183 | 737 |
by (case_tac "n <= na" 1); |
738 |
by (subgoal_tac "m <= na" 1); |
|
4089 | 739 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le]) 1); |
740 |
by (fast_tac (claset() addEs [le_trans]) 1); |
|
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
741 |
by (dtac not_leE 1); |
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
742 |
by (asm_simp_tac (simpset() addsimps [if_Suc_diff_le]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
743 |
qed_spec_mp "diff_le_mono2"; |