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