author | paulson |
Fri, 02 Oct 1998 10:41:35 +0200 | |
changeset 5604 | cd17004d09e1 |
parent 5598 | 6b8dee1a6ebb |
child 5654 | 8b872d546b9e |
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 |
by (etac le_trans 1); |
158 |
by (rtac (lessI RS less_imp_le) 1); |
|
159 |
qed "le_add2"; |
|
160 |
||
5069 | 161 |
Goal "n <= ((n + m)::nat)"; |
4089 | 162 |
by (simp_tac (simpset() addsimps add_ac) 1); |
923 | 163 |
by (rtac le_add2 1); |
164 |
qed "le_add1"; |
|
165 |
||
166 |
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); |
|
167 |
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); |
|
168 |
||
5429 | 169 |
Goal "(m<n) = (? k. n=Suc(m+k))"; |
170 |
by (blast_tac (claset() addSIs [less_add_Suc1, less_eq_Suc_add]) 1); |
|
171 |
qed "less_iff_Suc_add"; |
|
172 |
||
173 |
||
923 | 174 |
(*"i <= j ==> i <= j+m"*) |
175 |
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); |
|
176 |
||
177 |
(*"i <= j ==> i <= m+j"*) |
|
178 |
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); |
|
179 |
||
180 |
(*"i < j ==> i < j+m"*) |
|
181 |
bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); |
|
182 |
||
183 |
(*"i < j ==> i < m+j"*) |
|
184 |
bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); |
|
185 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
186 |
Goal "i+j < (k::nat) ==> i<k"; |
1552 | 187 |
by (etac rev_mp 1); |
3339 | 188 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
189 |
by (ALLGOALS Asm_simp_tac); |
4089 | 190 |
by (blast_tac (claset() addDs [Suc_lessD]) 1); |
1152 | 191 |
qed "add_lessD1"; |
192 |
||
5429 | 193 |
Goal "~ (i+j < (i::nat))"; |
3457 | 194 |
by (rtac notI 1); |
195 |
by (etac (add_lessD1 RS less_irrefl) 1); |
|
3234 | 196 |
qed "not_add_less1"; |
197 |
||
5429 | 198 |
Goal "~ (j+i < (i::nat))"; |
4089 | 199 |
by (simp_tac (simpset() addsimps [add_commute, not_add_less1]) 1); |
3234 | 200 |
qed "not_add_less2"; |
201 |
AddIffs [not_add_less1, not_add_less2]; |
|
202 |
||
5069 | 203 |
Goal "m+k<=n --> m<=(n::nat)"; |
3339 | 204 |
by (induct_tac "k" 1); |
5497 | 205 |
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
|
206 |
qed_spec_mp "add_leD1"; |
923 | 207 |
|
5429 | 208 |
Goal "m+k<=n ==> k<=(n::nat)"; |
4089 | 209 |
by (full_simp_tac (simpset() addsimps [add_commute]) 1); |
2498 | 210 |
by (etac add_leD1 1); |
211 |
qed_spec_mp "add_leD2"; |
|
212 |
||
5429 | 213 |
Goal "m+k<=n ==> m<=n & k<=(n::nat)"; |
4089 | 214 |
by (blast_tac (claset() addDs [add_leD1, add_leD2]) 1); |
2498 | 215 |
bind_thm ("add_leE", result() RS conjE); |
216 |
||
5429 | 217 |
(*needs !!k for add_ac to work*) |
218 |
Goal "!!k:: nat. [| k<l; m+l = k+n |] ==> m<n"; |
|
5497 | 219 |
by (auto_tac (claset(), |
220 |
simpset() delsimps [add_Suc_right] |
|
5537 | 221 |
addsimps [less_iff_Suc_add, |
222 |
add_Suc_right RS sym] @ add_ac)); |
|
923 | 223 |
qed "less_add_eq_less"; |
224 |
||
225 |
||
1713 | 226 |
(*** Monotonicity of Addition ***) |
923 | 227 |
|
228 |
(*strict, in 1st argument*) |
|
5429 | 229 |
Goal "i < j ==> i + k < j + (k::nat)"; |
3339 | 230 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
231 |
by (ALLGOALS Asm_simp_tac); |
923 | 232 |
qed "add_less_mono1"; |
233 |
||
234 |
(*strict, in both arguments*) |
|
5429 | 235 |
Goal "[|i < j; k < l|] ==> i + k < j + (l::nat)"; |
923 | 236 |
by (rtac (add_less_mono1 RS less_trans) 1); |
1198 | 237 |
by (REPEAT (assume_tac 1)); |
3339 | 238 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
239 |
by (ALLGOALS Asm_simp_tac); |
923 | 240 |
qed "add_less_mono"; |
241 |
||
242 |
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) |
|
5316 | 243 |
val [lt_mono,le] = Goal |
1465 | 244 |
"[| !!i j::nat. i<j ==> f(i) < f(j); \ |
245 |
\ i <= j \ |
|
923 | 246 |
\ |] ==> f(i) <= (f(j)::nat)"; |
247 |
by (cut_facts_tac [le] 1); |
|
5604 | 248 |
by (asm_full_simp_tac (simpset() addsimps [order_le_less]) 1); |
4089 | 249 |
by (blast_tac (claset() addSIs [lt_mono]) 1); |
923 | 250 |
qed "less_mono_imp_le_mono"; |
251 |
||
252 |
(*non-strict, in 1st argument*) |
|
5429 | 253 |
Goal "i<=j ==> i + k <= j + (k::nat)"; |
3842 | 254 |
by (res_inst_tac [("f", "%j. j+k")] less_mono_imp_le_mono 1); |
1552 | 255 |
by (etac add_less_mono1 1); |
923 | 256 |
by (assume_tac 1); |
257 |
qed "add_le_mono1"; |
|
258 |
||
259 |
(*non-strict, in both arguments*) |
|
5429 | 260 |
Goal "[|i<=j; k<=l |] ==> i + k <= j + (l::nat)"; |
923 | 261 |
by (etac (add_le_mono1 RS le_trans) 1); |
4089 | 262 |
by (simp_tac (simpset() addsimps [add_commute]) 1); |
923 | 263 |
qed "add_le_mono"; |
1713 | 264 |
|
3234 | 265 |
|
266 |
(*** Multiplication ***) |
|
267 |
||
268 |
(*right annihilation in product*) |
|
4732 | 269 |
qed_goal "mult_0_right" thy "m * 0 = 0" |
3339 | 270 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 271 |
|
3293 | 272 |
(*right successor law for multiplication*) |
4732 | 273 |
qed_goal "mult_Suc_right" thy "m * Suc(n) = m + (m * n)" |
3339 | 274 |
(fn _ => [induct_tac "m" 1, |
4089 | 275 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 276 |
|
3293 | 277 |
Addsimps [mult_0_right, mult_Suc_right]; |
3234 | 278 |
|
5069 | 279 |
Goal "1 * n = n"; |
3234 | 280 |
by (Asm_simp_tac 1); |
281 |
qed "mult_1"; |
|
282 |
||
5069 | 283 |
Goal "n * 1 = n"; |
3234 | 284 |
by (Asm_simp_tac 1); |
285 |
qed "mult_1_right"; |
|
286 |
||
287 |
(*Commutative law for multiplication*) |
|
4732 | 288 |
qed_goal "mult_commute" thy "m * n = n * (m::nat)" |
3339 | 289 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 290 |
|
291 |
(*addition distributes over multiplication*) |
|
4732 | 292 |
qed_goal "add_mult_distrib" thy "(m + n)*k = (m*k) + ((n*k)::nat)" |
3339 | 293 |
(fn _ => [induct_tac "m" 1, |
4089 | 294 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 295 |
|
4732 | 296 |
qed_goal "add_mult_distrib2" thy "k*(m + n) = (k*m) + ((k*n)::nat)" |
3339 | 297 |
(fn _ => [induct_tac "m" 1, |
4089 | 298 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 299 |
|
300 |
(*Associative law for multiplication*) |
|
4732 | 301 |
qed_goal "mult_assoc" thy "(m * n) * k = m * ((n * k)::nat)" |
3339 | 302 |
(fn _ => [induct_tac "m" 1, |
4089 | 303 |
ALLGOALS (asm_simp_tac (simpset() addsimps [add_mult_distrib]))]); |
3234 | 304 |
|
4732 | 305 |
qed_goal "mult_left_commute" thy "x*(y*z) = y*((x*z)::nat)" |
3234 | 306 |
(fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1, |
307 |
rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]); |
|
308 |
||
309 |
val mult_ac = [mult_assoc,mult_commute,mult_left_commute]; |
|
310 |
||
5069 | 311 |
Goal "(m*n = 0) = (m=0 | n=0)"; |
3339 | 312 |
by (induct_tac "m" 1); |
313 |
by (induct_tac "n" 2); |
|
3293 | 314 |
by (ALLGOALS Asm_simp_tac); |
315 |
qed "mult_is_0"; |
|
316 |
Addsimps [mult_is_0]; |
|
317 |
||
5429 | 318 |
Goal "m <= m*(m::nat)"; |
4158 | 319 |
by (induct_tac "m" 1); |
320 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_assoc RS sym]))); |
|
321 |
by (etac (le_add2 RSN (2,le_trans)) 1); |
|
322 |
qed "le_square"; |
|
323 |
||
3234 | 324 |
|
325 |
(*** Difference ***) |
|
326 |
||
327 |
||
4732 | 328 |
qed_goal "diff_self_eq_0" thy "m - m = 0" |
3339 | 329 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 330 |
Addsimps [diff_self_eq_0]; |
331 |
||
332 |
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) |
|
5069 | 333 |
Goal "~ m<n --> n+(m-n) = (m::nat)"; |
3234 | 334 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
3352 | 335 |
by (ALLGOALS Asm_simp_tac); |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
336 |
qed_spec_mp "add_diff_inverse"; |
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
337 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
338 |
Goal "n<=m ==> n+(m-n) = (m::nat)"; |
4089 | 339 |
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
|
340 |
qed "le_add_diff_inverse"; |
3234 | 341 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
342 |
Goal "n<=m ==> (m-n)+n = (m::nat)"; |
4089 | 343 |
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
|
344 |
qed "le_add_diff_inverse2"; |
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
345 |
|
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
346 |
Addsimps [le_add_diff_inverse, le_add_diff_inverse2]; |
3234 | 347 |
|
348 |
||
349 |
(*** More results about difference ***) |
|
350 |
||
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 |
Goal "n <= m ==> Suc(m)-n = Suc(m-n)"; |
5316 | 352 |
by (etac rev_mp 1); |
3352 | 353 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
354 |
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
|
355 |
qed "Suc_diff_le"; |
3352 | 356 |
|
5429 | 357 |
Goal "n<=(l::nat) --> Suc l - n + m = Suc (l - n + m)"; |
358 |
by (res_inst_tac [("m","n"),("n","l")] diff_induct 1); |
|
359 |
by (ALLGOALS Asm_simp_tac); |
|
360 |
qed_spec_mp "Suc_diff_add_le"; |
|
361 |
||
5069 | 362 |
Goal "m - n < Suc(m)"; |
3234 | 363 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
364 |
by (etac less_SucE 3); |
|
4089 | 365 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq]))); |
3234 | 366 |
qed "diff_less_Suc"; |
367 |
||
5429 | 368 |
Goal "m - n <= (m::nat)"; |
3234 | 369 |
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); |
370 |
by (ALLGOALS Asm_simp_tac); |
|
371 |
qed "diff_le_self"; |
|
3903
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
372 |
Addsimps [diff_le_self]; |
3234 | 373 |
|
4732 | 374 |
(* j<k ==> j-n < k *) |
375 |
bind_thm ("less_imp_diff_less", diff_le_self RS le_less_trans); |
|
376 |
||
5069 | 377 |
Goal "!!i::nat. i-j-k = i - (j+k)"; |
3352 | 378 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
379 |
by (ALLGOALS Asm_simp_tac); |
|
380 |
qed "diff_diff_left"; |
|
381 |
||
5069 | 382 |
Goal "(Suc m - n) - Suc k = m - n - k"; |
4423 | 383 |
by (simp_tac (simpset() addsimps [diff_diff_left]) 1); |
4736 | 384 |
qed "Suc_diff_diff"; |
385 |
Addsimps [Suc_diff_diff]; |
|
4360 | 386 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
387 |
Goal "0<n ==> n - Suc i < n"; |
5183 | 388 |
by (exhaust_tac "n" 1); |
4732 | 389 |
by Safe_tac; |
5497 | 390 |
by (asm_simp_tac (simpset() addsimps le_simps) 1); |
4732 | 391 |
qed "diff_Suc_less"; |
392 |
Addsimps [diff_Suc_less]; |
|
393 |
||
5329 | 394 |
Goal "i<n ==> n - Suc i < n - i"; |
395 |
by (exhaust_tac "n" 1); |
|
5497 | 396 |
by (auto_tac (claset(), |
5537 | 397 |
simpset() addsimps [Suc_diff_le]@le_simps)); |
5329 | 398 |
qed "diff_Suc_less_diff"; |
399 |
||
3396 | 400 |
(*This and the next few suggested by Florian Kammueller*) |
5069 | 401 |
Goal "!!i::nat. i-j-k = i-k-j"; |
4089 | 402 |
by (simp_tac (simpset() addsimps [diff_diff_left, add_commute]) 1); |
3352 | 403 |
qed "diff_commute"; |
404 |
||
5429 | 405 |
Goal "k<=j --> j<=i --> i - (j - k) = i - j + (k::nat)"; |
3352 | 406 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
407 |
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
|
408 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1); |
3352 | 409 |
qed_spec_mp "diff_diff_right"; |
410 |
||
5429 | 411 |
Goal "k <= (j::nat) --> (i + j) - k = i + (j - k)"; |
3352 | 412 |
by (res_inst_tac [("m","j"),("n","k")] diff_induct 1); |
413 |
by (ALLGOALS Asm_simp_tac); |
|
414 |
qed_spec_mp "diff_add_assoc"; |
|
415 |
||
5429 | 416 |
Goal "k <= (j::nat) --> (j + i) - k = i + (j - k)"; |
4732 | 417 |
by (asm_simp_tac (simpset() addsimps [add_commute, diff_add_assoc]) 1); |
418 |
qed_spec_mp "diff_add_assoc2"; |
|
419 |
||
5429 | 420 |
Goal "(n+m) - n = (m::nat)"; |
3339 | 421 |
by (induct_tac "n" 1); |
3234 | 422 |
by (ALLGOALS Asm_simp_tac); |
423 |
qed "diff_add_inverse"; |
|
424 |
Addsimps [diff_add_inverse]; |
|
425 |
||
5429 | 426 |
Goal "(m+n) - n = (m::nat)"; |
4089 | 427 |
by (simp_tac (simpset() addsimps [diff_add_assoc]) 1); |
3234 | 428 |
qed "diff_add_inverse2"; |
429 |
Addsimps [diff_add_inverse2]; |
|
430 |
||
5429 | 431 |
Goal "i <= (j::nat) ==> (j-i=k) = (j=k+i)"; |
3724 | 432 |
by Safe_tac; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
433 |
by (ALLGOALS Asm_simp_tac); |
3366 | 434 |
qed "le_imp_diff_is_add"; |
435 |
||
5356 | 436 |
Goal "(m-n = 0) = (m <= n)"; |
3234 | 437 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
5497 | 438 |
by (ALLGOALS Asm_simp_tac); |
5356 | 439 |
qed "diff_is_0_eq"; |
440 |
Addsimps [diff_is_0_eq RS iffD2]; |
|
3234 | 441 |
|
5316 | 442 |
Goal "m-n = 0 --> n-m = 0 --> m=n"; |
3234 | 443 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
444 |
by (REPEAT(Simp_tac 1 THEN TRY(atac 1))); |
|
445 |
qed_spec_mp "diffs0_imp_equal"; |
|
446 |
||
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
447 |
Goal "(0<n-m) = (m<n)"; |
3234 | 448 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
3352 | 449 |
by (ALLGOALS Asm_simp_tac); |
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
450 |
qed "zero_less_diff"; |
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
451 |
Addsimps [zero_less_diff]; |
3234 | 452 |
|
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
453 |
Goal "i < j ==> ? k. 0<k & i+k = j"; |
5078 | 454 |
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
|
455 |
by (asm_simp_tac (simpset() addsimps [add_diff_inverse, less_not_sym]) 1); |
5078 | 456 |
qed "less_imp_add_positive"; |
457 |
||
5069 | 458 |
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
|
459 |
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
|
460 |
qed "if_Suc_diff_le"; |
3234 | 461 |
|
5069 | 462 |
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
|
463 |
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
|
464 |
qed "diff_Suc_le_Suc_diff"; |
9d55bc687e1e
New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents:
4423
diff
changeset
|
465 |
|
5069 | 466 |
Goal "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)"; |
3234 | 467 |
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); |
3718 | 468 |
by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac)); |
3234 | 469 |
qed "zero_induct_lemma"; |
470 |
||
5316 | 471 |
val prems = Goal "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; |
3234 | 472 |
by (rtac (diff_self_eq_0 RS subst) 1); |
473 |
by (rtac (zero_induct_lemma RS mp RS mp) 1); |
|
474 |
by (REPEAT (ares_tac ([impI,allI]@prems) 1)); |
|
475 |
qed "zero_induct"; |
|
476 |
||
5429 | 477 |
Goal "(k+m) - (k+n) = m - (n::nat)"; |
3339 | 478 |
by (induct_tac "k" 1); |
3234 | 479 |
by (ALLGOALS Asm_simp_tac); |
480 |
qed "diff_cancel"; |
|
481 |
Addsimps [diff_cancel]; |
|
482 |
||
5429 | 483 |
Goal "(m+k) - (n+k) = m - (n::nat)"; |
3234 | 484 |
val add_commute_k = read_instantiate [("n","k")] add_commute; |
5537 | 485 |
by (asm_simp_tac (simpset() addsimps [add_commute_k]) 1); |
3234 | 486 |
qed "diff_cancel2"; |
487 |
Addsimps [diff_cancel2]; |
|
488 |
||
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
489 |
(*From Clemens Ballarin, proof by lcp*) |
5429 | 490 |
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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
(*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
|
495 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1); |
3234 | 496 |
qed "diff_right_cancel"; |
497 |
||
5429 | 498 |
Goal "n - (n+m) = 0"; |
3339 | 499 |
by (induct_tac "n" 1); |
3234 | 500 |
by (ALLGOALS Asm_simp_tac); |
501 |
qed "diff_add_0"; |
|
502 |
Addsimps [diff_add_0]; |
|
503 |
||
5409 | 504 |
|
3234 | 505 |
(** Difference distributes over multiplication **) |
506 |
||
5069 | 507 |
Goal "!!m::nat. (m - n) * k = (m * k) - (n * k)"; |
3234 | 508 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
509 |
by (ALLGOALS Asm_simp_tac); |
|
510 |
qed "diff_mult_distrib" ; |
|
511 |
||
5069 | 512 |
Goal "!!m::nat. k * (m - n) = (k * m) - (k * n)"; |
3234 | 513 |
val mult_commute_k = read_instantiate [("m","k")] mult_commute; |
4089 | 514 |
by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1); |
3234 | 515 |
qed "diff_mult_distrib2" ; |
516 |
(*NOT added as rewrites, since sometimes they are used from right-to-left*) |
|
517 |
||
518 |
||
1713 | 519 |
(*** Monotonicity of Multiplication ***) |
520 |
||
5429 | 521 |
Goal "i <= (j::nat) ==> i*k<=j*k"; |
3339 | 522 |
by (induct_tac "k" 1); |
4089 | 523 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_le_mono]))); |
1713 | 524 |
qed "mult_le_mono1"; |
525 |
||
526 |
(*<=monotonicity, BOTH arguments*) |
|
5429 | 527 |
Goal "[| i <= (j::nat); k <= l |] ==> i*k <= j*l"; |
2007 | 528 |
by (etac (mult_le_mono1 RS le_trans) 1); |
1713 | 529 |
by (rtac le_trans 1); |
2007 | 530 |
by (stac mult_commute 2); |
531 |
by (etac mult_le_mono1 2); |
|
4089 | 532 |
by (simp_tac (simpset() addsimps [mult_commute]) 1); |
1713 | 533 |
qed "mult_le_mono"; |
534 |
||
535 |
(*strict, in 1st argument; proof is by induction on k>0*) |
|
5429 | 536 |
Goal "[| i<j; 0<k |] ==> k*i < k*j"; |
5078 | 537 |
by (eres_inst_tac [("m1","0")] (less_eq_Suc_add RS exE) 1); |
1713 | 538 |
by (Asm_simp_tac 1); |
3339 | 539 |
by (induct_tac "x" 1); |
4089 | 540 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_less_mono]))); |
1713 | 541 |
qed "mult_less_mono2"; |
542 |
||
5429 | 543 |
Goal "[| i<j; 0<k |] ==> i*k < j*k"; |
3457 | 544 |
by (dtac mult_less_mono2 1); |
4089 | 545 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute]))); |
3234 | 546 |
qed "mult_less_mono1"; |
547 |
||
5069 | 548 |
Goal "(0 < m*n) = (0<m & 0<n)"; |
3339 | 549 |
by (induct_tac "m" 1); |
550 |
by (induct_tac "n" 2); |
|
1713 | 551 |
by (ALLGOALS Asm_simp_tac); |
552 |
qed "zero_less_mult_iff"; |
|
4356 | 553 |
Addsimps [zero_less_mult_iff]; |
1713 | 554 |
|
5069 | 555 |
Goal "(m*n = 1) = (m=1 & n=1)"; |
3339 | 556 |
by (induct_tac "m" 1); |
1795 | 557 |
by (Simp_tac 1); |
3339 | 558 |
by (induct_tac "n" 1); |
1795 | 559 |
by (Simp_tac 1); |
4089 | 560 |
by (fast_tac (claset() addss simpset()) 1); |
1795 | 561 |
qed "mult_eq_1_iff"; |
4356 | 562 |
Addsimps [mult_eq_1_iff]; |
1795 | 563 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
564 |
Goal "0<k ==> (m*k < n*k) = (m<n)"; |
4089 | 565 |
by (safe_tac (claset() addSIs [mult_less_mono1])); |
3234 | 566 |
by (cut_facts_tac [less_linear] 1); |
4389 | 567 |
by (blast_tac (claset() addIs [mult_less_mono1] addEs [less_asym]) 1); |
3234 | 568 |
qed "mult_less_cancel2"; |
569 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
570 |
Goal "0<k ==> (k*m < k*n) = (m<n)"; |
3457 | 571 |
by (dtac mult_less_cancel2 1); |
4089 | 572 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 573 |
qed "mult_less_cancel1"; |
574 |
Addsimps [mult_less_cancel1, mult_less_cancel2]; |
|
575 |
||
5069 | 576 |
Goal "(Suc k * m < Suc k * n) = (m < n)"; |
4423 | 577 |
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
|
578 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
579 |
qed "Suc_mult_less_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
580 |
|
5069 | 581 |
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
|
582 |
by (simp_tac (simpset_of HOL.thy) 1); |
4423 | 583 |
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
|
584 |
qed "Suc_mult_le_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
585 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
586 |
Goal "0<k ==> (m*k = n*k) = (m=n)"; |
3234 | 587 |
by (cut_facts_tac [less_linear] 1); |
3724 | 588 |
by Safe_tac; |
3457 | 589 |
by (assume_tac 2); |
3234 | 590 |
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac)); |
591 |
by (ALLGOALS Asm_full_simp_tac); |
|
592 |
qed "mult_cancel2"; |
|
593 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
594 |
Goal "0<k ==> (k*m = k*n) = (m=n)"; |
3457 | 595 |
by (dtac mult_cancel2 1); |
4089 | 596 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 597 |
qed "mult_cancel1"; |
598 |
Addsimps [mult_cancel1, mult_cancel2]; |
|
599 |
||
5069 | 600 |
Goal "(Suc k * m = Suc k * n) = (m = n)"; |
4423 | 601 |
by (rtac mult_cancel1 1); |
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
602 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
603 |
qed "Suc_mult_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
604 |
|
3234 | 605 |
|
1795 | 606 |
(** Lemma for gcd **) |
607 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
608 |
Goal "m = m*n ==> n=1 | m=0"; |
1795 | 609 |
by (dtac sym 1); |
610 |
by (rtac disjCI 1); |
|
611 |
by (rtac nat_less_cases 1 THEN assume_tac 2); |
|
4089 | 612 |
by (fast_tac (claset() addSEs [less_SucE] addss simpset()) 1); |
4356 | 613 |
by (best_tac (claset() addDs [mult_less_mono2] addss simpset()) 1); |
1795 | 614 |
qed "mult_eq_self_implies_10"; |
615 |
||
616 |
||
4736 | 617 |
(*** Subtraction laws -- mostly from Clemens Ballarin ***) |
3234 | 618 |
|
5429 | 619 |
Goal "[| a < (b::nat); c <= a |] ==> a-c < b-c"; |
3234 | 620 |
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
|
621 |
by (Full_simp_tac 1); |
3234 | 622 |
by (subgoal_tac "c <= b" 1); |
4089 | 623 |
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
|
624 |
by (Asm_simp_tac 1); |
3234 | 625 |
qed "diff_less_mono"; |
626 |
||
5429 | 627 |
Goal "a+b < (c::nat) ==> a < c-b"; |
3457 | 628 |
by (dtac diff_less_mono 1); |
629 |
by (rtac le_add2 1); |
|
3234 | 630 |
by (Asm_full_simp_tac 1); |
631 |
qed "add_less_imp_less_diff"; |
|
632 |
||
5427 | 633 |
Goal "(i < j-k) = (i+k < (j::nat))"; |
5497 | 634 |
by (rtac iffI 1); |
635 |
by (case_tac "k <= j" 1); |
|
636 |
by (dtac le_add_diff_inverse2 1); |
|
637 |
by (dres_inst_tac [("k","k")] add_less_mono1 1); |
|
638 |
by (Asm_full_simp_tac 1); |
|
639 |
by (rotate_tac 1 1); |
|
640 |
by (asm_full_simp_tac (simpset() addSolver cut_trans_tac) 1); |
|
641 |
by (etac add_less_imp_less_diff 1); |
|
5427 | 642 |
qed "less_diff_conv"; |
643 |
||
5497 | 644 |
Goal "(j-k <= (i::nat)) = (j <= i+k)"; |
645 |
by (simp_tac (simpset() addsimps [less_diff_conv, le_def]) 1); |
|
5485 | 646 |
qed "le_diff_conv"; |
647 |
||
5497 | 648 |
Goal "k <= j ==> (i <= j-k) = (i+k <= (j::nat))"; |
649 |
by (asm_full_simp_tac |
|
650 |
(simpset() delsimps [less_Suc_eq_le] |
|
651 |
addsimps [less_Suc_eq_le RS sym, less_diff_conv, |
|
652 |
Suc_diff_le RS sym]) 1); |
|
653 |
qed "le_diff_conv2"; |
|
654 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
655 |
Goal "Suc i <= n ==> Suc (n - Suc i) = n - i"; |
5497 | 656 |
by (asm_full_simp_tac (simpset() addsimps [Suc_diff_le RS sym]) 1); |
3234 | 657 |
qed "Suc_diff_Suc"; |
658 |
||
5429 | 659 |
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
|
660 |
by (etac rev_mp 1); |
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
661 |
by (res_inst_tac [("m","n"),("n","i")] diff_induct 1); |
4089 | 662 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Suc_diff_le]))); |
3234 | 663 |
qed "diff_diff_cancel"; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
664 |
Addsimps [diff_diff_cancel]; |
3234 | 665 |
|
5429 | 666 |
Goal "k <= (n::nat) ==> m <= n + m - k"; |
3457 | 667 |
by (etac rev_mp 1); |
3234 | 668 |
by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1); |
669 |
by (Simp_tac 1); |
|
5497 | 670 |
by (simp_tac (simpset() addsimps [le_add2, less_imp_le]) 1); |
3234 | 671 |
by (Simp_tac 1); |
672 |
qed "le_add_diff"; |
|
673 |
||
5429 | 674 |
Goal "0<k ==> j<i --> j+k-i < k"; |
4736 | 675 |
by (res_inst_tac [("m","j"),("n","i")] diff_induct 1); |
676 |
by (ALLGOALS Asm_simp_tac); |
|
677 |
qed_spec_mp "add_diff_less"; |
|
678 |
||
3234 | 679 |
|
5356 | 680 |
Goal "m-1 < n ==> m <= n"; |
681 |
by (exhaust_tac "m" 1); |
|
682 |
by (auto_tac (claset(), simpset() addsimps [Suc_le_eq])); |
|
683 |
qed "pred_less_imp_le"; |
|
684 |
||
685 |
Goal "j<=i ==> i - j < Suc i - j"; |
|
686 |
by (REPEAT (etac rev_mp 1)); |
|
687 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
|
688 |
by Auto_tac; |
|
689 |
qed "diff_less_Suc_diff"; |
|
690 |
||
691 |
Goal "i - j <= Suc i - j"; |
|
692 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
|
693 |
by Auto_tac; |
|
694 |
qed "diff_le_Suc_diff"; |
|
695 |
AddIffs [diff_le_Suc_diff]; |
|
696 |
||
697 |
Goal "n - Suc i <= n - i"; |
|
698 |
by (case_tac "i<n" 1); |
|
5497 | 699 |
by (dtac diff_Suc_less_diff 1); |
5604 | 700 |
by (auto_tac (claset(), simpset() addsimps [less_imp_le, leI])); |
5356 | 701 |
qed "diff_Suc_le_diff"; |
702 |
AddIffs [diff_Suc_le_diff]; |
|
703 |
||
5409 | 704 |
Goal "0 < n ==> (m <= n-1) = (m<n)"; |
705 |
by (exhaust_tac "n" 1); |
|
5497 | 706 |
by (auto_tac (claset(), simpset() addsimps le_simps)); |
5409 | 707 |
qed "le_pred_eq"; |
708 |
||
709 |
Goal "0 < n ==> (m-1 < n) = (m<=n)"; |
|
710 |
by (exhaust_tac "m" 1); |
|
711 |
by (auto_tac (claset(), simpset() addsimps [Suc_le_eq])); |
|
712 |
qed "less_pred_eq"; |
|
713 |
||
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
714 |
(*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
|
715 |
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
|
716 |
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
|
717 |
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
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
|
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
722 |
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
|
723 |
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
|
724 |
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
|
725 |
|
5356 | 726 |
|
4732 | 727 |
|
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
728 |
(** (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
|
729 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
730 |
(* Monotonicity of subtraction in first argument *) |
5429 | 731 |
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
|
732 |
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
|
733 |
by (Simp_tac 1); |
4089 | 734 |
by (simp_tac (simpset() addsimps [le_Suc_eq]) 1); |
4732 | 735 |
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
|
736 |
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
|
737 |
|
5429 | 738 |
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
|
739 |
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
|
740 |
by (Simp_tac 1); |
5183 | 741 |
by (case_tac "n <= na" 1); |
742 |
by (subgoal_tac "m <= na" 1); |
|
4089 | 743 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le]) 1); |
744 |
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
|
745 |
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
|
746 |
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
|
747 |
qed_spec_mp "diff_le_mono2"; |