author | paulson |
Mon, 26 May 1997 12:38:29 +0200 | |
changeset 3342 | ec3b55fcb165 |
parent 3339 | cfa72a70f2b5 |
child 3352 | 04502e5431fb |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/Arith.ML |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
6 |
Proofs about elementary arithmetic: addition, multiplication, etc. |
|
3234 | 7 |
Some from the Hoare example from Norbert Galm |
923 | 8 |
*) |
9 |
||
10 |
open Arith; |
|
11 |
||
12 |
(*** Basic rewrite rules for the arithmetic operators ***) |
|
13 |
||
2099 | 14 |
goalw Arith.thy [pred_def] "pred 0 = 0"; |
15 |
by(Simp_tac 1); |
|
16 |
qed "pred_0"; |
|
17 |
||
18 |
goalw Arith.thy [pred_def] "pred(Suc n) = n"; |
|
19 |
by(Simp_tac 1); |
|
20 |
qed "pred_Suc"; |
|
21 |
||
2682
13cdbf95ed92
minor changes due to new primrec definitions for +,-,*
pusch
parents:
2498
diff
changeset
|
22 |
Addsimps [pred_0,pred_Suc]; |
1301 | 23 |
|
24 |
(** pred **) |
|
25 |
||
26 |
val prems = goal Arith.thy "n ~= 0 ==> Suc(pred n) = n"; |
|
1552 | 27 |
by (res_inst_tac [("n","n")] natE 1); |
28 |
by (cut_facts_tac prems 1); |
|
29 |
by (ALLGOALS Asm_full_simp_tac); |
|
1301 | 30 |
qed "Suc_pred"; |
31 |
Addsimps [Suc_pred]; |
|
923 | 32 |
|
33 |
(** Difference **) |
|
34 |
||
2682
13cdbf95ed92
minor changes due to new primrec definitions for +,-,*
pusch
parents:
2498
diff
changeset
|
35 |
qed_goalw "diff_0_eq_0" Arith.thy [pred_def] |
923 | 36 |
"0 - n = 0" |
3339 | 37 |
(fn _ => [induct_tac "n" 1, ALLGOALS Asm_simp_tac]); |
923 | 38 |
|
39 |
(*Must simplify BEFORE the induction!! (Else we get a critical pair) |
|
40 |
Suc(m) - Suc(n) rewrites to pred(Suc(m) - n) *) |
|
2682
13cdbf95ed92
minor changes due to new primrec definitions for +,-,*
pusch
parents:
2498
diff
changeset
|
41 |
qed_goalw "diff_Suc_Suc" Arith.thy [pred_def] |
923 | 42 |
"Suc(m) - Suc(n) = m - n" |
43 |
(fn _ => |
|
3339 | 44 |
[Simp_tac 1, induct_tac "n" 1, ALLGOALS Asm_simp_tac]); |
923 | 45 |
|
2682
13cdbf95ed92
minor changes due to new primrec definitions for +,-,*
pusch
parents:
2498
diff
changeset
|
46 |
Addsimps [diff_0_eq_0, diff_Suc_Suc]; |
923 | 47 |
|
48 |
||
49 |
(**** Inductive properties of the operators ****) |
|
50 |
||
51 |
(*** Addition ***) |
|
52 |
||
53 |
qed_goal "add_0_right" Arith.thy "m + 0 = m" |
|
3339 | 54 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 55 |
|
56 |
qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)" |
|
3339 | 57 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 58 |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
59 |
Addsimps [add_0_right,add_Suc_right]; |
923 | 60 |
|
61 |
(*Associative law for addition*) |
|
62 |
qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)" |
|
3339 | 63 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 64 |
|
65 |
(*Commutative law for addition*) |
|
66 |
qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)" |
|
3339 | 67 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 68 |
|
69 |
qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)" |
|
70 |
(fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1, |
|
71 |
rtac (add_commute RS arg_cong) 1]); |
|
72 |
||
73 |
(*Addition is an AC-operator*) |
|
74 |
val add_ac = [add_assoc, add_commute, add_left_commute]; |
|
75 |
||
76 |
goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)"; |
|
3339 | 77 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
78 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
79 |
by (Asm_simp_tac 1); |
923 | 80 |
qed "add_left_cancel"; |
81 |
||
82 |
goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)"; |
|
3339 | 83 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
84 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
85 |
by (Asm_simp_tac 1); |
923 | 86 |
qed "add_right_cancel"; |
87 |
||
88 |
goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)"; |
|
3339 | 89 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
90 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
91 |
by (Asm_simp_tac 1); |
923 | 92 |
qed "add_left_cancel_le"; |
93 |
||
94 |
goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)"; |
|
3339 | 95 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
96 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
97 |
by (Asm_simp_tac 1); |
923 | 98 |
qed "add_left_cancel_less"; |
99 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
100 |
Addsimps [add_left_cancel, add_right_cancel, |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
101 |
add_left_cancel_le, add_left_cancel_less]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
102 |
|
3339 | 103 |
(** Reasoning about m+0=0, etc. **) |
104 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
105 |
goal Arith.thy "(m+n = 0) = (m=0 & n=0)"; |
3339 | 106 |
by (induct_tac "m" 1); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
107 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
108 |
qed "add_is_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
109 |
Addsimps [add_is_0]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
110 |
|
3293 | 111 |
goal Arith.thy "(pred (m+n) = 0) = (m=0 & pred n = 0 | pred m = 0 & n=0)"; |
3339 | 112 |
by (induct_tac "m" 1); |
3293 | 113 |
by (ALLGOALS (fast_tac (!claset addss (!simpset)))); |
114 |
qed "pred_add_is_0"; |
|
115 |
Addsimps [pred_add_is_0]; |
|
116 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
117 |
goal Arith.thy "!!n. n ~= 0 ==> m + pred n = pred(m+n)"; |
3339 | 118 |
by (induct_tac "m" 1); |
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
119 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
120 |
qed "add_pred"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
121 |
Addsimps [add_pred]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
122 |
|
1626 | 123 |
|
923 | 124 |
(**** Additional theorems about "less than" ****) |
125 |
||
3339 | 126 |
goal Arith.thy "i<j --> (EX k. j = Suc(i+k))"; |
127 |
by (induct_tac "j" 1); |
|
1909 | 128 |
by (Simp_tac 1); |
3339 | 129 |
by (blast_tac (!claset addSEs [less_SucE] |
130 |
addSIs [add_0_right RS sym, add_Suc_right RS sym]) 1); |
|
1909 | 131 |
val lemma = result(); |
132 |
||
3339 | 133 |
(* [| i<j; !!x. j = Suc(i+x) ==> Q |] ==> Q *) |
134 |
bind_thm ("less_natE", lemma RS mp RS exE); |
|
135 |
||
923 | 136 |
goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))"; |
3339 | 137 |
by (induct_tac "n" 1); |
1909 | 138 |
by (ALLGOALS (simp_tac (!simpset addsimps [less_Suc_eq]))); |
3339 | 139 |
by (blast_tac (!claset addSEs [less_SucE] |
140 |
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
|
141 |
qed_spec_mp "less_eq_Suc_add"; |
923 | 142 |
|
143 |
goal Arith.thy "n <= ((m + n)::nat)"; |
|
3339 | 144 |
by (induct_tac "m" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
145 |
by (ALLGOALS Simp_tac); |
923 | 146 |
by (etac le_trans 1); |
147 |
by (rtac (lessI RS less_imp_le) 1); |
|
148 |
qed "le_add2"; |
|
149 |
||
150 |
goal Arith.thy "n <= ((n + m)::nat)"; |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
151 |
by (simp_tac (!simpset addsimps add_ac) 1); |
923 | 152 |
by (rtac le_add2 1); |
153 |
qed "le_add1"; |
|
154 |
||
155 |
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); |
|
156 |
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); |
|
157 |
||
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 |
||
1152 | 170 |
goal Arith.thy "!!i. 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); |
2922 | 174 |
by (blast_tac (!claset addDs [Suc_lessD]) 1); |
1152 | 175 |
qed "add_lessD1"; |
176 |
||
3234 | 177 |
goal Arith.thy "!!i::nat. ~ (i+j < i)"; |
178 |
br notI 1; |
|
179 |
be (add_lessD1 RS less_irrefl) 1; |
|
180 |
qed "not_add_less1"; |
|
181 |
||
182 |
goal Arith.thy "!!i::nat. ~ (j+i < i)"; |
|
183 |
by (simp_tac (!simpset addsimps [add_commute, not_add_less1]) 1); |
|
184 |
qed "not_add_less2"; |
|
185 |
AddIffs [not_add_less1, not_add_less2]; |
|
186 |
||
923 | 187 |
goal Arith.thy "!!k::nat. m <= n ==> m <= n+k"; |
1552 | 188 |
by (etac le_trans 1); |
189 |
by (rtac le_add1 1); |
|
923 | 190 |
qed "le_imp_add_le"; |
191 |
||
192 |
goal Arith.thy "!!k::nat. m < n ==> m < n+k"; |
|
1552 | 193 |
by (etac less_le_trans 1); |
194 |
by (rtac le_add1 1); |
|
923 | 195 |
qed "less_imp_add_less"; |
196 |
||
197 |
goal Arith.thy "m+k<=n --> m<=(n::nat)"; |
|
3339 | 198 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
199 |
by (ALLGOALS Asm_simp_tac); |
2922 | 200 |
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
|
201 |
qed_spec_mp "add_leD1"; |
923 | 202 |
|
2498 | 203 |
goal Arith.thy "!!n::nat. m+k<=n ==> k<=n"; |
204 |
by (full_simp_tac (!simpset addsimps [add_commute]) 1); |
|
205 |
by (etac add_leD1 1); |
|
206 |
qed_spec_mp "add_leD2"; |
|
207 |
||
208 |
goal Arith.thy "!!n::nat. m+k<=n ==> m<=n & k<=n"; |
|
2922 | 209 |
by (blast_tac (!claset addDs [add_leD1, add_leD2]) 1); |
2498 | 210 |
bind_thm ("add_leE", result() RS conjE); |
211 |
||
923 | 212 |
goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n"; |
1786
8a31d85d27b8
best_tac, deepen_tac and safe_tac now also use default claset.
berghofe
parents:
1767
diff
changeset
|
213 |
by (safe_tac (!claset addSDs [less_eq_Suc_add])); |
923 | 214 |
by (asm_full_simp_tac |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
215 |
(!simpset delsimps [add_Suc_right] |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
216 |
addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1); |
1552 | 217 |
by (etac subst 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
218 |
by (simp_tac (!simpset addsimps [less_add_Suc1]) 1); |
923 | 219 |
qed "less_add_eq_less"; |
220 |
||
221 |
||
1713 | 222 |
(*** Monotonicity of Addition ***) |
923 | 223 |
|
224 |
(*strict, in 1st argument*) |
|
225 |
goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k"; |
|
3339 | 226 |
by (induct_tac "k" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
227 |
by (ALLGOALS Asm_simp_tac); |
923 | 228 |
qed "add_less_mono1"; |
229 |
||
230 |
(*strict, in both arguments*) |
|
231 |
goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l"; |
|
232 |
by (rtac (add_less_mono1 RS less_trans) 1); |
|
1198 | 233 |
by (REPEAT (assume_tac 1)); |
3339 | 234 |
by (induct_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
235 |
by (ALLGOALS Asm_simp_tac); |
923 | 236 |
qed "add_less_mono"; |
237 |
||
238 |
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) |
|
239 |
val [lt_mono,le] = goal Arith.thy |
|
1465 | 240 |
"[| !!i j::nat. i<j ==> f(i) < f(j); \ |
241 |
\ i <= j \ |
|
923 | 242 |
\ |] ==> f(i) <= (f(j)::nat)"; |
243 |
by (cut_facts_tac [le] 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
244 |
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1); |
2922 | 245 |
by (blast_tac (!claset addSIs [lt_mono]) 1); |
923 | 246 |
qed "less_mono_imp_le_mono"; |
247 |
||
248 |
(*non-strict, in 1st argument*) |
|
249 |
goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k"; |
|
250 |
by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1); |
|
1552 | 251 |
by (etac add_less_mono1 1); |
923 | 252 |
by (assume_tac 1); |
253 |
qed "add_le_mono1"; |
|
254 |
||
255 |
(*non-strict, in both arguments*) |
|
256 |
goal Arith.thy "!!k l::nat. [|i<=j; k<=l |] ==> i + k <= j + l"; |
|
257 |
by (etac (add_le_mono1 RS le_trans) 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
258 |
by (simp_tac (!simpset addsimps [add_commute]) 1); |
923 | 259 |
(*j moves to the end because it is free while k, l are bound*) |
1552 | 260 |
by (etac add_le_mono1 1); |
923 | 261 |
qed "add_le_mono"; |
1713 | 262 |
|
3234 | 263 |
|
264 |
(*** Multiplication ***) |
|
265 |
||
266 |
(*right annihilation in product*) |
|
267 |
qed_goal "mult_0_right" Arith.thy "m * 0 = 0" |
|
3339 | 268 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 269 |
|
3293 | 270 |
(*right successor law for multiplication*) |
3234 | 271 |
qed_goal "mult_Suc_right" Arith.thy "m * Suc(n) = m + (m * n)" |
3339 | 272 |
(fn _ => [induct_tac "m" 1, |
3234 | 273 |
ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); |
274 |
||
3293 | 275 |
Addsimps [mult_0_right, mult_Suc_right]; |
3234 | 276 |
|
277 |
goal Arith.thy "1 * n = n"; |
|
278 |
by (Asm_simp_tac 1); |
|
279 |
qed "mult_1"; |
|
280 |
||
281 |
goal Arith.thy "n * 1 = n"; |
|
282 |
by (Asm_simp_tac 1); |
|
283 |
qed "mult_1_right"; |
|
284 |
||
285 |
(*Commutative law for multiplication*) |
|
286 |
qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)" |
|
3339 | 287 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 288 |
|
289 |
(*addition distributes over multiplication*) |
|
290 |
qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)" |
|
3339 | 291 |
(fn _ => [induct_tac "m" 1, |
3234 | 292 |
ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); |
293 |
||
294 |
qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)" |
|
3339 | 295 |
(fn _ => [induct_tac "m" 1, |
3234 | 296 |
ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); |
297 |
||
298 |
(*Associative law for multiplication*) |
|
299 |
qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)" |
|
3339 | 300 |
(fn _ => [induct_tac "m" 1, |
3234 | 301 |
ALLGOALS (asm_simp_tac (!simpset addsimps [add_mult_distrib]))]); |
302 |
||
303 |
qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)" |
|
304 |
(fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1, |
|
305 |
rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]); |
|
306 |
||
307 |
val mult_ac = [mult_assoc,mult_commute,mult_left_commute]; |
|
308 |
||
3293 | 309 |
goal Arith.thy "(m*n = 0) = (m=0 | n=0)"; |
3339 | 310 |
by (induct_tac "m" 1); |
311 |
by (induct_tac "n" 2); |
|
3293 | 312 |
by (ALLGOALS Asm_simp_tac); |
313 |
qed "mult_is_0"; |
|
314 |
Addsimps [mult_is_0]; |
|
315 |
||
3234 | 316 |
|
317 |
(*** Difference ***) |
|
318 |
||
319 |
qed_goal "pred_Suc_diff" Arith.thy "pred(Suc m - n) = m - n" |
|
3339 | 320 |
(fn _ => [induct_tac "n" 1, ALLGOALS Asm_simp_tac]); |
3234 | 321 |
Addsimps [pred_Suc_diff]; |
322 |
||
323 |
qed_goal "diff_self_eq_0" Arith.thy "m - m = 0" |
|
3339 | 324 |
(fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]); |
3234 | 325 |
Addsimps [diff_self_eq_0]; |
326 |
||
327 |
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) |
|
328 |
val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)"; |
|
329 |
by (rtac (prem RS rev_mp) 1); |
|
330 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
331 |
by (ALLGOALS (Asm_simp_tac)); |
|
332 |
qed "add_diff_inverse"; |
|
333 |
||
334 |
Delsimps [diff_Suc]; |
|
335 |
||
336 |
||
337 |
(*** More results about difference ***) |
|
338 |
||
339 |
goal Arith.thy "m - n < Suc(m)"; |
|
340 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
341 |
by (etac less_SucE 3); |
|
342 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [less_Suc_eq]))); |
|
343 |
qed "diff_less_Suc"; |
|
344 |
||
345 |
goal Arith.thy "!!m::nat. m - n <= m"; |
|
346 |
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); |
|
347 |
by (ALLGOALS Asm_simp_tac); |
|
348 |
qed "diff_le_self"; |
|
349 |
||
350 |
goal Arith.thy "!!n::nat. (n+m) - n = m"; |
|
3339 | 351 |
by (induct_tac "n" 1); |
3234 | 352 |
by (ALLGOALS Asm_simp_tac); |
353 |
qed "diff_add_inverse"; |
|
354 |
Addsimps [diff_add_inverse]; |
|
355 |
||
356 |
goal Arith.thy "!!n::nat.(m+n) - n = m"; |
|
357 |
by (res_inst_tac [("m1","m")] (add_commute RS ssubst) 1); |
|
358 |
by (REPEAT (ares_tac [diff_add_inverse] 1)); |
|
359 |
qed "diff_add_inverse2"; |
|
360 |
Addsimps [diff_add_inverse2]; |
|
361 |
||
362 |
val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0"; |
|
363 |
by (rtac (prem RS rev_mp) 1); |
|
364 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
365 |
by (asm_simp_tac (!simpset addsimps [less_Suc_eq]) 1); |
|
366 |
by (ALLGOALS (Asm_simp_tac)); |
|
367 |
qed "less_imp_diff_is_0"; |
|
368 |
||
369 |
val prems = goal Arith.thy "m-n = 0 --> n-m = 0 --> m=n"; |
|
370 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
371 |
by (REPEAT(Simp_tac 1 THEN TRY(atac 1))); |
|
372 |
qed_spec_mp "diffs0_imp_equal"; |
|
373 |
||
374 |
val [prem] = goal Arith.thy "m<n ==> 0<n-m"; |
|
375 |
by (rtac (prem RS rev_mp) 1); |
|
376 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
377 |
by (ALLGOALS (Asm_simp_tac)); |
|
378 |
qed "less_imp_diff_positive"; |
|
379 |
||
380 |
val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)"; |
|
381 |
by (rtac (prem RS rev_mp) 1); |
|
382 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
383 |
by (ALLGOALS (Asm_simp_tac)); |
|
384 |
qed "Suc_diff_n"; |
|
385 |
||
386 |
goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))"; |
|
387 |
by (simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n] |
|
388 |
setloop (split_tac [expand_if])) 1); |
|
389 |
qed "if_Suc_diff_n"; |
|
390 |
||
391 |
goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)"; |
|
392 |
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); |
|
393 |
by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o Blast_tac)); |
|
394 |
qed "zero_induct_lemma"; |
|
395 |
||
396 |
val prems = goal Arith.thy "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; |
|
397 |
by (rtac (diff_self_eq_0 RS subst) 1); |
|
398 |
by (rtac (zero_induct_lemma RS mp RS mp) 1); |
|
399 |
by (REPEAT (ares_tac ([impI,allI]@prems) 1)); |
|
400 |
qed "zero_induct"; |
|
401 |
||
402 |
goal Arith.thy "!!k::nat. (k+m) - (k+n) = m - n"; |
|
3339 | 403 |
by (induct_tac "k" 1); |
3234 | 404 |
by (ALLGOALS Asm_simp_tac); |
405 |
qed "diff_cancel"; |
|
406 |
Addsimps [diff_cancel]; |
|
407 |
||
408 |
goal Arith.thy "!!m::nat. (m+k) - (n+k) = m - n"; |
|
409 |
val add_commute_k = read_instantiate [("n","k")] add_commute; |
|
410 |
by (asm_simp_tac (!simpset addsimps ([add_commute_k])) 1); |
|
411 |
qed "diff_cancel2"; |
|
412 |
Addsimps [diff_cancel2]; |
|
413 |
||
414 |
(*From Clemens Ballarin*) |
|
415 |
goal Arith.thy "!!n::nat. [| k<=n; n<=m |] ==> (m-k) - (n-k) = m-n"; |
|
416 |
by (subgoal_tac "k<=n --> n<=m --> (m-k) - (n-k) = m-n" 1); |
|
417 |
by (Asm_full_simp_tac 1); |
|
3339 | 418 |
by (induct_tac "k" 1); |
3234 | 419 |
by (Simp_tac 1); |
420 |
(* Induction step *) |
|
421 |
by (subgoal_tac "Suc na <= m --> n <= m --> Suc na <= n --> \ |
|
422 |
\ Suc (m - Suc na) - Suc (n - Suc na) = m-n" 1); |
|
423 |
by (Asm_full_simp_tac 1); |
|
424 |
by (blast_tac (!claset addIs [le_trans]) 1); |
|
425 |
by (auto_tac (!claset addIs [Suc_leD], !simpset delsimps [diff_Suc_Suc])); |
|
426 |
by (asm_full_simp_tac (!simpset delsimps [Suc_less_eq] |
|
427 |
addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1); |
|
428 |
qed "diff_right_cancel"; |
|
429 |
||
430 |
goal Arith.thy "!!n::nat. n - (n+m) = 0"; |
|
3339 | 431 |
by (induct_tac "n" 1); |
3234 | 432 |
by (ALLGOALS Asm_simp_tac); |
433 |
qed "diff_add_0"; |
|
434 |
Addsimps [diff_add_0]; |
|
435 |
||
436 |
(** Difference distributes over multiplication **) |
|
437 |
||
438 |
goal Arith.thy "!!m::nat. (m - n) * k = (m * k) - (n * k)"; |
|
439 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
440 |
by (ALLGOALS Asm_simp_tac); |
|
441 |
qed "diff_mult_distrib" ; |
|
442 |
||
443 |
goal Arith.thy "!!m::nat. k * (m - n) = (k * m) - (k * n)"; |
|
444 |
val mult_commute_k = read_instantiate [("m","k")] mult_commute; |
|
445 |
by (simp_tac (!simpset addsimps [diff_mult_distrib, mult_commute_k]) 1); |
|
446 |
qed "diff_mult_distrib2" ; |
|
447 |
(*NOT added as rewrites, since sometimes they are used from right-to-left*) |
|
448 |
||
449 |
||
450 |
(** Less-then properties **) |
|
451 |
||
452 |
(*In ordinary notation: if 0<n and n<=m then m-n < m *) |
|
453 |
goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m"; |
|
454 |
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1); |
|
455 |
by (Blast_tac 1); |
|
456 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
457 |
by (ALLGOALS(asm_simp_tac(!simpset addsimps [diff_less_Suc]))); |
|
458 |
qed "diff_less"; |
|
459 |
||
460 |
val wf_less_trans = [eq_reflection, wf_pred_nat RS wf_trancl] MRS |
|
461 |
def_wfrec RS trans; |
|
462 |
||
463 |
goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m<n)"; |
|
464 |
by (rtac refl 1); |
|
465 |
qed "less_eq"; |
|
466 |
||
467 |
(*** Remainder ***) |
|
468 |
||
469 |
goal Arith.thy "(%m. m mod n) = wfrec (trancl pred_nat) \ |
|
470 |
\ (%f j. if j<n then j else f (j-n))"; |
|
471 |
by (simp_tac (!simpset addsimps [mod_def]) 1); |
|
472 |
qed "mod_eq"; |
|
473 |
||
474 |
goal Arith.thy "!!m. m<n ==> m mod n = m"; |
|
475 |
by (rtac (mod_eq RS wf_less_trans) 1); |
|
476 |
by (Asm_simp_tac 1); |
|
477 |
qed "mod_less"; |
|
478 |
||
479 |
goal Arith.thy "!!m. [| 0<n; ~m<n |] ==> m mod n = (m-n) mod n"; |
|
480 |
by (rtac (mod_eq RS wf_less_trans) 1); |
|
481 |
by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1); |
|
482 |
qed "mod_geq"; |
|
483 |
||
484 |
goal thy "!!n. 0<n ==> n mod n = 0"; |
|
485 |
by (rtac (mod_eq RS wf_less_trans) 1); |
|
486 |
by (asm_simp_tac (!simpset addsimps [mod_less, diff_self_eq_0, |
|
487 |
cut_def, less_eq]) 1); |
|
488 |
qed "mod_nn_is_0"; |
|
489 |
||
490 |
goal thy "!!n. 0<n ==> (m+n) mod n = m mod n"; |
|
491 |
by (subgoal_tac "(n + m) mod n = (n+m-n) mod n" 1); |
|
492 |
by (stac (mod_geq RS sym) 2); |
|
493 |
by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [add_commute]))); |
|
494 |
qed "mod_eq_add"; |
|
495 |
||
496 |
goal thy "!!n. 0<n ==> m*n mod n = 0"; |
|
3339 | 497 |
by (induct_tac "m" 1); |
3234 | 498 |
by (asm_simp_tac (!simpset addsimps [mod_less]) 1); |
499 |
by (dres_inst_tac [("m","m*n")] mod_eq_add 1); |
|
500 |
by (asm_full_simp_tac (!simpset addsimps [add_commute]) 1); |
|
501 |
qed "mod_prod_nn_is_0"; |
|
502 |
||
503 |
||
504 |
(*** Quotient ***) |
|
505 |
||
506 |
goal Arith.thy "(%m. m div n) = wfrec (trancl pred_nat) \ |
|
507 |
\ (%f j. if j<n then 0 else Suc (f (j-n)))"; |
|
508 |
by (simp_tac (!simpset addsimps [div_def]) 1); |
|
509 |
qed "div_eq"; |
|
510 |
||
511 |
goal Arith.thy "!!m. m<n ==> m div n = 0"; |
|
512 |
by (rtac (div_eq RS wf_less_trans) 1); |
|
513 |
by (Asm_simp_tac 1); |
|
514 |
qed "div_less"; |
|
515 |
||
516 |
goal Arith.thy "!!M. [| 0<n; ~m<n |] ==> m div n = Suc((m-n) div n)"; |
|
517 |
by (rtac (div_eq RS wf_less_trans) 1); |
|
518 |
by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1); |
|
519 |
qed "div_geq"; |
|
520 |
||
521 |
(*Main Result about quotient and remainder.*) |
|
522 |
goal Arith.thy "!!m. 0<n ==> (m div n)*n + m mod n = m"; |
|
523 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
524 |
by (rename_tac "k" 1); (*Variable name used in line below*) |
|
525 |
by (case_tac "k<n" 1); |
|
526 |
by (ALLGOALS (asm_simp_tac(!simpset addsimps ([add_assoc] @ |
|
527 |
[mod_less, mod_geq, div_less, div_geq, |
|
528 |
add_diff_inverse, diff_less])))); |
|
529 |
qed "mod_div_equality"; |
|
530 |
||
531 |
||
3293 | 532 |
(*** Further facts about mod (mainly for the mutilated chess board ***) |
3234 | 533 |
|
534 |
goal Arith.thy |
|
535 |
"!!m n. 0<n ==> \ |
|
536 |
\ Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))"; |
|
537 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
538 |
by (excluded_middle_tac "Suc(na)<n" 1); |
|
539 |
(* case Suc(na) < n *) |
|
540 |
by (forward_tac [lessI RS less_trans] 2); |
|
541 |
by (asm_simp_tac (!simpset addsimps [mod_less, less_not_refl2 RS not_sym]) 2); |
|
542 |
(* case n <= Suc(na) *) |
|
543 |
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, mod_geq]) 1); |
|
544 |
by (etac (le_imp_less_or_eq RS disjE) 1); |
|
545 |
by (asm_simp_tac (!simpset addsimps [Suc_diff_n]) 1); |
|
546 |
by (asm_full_simp_tac (!simpset addsimps [not_less_eq RS sym, |
|
547 |
diff_less, mod_geq]) 1); |
|
548 |
by (asm_simp_tac (!simpset addsimps [mod_less]) 1); |
|
549 |
qed "mod_Suc"; |
|
550 |
||
551 |
goal Arith.thy "!!m n. 0<n ==> m mod n < n"; |
|
552 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
553 |
by (excluded_middle_tac "na<n" 1); |
|
554 |
(*case na<n*) |
|
555 |
by (asm_simp_tac (!simpset addsimps [mod_less]) 2); |
|
556 |
(*case n le na*) |
|
557 |
by (asm_full_simp_tac (!simpset addsimps [mod_geq, diff_less]) 1); |
|
558 |
qed "mod_less_divisor"; |
|
559 |
||
560 |
||
561 |
(** Evens and Odds **) |
|
562 |
||
563 |
(*With less_zeroE, causes case analysis on b<2*) |
|
564 |
AddSEs [less_SucE]; |
|
565 |
||
566 |
goal thy "!!k b. b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)"; |
|
567 |
by (subgoal_tac "k mod 2 < 2" 1); |
|
568 |
by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2); |
|
569 |
by (asm_simp_tac (!simpset setloop split_tac [expand_if]) 1); |
|
570 |
by (Blast_tac 1); |
|
571 |
qed "mod2_cases"; |
|
572 |
||
573 |
goal thy "Suc(Suc(m)) mod 2 = m mod 2"; |
|
574 |
by (subgoal_tac "m mod 2 < 2" 1); |
|
575 |
by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2); |
|
576 |
by (Step_tac 1); |
|
577 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [mod_Suc]))); |
|
578 |
qed "mod2_Suc_Suc"; |
|
579 |
Addsimps [mod2_Suc_Suc]; |
|
580 |
||
3293 | 581 |
goal Arith.thy "!!m. m mod 2 ~= 0 ==> m mod 2 = 1"; |
582 |
by (subgoal_tac "m mod 2 < 2" 1); |
|
583 |
by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2); |
|
584 |
by (safe_tac (!claset addSEs [lessE])); |
|
585 |
by (ALLGOALS (blast_tac (!claset addIs [sym]))); |
|
586 |
qed "mod2_neq_0"; |
|
587 |
||
3234 | 588 |
goal thy "(m+m) mod 2 = 0"; |
3339 | 589 |
by (induct_tac "m" 1); |
3234 | 590 |
by (simp_tac (!simpset addsimps [mod_less]) 1); |
591 |
by (asm_simp_tac (!simpset addsimps [mod2_Suc_Suc, add_Suc_right]) 1); |
|
592 |
qed "mod2_add_self"; |
|
593 |
Addsimps [mod2_add_self]; |
|
594 |
||
595 |
Delrules [less_SucE]; |
|
596 |
||
597 |
||
1713 | 598 |
(*** Monotonicity of Multiplication ***) |
599 |
||
600 |
goal Arith.thy "!!i::nat. i<=j ==> i*k<=j*k"; |
|
3339 | 601 |
by (induct_tac "k" 1); |
1713 | 602 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_le_mono]))); |
603 |
qed "mult_le_mono1"; |
|
604 |
||
605 |
(*<=monotonicity, BOTH arguments*) |
|
606 |
goal Arith.thy "!!i::nat. [| i<=j; k<=l |] ==> i*k<=j*l"; |
|
2007 | 607 |
by (etac (mult_le_mono1 RS le_trans) 1); |
1713 | 608 |
by (rtac le_trans 1); |
2007 | 609 |
by (stac mult_commute 2); |
610 |
by (etac mult_le_mono1 2); |
|
611 |
by (simp_tac (!simpset addsimps [mult_commute]) 1); |
|
1713 | 612 |
qed "mult_le_mono"; |
613 |
||
614 |
(*strict, in 1st argument; proof is by induction on k>0*) |
|
615 |
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j"; |
|
3339 | 616 |
by (eres_inst_tac [("i","0")] less_natE 1); |
1713 | 617 |
by (Asm_simp_tac 1); |
3339 | 618 |
by (induct_tac "x" 1); |
1713 | 619 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_less_mono]))); |
620 |
qed "mult_less_mono2"; |
|
621 |
||
3234 | 622 |
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k"; |
623 |
bd mult_less_mono2 1; |
|
624 |
by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [mult_commute]))); |
|
625 |
qed "mult_less_mono1"; |
|
626 |
||
1713 | 627 |
goal Arith.thy "(0 < m*n) = (0<m & 0<n)"; |
3339 | 628 |
by (induct_tac "m" 1); |
629 |
by (induct_tac "n" 2); |
|
1713 | 630 |
by (ALLGOALS Asm_simp_tac); |
631 |
qed "zero_less_mult_iff"; |
|
632 |
||
1795 | 633 |
goal Arith.thy "(m*n = 1) = (m=1 & n=1)"; |
3339 | 634 |
by (induct_tac "m" 1); |
1795 | 635 |
by (Simp_tac 1); |
3339 | 636 |
by (induct_tac "n" 1); |
1795 | 637 |
by (Simp_tac 1); |
638 |
by (fast_tac (!claset addss !simpset) 1); |
|
639 |
qed "mult_eq_1_iff"; |
|
640 |
||
3234 | 641 |
goal Arith.thy "!!k. 0<k ==> (m*k < n*k) = (m<n)"; |
642 |
by (safe_tac (!claset addSIs [mult_less_mono1])); |
|
643 |
by (cut_facts_tac [less_linear] 1); |
|
644 |
by (blast_tac (!claset addDs [mult_less_mono1] addEs [less_asym]) 1); |
|
645 |
qed "mult_less_cancel2"; |
|
646 |
||
647 |
goal Arith.thy "!!k. 0<k ==> (k*m < k*n) = (m<n)"; |
|
648 |
bd mult_less_cancel2 1; |
|
649 |
by (asm_full_simp_tac (!simpset addsimps [mult_commute]) 1); |
|
650 |
qed "mult_less_cancel1"; |
|
651 |
Addsimps [mult_less_cancel1, mult_less_cancel2]; |
|
652 |
||
653 |
goal Arith.thy "!!k. 0<k ==> (m*k = n*k) = (m=n)"; |
|
654 |
by (cut_facts_tac [less_linear] 1); |
|
655 |
by(Step_tac 1); |
|
656 |
ba 2; |
|
657 |
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac)); |
|
658 |
by (ALLGOALS Asm_full_simp_tac); |
|
659 |
qed "mult_cancel2"; |
|
660 |
||
661 |
goal Arith.thy "!!k. 0<k ==> (k*m = k*n) = (m=n)"; |
|
662 |
bd mult_cancel2 1; |
|
663 |
by (asm_full_simp_tac (!simpset addsimps [mult_commute]) 1); |
|
664 |
qed "mult_cancel1"; |
|
665 |
Addsimps [mult_cancel1, mult_cancel2]; |
|
666 |
||
667 |
||
668 |
(*** More division laws ***) |
|
669 |
||
670 |
goal thy "!!n. 0<n ==> m*n div n = m"; |
|
671 |
by (cut_inst_tac [("m", "m*n")] mod_div_equality 1); |
|
672 |
ba 1; |
|
673 |
by (asm_full_simp_tac (!simpset addsimps [mod_prod_nn_is_0]) 1); |
|
674 |
qed "div_prod_nn_is_m"; |
|
675 |
Addsimps [div_prod_nn_is_m]; |
|
676 |
||
1713 | 677 |
(*Cancellation law for division*) |
678 |
goal Arith.thy "!!k. [| 0<n; 0<k |] ==> (k*m) div (k*n) = m div n"; |
|
679 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
680 |
by (case_tac "na<n" 1); |
|
681 |
by (asm_simp_tac (!simpset addsimps [div_less, zero_less_mult_iff, |
|
2031 | 682 |
mult_less_mono2]) 1); |
1713 | 683 |
by (subgoal_tac "~ k*na < k*n" 1); |
684 |
by (asm_simp_tac |
|
685 |
(!simpset addsimps [zero_less_mult_iff, div_geq, |
|
2031 | 686 |
diff_mult_distrib2 RS sym, diff_less]) 1); |
1713 | 687 |
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, |
2031 | 688 |
le_refl RS mult_le_mono]) 1); |
1713 | 689 |
qed "div_cancel"; |
3234 | 690 |
Addsimps [div_cancel]; |
1713 | 691 |
|
692 |
goal Arith.thy "!!k. [| 0<n; 0<k |] ==> (k*m) mod (k*n) = k * (m mod n)"; |
|
693 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
694 |
by (case_tac "na<n" 1); |
|
695 |
by (asm_simp_tac (!simpset addsimps [mod_less, zero_less_mult_iff, |
|
2031 | 696 |
mult_less_mono2]) 1); |
1713 | 697 |
by (subgoal_tac "~ k*na < k*n" 1); |
698 |
by (asm_simp_tac |
|
699 |
(!simpset addsimps [zero_less_mult_iff, mod_geq, |
|
2031 | 700 |
diff_mult_distrib2 RS sym, diff_less]) 1); |
1713 | 701 |
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, |
2031 | 702 |
le_refl RS mult_le_mono]) 1); |
1713 | 703 |
qed "mult_mod_distrib"; |
704 |
||
705 |
||
1795 | 706 |
(** Lemma for gcd **) |
707 |
||
708 |
goal Arith.thy "!!m n. m = m*n ==> n=1 | m=0"; |
|
709 |
by (dtac sym 1); |
|
710 |
by (rtac disjCI 1); |
|
711 |
by (rtac nat_less_cases 1 THEN assume_tac 2); |
|
1909 | 712 |
by (fast_tac (!claset addSEs [less_SucE] addss !simpset) 1); |
1979 | 713 |
by (best_tac (!claset addDs [mult_less_mono2] |
1795 | 714 |
addss (!simpset addsimps [zero_less_eq RS sym])) 1); |
715 |
qed "mult_eq_self_implies_10"; |
|
716 |
||
717 |
||
3234 | 718 |
(*** Subtraction laws -- from Clemens Ballarin ***) |
719 |
||
720 |
goal Arith.thy "!! a b c::nat. [| a < b; c <= a |] ==> a-c < b-c"; |
|
721 |
by (subgoal_tac "c+(a-c) < c+(b-c)" 1); |
|
722 |
by (Asm_full_simp_tac 1); |
|
723 |
by (subgoal_tac "c <= b" 1); |
|
724 |
by (blast_tac (!claset addIs [less_imp_le, le_trans]) 2); |
|
725 |
by (asm_simp_tac (!simpset addsimps [leD RS add_diff_inverse]) 1); |
|
726 |
qed "diff_less_mono"; |
|
727 |
||
728 |
goal Arith.thy "!! a b c::nat. a+b < c ==> a < c-b"; |
|
729 |
bd diff_less_mono 1; |
|
730 |
br le_add2 1; |
|
731 |
by (Asm_full_simp_tac 1); |
|
732 |
qed "add_less_imp_less_diff"; |
|
733 |
||
734 |
goal Arith.thy "!! n. n <= m ==> Suc m - n = Suc (m - n)"; |
|
735 |
br Suc_diff_n 1; |
|
736 |
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_Suc]) 1); |
|
737 |
qed "Suc_diff_le"; |
|
738 |
||
739 |
goal Arith.thy "!! n. Suc i <= n ==> Suc (n - Suc i) = n - i"; |
|
740 |
by (asm_full_simp_tac |
|
741 |
(!simpset addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1); |
|
742 |
qed "Suc_diff_Suc"; |
|
743 |
||
744 |
goal Arith.thy "!! i::nat. i <= n ==> n - (n - i) = i"; |
|
745 |
by (subgoal_tac "(n-i) + (n - (n-i)) = (n-i) + i" 1); |
|
746 |
by (Asm_full_simp_tac 1); |
|
747 |
by (asm_simp_tac (!simpset addsimps [leD RS add_diff_inverse, diff_le_self, |
|
748 |
add_commute]) 1); |
|
749 |
qed "diff_diff_cancel"; |
|
750 |
||
751 |
goal Arith.thy "!!k::nat. k <= n ==> m <= n + m - k"; |
|
752 |
be rev_mp 1; |
|
753 |
by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1); |
|
754 |
by (Simp_tac 1); |
|
755 |
by (simp_tac (!simpset addsimps [less_add_Suc2, less_imp_le]) 1); |
|
756 |
by (Simp_tac 1); |
|
757 |
qed "le_add_diff"; |
|
758 |
||
759 |