author | paulson |
Wed, 06 May 1998 13:01:30 +0200 | |
changeset 4898 | 68fd1a2b8b7b |
parent 4830 | bd73675adbed |
child 5069 | 3ea049f7979d |
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 |
|
19 |
(*Must simplify BEFORE the induction!! (Else we get a critical pair) |
|
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 *) |
|
4732 | 31 |
goal thy "!!n. 0 < n ==> Suc(n-1) = n"; |
4830 | 32 |
by (asm_simp_tac (simpset() addsplits [split_nat_case]) 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 |
||
4732 | 66 |
goal thy "!!k::nat. (k + m = k + n) = (m=n)"; |
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 |
||
4732 | 72 |
goal thy "!!k::nat. (m + k = n + k) = (m=n)"; |
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 |
||
4732 | 78 |
goal thy "!!k::nat. (k + m <= k + n) = (m<=n)"; |
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 |
||
4732 | 84 |
goal thy "!!k::nat. (k + m < k + n) = (m<n)"; |
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 |
||
4732 | 95 |
goal thy "(m+n = 0) = (m=0 & n=0)"; |
3339 | 96 |
by (induct_tac "m" 1); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
97 |
by (ALLGOALS Asm_simp_tac); |
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 |
|
4732 | 101 |
goal thy "(0<m+n) = (0<m | 0<n)"; |
4423 | 102 |
by (simp_tac (simpset() delsimps [neq0_conv] addsimps [neq0_conv RS sym]) 1); |
4360 | 103 |
qed "add_gr_0"; |
104 |
AddIffs [add_gr_0]; |
|
105 |
||
106 |
(* FIXME: really needed?? *) |
|
4732 | 107 |
goal thy "((m+n)-1 = 0) = (m=0 & n-1 = 0 | m-1 = 0 & n=0)"; |
4360 | 108 |
by (exhaust_tac "m" 1); |
4089 | 109 |
by (ALLGOALS (fast_tac (claset() addss (simpset())))); |
3293 | 110 |
qed "pred_add_is_0"; |
111 |
Addsimps [pred_add_is_0]; |
|
112 |
||
4360 | 113 |
(* Could be generalized, eg to "!!n. k<n ==> m+(n-(Suc k)) = (m+n)-(Suc k)" *) |
4732 | 114 |
goal thy "!!n. 0<n ==> m + (n-1) = (m+n)-1"; |
4360 | 115 |
by (exhaust_tac "m" 1); |
116 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_Suc] |
|
4830 | 117 |
addsplits [split_nat_case]))); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
118 |
qed "add_pred"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
119 |
Addsimps [add_pred]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
120 |
|
1626 | 121 |
|
923 | 122 |
(**** Additional theorems about "less than" ****) |
123 |
||
4732 | 124 |
goal thy "i<j --> (EX k. j = Suc(i+k))"; |
3339 | 125 |
by (induct_tac "j" 1); |
1909 | 126 |
by (Simp_tac 1); |
4089 | 127 |
by (blast_tac (claset() addSEs [less_SucE] |
3339 | 128 |
addSIs [add_0_right RS sym, add_Suc_right RS sym]) 1); |
1909 | 129 |
val lemma = result(); |
130 |
||
3339 | 131 |
(* [| i<j; !!x. j = Suc(i+x) ==> Q |] ==> Q *) |
132 |
bind_thm ("less_natE", lemma RS mp RS exE); |
|
133 |
||
4732 | 134 |
goal thy "!!m. m<n --> (? k. n=Suc(m+k))"; |
3339 | 135 |
by (induct_tac "n" 1); |
4089 | 136 |
by (ALLGOALS (simp_tac (simpset() addsimps [less_Suc_eq]))); |
137 |
by (blast_tac (claset() addSEs [less_SucE] |
|
3339 | 138 |
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
|
139 |
qed_spec_mp "less_eq_Suc_add"; |
923 | 140 |
|
4732 | 141 |
goal thy "n <= ((m + n)::nat)"; |
3339 | 142 |
by (induct_tac "m" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
143 |
by (ALLGOALS Simp_tac); |
923 | 144 |
by (etac le_trans 1); |
145 |
by (rtac (lessI RS less_imp_le) 1); |
|
146 |
qed "le_add2"; |
|
147 |
||
4732 | 148 |
goal thy "n <= ((n + m)::nat)"; |
4089 | 149 |
by (simp_tac (simpset() addsimps add_ac) 1); |
923 | 150 |
by (rtac le_add2 1); |
151 |
qed "le_add1"; |
|
152 |
||
153 |
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); |
|
154 |
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); |
|
155 |
||
156 |
(*"i <= j ==> i <= j+m"*) |
|
157 |
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); |
|
158 |
||
159 |
(*"i <= j ==> i <= m+j"*) |
|
160 |
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); |
|
161 |
||
162 |
(*"i < j ==> i < j+m"*) |
|
163 |
bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); |
|
164 |
||
165 |
(*"i < j ==> i < m+j"*) |
|
166 |
bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); |
|
167 |
||
4732 | 168 |
goal thy "!!i. i+j < (k::nat) ==> i<k"; |
1552 | 169 |
by (etac rev_mp 1); |
3339 | 170 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
171 |
by (ALLGOALS Asm_simp_tac); |
4089 | 172 |
by (blast_tac (claset() addDs [Suc_lessD]) 1); |
1152 | 173 |
qed "add_lessD1"; |
174 |
||
4732 | 175 |
goal thy "!!i::nat. ~ (i+j < i)"; |
3457 | 176 |
by (rtac notI 1); |
177 |
by (etac (add_lessD1 RS less_irrefl) 1); |
|
3234 | 178 |
qed "not_add_less1"; |
179 |
||
4732 | 180 |
goal thy "!!i::nat. ~ (j+i < i)"; |
4089 | 181 |
by (simp_tac (simpset() addsimps [add_commute, not_add_less1]) 1); |
3234 | 182 |
qed "not_add_less2"; |
183 |
AddIffs [not_add_less1, not_add_less2]; |
|
184 |
||
4732 | 185 |
goal thy "!!k::nat. m <= n ==> m <= n+k"; |
1552 | 186 |
by (etac le_trans 1); |
187 |
by (rtac le_add1 1); |
|
923 | 188 |
qed "le_imp_add_le"; |
189 |
||
4732 | 190 |
goal thy "!!k::nat. m < n ==> m < n+k"; |
1552 | 191 |
by (etac less_le_trans 1); |
192 |
by (rtac le_add1 1); |
|
923 | 193 |
qed "less_imp_add_less"; |
194 |
||
4732 | 195 |
goal thy "m+k<=n --> m<=(n::nat)"; |
3339 | 196 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
197 |
by (ALLGOALS Asm_simp_tac); |
4089 | 198 |
by (blast_tac (claset() addDs [Suc_leD]) 1); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1475
diff
changeset
|
199 |
qed_spec_mp "add_leD1"; |
923 | 200 |
|
4732 | 201 |
goal thy "!!n::nat. m+k<=n ==> k<=n"; |
4089 | 202 |
by (full_simp_tac (simpset() addsimps [add_commute]) 1); |
2498 | 203 |
by (etac add_leD1 1); |
204 |
qed_spec_mp "add_leD2"; |
|
205 |
||
4732 | 206 |
goal thy "!!n::nat. m+k<=n ==> m<=n & k<=n"; |
4089 | 207 |
by (blast_tac (claset() addDs [add_leD1, add_leD2]) 1); |
2498 | 208 |
bind_thm ("add_leE", result() RS conjE); |
209 |
||
4732 | 210 |
goal thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n"; |
4089 | 211 |
by (safe_tac (claset() addSDs [less_eq_Suc_add])); |
923 | 212 |
by (asm_full_simp_tac |
4089 | 213 |
(simpset() delsimps [add_Suc_right] |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
214 |
addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1); |
1552 | 215 |
by (etac subst 1); |
4089 | 216 |
by (simp_tac (simpset() addsimps [less_add_Suc1]) 1); |
923 | 217 |
qed "less_add_eq_less"; |
218 |
||
219 |
||
1713 | 220 |
(*** Monotonicity of Addition ***) |
923 | 221 |
|
222 |
(*strict, in 1st argument*) |
|
4732 | 223 |
goal thy "!!i j k::nat. i < j ==> i + k < j + k"; |
3339 | 224 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
225 |
by (ALLGOALS Asm_simp_tac); |
923 | 226 |
qed "add_less_mono1"; |
227 |
||
228 |
(*strict, in both arguments*) |
|
4732 | 229 |
goal thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l"; |
923 | 230 |
by (rtac (add_less_mono1 RS less_trans) 1); |
1198 | 231 |
by (REPEAT (assume_tac 1)); |
3339 | 232 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
233 |
by (ALLGOALS Asm_simp_tac); |
923 | 234 |
qed "add_less_mono"; |
235 |
||
236 |
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) |
|
4732 | 237 |
val [lt_mono,le] = goal thy |
1465 | 238 |
"[| !!i j::nat. i<j ==> f(i) < f(j); \ |
239 |
\ i <= j \ |
|
923 | 240 |
\ |] ==> f(i) <= (f(j)::nat)"; |
241 |
by (cut_facts_tac [le] 1); |
|
4089 | 242 |
by (asm_full_simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); |
243 |
by (blast_tac (claset() addSIs [lt_mono]) 1); |
|
923 | 244 |
qed "less_mono_imp_le_mono"; |
245 |
||
246 |
(*non-strict, in 1st argument*) |
|
4732 | 247 |
goal thy "!!i j k::nat. i<=j ==> i + k <= j + k"; |
3842 | 248 |
by (res_inst_tac [("f", "%j. j+k")] less_mono_imp_le_mono 1); |
1552 | 249 |
by (etac add_less_mono1 1); |
923 | 250 |
by (assume_tac 1); |
251 |
qed "add_le_mono1"; |
|
252 |
||
253 |
(*non-strict, in both arguments*) |
|
4732 | 254 |
goal thy "!!k l::nat. [|i<=j; k<=l |] ==> i + k <= j + l"; |
923 | 255 |
by (etac (add_le_mono1 RS le_trans) 1); |
4089 | 256 |
by (simp_tac (simpset() addsimps [add_commute]) 1); |
923 | 257 |
(*j moves to the end because it is free while k, l are bound*) |
1552 | 258 |
by (etac add_le_mono1 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 |
|
4732 | 275 |
goal thy "1 * n = n"; |
3234 | 276 |
by (Asm_simp_tac 1); |
277 |
qed "mult_1"; |
|
278 |
||
4732 | 279 |
goal thy "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 |
||
4732 | 307 |
goal thy "(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 |
||
4732 | 314 |
goal thy "!!m::nat. m <= m*m"; |
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. *) |
|
4732 | 329 |
goal thy "~ 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 |
|
4732 | 334 |
goal thy "!!m. 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 |
|
4732 | 338 |
goal thy "!!m. 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 |
||
4732 | 347 |
val [prem] = goal thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)"; |
3352 | 348 |
by (rtac (prem RS rev_mp) 1); |
349 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
350 |
by (ALLGOALS Asm_simp_tac); |
|
351 |
qed "Suc_diff_n"; |
|
352 |
||
4732 | 353 |
goal thy "m - n < Suc(m)"; |
3234 | 354 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
355 |
by (etac less_SucE 3); |
|
4089 | 356 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq]))); |
3234 | 357 |
qed "diff_less_Suc"; |
358 |
||
4732 | 359 |
goal thy "!!m::nat. m - n <= m"; |
3234 | 360 |
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); |
361 |
by (ALLGOALS Asm_simp_tac); |
|
362 |
qed "diff_le_self"; |
|
3903
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
363 |
Addsimps [diff_le_self]; |
3234 | 364 |
|
4732 | 365 |
(* j<k ==> j-n < k *) |
366 |
bind_thm ("less_imp_diff_less", diff_le_self RS le_less_trans); |
|
367 |
||
368 |
goal thy "!!i::nat. i-j-k = i - (j+k)"; |
|
3352 | 369 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
370 |
by (ALLGOALS Asm_simp_tac); |
|
371 |
qed "diff_diff_left"; |
|
372 |
||
4736 | 373 |
goal Arith.thy "(Suc m - n) - Suc k = m - n - k"; |
4423 | 374 |
by (simp_tac (simpset() addsimps [diff_diff_left]) 1); |
4736 | 375 |
qed "Suc_diff_diff"; |
376 |
Addsimps [Suc_diff_diff]; |
|
4360 | 377 |
|
4732 | 378 |
goal thy "!!n. 0<n ==> n - Suc i < n"; |
379 |
by (res_inst_tac [("n","n")] natE 1); |
|
380 |
by Safe_tac; |
|
381 |
by (asm_simp_tac (simpset() addsimps [le_eq_less_Suc RS sym]) 1); |
|
382 |
qed "diff_Suc_less"; |
|
383 |
Addsimps [diff_Suc_less]; |
|
384 |
||
385 |
goal thy "!!n::nat. m - n <= Suc m - n"; |
|
386 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
387 |
by (ALLGOALS Asm_simp_tac); |
|
388 |
qed "diff_le_Suc_diff"; |
|
389 |
||
3396 | 390 |
(*This and the next few suggested by Florian Kammueller*) |
4732 | 391 |
goal thy "!!i::nat. i-j-k = i-k-j"; |
4089 | 392 |
by (simp_tac (simpset() addsimps [diff_diff_left, add_commute]) 1); |
3352 | 393 |
qed "diff_commute"; |
394 |
||
4732 | 395 |
goal thy "!!i j k:: nat. k<=j --> j<=i --> i - (j - k) = i - j + k"; |
3352 | 396 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
397 |
by (ALLGOALS Asm_simp_tac); |
|
398 |
by (asm_simp_tac |
|
4089 | 399 |
(simpset() addsimps [Suc_diff_n, le_imp_less_Suc, le_Suc_eq]) 1); |
3352 | 400 |
qed_spec_mp "diff_diff_right"; |
401 |
||
4732 | 402 |
goal thy "!!i j k:: nat. k<=j --> (i + j) - k = i + (j - k)"; |
3352 | 403 |
by (res_inst_tac [("m","j"),("n","k")] diff_induct 1); |
404 |
by (ALLGOALS Asm_simp_tac); |
|
405 |
qed_spec_mp "diff_add_assoc"; |
|
406 |
||
4732 | 407 |
goal thy "!!i j k:: nat. k<=j --> (j + i) - k = i + (j - k)"; |
408 |
by (asm_simp_tac (simpset() addsimps [add_commute, diff_add_assoc]) 1); |
|
409 |
qed_spec_mp "diff_add_assoc2"; |
|
410 |
||
411 |
goal thy "!!n::nat. (n+m) - n = m"; |
|
3339 | 412 |
by (induct_tac "n" 1); |
3234 | 413 |
by (ALLGOALS Asm_simp_tac); |
414 |
qed "diff_add_inverse"; |
|
415 |
Addsimps [diff_add_inverse]; |
|
416 |
||
4732 | 417 |
goal thy "!!n::nat.(m+n) - n = m"; |
4089 | 418 |
by (simp_tac (simpset() addsimps [diff_add_assoc]) 1); |
3234 | 419 |
qed "diff_add_inverse2"; |
420 |
Addsimps [diff_add_inverse2]; |
|
421 |
||
4732 | 422 |
goal thy "!!i j k::nat. i<=j ==> (j-i=k) = (j=k+i)"; |
3724 | 423 |
by Safe_tac; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
424 |
by (ALLGOALS Asm_simp_tac); |
3366 | 425 |
qed "le_imp_diff_is_add"; |
426 |
||
4732 | 427 |
val [prem] = goal thy "m < Suc(n) ==> m-n = 0"; |
3234 | 428 |
by (rtac (prem RS rev_mp) 1); |
429 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
4089 | 430 |
by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
3352 | 431 |
by (ALLGOALS Asm_simp_tac); |
3234 | 432 |
qed "less_imp_diff_is_0"; |
433 |
||
4732 | 434 |
val prems = goal thy "m-n = 0 --> n-m = 0 --> m=n"; |
3234 | 435 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
436 |
by (REPEAT(Simp_tac 1 THEN TRY(atac 1))); |
|
437 |
qed_spec_mp "diffs0_imp_equal"; |
|
438 |
||
4732 | 439 |
val [prem] = goal thy "m<n ==> 0<n-m"; |
3234 | 440 |
by (rtac (prem RS rev_mp) 1); |
441 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
3352 | 442 |
by (ALLGOALS Asm_simp_tac); |
3234 | 443 |
qed "less_imp_diff_positive"; |
444 |
||
4732 | 445 |
goal thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))"; |
4686 | 446 |
by (simp_tac (simpset() addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]) 1); |
3234 | 447 |
qed "if_Suc_diff_n"; |
448 |
||
4732 | 449 |
goal thy "Suc(m)-n <= Suc(m-n)"; |
4686 | 450 |
by (simp_tac (simpset() addsimps [if_Suc_diff_n]) 1); |
4672
9d55bc687e1e
New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents:
4423
diff
changeset
|
451 |
qed "diff_Suc_le_Suc_diff"; |
9d55bc687e1e
New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents:
4423
diff
changeset
|
452 |
|
4732 | 453 |
goal thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)"; |
3234 | 454 |
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); |
3718 | 455 |
by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac)); |
3234 | 456 |
qed "zero_induct_lemma"; |
457 |
||
4732 | 458 |
val prems = goal thy "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; |
3234 | 459 |
by (rtac (diff_self_eq_0 RS subst) 1); |
460 |
by (rtac (zero_induct_lemma RS mp RS mp) 1); |
|
461 |
by (REPEAT (ares_tac ([impI,allI]@prems) 1)); |
|
462 |
qed "zero_induct"; |
|
463 |
||
4732 | 464 |
goal thy "!!k::nat. (k+m) - (k+n) = m - n"; |
3339 | 465 |
by (induct_tac "k" 1); |
3234 | 466 |
by (ALLGOALS Asm_simp_tac); |
467 |
qed "diff_cancel"; |
|
468 |
Addsimps [diff_cancel]; |
|
469 |
||
4732 | 470 |
goal thy "!!m::nat. (m+k) - (n+k) = m - n"; |
3234 | 471 |
val add_commute_k = read_instantiate [("n","k")] add_commute; |
4089 | 472 |
by (asm_simp_tac (simpset() addsimps ([add_commute_k])) 1); |
3234 | 473 |
qed "diff_cancel2"; |
474 |
Addsimps [diff_cancel2]; |
|
475 |
||
476 |
(*From Clemens Ballarin*) |
|
4732 | 477 |
goal thy "!!n::nat. [| k<=n; n<=m |] ==> (m-k) - (n-k) = m-n"; |
3234 | 478 |
by (subgoal_tac "k<=n --> n<=m --> (m-k) - (n-k) = m-n" 1); |
479 |
by (Asm_full_simp_tac 1); |
|
3339 | 480 |
by (induct_tac "k" 1); |
3234 | 481 |
by (Simp_tac 1); |
482 |
(* Induction step *) |
|
483 |
by (subgoal_tac "Suc na <= m --> n <= m --> Suc na <= n --> \ |
|
484 |
\ Suc (m - Suc na) - Suc (n - Suc na) = m-n" 1); |
|
485 |
by (Asm_full_simp_tac 1); |
|
4089 | 486 |
by (blast_tac (claset() addIs [le_trans]) 1); |
487 |
by (auto_tac (claset() addIs [Suc_leD], simpset() delsimps [diff_Suc_Suc])); |
|
488 |
by (asm_full_simp_tac (simpset() delsimps [Suc_less_eq] |
|
3234 | 489 |
addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1); |
490 |
qed "diff_right_cancel"; |
|
491 |
||
4732 | 492 |
goal thy "!!n::nat. n - (n+m) = 0"; |
3339 | 493 |
by (induct_tac "n" 1); |
3234 | 494 |
by (ALLGOALS Asm_simp_tac); |
495 |
qed "diff_add_0"; |
|
496 |
Addsimps [diff_add_0]; |
|
497 |
||
498 |
(** Difference distributes over multiplication **) |
|
499 |
||
4732 | 500 |
goal thy "!!m::nat. (m - n) * k = (m * k) - (n * k)"; |
3234 | 501 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
502 |
by (ALLGOALS Asm_simp_tac); |
|
503 |
qed "diff_mult_distrib" ; |
|
504 |
||
4732 | 505 |
goal thy "!!m::nat. k * (m - n) = (k * m) - (k * n)"; |
3234 | 506 |
val mult_commute_k = read_instantiate [("m","k")] mult_commute; |
4089 | 507 |
by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1); |
3234 | 508 |
qed "diff_mult_distrib2" ; |
509 |
(*NOT added as rewrites, since sometimes they are used from right-to-left*) |
|
510 |
||
511 |
||
1713 | 512 |
(*** Monotonicity of Multiplication ***) |
513 |
||
4732 | 514 |
goal thy "!!i::nat. i<=j ==> i*k<=j*k"; |
3339 | 515 |
by (induct_tac "k" 1); |
4089 | 516 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_le_mono]))); |
1713 | 517 |
qed "mult_le_mono1"; |
518 |
||
519 |
(*<=monotonicity, BOTH arguments*) |
|
4732 | 520 |
goal thy "!!i::nat. [| i<=j; k<=l |] ==> i*k<=j*l"; |
2007 | 521 |
by (etac (mult_le_mono1 RS le_trans) 1); |
1713 | 522 |
by (rtac le_trans 1); |
2007 | 523 |
by (stac mult_commute 2); |
524 |
by (etac mult_le_mono1 2); |
|
4089 | 525 |
by (simp_tac (simpset() addsimps [mult_commute]) 1); |
1713 | 526 |
qed "mult_le_mono"; |
527 |
||
528 |
(*strict, in 1st argument; proof is by induction on k>0*) |
|
4732 | 529 |
goal thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j"; |
3339 | 530 |
by (eres_inst_tac [("i","0")] less_natE 1); |
1713 | 531 |
by (Asm_simp_tac 1); |
3339 | 532 |
by (induct_tac "x" 1); |
4089 | 533 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_less_mono]))); |
1713 | 534 |
qed "mult_less_mono2"; |
535 |
||
4732 | 536 |
goal thy "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k"; |
3457 | 537 |
by (dtac mult_less_mono2 1); |
4089 | 538 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute]))); |
3234 | 539 |
qed "mult_less_mono1"; |
540 |
||
4732 | 541 |
goal thy "(0 < m*n) = (0<m & 0<n)"; |
3339 | 542 |
by (induct_tac "m" 1); |
543 |
by (induct_tac "n" 2); |
|
1713 | 544 |
by (ALLGOALS Asm_simp_tac); |
545 |
qed "zero_less_mult_iff"; |
|
4356 | 546 |
Addsimps [zero_less_mult_iff]; |
1713 | 547 |
|
4732 | 548 |
goal thy "(m*n = 1) = (m=1 & n=1)"; |
3339 | 549 |
by (induct_tac "m" 1); |
1795 | 550 |
by (Simp_tac 1); |
3339 | 551 |
by (induct_tac "n" 1); |
1795 | 552 |
by (Simp_tac 1); |
4089 | 553 |
by (fast_tac (claset() addss simpset()) 1); |
1795 | 554 |
qed "mult_eq_1_iff"; |
4356 | 555 |
Addsimps [mult_eq_1_iff]; |
1795 | 556 |
|
4732 | 557 |
goal thy "!!k. 0<k ==> (m*k < n*k) = (m<n)"; |
4089 | 558 |
by (safe_tac (claset() addSIs [mult_less_mono1])); |
3234 | 559 |
by (cut_facts_tac [less_linear] 1); |
4389 | 560 |
by (blast_tac (claset() addIs [mult_less_mono1] addEs [less_asym]) 1); |
3234 | 561 |
qed "mult_less_cancel2"; |
562 |
||
4732 | 563 |
goal thy "!!k. 0<k ==> (k*m < k*n) = (m<n)"; |
3457 | 564 |
by (dtac mult_less_cancel2 1); |
4089 | 565 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 566 |
qed "mult_less_cancel1"; |
567 |
Addsimps [mult_less_cancel1, mult_less_cancel2]; |
|
568 |
||
4732 | 569 |
goal thy "(Suc k * m < Suc k * n) = (m < n)"; |
4423 | 570 |
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
|
571 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
572 |
qed "Suc_mult_less_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
573 |
|
4732 | 574 |
goalw thy [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
|
575 |
by (simp_tac (simpset_of HOL.thy) 1); |
4423 | 576 |
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
|
577 |
qed "Suc_mult_le_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
578 |
|
4732 | 579 |
goal thy "!!k. 0<k ==> (m*k = n*k) = (m=n)"; |
3234 | 580 |
by (cut_facts_tac [less_linear] 1); |
3724 | 581 |
by Safe_tac; |
3457 | 582 |
by (assume_tac 2); |
3234 | 583 |
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac)); |
584 |
by (ALLGOALS Asm_full_simp_tac); |
|
585 |
qed "mult_cancel2"; |
|
586 |
||
4732 | 587 |
goal thy "!!k. 0<k ==> (k*m = k*n) = (m=n)"; |
3457 | 588 |
by (dtac mult_cancel2 1); |
4089 | 589 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 590 |
qed "mult_cancel1"; |
591 |
Addsimps [mult_cancel1, mult_cancel2]; |
|
592 |
||
4732 | 593 |
goal thy "(Suc k * m = Suc k * n) = (m = n)"; |
4423 | 594 |
by (rtac mult_cancel1 1); |
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
595 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
596 |
qed "Suc_mult_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
597 |
|
3234 | 598 |
|
1795 | 599 |
(** Lemma for gcd **) |
600 |
||
4732 | 601 |
goal thy "!!m n. m = m*n ==> n=1 | m=0"; |
1795 | 602 |
by (dtac sym 1); |
603 |
by (rtac disjCI 1); |
|
604 |
by (rtac nat_less_cases 1 THEN assume_tac 2); |
|
4089 | 605 |
by (fast_tac (claset() addSEs [less_SucE] addss simpset()) 1); |
4356 | 606 |
by (best_tac (claset() addDs [mult_less_mono2] addss simpset()) 1); |
1795 | 607 |
qed "mult_eq_self_implies_10"; |
608 |
||
609 |
||
4736 | 610 |
(*** Subtraction laws -- mostly from Clemens Ballarin ***) |
3234 | 611 |
|
4732 | 612 |
goal thy "!! a b c::nat. [| a < b; c <= a |] ==> a-c < b-c"; |
3234 | 613 |
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
|
614 |
by (Full_simp_tac 1); |
3234 | 615 |
by (subgoal_tac "c <= b" 1); |
4089 | 616 |
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
|
617 |
by (Asm_simp_tac 1); |
3234 | 618 |
qed "diff_less_mono"; |
619 |
||
4732 | 620 |
goal thy "!! a b c::nat. a+b < c ==> a < c-b"; |
3457 | 621 |
by (dtac diff_less_mono 1); |
622 |
by (rtac le_add2 1); |
|
3234 | 623 |
by (Asm_full_simp_tac 1); |
624 |
qed "add_less_imp_less_diff"; |
|
625 |
||
4732 | 626 |
goal thy "!! n. n <= m ==> Suc m - n = Suc (m - n)"; |
4672
9d55bc687e1e
New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents:
4423
diff
changeset
|
627 |
by (asm_full_simp_tac (simpset() addsimps [Suc_diff_n, le_eq_less_Suc]) 1); |
3234 | 628 |
qed "Suc_diff_le"; |
629 |
||
4732 | 630 |
goal thy "!! n. Suc i <= n ==> Suc (n - Suc i) = n - i"; |
3234 | 631 |
by (asm_full_simp_tac |
4089 | 632 |
(simpset() addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1); |
3234 | 633 |
qed "Suc_diff_Suc"; |
634 |
||
4732 | 635 |
goal thy "!! i::nat. i <= n ==> n - (n - i) = i"; |
3903
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
636 |
by (etac rev_mp 1); |
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
637 |
by (res_inst_tac [("m","n"),("n","i")] diff_induct 1); |
4089 | 638 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Suc_diff_le]))); |
3234 | 639 |
qed "diff_diff_cancel"; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
640 |
Addsimps [diff_diff_cancel]; |
3234 | 641 |
|
4732 | 642 |
goal thy "!!k::nat. k <= n ==> m <= n + m - k"; |
3457 | 643 |
by (etac rev_mp 1); |
3234 | 644 |
by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1); |
645 |
by (Simp_tac 1); |
|
4089 | 646 |
by (simp_tac (simpset() addsimps [less_add_Suc2, less_imp_le]) 1); |
3234 | 647 |
by (Simp_tac 1); |
648 |
qed "le_add_diff"; |
|
649 |
||
4736 | 650 |
goal Arith.thy "!!i::nat. 0<k ==> j<i --> j+k-i < k"; |
651 |
by (res_inst_tac [("m","j"),("n","i")] diff_induct 1); |
|
652 |
by (ALLGOALS Asm_simp_tac); |
|
653 |
qed_spec_mp "add_diff_less"; |
|
654 |
||
3234 | 655 |
|
4732 | 656 |
|
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
657 |
(** (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
|
658 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
659 |
(* Monotonicity of subtraction in first argument *) |
4732 | 660 |
goal thy "!!n::nat. m<=n --> (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
|
661 |
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
|
662 |
by (Simp_tac 1); |
4089 | 663 |
by (simp_tac (simpset() addsimps [le_Suc_eq]) 1); |
4732 | 664 |
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
|
665 |
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
|
666 |
|
4732 | 667 |
goal thy "!!n::nat. m<=n ==> (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
|
668 |
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
|
669 |
by (Simp_tac 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
670 |
by (case_tac "n <= l" 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
671 |
by (subgoal_tac "m <= l" 1); |
4089 | 672 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le]) 1); |
673 |
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
|
674 |
by (dtac not_leE 1); |
4089 | 675 |
by (asm_simp_tac (simpset() addsimps [if_Suc_diff_n]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
676 |
qed_spec_mp "diff_le_mono2"; |