author | wenzelm |
Mon, 16 Aug 1999 14:22:45 +0200 | |
changeset 7208 | 8b4acb408301 |
parent 7131 | 0b2fe9ec709c |
child 7428 | 80838c2af97b |
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 |
||
7007 | 15 |
Goal "0 - n = 0"; |
16 |
by (induct_tac "n" 1); |
|
17 |
by (ALLGOALS Asm_simp_tac); |
|
18 |
qed "diff_0_eq_0"; |
|
923 | 19 |
|
5429 | 20 |
(*Must simplify BEFORE the induction! (Else we get a critical pair) |
923 | 21 |
Suc(m) - Suc(n) rewrites to pred(Suc(m) - n) *) |
7007 | 22 |
Goal "Suc(m) - Suc(n) = m - n"; |
23 |
by (Simp_tac 1); |
|
24 |
by (induct_tac "n" 1); |
|
25 |
by (ALLGOALS Asm_simp_tac); |
|
26 |
qed "diff_Suc_Suc"; |
|
923 | 27 |
|
2682
13cdbf95ed92
minor changes due to new primrec definitions for +,-,*
pusch
parents:
2498
diff
changeset
|
28 |
Addsimps [diff_0_eq_0, diff_Suc_Suc]; |
923 | 29 |
|
4360 | 30 |
(* Could be (and is, below) generalized in various ways; |
31 |
However, none of the generalizations are currently in the simpset, |
|
32 |
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
|
33 |
Goal "0 < n ==> Suc(n-1) = n"; |
5183 | 34 |
by (asm_simp_tac (simpset() addsplits [nat.split]) 1); |
4360 | 35 |
qed "Suc_pred"; |
36 |
Addsimps [Suc_pred]; |
|
37 |
||
38 |
Delsimps [diff_Suc]; |
|
39 |
||
923 | 40 |
|
41 |
(**** Inductive properties of the operators ****) |
|
42 |
||
43 |
(*** Addition ***) |
|
44 |
||
7007 | 45 |
Goal "m + 0 = m"; |
46 |
by (induct_tac "m" 1); |
|
47 |
by (ALLGOALS Asm_simp_tac); |
|
48 |
qed "add_0_right"; |
|
923 | 49 |
|
7007 | 50 |
Goal "m + Suc(n) = Suc(m+n)"; |
51 |
by (induct_tac "m" 1); |
|
52 |
by (ALLGOALS Asm_simp_tac); |
|
53 |
qed "add_Suc_right"; |
|
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 |
|
7007 | 57 |
|
923 | 58 |
(*Associative law for addition*) |
7007 | 59 |
Goal "(m + n) + k = m + ((n + k)::nat)"; |
60 |
by (induct_tac "m" 1); |
|
61 |
by (ALLGOALS Asm_simp_tac); |
|
62 |
qed "add_assoc"; |
|
923 | 63 |
|
64 |
(*Commutative law for addition*) |
|
7007 | 65 |
Goal "m + n = n + (m::nat)"; |
66 |
by (induct_tac "m" 1); |
|
67 |
by (ALLGOALS Asm_simp_tac); |
|
68 |
qed "add_commute"; |
|
923 | 69 |
|
7007 | 70 |
Goal "x+(y+z)=y+((x+z)::nat)"; |
71 |
by (rtac (add_commute RS trans) 1); |
|
72 |
by (rtac (add_assoc RS trans) 1); |
|
73 |
by (rtac (add_commute RS arg_cong) 1); |
|
74 |
qed "add_left_commute"; |
|
923 | 75 |
|
76 |
(*Addition is an AC-operator*) |
|
77 |
val add_ac = [add_assoc, add_commute, add_left_commute]; |
|
78 |
||
5429 | 79 |
Goal "(k + m = k + n) = (m=(n::nat))"; |
3339 | 80 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
81 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
82 |
by (Asm_simp_tac 1); |
923 | 83 |
qed "add_left_cancel"; |
84 |
||
5429 | 85 |
Goal "(m + k = n + k) = (m=(n::nat))"; |
3339 | 86 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
87 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
88 |
by (Asm_simp_tac 1); |
923 | 89 |
qed "add_right_cancel"; |
90 |
||
5429 | 91 |
Goal "(k + m <= k + n) = (m<=(n::nat))"; |
3339 | 92 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
93 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
94 |
by (Asm_simp_tac 1); |
923 | 95 |
qed "add_left_cancel_le"; |
96 |
||
5429 | 97 |
Goal "(k + m < k + n) = (m<(n::nat))"; |
3339 | 98 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
99 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
100 |
by (Asm_simp_tac 1); |
923 | 101 |
qed "add_left_cancel_less"; |
102 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
103 |
Addsimps [add_left_cancel, add_right_cancel, |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
104 |
add_left_cancel_le, add_left_cancel_less]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
105 |
|
3339 | 106 |
(** Reasoning about m+0=0, etc. **) |
107 |
||
5069 | 108 |
Goal "(m+n = 0) = (m=0 & n=0)"; |
5598 | 109 |
by (exhaust_tac "m" 1); |
110 |
by (Auto_tac); |
|
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
111 |
qed "add_is_0"; |
4360 | 112 |
AddIffs [add_is_0]; |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
113 |
|
5598 | 114 |
Goal "(0 = m+n) = (m=0 & n=0)"; |
115 |
by (exhaust_tac "m" 1); |
|
116 |
by (Auto_tac); |
|
117 |
qed "zero_is_add"; |
|
118 |
AddIffs [zero_is_add]; |
|
119 |
||
120 |
Goal "(m+n=1) = (m=1 & n=0 | m=0 & n=1)"; |
|
6301 | 121 |
by (exhaust_tac "m" 1); |
122 |
by (Auto_tac); |
|
5598 | 123 |
qed "add_is_1"; |
124 |
||
125 |
Goal "(1=m+n) = (m=1 & n=0 | m=0 & n=1)"; |
|
6301 | 126 |
by (exhaust_tac "m" 1); |
127 |
by (Auto_tac); |
|
5598 | 128 |
qed "one_is_add"; |
129 |
||
5069 | 130 |
Goal "(0<m+n) = (0<m | 0<n)"; |
4423 | 131 |
by (simp_tac (simpset() delsimps [neq0_conv] addsimps [neq0_conv RS sym]) 1); |
4360 | 132 |
qed "add_gr_0"; |
133 |
AddIffs [add_gr_0]; |
|
134 |
||
135 |
(* FIXME: really needed?? *) |
|
5069 | 136 |
Goal "((m+n)-1 = 0) = (m=0 & n-1 = 0 | m-1 = 0 & n=0)"; |
4360 | 137 |
by (exhaust_tac "m" 1); |
4089 | 138 |
by (ALLGOALS (fast_tac (claset() addss (simpset())))); |
3293 | 139 |
qed "pred_add_is_0"; |
6075 | 140 |
(*Addsimps [pred_add_is_0];*) |
3293 | 141 |
|
5429 | 142 |
(* 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
|
143 |
Goal "0<n ==> m + (n-1) = (m+n)-1"; |
4360 | 144 |
by (exhaust_tac "m" 1); |
6075 | 145 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_Suc, Suc_n_not_n] |
5183 | 146 |
addsplits [nat.split]))); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
147 |
qed "add_pred"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
148 |
Addsimps [add_pred]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
149 |
|
5429 | 150 |
Goal "m + n = m ==> n = 0"; |
5078 | 151 |
by (dtac (add_0_right RS ssubst) 1); |
152 |
by (asm_full_simp_tac (simpset() addsimps [add_assoc] |
|
153 |
delsimps [add_0_right]) 1); |
|
154 |
qed "add_eq_self_zero"; |
|
155 |
||
1626 | 156 |
|
923 | 157 |
(**** Additional theorems about "less than" ****) |
158 |
||
5078 | 159 |
(*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
|
160 |
Goal "m<n --> (? k. n=Suc(m+k))"; |
3339 | 161 |
by (induct_tac "n" 1); |
5604 | 162 |
by (ALLGOALS (simp_tac (simpset() addsimps [order_le_less]))); |
4089 | 163 |
by (blast_tac (claset() addSEs [less_SucE] |
5497 | 164 |
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
|
165 |
qed_spec_mp "less_eq_Suc_add"; |
923 | 166 |
|
5069 | 167 |
Goal "n <= ((m + n)::nat)"; |
3339 | 168 |
by (induct_tac "m" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
169 |
by (ALLGOALS Simp_tac); |
5983 | 170 |
by (etac le_SucI 1); |
923 | 171 |
qed "le_add2"; |
172 |
||
5069 | 173 |
Goal "n <= ((n + m)::nat)"; |
4089 | 174 |
by (simp_tac (simpset() addsimps add_ac) 1); |
923 | 175 |
by (rtac le_add2 1); |
176 |
qed "le_add1"; |
|
177 |
||
178 |
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); |
|
179 |
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); |
|
180 |
||
5429 | 181 |
Goal "(m<n) = (? k. n=Suc(m+k))"; |
182 |
by (blast_tac (claset() addSIs [less_add_Suc1, less_eq_Suc_add]) 1); |
|
183 |
qed "less_iff_Suc_add"; |
|
184 |
||
185 |
||
923 | 186 |
(*"i <= j ==> i <= j+m"*) |
187 |
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); |
|
188 |
||
189 |
(*"i <= j ==> i <= m+j"*) |
|
190 |
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); |
|
191 |
||
192 |
(*"i < j ==> i < j+m"*) |
|
193 |
bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); |
|
194 |
||
195 |
(*"i < j ==> i < m+j"*) |
|
196 |
bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); |
|
197 |
||
5654 | 198 |
Goal "i+j < (k::nat) --> i<k"; |
3339 | 199 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
200 |
by (ALLGOALS Asm_simp_tac); |
6301 | 201 |
by (blast_tac (claset() addDs [Suc_lessD]) 1); |
5654 | 202 |
qed_spec_mp "add_lessD1"; |
1152 | 203 |
|
5429 | 204 |
Goal "~ (i+j < (i::nat))"; |
3457 | 205 |
by (rtac notI 1); |
206 |
by (etac (add_lessD1 RS less_irrefl) 1); |
|
3234 | 207 |
qed "not_add_less1"; |
208 |
||
5429 | 209 |
Goal "~ (j+i < (i::nat))"; |
4089 | 210 |
by (simp_tac (simpset() addsimps [add_commute, not_add_less1]) 1); |
3234 | 211 |
qed "not_add_less2"; |
212 |
AddIffs [not_add_less1, not_add_less2]; |
|
213 |
||
5069 | 214 |
Goal "m+k<=n --> m<=(n::nat)"; |
3339 | 215 |
by (induct_tac "k" 1); |
5497 | 216 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps le_simps))); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1475
diff
changeset
|
217 |
qed_spec_mp "add_leD1"; |
923 | 218 |
|
5429 | 219 |
Goal "m+k<=n ==> k<=(n::nat)"; |
4089 | 220 |
by (full_simp_tac (simpset() addsimps [add_commute]) 1); |
2498 | 221 |
by (etac add_leD1 1); |
222 |
qed_spec_mp "add_leD2"; |
|
223 |
||
5429 | 224 |
Goal "m+k<=n ==> m<=n & k<=(n::nat)"; |
4089 | 225 |
by (blast_tac (claset() addDs [add_leD1, add_leD2]) 1); |
2498 | 226 |
bind_thm ("add_leE", result() RS conjE); |
227 |
||
5429 | 228 |
(*needs !!k for add_ac to work*) |
229 |
Goal "!!k:: nat. [| k<l; m+l = k+n |] ==> m<n"; |
|
5758
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5654
diff
changeset
|
230 |
by (force_tac (claset(), |
5497 | 231 |
simpset() delsimps [add_Suc_right] |
5537 | 232 |
addsimps [less_iff_Suc_add, |
5758
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5654
diff
changeset
|
233 |
add_Suc_right RS sym] @ add_ac) 1); |
923 | 234 |
qed "less_add_eq_less"; |
235 |
||
236 |
||
1713 | 237 |
(*** Monotonicity of Addition ***) |
923 | 238 |
|
239 |
(*strict, in 1st argument*) |
|
5429 | 240 |
Goal "i < j ==> i + k < j + (k::nat)"; |
3339 | 241 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
242 |
by (ALLGOALS Asm_simp_tac); |
923 | 243 |
qed "add_less_mono1"; |
244 |
||
245 |
(*strict, in both arguments*) |
|
5429 | 246 |
Goal "[|i < j; k < l|] ==> i + k < j + (l::nat)"; |
923 | 247 |
by (rtac (add_less_mono1 RS less_trans) 1); |
1198 | 248 |
by (REPEAT (assume_tac 1)); |
3339 | 249 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
250 |
by (ALLGOALS Asm_simp_tac); |
923 | 251 |
qed "add_less_mono"; |
252 |
||
253 |
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) |
|
5316 | 254 |
val [lt_mono,le] = Goal |
1465 | 255 |
"[| !!i j::nat. i<j ==> f(i) < f(j); \ |
256 |
\ i <= j \ |
|
923 | 257 |
\ |] ==> f(i) <= (f(j)::nat)"; |
258 |
by (cut_facts_tac [le] 1); |
|
5604 | 259 |
by (asm_full_simp_tac (simpset() addsimps [order_le_less]) 1); |
4089 | 260 |
by (blast_tac (claset() addSIs [lt_mono]) 1); |
923 | 261 |
qed "less_mono_imp_le_mono"; |
262 |
||
263 |
(*non-strict, in 1st argument*) |
|
5429 | 264 |
Goal "i<=j ==> i + k <= j + (k::nat)"; |
3842 | 265 |
by (res_inst_tac [("f", "%j. j+k")] less_mono_imp_le_mono 1); |
1552 | 266 |
by (etac add_less_mono1 1); |
923 | 267 |
by (assume_tac 1); |
268 |
qed "add_le_mono1"; |
|
269 |
||
270 |
(*non-strict, in both arguments*) |
|
5429 | 271 |
Goal "[|i<=j; k<=l |] ==> i + k <= j + (l::nat)"; |
923 | 272 |
by (etac (add_le_mono1 RS le_trans) 1); |
4089 | 273 |
by (simp_tac (simpset() addsimps [add_commute]) 1); |
923 | 274 |
qed "add_le_mono"; |
1713 | 275 |
|
3234 | 276 |
|
277 |
(*** Multiplication ***) |
|
278 |
||
279 |
(*right annihilation in product*) |
|
7007 | 280 |
Goal "m * 0 = 0"; |
281 |
by (induct_tac "m" 1); |
|
282 |
by (ALLGOALS Asm_simp_tac); |
|
283 |
qed "mult_0_right"; |
|
3234 | 284 |
|
3293 | 285 |
(*right successor law for multiplication*) |
7007 | 286 |
Goal "m * Suc(n) = m + (m * n)"; |
287 |
by (induct_tac "m" 1); |
|
288 |
by (ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))); |
|
289 |
qed "mult_Suc_right"; |
|
3234 | 290 |
|
3293 | 291 |
Addsimps [mult_0_right, mult_Suc_right]; |
3234 | 292 |
|
5069 | 293 |
Goal "1 * n = n"; |
3234 | 294 |
by (Asm_simp_tac 1); |
295 |
qed "mult_1"; |
|
296 |
||
5069 | 297 |
Goal "n * 1 = n"; |
3234 | 298 |
by (Asm_simp_tac 1); |
299 |
qed "mult_1_right"; |
|
300 |
||
301 |
(*Commutative law for multiplication*) |
|
7007 | 302 |
Goal "m * n = n * (m::nat)"; |
303 |
by (induct_tac "m" 1); |
|
304 |
by (ALLGOALS Asm_simp_tac); |
|
305 |
qed "mult_commute"; |
|
3234 | 306 |
|
307 |
(*addition distributes over multiplication*) |
|
7007 | 308 |
Goal "(m + n)*k = (m*k) + ((n*k)::nat)"; |
309 |
by (induct_tac "m" 1); |
|
310 |
by (ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))); |
|
311 |
qed "add_mult_distrib"; |
|
3234 | 312 |
|
7007 | 313 |
Goal "k*(m + n) = (k*m) + ((k*n)::nat)"; |
314 |
by (induct_tac "m" 1); |
|
315 |
by (ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))); |
|
316 |
qed "add_mult_distrib2"; |
|
3234 | 317 |
|
318 |
(*Associative law for multiplication*) |
|
7007 | 319 |
Goal "(m * n) * k = m * ((n * k)::nat)"; |
320 |
by (induct_tac "m" 1); |
|
321 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_mult_distrib]))); |
|
322 |
qed "mult_assoc"; |
|
3234 | 323 |
|
7007 | 324 |
Goal "x*(y*z) = y*((x*z)::nat)"; |
325 |
by (rtac trans 1); |
|
326 |
by (rtac mult_commute 1); |
|
327 |
by (rtac trans 1); |
|
328 |
by (rtac mult_assoc 1); |
|
329 |
by (rtac (mult_commute RS arg_cong) 1); |
|
330 |
qed "mult_left_commute"; |
|
3234 | 331 |
|
332 |
val mult_ac = [mult_assoc,mult_commute,mult_left_commute]; |
|
333 |
||
5069 | 334 |
Goal "(m*n = 0) = (m=0 | n=0)"; |
3339 | 335 |
by (induct_tac "m" 1); |
336 |
by (induct_tac "n" 2); |
|
3293 | 337 |
by (ALLGOALS Asm_simp_tac); |
338 |
qed "mult_is_0"; |
|
339 |
Addsimps [mult_is_0]; |
|
340 |
||
5429 | 341 |
Goal "m <= m*(m::nat)"; |
4158 | 342 |
by (induct_tac "m" 1); |
343 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_assoc RS sym]))); |
|
344 |
by (etac (le_add2 RSN (2,le_trans)) 1); |
|
345 |
qed "le_square"; |
|
346 |
||
3234 | 347 |
|
348 |
(*** Difference ***) |
|
349 |
||
7007 | 350 |
Goal "m - m = 0"; |
351 |
by (induct_tac "m" 1); |
|
352 |
by (ALLGOALS Asm_simp_tac); |
|
353 |
qed "diff_self_eq_0"; |
|
3234 | 354 |
|
355 |
Addsimps [diff_self_eq_0]; |
|
356 |
||
357 |
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) |
|
5069 | 358 |
Goal "~ m<n --> n+(m-n) = (m::nat)"; |
3234 | 359 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
3352 | 360 |
by (ALLGOALS Asm_simp_tac); |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
361 |
qed_spec_mp "add_diff_inverse"; |
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
362 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
363 |
Goal "n<=m ==> n+(m-n) = (m::nat)"; |
4089 | 364 |
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
|
365 |
qed "le_add_diff_inverse"; |
3234 | 366 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
367 |
Goal "n<=m ==> (m-n)+n = (m::nat)"; |
4089 | 368 |
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
|
369 |
qed "le_add_diff_inverse2"; |
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
370 |
|
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
371 |
Addsimps [le_add_diff_inverse, le_add_diff_inverse2]; |
3234 | 372 |
|
373 |
||
374 |
(*** More results about difference ***) |
|
375 |
||
5414
8a458866637c
changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents:
5409
diff
changeset
|
376 |
Goal "n <= m ==> Suc(m)-n = Suc(m-n)"; |
5316 | 377 |
by (etac rev_mp 1); |
3352 | 378 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
379 |
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
|
380 |
qed "Suc_diff_le"; |
3352 | 381 |
|
5069 | 382 |
Goal "m - n < Suc(m)"; |
3234 | 383 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
384 |
by (etac less_SucE 3); |
|
4089 | 385 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq]))); |
3234 | 386 |
qed "diff_less_Suc"; |
387 |
||
5429 | 388 |
Goal "m - n <= (m::nat)"; |
3234 | 389 |
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); |
6075 | 390 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [le_SucI]))); |
3234 | 391 |
qed "diff_le_self"; |
3903
1b29151a1009
New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents:
3896
diff
changeset
|
392 |
Addsimps [diff_le_self]; |
3234 | 393 |
|
4732 | 394 |
(* j<k ==> j-n < k *) |
395 |
bind_thm ("less_imp_diff_less", diff_le_self RS le_less_trans); |
|
396 |
||
5069 | 397 |
Goal "!!i::nat. i-j-k = i - (j+k)"; |
3352 | 398 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
399 |
by (ALLGOALS Asm_simp_tac); |
|
400 |
qed "diff_diff_left"; |
|
401 |
||
5069 | 402 |
Goal "(Suc m - n) - Suc k = m - n - k"; |
4423 | 403 |
by (simp_tac (simpset() addsimps [diff_diff_left]) 1); |
4736 | 404 |
qed "Suc_diff_diff"; |
405 |
Addsimps [Suc_diff_diff]; |
|
4360 | 406 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
407 |
Goal "0<n ==> n - Suc i < n"; |
5183 | 408 |
by (exhaust_tac "n" 1); |
4732 | 409 |
by Safe_tac; |
5497 | 410 |
by (asm_simp_tac (simpset() addsimps le_simps) 1); |
4732 | 411 |
qed "diff_Suc_less"; |
412 |
Addsimps [diff_Suc_less]; |
|
413 |
||
3396 | 414 |
(*This and the next few suggested by Florian Kammueller*) |
5069 | 415 |
Goal "!!i::nat. i-j-k = i-k-j"; |
4089 | 416 |
by (simp_tac (simpset() addsimps [diff_diff_left, add_commute]) 1); |
3352 | 417 |
qed "diff_commute"; |
418 |
||
5429 | 419 |
Goal "k<=j --> j<=i --> i - (j - k) = i - j + (k::nat)"; |
3352 | 420 |
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1); |
421 |
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
|
422 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1); |
3352 | 423 |
qed_spec_mp "diff_diff_right"; |
424 |
||
5429 | 425 |
Goal "k <= (j::nat) --> (i + j) - k = i + (j - k)"; |
3352 | 426 |
by (res_inst_tac [("m","j"),("n","k")] diff_induct 1); |
427 |
by (ALLGOALS Asm_simp_tac); |
|
428 |
qed_spec_mp "diff_add_assoc"; |
|
429 |
||
5429 | 430 |
Goal "k <= (j::nat) --> (j + i) - k = i + (j - k)"; |
4732 | 431 |
by (asm_simp_tac (simpset() addsimps [add_commute, diff_add_assoc]) 1); |
432 |
qed_spec_mp "diff_add_assoc2"; |
|
433 |
||
5429 | 434 |
Goal "(n+m) - n = (m::nat)"; |
3339 | 435 |
by (induct_tac "n" 1); |
3234 | 436 |
by (ALLGOALS Asm_simp_tac); |
437 |
qed "diff_add_inverse"; |
|
438 |
Addsimps [diff_add_inverse]; |
|
439 |
||
5429 | 440 |
Goal "(m+n) - n = (m::nat)"; |
4089 | 441 |
by (simp_tac (simpset() addsimps [diff_add_assoc]) 1); |
3234 | 442 |
qed "diff_add_inverse2"; |
443 |
Addsimps [diff_add_inverse2]; |
|
444 |
||
5429 | 445 |
Goal "i <= (j::nat) ==> (j-i=k) = (j=k+i)"; |
3724 | 446 |
by Safe_tac; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
447 |
by (ALLGOALS Asm_simp_tac); |
3366 | 448 |
qed "le_imp_diff_is_add"; |
449 |
||
5356 | 450 |
Goal "(m-n = 0) = (m <= n)"; |
3234 | 451 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
5497 | 452 |
by (ALLGOALS Asm_simp_tac); |
5356 | 453 |
qed "diff_is_0_eq"; |
7059 | 454 |
|
455 |
Goal "(0 = m-n) = (m <= n)"; |
|
456 |
by (stac (diff_is_0_eq RS sym) 1); |
|
457 |
by (rtac eq_sym_conv 1); |
|
458 |
qed "zero_is_diff_eq"; |
|
459 |
Addsimps [diff_is_0_eq, zero_is_diff_eq]; |
|
3234 | 460 |
|
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
461 |
Goal "(0<n-m) = (m<n)"; |
3234 | 462 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
3352 | 463 |
by (ALLGOALS Asm_simp_tac); |
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
464 |
qed "zero_less_diff"; |
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
465 |
Addsimps [zero_less_diff]; |
3234 | 466 |
|
5333
ea33e66dcedd
Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents:
5329
diff
changeset
|
467 |
Goal "i < j ==> ? k. 0<k & i+k = j"; |
5078 | 468 |
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
|
469 |
by (asm_simp_tac (simpset() addsimps [add_diff_inverse, less_not_sym]) 1); |
5078 | 470 |
qed "less_imp_add_positive"; |
471 |
||
5069 | 472 |
Goal "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)"; |
3234 | 473 |
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); |
3718 | 474 |
by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac)); |
3234 | 475 |
qed "zero_induct_lemma"; |
476 |
||
5316 | 477 |
val prems = Goal "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; |
3234 | 478 |
by (rtac (diff_self_eq_0 RS subst) 1); |
479 |
by (rtac (zero_induct_lemma RS mp RS mp) 1); |
|
480 |
by (REPEAT (ares_tac ([impI,allI]@prems) 1)); |
|
481 |
qed "zero_induct"; |
|
482 |
||
5429 | 483 |
Goal "(k+m) - (k+n) = m - (n::nat)"; |
3339 | 484 |
by (induct_tac "k" 1); |
3234 | 485 |
by (ALLGOALS Asm_simp_tac); |
486 |
qed "diff_cancel"; |
|
487 |
Addsimps [diff_cancel]; |
|
488 |
||
5429 | 489 |
Goal "(m+k) - (n+k) = m - (n::nat)"; |
3234 | 490 |
val add_commute_k = read_instantiate [("n","k")] add_commute; |
5537 | 491 |
by (asm_simp_tac (simpset() addsimps [add_commute_k]) 1); |
3234 | 492 |
qed "diff_cancel2"; |
493 |
Addsimps [diff_cancel2]; |
|
494 |
||
5429 | 495 |
Goal "n - (n+m) = 0"; |
3339 | 496 |
by (induct_tac "n" 1); |
3234 | 497 |
by (ALLGOALS Asm_simp_tac); |
498 |
qed "diff_add_0"; |
|
499 |
Addsimps [diff_add_0]; |
|
500 |
||
5409 | 501 |
|
3234 | 502 |
(** Difference distributes over multiplication **) |
503 |
||
5069 | 504 |
Goal "!!m::nat. (m - n) * k = (m * k) - (n * k)"; |
3234 | 505 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
506 |
by (ALLGOALS Asm_simp_tac); |
|
507 |
qed "diff_mult_distrib" ; |
|
508 |
||
5069 | 509 |
Goal "!!m::nat. k * (m - n) = (k * m) - (k * n)"; |
3234 | 510 |
val mult_commute_k = read_instantiate [("m","k")] mult_commute; |
4089 | 511 |
by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1); |
3234 | 512 |
qed "diff_mult_distrib2" ; |
513 |
(*NOT added as rewrites, since sometimes they are used from right-to-left*) |
|
514 |
||
515 |
||
1713 | 516 |
(*** Monotonicity of Multiplication ***) |
517 |
||
5429 | 518 |
Goal "i <= (j::nat) ==> i*k<=j*k"; |
3339 | 519 |
by (induct_tac "k" 1); |
4089 | 520 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_le_mono]))); |
1713 | 521 |
qed "mult_le_mono1"; |
522 |
||
6987 | 523 |
Goal "i <= (j::nat) ==> k*i <= k*j"; |
524 |
by (dtac mult_le_mono1 1); |
|
525 |
by (asm_simp_tac (simpset() addsimps [mult_commute]) 1); |
|
526 |
qed "mult_le_mono2"; |
|
527 |
||
528 |
(* <= monotonicity, BOTH arguments*) |
|
5429 | 529 |
Goal "[| i <= (j::nat); k <= l |] ==> i*k <= j*l"; |
2007 | 530 |
by (etac (mult_le_mono1 RS le_trans) 1); |
6987 | 531 |
by (etac mult_le_mono2 1); |
1713 | 532 |
qed "mult_le_mono"; |
533 |
||
534 |
(*strict, in 1st argument; proof is by induction on k>0*) |
|
5429 | 535 |
Goal "[| i<j; 0<k |] ==> k*i < k*j"; |
5078 | 536 |
by (eres_inst_tac [("m1","0")] (less_eq_Suc_add RS exE) 1); |
1713 | 537 |
by (Asm_simp_tac 1); |
3339 | 538 |
by (induct_tac "x" 1); |
4089 | 539 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_less_mono]))); |
1713 | 540 |
qed "mult_less_mono2"; |
541 |
||
5429 | 542 |
Goal "[| i<j; 0<k |] ==> i*k < j*k"; |
3457 | 543 |
by (dtac mult_less_mono2 1); |
4089 | 544 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute]))); |
3234 | 545 |
qed "mult_less_mono1"; |
546 |
||
5069 | 547 |
Goal "(0 < m*n) = (0<m & 0<n)"; |
3339 | 548 |
by (induct_tac "m" 1); |
549 |
by (induct_tac "n" 2); |
|
1713 | 550 |
by (ALLGOALS Asm_simp_tac); |
551 |
qed "zero_less_mult_iff"; |
|
4356 | 552 |
Addsimps [zero_less_mult_iff]; |
1713 | 553 |
|
5069 | 554 |
Goal "(m*n = 1) = (m=1 & n=1)"; |
3339 | 555 |
by (induct_tac "m" 1); |
1795 | 556 |
by (Simp_tac 1); |
3339 | 557 |
by (induct_tac "n" 1); |
1795 | 558 |
by (Simp_tac 1); |
4089 | 559 |
by (fast_tac (claset() addss simpset()) 1); |
1795 | 560 |
qed "mult_eq_1_iff"; |
4356 | 561 |
Addsimps [mult_eq_1_iff]; |
1795 | 562 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
563 |
Goal "0<k ==> (m*k < n*k) = (m<n)"; |
4089 | 564 |
by (safe_tac (claset() addSIs [mult_less_mono1])); |
3234 | 565 |
by (cut_facts_tac [less_linear] 1); |
4389 | 566 |
by (blast_tac (claset() addIs [mult_less_mono1] addEs [less_asym]) 1); |
3234 | 567 |
qed "mult_less_cancel2"; |
568 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
569 |
Goal "0<k ==> (k*m < k*n) = (m<n)"; |
3457 | 570 |
by (dtac mult_less_cancel2 1); |
4089 | 571 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 572 |
qed "mult_less_cancel1"; |
573 |
Addsimps [mult_less_cancel1, mult_less_cancel2]; |
|
574 |
||
6864 | 575 |
Goal "0<k ==> (m*k <= n*k) = (m<=n)"; |
576 |
by (asm_full_simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1); |
|
577 |
qed "mult_le_cancel2"; |
|
578 |
||
579 |
Goal "0<k ==> (k*m <= k*n) = (m<=n)"; |
|
580 |
by (asm_full_simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1); |
|
581 |
qed "mult_le_cancel1"; |
|
582 |
Addsimps [mult_le_cancel1, mult_le_cancel2]; |
|
583 |
||
5069 | 584 |
Goal "(Suc k * m < Suc k * n) = (m < n)"; |
4423 | 585 |
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
|
586 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
587 |
qed "Suc_mult_less_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
588 |
|
5069 | 589 |
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
|
590 |
by (simp_tac (simpset_of HOL.thy) 1); |
4423 | 591 |
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
|
592 |
qed "Suc_mult_le_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
593 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
594 |
Goal "0<k ==> (m*k = n*k) = (m=n)"; |
3234 | 595 |
by (cut_facts_tac [less_linear] 1); |
3724 | 596 |
by Safe_tac; |
3457 | 597 |
by (assume_tac 2); |
3234 | 598 |
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac)); |
599 |
by (ALLGOALS Asm_full_simp_tac); |
|
600 |
qed "mult_cancel2"; |
|
601 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
602 |
Goal "0<k ==> (k*m = k*n) = (m=n)"; |
3457 | 603 |
by (dtac mult_cancel2 1); |
4089 | 604 |
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1); |
3234 | 605 |
qed "mult_cancel1"; |
606 |
Addsimps [mult_cancel1, mult_cancel2]; |
|
607 |
||
5069 | 608 |
Goal "(Suc k * m = Suc k * n) = (m = n)"; |
4423 | 609 |
by (rtac mult_cancel1 1); |
4297
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
610 |
by (Simp_tac 1); |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
611 |
qed "Suc_mult_cancel1"; |
5defc2105cc8
added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents:
4158
diff
changeset
|
612 |
|
3234 | 613 |
|
1795 | 614 |
(** Lemma for gcd **) |
615 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
616 |
Goal "m = m*n ==> n=1 | m=0"; |
1795 | 617 |
by (dtac sym 1); |
618 |
by (rtac disjCI 1); |
|
619 |
by (rtac nat_less_cases 1 THEN assume_tac 2); |
|
4089 | 620 |
by (fast_tac (claset() addSEs [less_SucE] addss simpset()) 1); |
4356 | 621 |
by (best_tac (claset() addDs [mult_less_mono2] addss simpset()) 1); |
1795 | 622 |
qed "mult_eq_self_implies_10"; |
623 |
||
624 |
||
5983 | 625 |
|
626 |
||
627 |
(*---------------------------------------------------------------------------*) |
|
628 |
(* Various arithmetic proof procedures *) |
|
629 |
(*---------------------------------------------------------------------------*) |
|
630 |
||
631 |
(*---------------------------------------------------------------------------*) |
|
632 |
(* 1. Cancellation of common terms *) |
|
633 |
(*---------------------------------------------------------------------------*) |
|
634 |
||
635 |
(* Title: HOL/arith_data.ML |
|
636 |
ID: $Id$ |
|
637 |
Author: Markus Wenzel and Stefan Berghofer, TU Muenchen |
|
638 |
||
639 |
Setup various arithmetic proof procedures. |
|
640 |
*) |
|
641 |
||
642 |
signature ARITH_DATA = |
|
643 |
sig |
|
6055 | 644 |
val nat_cancel_sums_add: simproc list |
5983 | 645 |
val nat_cancel_sums: simproc list |
646 |
val nat_cancel_factor: simproc list |
|
647 |
val nat_cancel: simproc list |
|
648 |
end; |
|
649 |
||
650 |
structure ArithData: ARITH_DATA = |
|
651 |
struct |
|
652 |
||
653 |
||
654 |
(** abstract syntax of structure nat: 0, Suc, + **) |
|
655 |
||
656 |
(* mk_sum, mk_norm_sum *) |
|
657 |
||
658 |
val one = HOLogic.mk_nat 1; |
|
659 |
val mk_plus = HOLogic.mk_binop "op +"; |
|
660 |
||
661 |
fun mk_sum [] = HOLogic.zero |
|
662 |
| mk_sum [t] = t |
|
663 |
| mk_sum (t :: ts) = mk_plus (t, mk_sum ts); |
|
664 |
||
665 |
(*normal form of sums: Suc (... (Suc (a + (b + ...))))*) |
|
666 |
fun mk_norm_sum ts = |
|
667 |
let val (ones, sums) = partition (equal one) ts in |
|
668 |
funpow (length ones) HOLogic.mk_Suc (mk_sum sums) |
|
669 |
end; |
|
670 |
||
671 |
||
672 |
(* dest_sum *) |
|
673 |
||
674 |
val dest_plus = HOLogic.dest_bin "op +" HOLogic.natT; |
|
675 |
||
676 |
fun dest_sum tm = |
|
677 |
if HOLogic.is_zero tm then [] |
|
678 |
else |
|
679 |
(case try HOLogic.dest_Suc tm of |
|
680 |
Some t => one :: dest_sum t |
|
681 |
| None => |
|
682 |
(case try dest_plus tm of |
|
683 |
Some (t, u) => dest_sum t @ dest_sum u |
|
684 |
| None => [tm])); |
|
685 |
||
686 |
||
687 |
(** generic proof tools **) |
|
688 |
||
689 |
(* prove conversions *) |
|
690 |
||
691 |
val mk_eqv = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
|
692 |
||
693 |
fun prove_conv expand_tac norm_tac sg (t, u) = |
|
694 |
mk_meta_eq (prove_goalw_cterm_nocheck [] (cterm_of sg (mk_eqv (t, u))) |
|
695 |
(K [expand_tac, norm_tac])) |
|
696 |
handle ERROR => error ("The error(s) above occurred while trying to prove " ^ |
|
697 |
(string_of_cterm (cterm_of sg (mk_eqv (t, u))))); |
|
698 |
||
699 |
val subst_equals = prove_goal HOL.thy "[| t = s; u = t |] ==> u = s" |
|
700 |
(fn prems => [cut_facts_tac prems 1, SIMPSET' asm_simp_tac 1]); |
|
701 |
||
702 |
||
703 |
(* rewriting *) |
|
704 |
||
705 |
fun simp_all rules = ALLGOALS (simp_tac (HOL_ss addsimps rules)); |
|
706 |
||
707 |
val add_rules = [add_Suc, add_Suc_right, add_0, add_0_right]; |
|
708 |
val mult_rules = [mult_Suc, mult_Suc_right, mult_0, mult_0_right]; |
|
709 |
||
710 |
||
711 |
||
712 |
(** cancel common summands **) |
|
713 |
||
714 |
structure Sum = |
|
715 |
struct |
|
716 |
val mk_sum = mk_norm_sum; |
|
717 |
val dest_sum = dest_sum; |
|
718 |
val prove_conv = prove_conv; |
|
719 |
val norm_tac = simp_all add_rules THEN simp_all add_ac; |
|
720 |
end; |
|
721 |
||
722 |
fun gen_uncancel_tac rule ct = |
|
723 |
rtac (instantiate' [] [None, Some ct] (rule RS subst_equals)) 1; |
|
724 |
||
725 |
||
726 |
(* nat eq *) |
|
727 |
||
728 |
structure EqCancelSums = CancelSumsFun |
|
729 |
(struct |
|
730 |
open Sum; |
|
731 |
val mk_bal = HOLogic.mk_eq; |
|
732 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT; |
|
733 |
val uncancel_tac = gen_uncancel_tac add_left_cancel; |
|
734 |
end); |
|
735 |
||
736 |
||
737 |
(* nat less *) |
|
738 |
||
739 |
structure LessCancelSums = CancelSumsFun |
|
740 |
(struct |
|
741 |
open Sum; |
|
742 |
val mk_bal = HOLogic.mk_binrel "op <"; |
|
743 |
val dest_bal = HOLogic.dest_bin "op <" HOLogic.natT; |
|
744 |
val uncancel_tac = gen_uncancel_tac add_left_cancel_less; |
|
745 |
end); |
|
746 |
||
747 |
||
748 |
(* nat le *) |
|
749 |
||
750 |
structure LeCancelSums = CancelSumsFun |
|
751 |
(struct |
|
752 |
open Sum; |
|
753 |
val mk_bal = HOLogic.mk_binrel "op <="; |
|
754 |
val dest_bal = HOLogic.dest_bin "op <=" HOLogic.natT; |
|
755 |
val uncancel_tac = gen_uncancel_tac add_left_cancel_le; |
|
756 |
end); |
|
757 |
||
758 |
||
759 |
(* nat diff *) |
|
760 |
||
761 |
structure DiffCancelSums = CancelSumsFun |
|
762 |
(struct |
|
763 |
open Sum; |
|
764 |
val mk_bal = HOLogic.mk_binop "op -"; |
|
765 |
val dest_bal = HOLogic.dest_bin "op -" HOLogic.natT; |
|
766 |
val uncancel_tac = gen_uncancel_tac diff_cancel; |
|
767 |
end); |
|
768 |
||
769 |
||
770 |
||
771 |
(** cancel common factor **) |
|
772 |
||
773 |
structure Factor = |
|
774 |
struct |
|
775 |
val mk_sum = mk_norm_sum; |
|
776 |
val dest_sum = dest_sum; |
|
777 |
val prove_conv = prove_conv; |
|
778 |
val norm_tac = simp_all (add_rules @ mult_rules) THEN simp_all add_ac; |
|
779 |
end; |
|
780 |
||
6394 | 781 |
fun mk_cnat n = cterm_of (Theory.sign_of Nat.thy) (HOLogic.mk_nat n); |
5983 | 782 |
|
783 |
fun gen_multiply_tac rule k = |
|
784 |
if k > 0 then |
|
785 |
rtac (instantiate' [] [None, Some (mk_cnat (k - 1))] (rule RS subst_equals)) 1 |
|
786 |
else no_tac; |
|
787 |
||
788 |
||
789 |
(* nat eq *) |
|
790 |
||
791 |
structure EqCancelFactor = CancelFactorFun |
|
792 |
(struct |
|
793 |
open Factor; |
|
794 |
val mk_bal = HOLogic.mk_eq; |
|
795 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT; |
|
796 |
val multiply_tac = gen_multiply_tac Suc_mult_cancel1; |
|
797 |
end); |
|
798 |
||
799 |
||
800 |
(* nat less *) |
|
801 |
||
802 |
structure LessCancelFactor = CancelFactorFun |
|
803 |
(struct |
|
804 |
open Factor; |
|
805 |
val mk_bal = HOLogic.mk_binrel "op <"; |
|
806 |
val dest_bal = HOLogic.dest_bin "op <" HOLogic.natT; |
|
807 |
val multiply_tac = gen_multiply_tac Suc_mult_less_cancel1; |
|
808 |
end); |
|
809 |
||
810 |
||
811 |
(* nat le *) |
|
812 |
||
813 |
structure LeCancelFactor = CancelFactorFun |
|
814 |
(struct |
|
815 |
open Factor; |
|
816 |
val mk_bal = HOLogic.mk_binrel "op <="; |
|
817 |
val dest_bal = HOLogic.dest_bin "op <=" HOLogic.natT; |
|
818 |
val multiply_tac = gen_multiply_tac Suc_mult_le_cancel1; |
|
819 |
end); |
|
820 |
||
821 |
||
822 |
||
823 |
(** prepare nat_cancel simprocs **) |
|
824 |
||
6394 | 825 |
fun prep_pat s = Thm.read_cterm (Theory.sign_of Arith.thy) (s, HOLogic.termTVar); |
5983 | 826 |
val prep_pats = map prep_pat; |
827 |
||
828 |
fun prep_simproc (name, pats, proc) = Simplifier.mk_simproc name pats proc; |
|
829 |
||
830 |
val eq_pats = prep_pats ["(l::nat) + m = n", "(l::nat) = m + n", "Suc m = n", "m = Suc n"]; |
|
831 |
val less_pats = prep_pats ["(l::nat) + m < n", "(l::nat) < m + n", "Suc m < n", "m < Suc n"]; |
|
832 |
val le_pats = prep_pats ["(l::nat) + m <= n", "(l::nat) <= m + n", "Suc m <= n", "m <= Suc n"]; |
|
833 |
val diff_pats = prep_pats ["((l::nat) + m) - n", "(l::nat) - (m + n)", "Suc m - n", "m - Suc n"]; |
|
834 |
||
6055 | 835 |
val nat_cancel_sums_add = map prep_simproc |
5983 | 836 |
[("nateq_cancel_sums", eq_pats, EqCancelSums.proc), |
837 |
("natless_cancel_sums", less_pats, LessCancelSums.proc), |
|
6055 | 838 |
("natle_cancel_sums", le_pats, LeCancelSums.proc)]; |
839 |
||
840 |
val nat_cancel_sums = nat_cancel_sums_add @ |
|
841 |
[prep_simproc("natdiff_cancel_sums", diff_pats, DiffCancelSums.proc)]; |
|
5983 | 842 |
|
843 |
val nat_cancel_factor = map prep_simproc |
|
844 |
[("nateq_cancel_factor", eq_pats, EqCancelFactor.proc), |
|
845 |
("natless_cancel_factor", less_pats, LessCancelFactor.proc), |
|
846 |
("natle_cancel_factor", le_pats, LeCancelFactor.proc)]; |
|
847 |
||
848 |
val nat_cancel = nat_cancel_factor @ nat_cancel_sums; |
|
849 |
||
850 |
||
851 |
end; |
|
852 |
||
853 |
open ArithData; |
|
854 |
||
855 |
Addsimprocs nat_cancel; |
|
856 |
||
857 |
(*---------------------------------------------------------------------------*) |
|
858 |
(* 2. Linear arithmetic *) |
|
859 |
(*---------------------------------------------------------------------------*) |
|
860 |
||
6101 | 861 |
(* Parameters data for general linear arithmetic functor *) |
862 |
||
863 |
structure LA_Logic: LIN_ARITH_LOGIC = |
|
5983 | 864 |
struct |
865 |
val ccontr = ccontr; |
|
866 |
val conjI = conjI; |
|
6101 | 867 |
val neqE = linorder_neqE; |
5983 | 868 |
val notI = notI; |
869 |
val sym = sym; |
|
6109 | 870 |
val not_lessD = linorder_not_less RS iffD1; |
6128 | 871 |
val not_leD = linorder_not_le RS iffD1; |
5983 | 872 |
|
6128 | 873 |
|
6968 | 874 |
fun mk_Eq thm = (thm RS Eq_FalseI) handle THM _ => (thm RS Eq_TrueI); |
6128 | 875 |
|
6073 | 876 |
val mk_Trueprop = HOLogic.mk_Trueprop; |
877 |
||
6079 | 878 |
fun neg_prop(TP$(Const("Not",_)$t)) = TP$t |
879 |
| neg_prop(TP$t) = TP $ (Const("Not",HOLogic.boolT-->HOLogic.boolT)$t); |
|
6073 | 880 |
|
6101 | 881 |
fun is_False thm = |
882 |
let val _ $ t = #prop(rep_thm thm) |
|
883 |
in t = Const("False",HOLogic.boolT) end; |
|
884 |
||
6128 | 885 |
fun is_nat(t) = fastype_of1 t = HOLogic.natT; |
886 |
||
887 |
fun mk_nat_thm sg t = |
|
888 |
let val ct = cterm_of sg t and cn = cterm_of sg (Var(("n",0),HOLogic.natT)) |
|
889 |
in instantiate ([],[(cn,ct)]) le0 end; |
|
890 |
||
6101 | 891 |
end; |
892 |
||
6128 | 893 |
structure Nat_LA_Data (* : LIN_ARITH_DATA *) = |
6101 | 894 |
struct |
895 |
||
6128 | 896 |
val lessD = [Suc_leI]; |
6101 | 897 |
|
6151 | 898 |
val dest_plus = HOLogic.dest_bin "op +" HOLogic.natT; |
899 |
||
5983 | 900 |
(* Turn term into list of summand * multiplicity plus a constant *) |
901 |
fun poly(Const("Suc",_)$t, (p,i)) = poly(t, (p,i+1)) |
|
6059
aa00e235ea27
In Main: moved Bin to the left to preserve the solver in its simpset.
nipkow
parents:
6055
diff
changeset
|
902 |
| poly(Const("op +",_) $ s $ t, pi) = poly(s,poly(t,pi)) |
5983 | 903 |
| poly(t,(p,i)) = |
6059
aa00e235ea27
In Main: moved Bin to the left to preserve the solver in its simpset.
nipkow
parents:
6055
diff
changeset
|
904 |
if t = Const("0",HOLogic.natT) then (p,i) |
5983 | 905 |
else (case assoc(p,t) of None => ((t,1)::p,i) |
906 |
| Some m => (overwrite(p,(t,m+1)), i)) |
|
6151 | 907 |
fun poly(t, pi as (p,i)) = |
908 |
if HOLogic.is_zero t then pi else |
|
909 |
(case try HOLogic.dest_Suc t of |
|
910 |
Some u => poly(u, (p,i+1)) |
|
911 |
| None => (case try dest_plus t of |
|
912 |
Some(r,s) => poly(r,poly(s,pi)) |
|
913 |
| None => (case assoc(p,t) of None => ((t,1)::p,i) |
|
914 |
| Some m => (overwrite(p,(t,m+1)), i)))) |
|
5983 | 915 |
|
6059
aa00e235ea27
In Main: moved Bin to the left to preserve the solver in its simpset.
nipkow
parents:
6055
diff
changeset
|
916 |
fun nnb T = T = ([HOLogic.natT,HOLogic.natT] ---> HOLogic.boolT); |
aa00e235ea27
In Main: moved Bin to the left to preserve the solver in its simpset.
nipkow
parents:
6055
diff
changeset
|
917 |
|
6128 | 918 |
fun decomp2(rel,lhs,rhs) = |
5983 | 919 |
let val (p,i) = poly(lhs,([],0)) and (q,j) = poly(rhs,([],0)) |
920 |
in case rel of |
|
921 |
"op <" => Some(p,i,"<",q,j) |
|
922 |
| "op <=" => Some(p,i,"<=",q,j) |
|
923 |
| "op =" => Some(p,i,"=",q,j) |
|
924 |
| _ => None |
|
925 |
end; |
|
926 |
||
927 |
fun negate(Some(x,i,rel,y,j)) = Some(x,i,"~"^rel,y,j) |
|
928 |
| negate None = None; |
|
929 |
||
6128 | 930 |
fun decomp1(T,xxx) = if nnb T then decomp2 xxx else None; |
931 |
||
932 |
fun decomp(_$(Const(rel,T)$lhs$rhs)) = decomp1(T,(rel,lhs,rhs)) |
|
5983 | 933 |
| decomp(_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) = |
6128 | 934 |
negate(decomp1(T,(rel,lhs,rhs))) |
5983 | 935 |
| decomp _ = None |
6055 | 936 |
|
5983 | 937 |
(* reduce contradictory <= to False. |
938 |
Most of the work is done by the cancel tactics. |
|
939 |
*) |
|
6151 | 940 |
val add_rules = [add_0,add_0_right,Zero_not_Suc,Suc_not_Zero,le_0_eq]; |
5983 | 941 |
|
942 |
val cancel_sums_ss = HOL_basic_ss addsimps add_rules |
|
6055 | 943 |
addsimprocs nat_cancel_sums_add; |
5983 | 944 |
|
945 |
val simp = simplify cancel_sums_ss; |
|
946 |
||
947 |
val add_mono_thms = map (fn s => prove_goal Arith.thy s |
|
948 |
(fn prems => [cut_facts_tac prems 1, |
|
949 |
blast_tac (claset() addIs [add_le_mono]) 1])) |
|
950 |
["(i <= j) & (k <= l) ==> i + k <= j + (l::nat)", |
|
6055 | 951 |
"(i = j) & (k <= l) ==> i + k <= j + (l::nat)", |
952 |
"(i <= j) & (k = l) ==> i + k <= j + (l::nat)", |
|
953 |
"(i = j) & (k = l) ==> i + k = j + (l::nat)" |
|
5983 | 954 |
]; |
955 |
||
6128 | 956 |
end; |
6055 | 957 |
|
6128 | 958 |
structure LA_Data_Ref = |
959 |
struct |
|
960 |
val add_mono_thms = ref Nat_LA_Data.add_mono_thms |
|
961 |
val lessD = ref Nat_LA_Data.lessD |
|
962 |
val decomp = ref Nat_LA_Data.decomp |
|
963 |
val simp = ref Nat_LA_Data.simp |
|
5983 | 964 |
end; |
965 |
||
6128 | 966 |
structure Fast_Arith = |
967 |
Fast_Lin_Arith(structure LA_Logic=LA_Logic and LA_Data=LA_Data_Ref); |
|
5983 | 968 |
|
6128 | 969 |
val fast_arith_tac = Fast_Arith.lin_arith_tac; |
6073 | 970 |
|
6128 | 971 |
val nat_arith_simproc_pats = |
6394 | 972 |
map (fn s => Thm.read_cterm (Theory.sign_of Arith.thy) (s, HOLogic.boolT)) |
6128 | 973 |
["(m::nat) < n","(m::nat) <= n", "(m::nat) = n"]; |
5983 | 974 |
|
6128 | 975 |
val fast_nat_arith_simproc = mk_simproc "fast_nat_arith" nat_arith_simproc_pats |
976 |
Fast_Arith.lin_arith_prover; |
|
6073 | 977 |
|
978 |
Addsimprocs [fast_nat_arith_simproc]; |
|
979 |
||
980 |
(* Because of fast_nat_arith_simproc, the arithmetic solver is really only |
|
981 |
useful to detect inconsistencies among the premises for subgoals which are |
|
982 |
*not* themselves (in)equalities, because the latter activate |
|
983 |
fast_nat_arith_simproc anyway. However, it seems cheaper to activate the |
|
984 |
solver all the time rather than add the additional check. *) |
|
985 |
||
6128 | 986 |
simpset_ref () := (simpset() addSolver Fast_Arith.cut_lin_arith_tac); |
6055 | 987 |
|
988 |
(* Elimination of `-' on nat due to John Harrison *) |
|
989 |
Goal "P(a - b::nat) = (!d. (b = a + d --> P 0) & (a = b + d --> P d))"; |
|
6301 | 990 |
by (case_tac "a <= b" 1); |
7059 | 991 |
by Auto_tac; |
6301 | 992 |
by (eres_inst_tac [("x","b-a")] allE 1); |
7059 | 993 |
by (asm_simp_tac (simpset() addsimps [diff_is_0_eq RS iffD2]) 1); |
6055 | 994 |
qed "nat_diff_split"; |
995 |
||
996 |
(* FIXME: K true should be replaced by a sensible test to speed things up |
|
6157 | 997 |
in case there are lots of irrelevant terms involved; |
998 |
elimination of min/max can be optimized: |
|
999 |
(max m n + k <= r) = (m+k <= r & n+k <= r) |
|
1000 |
(l <= min m n + k) = (l <= m+k & l <= n+k) |
|
6055 | 1001 |
*) |
6128 | 1002 |
val arith_tac = |
6157 | 1003 |
refute_tac (K true) (REPEAT o split_tac[nat_diff_split,split_min,split_max]) |
1004 |
((REPEAT_DETERM o etac linorder_neqE) THEN' fast_arith_tac); |
|
6055 | 1005 |
|
7131 | 1006 |
|
1007 |
(* proof method setup *) |
|
1008 |
||
1009 |
val arith_method = Method.METHOD (fn facts => FIRSTGOAL (Method.same_tac facts THEN' arith_tac)); |
|
1010 |
||
1011 |
val arith_setup = |
|
1012 |
[Method.add_methods |
|
1013 |
[("arith", Method.no_args arith_method, "decide linear arithmethic")]]; |
|
1014 |
||
5983 | 1015 |
(*---------------------------------------------------------------------------*) |
1016 |
(* End of proof procedures. Now go and USE them! *) |
|
1017 |
(*---------------------------------------------------------------------------*) |
|
1018 |
||
4736 | 1019 |
(*** Subtraction laws -- mostly from Clemens Ballarin ***) |
3234 | 1020 |
|
5429 | 1021 |
Goal "[| a < (b::nat); c <= a |] ==> a-c < b-c"; |
6301 | 1022 |
by (arith_tac 1); |
3234 | 1023 |
qed "diff_less_mono"; |
1024 |
||
5429 | 1025 |
Goal "a+b < (c::nat) ==> a < c-b"; |
6301 | 1026 |
by (arith_tac 1); |
3234 | 1027 |
qed "add_less_imp_less_diff"; |
1028 |
||
5427 | 1029 |
Goal "(i < j-k) = (i+k < (j::nat))"; |
6301 | 1030 |
by (arith_tac 1); |
5427 | 1031 |
qed "less_diff_conv"; |
1032 |
||
5497 | 1033 |
Goal "(j-k <= (i::nat)) = (j <= i+k)"; |
6301 | 1034 |
by (arith_tac 1); |
5485 | 1035 |
qed "le_diff_conv"; |
1036 |
||
5497 | 1037 |
Goal "k <= j ==> (i <= j-k) = (i+k <= (j::nat))"; |
6301 | 1038 |
by (arith_tac 1); |
5497 | 1039 |
qed "le_diff_conv2"; |
1040 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5078
diff
changeset
|
1041 |
Goal "Suc i <= n ==> Suc (n - Suc i) = n - i"; |
6301 | 1042 |
by (arith_tac 1); |
3234 | 1043 |
qed "Suc_diff_Suc"; |
1044 |
||
5429 | 1045 |
Goal "i <= (n::nat) ==> n - (n - i) = i"; |
6301 | 1046 |
by (arith_tac 1); |
3234 | 1047 |
qed "diff_diff_cancel"; |
3381
2bac33ec2b0d
New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents:
3366
diff
changeset
|
1048 |
Addsimps [diff_diff_cancel]; |
3234 | 1049 |
|
5429 | 1050 |
Goal "k <= (n::nat) ==> m <= n + m - k"; |
6301 | 1051 |
by (arith_tac 1); |
3234 | 1052 |
qed "le_add_diff"; |
1053 |
||
6055 | 1054 |
Goal "[| 0<k; j<i |] ==> j+k-i < k"; |
6301 | 1055 |
by (arith_tac 1); |
6055 | 1056 |
qed "add_diff_less"; |
3234 | 1057 |
|
5356 | 1058 |
Goal "m-1 < n ==> m <= n"; |
6301 | 1059 |
by (arith_tac 1); |
5356 | 1060 |
qed "pred_less_imp_le"; |
1061 |
||
1062 |
Goal "j<=i ==> i - j < Suc i - j"; |
|
6301 | 1063 |
by (arith_tac 1); |
5356 | 1064 |
qed "diff_less_Suc_diff"; |
1065 |
||
1066 |
Goal "i - j <= Suc i - j"; |
|
6301 | 1067 |
by (arith_tac 1); |
5356 | 1068 |
qed "diff_le_Suc_diff"; |
1069 |
AddIffs [diff_le_Suc_diff]; |
|
1070 |
||
1071 |
Goal "n - Suc i <= n - i"; |
|
6301 | 1072 |
by (arith_tac 1); |
5356 | 1073 |
qed "diff_Suc_le_diff"; |
1074 |
AddIffs [diff_Suc_le_diff]; |
|
1075 |
||
5409 | 1076 |
Goal "0 < n ==> (m <= n-1) = (m<n)"; |
6301 | 1077 |
by (arith_tac 1); |
5409 | 1078 |
qed "le_pred_eq"; |
1079 |
||
1080 |
Goal "0 < n ==> (m-1 < n) = (m<=n)"; |
|
6301 | 1081 |
by (arith_tac 1); |
5409 | 1082 |
qed "less_pred_eq"; |
1083 |
||
7059 | 1084 |
(*Replaces the previous diff_less and le_diff_less, which had the stronger |
1085 |
second premise n<=m*) |
|
1086 |
Goal "[| 0<n; 0<m |] ==> m - n < m"; |
|
6301 | 1087 |
by (arith_tac 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
|
1088 |
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
|
1089 |
|
4732 | 1090 |
|
7128 | 1091 |
(*** Reducting subtraction to addition ***) |
1092 |
||
1093 |
(*Intended for use with linear arithmetic, but useful in its own right*) |
|
1094 |
Goal "P (x-y) = (ALL z. (x<y --> P 0) & (x = y+z --> P z))"; |
|
1095 |
by (case_tac "x<y" 1); |
|
1096 |
by (auto_tac (claset(), simpset() addsimps [diff_is_0_eq RS iffD2])); |
|
1097 |
qed "split_diff"; |
|
1098 |
||
1099 |
val remove_diff_ss = |
|
1100 |
simpset() |
|
1101 |
delsimps ex_simps@all_simps |
|
1102 |
addsimps [le_diff_conv2, le_diff_conv, le_imp_diff_is_add, |
|
1103 |
diff_diff_right] |
|
1104 |
addcongs [conj_cong] |
|
1105 |
addsplits [split_diff]; |
|
1106 |
||
1107 |
Goal "n<=(l::nat) --> Suc l - n + m = Suc (l - n + m)"; |
|
1108 |
by (simp_tac remove_diff_ss 1); |
|
1109 |
qed_spec_mp "Suc_diff_add_le"; |
|
1110 |
||
1111 |
Goal "i<n ==> n - Suc i < n - i"; |
|
1112 |
by (asm_simp_tac remove_diff_ss 1); |
|
1113 |
qed "diff_Suc_less_diff"; |
|
1114 |
||
1115 |
Goal "Suc(m)-n = (if m<n then 0 else Suc(m-n))"; |
|
1116 |
by (simp_tac remove_diff_ss 1); |
|
1117 |
qed "if_Suc_diff_le"; |
|
1118 |
||
1119 |
Goal "Suc(m)-n <= Suc(m-n)"; |
|
1120 |
by (simp_tac remove_diff_ss 1); |
|
1121 |
qed "diff_Suc_le_Suc_diff"; |
|
1122 |
||
1123 |
Goal "[| k<=n; n<=m |] ==> (m-k) - (n-k) = m-(n::nat)"; |
|
1124 |
by (asm_simp_tac remove_diff_ss 1); |
|
1125 |
qed "diff_right_cancel"; |
|
1126 |
||
1127 |
||
7108 | 1128 |
(** (Anti)Monotonicity of subtraction -- by Stephan Merz **) |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
1129 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
1130 |
(* Monotonicity of subtraction in first argument *) |
6055 | 1131 |
Goal "m <= (n::nat) ==> (m-l) <= (n-l)"; |
7128 | 1132 |
by (asm_simp_tac remove_diff_ss 1); |
6055 | 1133 |
qed "diff_le_mono"; |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
1134 |
|
5429 | 1135 |
Goal "m <= (n::nat) ==> (l-n) <= (l-m)"; |
7128 | 1136 |
by (asm_simp_tac remove_diff_ss 1); |
6055 | 1137 |
qed "diff_le_mono2"; |
5983 | 1138 |
|
1139 |
(*This proof requires natdiff_cancel_sums*) |
|
6055 | 1140 |
Goal "[| m < (n::nat); m<l |] ==> (l-n) < (l-m)"; |
7128 | 1141 |
by (asm_simp_tac remove_diff_ss 1); |
6055 | 1142 |
qed "diff_less_mono2"; |
5983 | 1143 |
|
6055 | 1144 |
Goal "[| m-n = 0; n-m = 0 |] ==> m=n"; |
7128 | 1145 |
by (asm_full_simp_tac remove_diff_ss 1); |
6055 | 1146 |
qed "diffs0_imp_equal"; |