author | nipkow |
Sat, 07 Mar 1998 16:29:29 +0100 | |
changeset 4686 | 74a12e86b20b |
parent 4672 | 9d55bc687e1e |
child 4732 | 10af4886b33f |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/Arith.ML |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1993 University of Cambridge |
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 |
||
4360 | 15 |
qed_goal "diff_0_eq_0" Arith.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) *) |
|
4360 | 21 |
qed_goal "diff_Suc_Suc" Arith.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 *) |
|
31 |
goal Arith.thy "!!n. 0 < n ==> Suc(n-1) = n"; |
|
4423 | 32 |
by (asm_simp_tac (simpset() addsplits [expand_nat_case]) 1); |
4360 | 33 |
qed "Suc_pred"; |
34 |
Addsimps [Suc_pred]; |
|
35 |
||
36 |
(* Generalize? *) |
|
37 |
goal Arith.thy "!!n. 0<n ==> n-1 < n"; |
|
4423 | 38 |
by (asm_simp_tac (simpset() addsplits [expand_nat_case]) 1); |
4360 | 39 |
qed "pred_less"; |
40 |
Addsimps [pred_less]; |
|
41 |
||
42 |
Delsimps [diff_Suc]; |
|
43 |
||
923 | 44 |
|
45 |
(**** Inductive properties of the operators ****) |
|
46 |
||
47 |
(*** Addition ***) |
|
48 |
||
49 |
qed_goal "add_0_right" Arith.thy "m + 0 = m" |
|
3339 | 50 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 51 |
|
52 |
qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)" |
|
3339 | 53 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 54 |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
55 |
Addsimps [add_0_right,add_Suc_right]; |
923 | 56 |
|
57 |
(*Associative law for addition*) |
|
58 |
qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)" |
|
3339 | 59 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 60 |
|
61 |
(*Commutative law for addition*) |
|
62 |
qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)" |
|
3339 | 63 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 64 |
|
65 |
qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)" |
|
66 |
(fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1, |
|
67 |
rtac (add_commute RS arg_cong) 1]); |
|
68 |
||
69 |
(*Addition is an AC-operator*) |
|
70 |
val add_ac = [add_assoc, add_commute, add_left_commute]; |
|
71 |
||
72 |
goal Arith.thy "!!k::nat. (k + m = k + n) = (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_left_cancel"; |
77 |
||
78 |
goal Arith.thy "!!k::nat. (m + k = n + k) = (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_right_cancel"; |
83 |
||
84 |
goal Arith.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_le"; |
89 |
||
90 |
goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)"; |
|
3339 | 91 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
92 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
93 |
by (Asm_simp_tac 1); |
923 | 94 |
qed "add_left_cancel_less"; |
95 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
96 |
Addsimps [add_left_cancel, add_right_cancel, |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
97 |
add_left_cancel_le, add_left_cancel_less]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
98 |
|
3339 | 99 |
(** Reasoning about m+0=0, etc. **) |
100 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
101 |
goal Arith.thy "(m+n = 0) = (m=0 & n=0)"; |
3339 | 102 |
by (induct_tac "m" 1); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
103 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
104 |
qed "add_is_0"; |
4360 | 105 |
AddIffs [add_is_0]; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
106 |
|
4360 | 107 |
goal Arith.thy "(0<m+n) = (0<m | 0<n)"; |
4423 | 108 |
by (simp_tac (simpset() delsimps [neq0_conv] addsimps [neq0_conv RS sym]) 1); |
4360 | 109 |
qed "add_gr_0"; |
110 |
AddIffs [add_gr_0]; |
|
111 |
||
112 |
(* FIXME: really needed?? *) |
|
113 |
goal Arith.thy "((m+n)-1 = 0) = (m=0 & n-1 = 0 | m-1 = 0 & n=0)"; |
|
114 |
by (exhaust_tac "m" 1); |
|
4089 | 115 |
by (ALLGOALS (fast_tac (claset() addss (simpset())))); |
3293 | 116 |
qed "pred_add_is_0"; |
117 |
Addsimps [pred_add_is_0]; |
|
118 |
||
4360 | 119 |
(* Could be generalized, eg to "!!n. k<n ==> m+(n-(Suc k)) = (m+n)-(Suc k)" *) |
4378
e52f864c5b88
Got rid of some preds and replaced some n~=0 by 0<n.
nipkow
parents:
4360
diff
changeset
|
120 |
goal Arith.thy "!!n. 0<n ==> m + (n-1) = (m+n)-1"; |
4360 | 121 |
by (exhaust_tac "m" 1); |
122 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_Suc] |
|
123 |
addsplits [expand_nat_case]))); |
|
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
124 |
qed "add_pred"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
125 |
Addsimps [add_pred]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
126 |
|
1626 | 127 |
|
923 | 128 |
(**** Additional theorems about "less than" ****) |
129 |
||
3339 | 130 |
goal Arith.thy "i<j --> (EX k. j = Suc(i+k))"; |
131 |
by (induct_tac "j" 1); |
|
1909 | 132 |
by (Simp_tac 1); |
4089 | 133 |
by (blast_tac (claset() addSEs [less_SucE] |
3339 | 134 |
addSIs [add_0_right RS sym, add_Suc_right RS sym]) 1); |
1909 | 135 |
val lemma = result(); |
136 |
||
3339 | 137 |
(* [| i<j; !!x. j = Suc(i+x) ==> Q |] ==> Q *) |
138 |
bind_thm ("less_natE", lemma RS mp RS exE); |
|
139 |
||
923 | 140 |
goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))"; |
3339 | 141 |
by (induct_tac "n" 1); |
4089 | 142 |
by (ALLGOALS (simp_tac (simpset() addsimps [less_Suc_eq]))); |
143 |
by (blast_tac (claset() addSEs [less_SucE] |
|
3339 | 144 |
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
|
145 |
qed_spec_mp "less_eq_Suc_add"; |
923 | 146 |
|
147 |
goal Arith.thy "n <= ((m + n)::nat)"; |
|
3339 | 148 |
by (induct_tac "m" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
149 |
by (ALLGOALS Simp_tac); |
923 | 150 |
by (etac le_trans 1); |
151 |
by (rtac (lessI RS less_imp_le) 1); |
|
152 |
qed "le_add2"; |
|
153 |
||
154 |
goal Arith.thy "n <= ((n + m)::nat)"; |
|
4089 | 155 |
by (simp_tac (simpset() addsimps add_ac) 1); |
923 | 156 |
by (rtac le_add2 1); |
157 |
qed "le_add1"; |
|
158 |
||
159 |
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); |
|
160 |
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); |
|
161 |
||
162 |
(*"i <= j ==> i <= j+m"*) |
|
163 |
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); |
|
164 |
||
165 |
(*"i <= j ==> i <= m+j"*) |
|
166 |
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); |
|
167 |
||
168 |
(*"i < j ==> i < j+m"*) |
|
169 |
bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); |
|
170 |
||
171 |
(*"i < j ==> i < m+j"*) |
|
172 |
bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); |
|
173 |
||
1152 | 174 |
goal Arith.thy "!!i. i+j < (k::nat) ==> i<k"; |
1552 | 175 |
by (etac rev_mp 1); |
3339 | 176 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
177 |
by (ALLGOALS Asm_simp_tac); |
4089 | 178 |
by (blast_tac (claset() addDs [Suc_lessD]) 1); |
1152 | 179 |
qed "add_lessD1"; |
180 |
||
3234 | 181 |
goal Arith.thy "!!i::nat. ~ (i+j < i)"; |
3457 | 182 |
by (rtac notI 1); |
183 |
by (etac (add_lessD1 RS less_irrefl) 1); |
|
3234 | 184 |
qed "not_add_less1"; |
185 |
||
186 |
goal Arith.thy "!!i::nat. ~ (j+i < i)"; |
|
4089 | 187 |
by (simp_tac (simpset() addsimps [add_commute, not_add_less1]) 1); |
3234 | 188 |
qed "not_add_less2"; |
189 |
AddIffs [not_add_less1, not_add_less2]; |
|
190 |
||
923 | 191 |
goal Arith.thy "!!k::nat. m <= n ==> m <= n+k"; |
1552 | 192 |
by (etac le_trans 1); |
193 |
by (rtac le_add1 1); |
|
923 | 194 |
qed "le_imp_add_le"; |
195 |
||
196 |
goal Arith.thy "!!k::nat. m < n ==> m < n+k"; |
|
1552 | 197 |
by (etac less_le_trans 1); |
198 |
by (rtac le_add1 1); |
|
923 | 199 |
qed "less_imp_add_less"; |
200 |
||
201 |
goal Arith.thy "m+k<=n --> m<=(n::nat)"; |
|
3339 | 202 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
203 |
by (ALLGOALS Asm_simp_tac); |
4089 | 204 |
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
|
205 |
qed_spec_mp "add_leD1"; |
923 | 206 |
|
2498 | 207 |
goal Arith.thy "!!n::nat. m+k<=n ==> k<=n"; |
4089 | 208 |
by (full_simp_tac (simpset() addsimps [add_commute]) 1); |
2498 | 209 |
by (etac add_leD1 1); |
210 |
qed_spec_mp "add_leD2"; |
|
211 |
||
212 |
goal Arith.thy "!!n::nat. m+k<=n ==> m<=n & k<=n"; |
|
4089 | 213 |
by (blast_tac (claset() addDs [add_leD1, add_leD2]) 1); |
2498 | 214 |
bind_thm ("add_leE", result() RS conjE); |
215 |
||
923 | 216 |
goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n"; |
4089 | 217 |
by (safe_tac (claset() addSDs [less_eq_Suc_add])); |
923 | 218 |
by (asm_full_simp_tac |
4089 | 219 |
(simpset() delsimps [add_Suc_right] |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
220 |
addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1); |
1552 | 221 |
by (etac subst 1); |
4089 | 222 |
by (simp_tac (simpset() addsimps [less_add_Suc1]) 1); |
923 | 223 |
qed "less_add_eq_less"; |
224 |
||
225 |
||
1713 | 226 |
(*** Monotonicity of Addition ***) |
923 | 227 |
|
228 |
(*strict, in 1st argument*) |
|
229 |
goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k"; |
|
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*) |
|
235 |
goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l"; |
|
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 *) |
|
243 |
val [lt_mono,le] = goal Arith.thy |
|
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); |
|
4089 | 248 |
by (asm_full_simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); |
249 |
by (blast_tac (claset() addSIs [lt_mono]) 1); |
|
923 | 250 |
qed "less_mono_imp_le_mono"; |
251 |
||
252 |
(*non-strict, in 1st argument*) |
|
253 |
goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k"; |
|
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*) |
|
260 |
goal Arith.thy "!!k l::nat. [|i<=j; k<=l |] ==> i + k <= j + l"; |
|
261 |
by (etac (add_le_mono1 RS le_trans) 1); |
|
4089 | 262 |
by (simp_tac (simpset() addsimps [add_commute]) 1); |
923 | 263 |
(*j moves to the end because it is free while k, l are bound*) |
1552 | 264 |
by (etac add_le_mono1 1); |
923 | 265 |
qed "add_le_mono"; |
1713 | 266 |
|
3234 | 267 |
|
268 |
(*** Multiplication ***) |
|
269 |
||
270 |
(*right annihilation in product*) |
|
271 |
qed_goal "mult_0_right" Arith.thy "m * 0 = 0" |
|
3339 | 272 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 273 |
|
3293 | 274 |
(*right successor law for multiplication*) |
3234 | 275 |
qed_goal "mult_Suc_right" Arith.thy "m * Suc(n) = m + (m * n)" |
3339 | 276 |
(fn _ => [induct_tac "m" 1, |
4089 | 277 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 278 |
|
3293 | 279 |
Addsimps [mult_0_right, mult_Suc_right]; |
3234 | 280 |
|
281 |
goal Arith.thy "1 * n = n"; |
|
282 |
by (Asm_simp_tac 1); |
|
283 |
qed "mult_1"; |
|
284 |
||
285 |
goal Arith.thy "n * 1 = n"; |
|
286 |
by (Asm_simp_tac 1); |
|
287 |
qed "mult_1_right"; |
|
288 |
||
289 |
(*Commutative law for multiplication*) |
|
290 |
qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)" |
|
3339 | 291 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 292 |
|
293 |
(*addition distributes over multiplication*) |
|
294 |
qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)" |
|
3339 | 295 |
(fn _ => [induct_tac "m" 1, |
4089 | 296 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 297 |
|
298 |
qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)" |
|
3339 | 299 |
(fn _ => [induct_tac "m" 1, |
4089 | 300 |
ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]); |
3234 | 301 |
|
302 |
(*Associative law for multiplication*) |
|
303 |
qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)" |
|
3339 | 304 |
(fn _ => [induct_tac "m" 1, |
4089 | 305 |
ALLGOALS (asm_simp_tac (simpset() addsimps [add_mult_distrib]))]); |
3234 | 306 |
|
307 |
qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)" |
|
308 |
(fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1, |
|
309 |
rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]); |
|
310 |
||
311 |
val mult_ac = [mult_assoc,mult_commute,mult_left_commute]; |
|
312 |
||
3293 | 313 |
goal Arith.thy "(m*n = 0) = (m=0 | n=0)"; |
3339 | 314 |
by (induct_tac "m" 1); |
315 |
by (induct_tac "n" 2); |
|
3293 | 316 |
by (ALLGOALS Asm_simp_tac); |
317 |
qed "mult_is_0"; |
|
318 |
Addsimps [mult_is_0]; |
|
319 |
||
4158 | 320 |
goal Arith.thy "!!m::nat. m <= m*m"; |
321 |
by (induct_tac "m" 1); |
|
322 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_assoc RS sym]))); |
|
323 |
by (etac (le_add2 RSN (2,le_trans)) 1); |
|
324 |
qed "le_square"; |
|
325 |
||
3234 | 326 |
|
327 |
(*** Difference ***) |
|
328 |
||
329 |
||
330 |
qed_goal "diff_self_eq_0" Arith.thy "m - m = 0" |
|
3339 | 331 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 332 |
Addsimps [diff_self_eq_0]; |
333 |
||
334 |
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) |
|
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
335 |
goal Arith.thy "~ m<n --> n+(m-n) = (m::nat)"; |
3234 | 336 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
3352 | 337 |
by (ALLGOALS Asm_simp_tac); |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
338 |
qed_spec_mp "add_diff_inverse"; |
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
339 |
|
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
340 |
goal Arith.thy "!!m. n<=m ==> n+(m-n) = (m::nat)"; |
4089 | 341 |
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
|
342 |
qed "le_add_diff_inverse"; |
3234 | 343 |
|
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
344 |
goal Arith.thy "!!m. n<=m ==> (m-n)+n = (m::nat)"; |
4089 | 345 |
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
|
346 |
qed "le_add_diff_inverse2"; |
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
347 |
|
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
348 |
Addsimps [le_add_diff_inverse, le_add_diff_inverse2]; |
3234 | 349 |
|
350 |
||
351 |
(*** More results about difference ***) |
|
352 |
||
3352 | 353 |
val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)"; |
354 |
by (rtac (prem RS rev_mp) 1); |
|
355 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
356 |
by (ALLGOALS Asm_simp_tac); |
|
357 |
qed "Suc_diff_n"; |
|
358 |
||
3234 | 359 |
goal Arith.thy "m - n < Suc(m)"; |
360 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
361 |
by (etac less_SucE 3); |
|
4089 | 362 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq]))); |
3234 | 363 |
qed "diff_less_Suc"; |
364 |
||
365 |
goal Arith.thy "!!m::nat. m - n <= m"; |
|
366 |
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); |
|
367 |
by (ALLGOALS Asm_simp_tac); |
|
368 |
qed "diff_le_self"; |
|
3903
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
369 |
Addsimps [diff_le_self]; |
3234 | 370 |
|
3352 | 371 |
goal Arith.thy "!!i::nat. i-j-k = i - (j+k)"; |
372 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
|
373 |
by (ALLGOALS Asm_simp_tac); |
|
374 |
qed "diff_diff_left"; |
|
375 |
||
4360 | 376 |
(* This is a trivial consequence of diff_diff_left; |
377 |
could be got rid of if diff_diff_left were in the simpset... |
|
378 |
*) |
|
379 |
goal Arith.thy "(Suc m - n)-1 = m - n"; |
|
4423 | 380 |
by (simp_tac (simpset() addsimps [diff_diff_left]) 1); |
4360 | 381 |
qed "pred_Suc_diff"; |
382 |
Addsimps [pred_Suc_diff]; |
|
383 |
||
3396 | 384 |
(*This and the next few suggested by Florian Kammueller*) |
3352 | 385 |
goal Arith.thy "!!i::nat. i-j-k = i-k-j"; |
4089 | 386 |
by (simp_tac (simpset() addsimps [diff_diff_left, add_commute]) 1); |
3352 | 387 |
qed "diff_commute"; |
388 |
||
389 |
goal Arith.thy "!!i j k:: nat. k<=j --> j<=i --> i - (j - k) = i - j + k"; |
|
390 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
|
391 |
by (ALLGOALS Asm_simp_tac); |
|
392 |
by (asm_simp_tac |
|
4089 | 393 |
(simpset() addsimps [Suc_diff_n, le_imp_less_Suc, le_Suc_eq]) 1); |
3352 | 394 |
qed_spec_mp "diff_diff_right"; |
395 |
||
396 |
goal Arith.thy "!!i j k:: nat. k<=j --> (i + j) - k = i + (j - k)"; |
|
397 |
by (res_inst_tac [("m","j"),("n","k")] diff_induct 1); |
|
398 |
by (ALLGOALS Asm_simp_tac); |
|
399 |
qed_spec_mp "diff_add_assoc"; |
|
400 |
||
3234 | 401 |
goal Arith.thy "!!n::nat. (n+m) - n = m"; |
3339 | 402 |
by (induct_tac "n" 1); |
3234 | 403 |
by (ALLGOALS Asm_simp_tac); |
404 |
qed "diff_add_inverse"; |
|
405 |
Addsimps [diff_add_inverse]; |
|
406 |
||
407 |
goal Arith.thy "!!n::nat.(m+n) - n = m"; |
|
4089 | 408 |
by (simp_tac (simpset() addsimps [diff_add_assoc]) 1); |
3234 | 409 |
qed "diff_add_inverse2"; |
410 |
Addsimps [diff_add_inverse2]; |
|
411 |
||
3366 | 412 |
goal Arith.thy "!!i j k::nat. i<=j ==> (j-i=k) = (j=k+i)"; |
3724 | 413 |
by Safe_tac; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
414 |
by (ALLGOALS Asm_simp_tac); |
3366 | 415 |
qed "le_imp_diff_is_add"; |
416 |
||
3234 | 417 |
val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0"; |
418 |
by (rtac (prem RS rev_mp) 1); |
|
419 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
4089 | 420 |
by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
3352 | 421 |
by (ALLGOALS Asm_simp_tac); |
3234 | 422 |
qed "less_imp_diff_is_0"; |
423 |
||
424 |
val prems = goal Arith.thy "m-n = 0 --> n-m = 0 --> m=n"; |
|
425 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
426 |
by (REPEAT(Simp_tac 1 THEN TRY(atac 1))); |
|
427 |
qed_spec_mp "diffs0_imp_equal"; |
|
428 |
||
429 |
val [prem] = goal Arith.thy "m<n ==> 0<n-m"; |
|
430 |
by (rtac (prem RS rev_mp) 1); |
|
431 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
3352 | 432 |
by (ALLGOALS Asm_simp_tac); |
3234 | 433 |
qed "less_imp_diff_positive"; |
434 |
||
435 |
goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))"; |
|
4686 | 436 |
by (simp_tac (simpset() addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]) 1); |
3234 | 437 |
qed "if_Suc_diff_n"; |
438 |
||
4672
9d55bc687e1e
New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents:
4423
diff
changeset
|
439 |
goal Arith.thy "Suc(m)-n <= Suc(m-n)"; |
4686 | 440 |
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
|
441 |
qed "diff_Suc_le_Suc_diff"; |
9d55bc687e1e
New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents:
4423
diff
changeset
|
442 |
|
3234 | 443 |
goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)"; |
444 |
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); |
|
3718 | 445 |
by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac)); |
3234 | 446 |
qed "zero_induct_lemma"; |
447 |
||
448 |
val prems = goal Arith.thy "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; |
|
449 |
by (rtac (diff_self_eq_0 RS subst) 1); |
|
450 |
by (rtac (zero_induct_lemma RS mp RS mp) 1); |
|
451 |
by (REPEAT (ares_tac ([impI,allI]@prems) 1)); |
|
452 |
qed "zero_induct"; |
|
453 |
||
454 |
goal Arith.thy "!!k::nat. (k+m) - (k+n) = m - n"; |
|
3339 | 455 |
by (induct_tac "k" 1); |
3234 | 456 |
by (ALLGOALS Asm_simp_tac); |
457 |
qed "diff_cancel"; |
|
458 |
Addsimps [diff_cancel]; |
|
459 |
||
460 |
goal Arith.thy "!!m::nat. (m+k) - (n+k) = m - n"; |
|
461 |
val add_commute_k = read_instantiate [("n","k")] add_commute; |
|
4089 | 462 |
by (asm_simp_tac (simpset() addsimps ([add_commute_k])) 1); |
3234 | 463 |
qed "diff_cancel2"; |
464 |
Addsimps [diff_cancel2]; |
|
465 |
||
466 |
(*From Clemens Ballarin*) |
|
467 |
goal Arith.thy "!!n::nat. [| k<=n; n<=m |] ==> (m-k) - (n-k) = m-n"; |
|
468 |
by (subgoal_tac "k<=n --> n<=m --> (m-k) - (n-k) = m-n" 1); |
|
469 |
by (Asm_full_simp_tac 1); |
|
3339 | 470 |
by (induct_tac "k" 1); |
3234 | 471 |
by (Simp_tac 1); |
472 |
(* Induction step *) |
|
473 |
by (subgoal_tac "Suc na <= m --> n <= m --> Suc na <= n --> \ |
|
474 |
\ Suc (m - Suc na) - Suc (n - Suc na) = m-n" 1); |
|
475 |
by (Asm_full_simp_tac 1); |
|
4089 | 476 |
by (blast_tac (claset() addIs [le_trans]) 1); |
477 |
by (auto_tac (claset() addIs [Suc_leD], simpset() delsimps [diff_Suc_Suc])); |
|
478 |
by (asm_full_simp_tac (simpset() delsimps [Suc_less_eq] |
|
3234 | 479 |
addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1); |
480 |
qed "diff_right_cancel"; |
|
481 |
||
482 |
goal Arith.thy "!!n::nat. n - (n+m) = 0"; |
|
3339 | 483 |
by (induct_tac "n" 1); |
3234 | 484 |
by (ALLGOALS Asm_simp_tac); |
485 |
qed "diff_add_0"; |
|
486 |
Addsimps [diff_add_0]; |
|
487 |
||
488 |
(** Difference distributes over multiplication **) |
|
489 |
||
490 |
goal Arith.thy "!!m::nat. (m - n) * k = (m * k) - (n * k)"; |
|
491 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
492 |
by (ALLGOALS Asm_simp_tac); |
|
493 |
qed "diff_mult_distrib" ; |
|
494 |
||
495 |
goal Arith.thy "!!m::nat. k * (m - n) = (k * m) - (k * n)"; |
|
496 |
val mult_commute_k = read_instantiate [("m","k")] mult_commute; |
|
4089 | 497 |
by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1); |
3234 | 498 |
qed "diff_mult_distrib2" ; |
499 |
(*NOT added as rewrites, since sometimes they are used from right-to-left*) |
|
500 |
||
501 |
||
1713 | 502 |
(*** Monotonicity of Multiplication ***) |
503 |
||
504 |
goal Arith.thy "!!i::nat. i<=j ==> i*k<=j*k"; |
|
3339 | 505 |
by (induct_tac "k" 1); |
4089 | 506 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_le_mono]))); |
1713 | 507 |
qed "mult_le_mono1"; |
508 |
||
509 |
(*<=monotonicity, BOTH arguments*) |
|
510 |
goal Arith.thy "!!i::nat. [| i<=j; k<=l |] ==> i*k<=j*l"; |
|
2007 | 511 |
by (etac (mult_le_mono1 RS le_trans) 1); |
1713 | 512 |
by (rtac le_trans 1); |
2007 | 513 |
by (stac mult_commute 2); |
514 |
by (etac mult_le_mono1 2); |
|
4089 | 515 |
by (simp_tac (simpset() addsimps [mult_commute]) 1); |
1713 | 516 |
qed "mult_le_mono"; |
517 |
||
518 |
(*strict, in 1st argument; proof is by induction on k>0*) |
|
519 |
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j"; |
|
3339 | 520 |
by (eres_inst_tac [("i","0")] less_natE 1); |
1713 | 521 |
by (Asm_simp_tac 1); |
3339 | 522 |
by (induct_tac "x" 1); |
4089 | 523 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_less_mono]))); |
1713 | 524 |
qed "mult_less_mono2"; |
525 |
||
3234 | 526 |
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k"; |
3457 | 527 |
by (dtac mult_less_mono2 1); |
4089 | 528 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute]))); |
3234 | 529 |
qed "mult_less_mono1"; |
530 |
||
1713 | 531 |
goal Arith.thy "(0 < m*n) = (0<m & 0<n)"; |
3339 | 532 |
by (induct_tac "m" 1); |
533 |
by (induct_tac "n" 2); |
|
1713 | 534 |
by (ALLGOALS Asm_simp_tac); |
535 |
qed "zero_less_mult_iff"; |
|
4356 | 536 |
Addsimps [zero_less_mult_iff]; |
1713 | 537 |
|
1795 | 538 |
goal Arith.thy "(m*n = 1) = (m=1 & n=1)"; |
3339 | 539 |
by (induct_tac "m" 1); |
1795 | 540 |
by (Simp_tac 1); |
3339 | 541 |
by (induct_tac "n" 1); |
1795 | 542 |
by (Simp_tac 1); |
4089 | 543 |
by (fast_tac (claset() addss simpset()) 1); |
1795 | 544 |
qed "mult_eq_1_iff"; |
4356 | 545 |
Addsimps [mult_eq_1_iff]; |
1795 | 546 |
|
3234 | 547 |
goal Arith.thy "!!k. 0<k ==> (m*k < n*k) = (m<n)"; |
4089 | 548 |
by (safe_tac (claset() addSIs [mult_less_mono1])); |
3234 | 549 |
by (cut_facts_tac [less_linear] 1); |
4389 | 550 |
by (blast_tac (claset() addIs [mult_less_mono1] addEs [less_asym]) 1); |
3234 | 551 |
qed "mult_less_cancel2"; |
552 |
||
553 |
goal Arith.thy "!!k. 0<k ==> (k*m < k*n) = (m<n)"; |
|
3457 | 554 |
by (dtac mult_less_cancel2 1); |
4089 | 555 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 556 |
qed "mult_less_cancel1"; |
557 |
Addsimps [mult_less_cancel1, mult_less_cancel2]; |
|
558 |
||
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
559 |
goal Arith.thy "(Suc k * m < Suc k * n) = (m < n)"; |
4423 | 560 |
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
|
561 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
562 |
qed "Suc_mult_less_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
563 |
|
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
564 |
goalw Arith.thy [le_def] "(Suc k * m <= Suc k * n) = (m <= n)"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
565 |
by (simp_tac (simpset_of HOL.thy) 1); |
4423 | 566 |
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
|
567 |
qed "Suc_mult_le_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
568 |
|
3234 | 569 |
goal Arith.thy "!!k. 0<k ==> (m*k = n*k) = (m=n)"; |
570 |
by (cut_facts_tac [less_linear] 1); |
|
3724 | 571 |
by Safe_tac; |
3457 | 572 |
by (assume_tac 2); |
3234 | 573 |
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac)); |
574 |
by (ALLGOALS Asm_full_simp_tac); |
|
575 |
qed "mult_cancel2"; |
|
576 |
||
577 |
goal Arith.thy "!!k. 0<k ==> (k*m = k*n) = (m=n)"; |
|
3457 | 578 |
by (dtac mult_cancel2 1); |
4089 | 579 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 580 |
qed "mult_cancel1"; |
581 |
Addsimps [mult_cancel1, mult_cancel2]; |
|
582 |
||
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
583 |
goal Arith.thy "(Suc k * m = Suc k * n) = (m = n)"; |
4423 | 584 |
by (rtac mult_cancel1 1); |
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
585 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
586 |
qed "Suc_mult_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
587 |
|
3234 | 588 |
|
1795 | 589 |
(** Lemma for gcd **) |
590 |
||
591 |
goal Arith.thy "!!m n. m = m*n ==> n=1 | m=0"; |
|
592 |
by (dtac sym 1); |
|
593 |
by (rtac disjCI 1); |
|
594 |
by (rtac nat_less_cases 1 THEN assume_tac 2); |
|
4089 | 595 |
by (fast_tac (claset() addSEs [less_SucE] addss simpset()) 1); |
4356 | 596 |
by (best_tac (claset() addDs [mult_less_mono2] addss simpset()) 1); |
1795 | 597 |
qed "mult_eq_self_implies_10"; |
598 |
||
599 |
||
3234 | 600 |
(*** Subtraction laws -- from Clemens Ballarin ***) |
601 |
||
602 |
goal Arith.thy "!! a b c::nat. [| a < b; c <= a |] ==> a-c < b-c"; |
|
603 |
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
|
604 |
by (Full_simp_tac 1); |
3234 | 605 |
by (subgoal_tac "c <= b" 1); |
4089 | 606 |
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
|
607 |
by (Asm_simp_tac 1); |
3234 | 608 |
qed "diff_less_mono"; |
609 |
||
610 |
goal Arith.thy "!! a b c::nat. a+b < c ==> a < c-b"; |
|
3457 | 611 |
by (dtac diff_less_mono 1); |
612 |
by (rtac le_add2 1); |
|
3234 | 613 |
by (Asm_full_simp_tac 1); |
614 |
qed "add_less_imp_less_diff"; |
|
615 |
||
616 |
goal Arith.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
|
617 |
by (asm_full_simp_tac (simpset() addsimps [Suc_diff_n, le_eq_less_Suc]) 1); |
3234 | 618 |
qed "Suc_diff_le"; |
619 |
||
620 |
goal Arith.thy "!! n. Suc i <= n ==> Suc (n - Suc i) = n - i"; |
|
621 |
by (asm_full_simp_tac |
|
4089 | 622 |
(simpset() addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1); |
3234 | 623 |
qed "Suc_diff_Suc"; |
624 |
||
625 |
goal Arith.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
|
626 |
by (etac rev_mp 1); |
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
627 |
by (res_inst_tac [("m","n"),("n","i")] diff_induct 1); |
4089 | 628 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Suc_diff_le]))); |
3234 | 629 |
qed "diff_diff_cancel"; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
630 |
Addsimps [diff_diff_cancel]; |
3234 | 631 |
|
632 |
goal Arith.thy "!!k::nat. k <= n ==> m <= n + m - k"; |
|
3457 | 633 |
by (etac rev_mp 1); |
3234 | 634 |
by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1); |
635 |
by (Simp_tac 1); |
|
4089 | 636 |
by (simp_tac (simpset() addsimps [less_add_Suc2, less_imp_le]) 1); |
3234 | 637 |
by (Simp_tac 1); |
638 |
qed "le_add_diff"; |
|
639 |
||
640 |
||
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
641 |
(** (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
|
642 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
643 |
(* Monotonicity of subtraction in first argument *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
644 |
goal Arith.thy "!!n::nat. m<=n --> (m-l) <= (n-l)"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
645 |
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
|
646 |
by (Simp_tac 1); |
4089 | 647 |
by (simp_tac (simpset() addsimps [le_Suc_eq]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
648 |
by (rtac impI 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
649 |
by (etac impE 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
650 |
by (atac 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
651 |
by (etac le_trans 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
652 |
by (res_inst_tac [("m1","n")] (pred_Suc_diff RS subst) 1); |
4360 | 653 |
by (simp_tac (simpset() addsimps [diff_Suc] addsplits [expand_nat_case]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
654 |
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
|
655 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
656 |
goal Arith.thy "!!n::nat. m<=n ==> (l-n) <= (l-m)"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
657 |
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
|
658 |
by (Simp_tac 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
659 |
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
|
660 |
by (subgoal_tac "m <= l" 1); |
4089 | 661 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le]) 1); |
662 |
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
|
663 |
by (dtac not_leE 1); |
4089 | 664 |
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
|
665 |
qed_spec_mp "diff_le_mono2"; |