author | nipkow |
Sun, 05 Jan 2003 21:03:14 +0100 | |
changeset 13771 | 6cd59cc885a1 |
parent 13361 | 5005d34425bb |
child 13784 | b9f6154427a4 |
permissions | -rw-r--r-- |
9654
9754ba005b64
X-symbols for ordinal, cardinal, integer arithmetic
paulson
parents:
9492
diff
changeset
|
1 |
(* Title: ZF/Arith.thy |
0 | 2 |
ID: $Id$ |
1478 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1992 University of Cambridge |
5 |
||
6 |
*) |
|
7 |
||
13163 | 8 |
(*"Difference" is subtraction of natural numbers. |
9 |
There are no negative numbers; we have |
|
10 |
m #- n = 0 iff m<=n and m #- n = succ(k) iff m>n. |
|
11 |
Also, rec(m, 0, %z w.z) is pred(m). |
|
12 |
*) |
|
13 |
||
13328 | 14 |
header{*Arithmetic Operators and Their Definitions*} |
15 |
||
13163 | 16 |
theory Arith = Univ: |
6070 | 17 |
|
13328 | 18 |
text{*Proofs about elementary arithmetic: addition, multiplication, etc.*} |
19 |
||
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
20 |
constdefs |
13163 | 21 |
pred :: "i=>i" (*inverse of succ*) |
13361 | 22 |
"pred(y) == nat_case(0, %x. x, y)" |
6070 | 23 |
|
13163 | 24 |
natify :: "i=>i" (*coerces non-nats to nats*) |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
25 |
"natify == Vrecursor(%f a. if a = succ(pred(a)) then succ(f`pred(a)) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
26 |
else 0)" |
6070 | 27 |
|
0 | 28 |
consts |
13163 | 29 |
raw_add :: "[i,i]=>i" |
30 |
raw_diff :: "[i,i]=>i" |
|
31 |
raw_mult :: "[i,i]=>i" |
|
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
32 |
|
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
33 |
primrec |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
34 |
"raw_add (0, n) = n" |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
35 |
"raw_add (succ(m), n) = succ(raw_add(m, n))" |
0 | 36 |
|
6070 | 37 |
primrec |
13163 | 38 |
raw_diff_0: "raw_diff(m, 0) = m" |
39 |
raw_diff_succ: "raw_diff(m, succ(n)) = |
|
40 |
nat_case(0, %x. x, raw_diff(m, n))" |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
41 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
42 |
primrec |
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
43 |
"raw_mult(0, n) = 0" |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
44 |
"raw_mult(succ(m), n) = raw_add (n, raw_mult(m, n))" |
13163 | 45 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
46 |
constdefs |
13163 | 47 |
add :: "[i,i]=>i" (infixl "#+" 65) |
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
48 |
"m #+ n == raw_add (natify(m), natify(n))" |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
49 |
|
13163 | 50 |
diff :: "[i,i]=>i" (infixl "#-" 65) |
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
51 |
"m #- n == raw_diff (natify(m), natify(n))" |
0 | 52 |
|
13163 | 53 |
mult :: "[i,i]=>i" (infixl "#*" 70) |
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
54 |
"m #* n == raw_mult (natify(m), natify(n))" |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
55 |
|
13163 | 56 |
raw_div :: "[i,i]=>i" |
57 |
"raw_div (m, n) == |
|
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
58 |
transrec(m, %j f. if j<n | n=0 then 0 else succ(f`(j#-n)))" |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
59 |
|
13163 | 60 |
raw_mod :: "[i,i]=>i" |
61 |
"raw_mod (m, n) == |
|
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
62 |
transrec(m, %j f. if j<n | n=0 then j else f`(j#-n))" |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
63 |
|
13163 | 64 |
div :: "[i,i]=>i" (infixl "div" 70) |
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
65 |
"m div n == raw_div (natify(m), natify(n))" |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
66 |
|
13163 | 67 |
mod :: "[i,i]=>i" (infixl "mod" 70) |
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
68 |
"m mod n == raw_mod (natify(m), natify(n))" |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6070
diff
changeset
|
69 |
|
12114
a8e860c86252
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
9964
diff
changeset
|
70 |
syntax (xsymbols) |
13163 | 71 |
"mult" :: "[i,i] => i" (infixr "#\<times>" 70) |
9964 | 72 |
|
73 |
syntax (HTML output) |
|
13163 | 74 |
"mult" :: "[i, i] => i" (infixr "#\<times>" 70) |
75 |
||
76 |
||
77 |
declare rec_type [simp] |
|
78 |
nat_0_le [simp] |
|
79 |
||
80 |
||
81 |
lemma zero_lt_lemma: "[| 0<k; k: nat |] ==> EX j: nat. k = succ(j)" |
|
82 |
apply (erule rev_mp) |
|
83 |
apply (induct_tac "k", auto) |
|
84 |
done |
|
85 |
||
86 |
(* [| 0 < k; k: nat; !!j. [| j: nat; k = succ(j) |] ==> Q |] ==> Q *) |
|
87 |
lemmas zero_lt_natE = zero_lt_lemma [THEN bexE, standard] |
|
88 |
||
89 |
||
13356 | 90 |
subsection{*@{text natify}, the Coercion to @{term nat}*} |
13163 | 91 |
|
92 |
lemma pred_succ_eq [simp]: "pred(succ(y)) = y" |
|
93 |
by (unfold pred_def, auto) |
|
94 |
||
95 |
lemma natify_succ: "natify(succ(x)) = succ(natify(x))" |
|
96 |
by (rule natify_def [THEN def_Vrecursor, THEN trans], auto) |
|
97 |
||
98 |
lemma natify_0 [simp]: "natify(0) = 0" |
|
99 |
by (rule natify_def [THEN def_Vrecursor, THEN trans], auto) |
|
100 |
||
101 |
lemma natify_non_succ: "ALL z. x ~= succ(z) ==> natify(x) = 0" |
|
102 |
by (rule natify_def [THEN def_Vrecursor, THEN trans], auto) |
|
103 |
||
104 |
lemma natify_in_nat [iff,TC]: "natify(x) : nat" |
|
105 |
apply (rule_tac a=x in eps_induct) |
|
106 |
apply (case_tac "EX z. x = succ(z)") |
|
107 |
apply (auto simp add: natify_succ natify_non_succ) |
|
108 |
done |
|
109 |
||
110 |
lemma natify_ident [simp]: "n : nat ==> natify(n) = n" |
|
111 |
apply (induct_tac "n") |
|
112 |
apply (auto simp add: natify_succ) |
|
113 |
done |
|
114 |
||
115 |
lemma natify_eqE: "[|natify(x) = y; x: nat|] ==> x=y" |
|
116 |
by auto |
|
117 |
||
118 |
||
119 |
(*** Collapsing rules: to remove natify from arithmetic expressions ***) |
|
120 |
||
121 |
lemma natify_idem [simp]: "natify(natify(x)) = natify(x)" |
|
122 |
by simp |
|
123 |
||
124 |
(** Addition **) |
|
125 |
||
126 |
lemma add_natify1 [simp]: "natify(m) #+ n = m #+ n" |
|
127 |
by (simp add: add_def) |
|
128 |
||
129 |
lemma add_natify2 [simp]: "m #+ natify(n) = m #+ n" |
|
130 |
by (simp add: add_def) |
|
131 |
||
132 |
(** Multiplication **) |
|
133 |
||
134 |
lemma mult_natify1 [simp]: "natify(m) #* n = m #* n" |
|
135 |
by (simp add: mult_def) |
|
136 |
||
137 |
lemma mult_natify2 [simp]: "m #* natify(n) = m #* n" |
|
138 |
by (simp add: mult_def) |
|
139 |
||
140 |
(** Difference **) |
|
141 |
||
142 |
lemma diff_natify1 [simp]: "natify(m) #- n = m #- n" |
|
143 |
by (simp add: diff_def) |
|
144 |
||
145 |
lemma diff_natify2 [simp]: "m #- natify(n) = m #- n" |
|
146 |
by (simp add: diff_def) |
|
147 |
||
148 |
(** Remainder **) |
|
149 |
||
150 |
lemma mod_natify1 [simp]: "natify(m) mod n = m mod n" |
|
151 |
by (simp add: mod_def) |
|
152 |
||
153 |
lemma mod_natify2 [simp]: "m mod natify(n) = m mod n" |
|
154 |
by (simp add: mod_def) |
|
155 |
||
156 |
||
157 |
(** Quotient **) |
|
158 |
||
159 |
lemma div_natify1 [simp]: "natify(m) div n = m div n" |
|
160 |
by (simp add: div_def) |
|
161 |
||
162 |
lemma div_natify2 [simp]: "m div natify(n) = m div n" |
|
163 |
by (simp add: div_def) |
|
164 |
||
165 |
||
13356 | 166 |
subsection{*Typing rules*} |
13163 | 167 |
|
168 |
(** Addition **) |
|
169 |
||
170 |
lemma raw_add_type: "[| m:nat; n:nat |] ==> raw_add (m, n) : nat" |
|
171 |
by (induct_tac "m", auto) |
|
172 |
||
173 |
lemma add_type [iff,TC]: "m #+ n : nat" |
|
174 |
by (simp add: add_def raw_add_type) |
|
175 |
||
176 |
(** Multiplication **) |
|
177 |
||
178 |
lemma raw_mult_type: "[| m:nat; n:nat |] ==> raw_mult (m, n) : nat" |
|
179 |
apply (induct_tac "m") |
|
180 |
apply (simp_all add: raw_add_type) |
|
181 |
done |
|
182 |
||
183 |
lemma mult_type [iff,TC]: "m #* n : nat" |
|
184 |
by (simp add: mult_def raw_mult_type) |
|
185 |
||
186 |
||
187 |
(** Difference **) |
|
188 |
||
189 |
lemma raw_diff_type: "[| m:nat; n:nat |] ==> raw_diff (m, n) : nat" |
|
13173 | 190 |
by (induct_tac "n", auto) |
13163 | 191 |
|
192 |
lemma diff_type [iff,TC]: "m #- n : nat" |
|
193 |
by (simp add: diff_def raw_diff_type) |
|
194 |
||
195 |
lemma diff_0_eq_0 [simp]: "0 #- n = 0" |
|
196 |
apply (unfold diff_def) |
|
197 |
apply (rule natify_in_nat [THEN nat_induct], auto) |
|
198 |
done |
|
199 |
||
200 |
(*Must simplify BEFORE the induction: else we get a critical pair*) |
|
201 |
lemma diff_succ_succ [simp]: "succ(m) #- succ(n) = m #- n" |
|
202 |
apply (simp add: natify_succ diff_def) |
|
203 |
apply (rule_tac x1 = "n" in natify_in_nat [THEN nat_induct], auto) |
|
204 |
done |
|
205 |
||
206 |
(*This defining property is no longer wanted*) |
|
207 |
declare raw_diff_succ [simp del] |
|
208 |
||
209 |
(*Natify has weakened this law, compared with the older approach*) |
|
210 |
lemma diff_0 [simp]: "m #- 0 = natify(m)" |
|
211 |
by (simp add: diff_def) |
|
212 |
||
213 |
lemma diff_le_self: "m:nat ==> (m #- n) le m" |
|
214 |
apply (subgoal_tac " (m #- natify (n)) le m") |
|
215 |
apply (rule_tac [2] m = "m" and n = "natify (n) " in diff_induct) |
|
216 |
apply (erule_tac [6] leE) |
|
217 |
apply (simp_all add: le_iff) |
|
218 |
done |
|
219 |
||
220 |
||
13356 | 221 |
subsection{*Addition*} |
13163 | 222 |
|
223 |
(*Natify has weakened this law, compared with the older approach*) |
|
224 |
lemma add_0_natify [simp]: "0 #+ m = natify(m)" |
|
225 |
by (simp add: add_def) |
|
226 |
||
227 |
lemma add_succ [simp]: "succ(m) #+ n = succ(m #+ n)" |
|
228 |
by (simp add: natify_succ add_def) |
|
229 |
||
230 |
lemma add_0: "m: nat ==> 0 #+ m = m" |
|
231 |
by simp |
|
232 |
||
233 |
(*Associative law for addition*) |
|
234 |
lemma add_assoc: "(m #+ n) #+ k = m #+ (n #+ k)" |
|
235 |
apply (subgoal_tac "(natify(m) #+ natify(n)) #+ natify(k) = |
|
236 |
natify(m) #+ (natify(n) #+ natify(k))") |
|
237 |
apply (rule_tac [2] n = "natify(m)" in nat_induct) |
|
238 |
apply auto |
|
239 |
done |
|
240 |
||
241 |
(*The following two lemmas are used for add_commute and sometimes |
|
242 |
elsewhere, since they are safe for rewriting.*) |
|
243 |
lemma add_0_right_natify [simp]: "m #+ 0 = natify(m)" |
|
244 |
apply (subgoal_tac "natify(m) #+ 0 = natify(m)") |
|
245 |
apply (rule_tac [2] n = "natify(m)" in nat_induct) |
|
246 |
apply auto |
|
247 |
done |
|
248 |
||
249 |
lemma add_succ_right [simp]: "m #+ succ(n) = succ(m #+ n)" |
|
250 |
apply (unfold add_def) |
|
251 |
apply (rule_tac n = "natify(m) " in nat_induct) |
|
252 |
apply (auto simp add: natify_succ) |
|
253 |
done |
|
254 |
||
255 |
lemma add_0_right: "m: nat ==> m #+ 0 = m" |
|
256 |
by auto |
|
257 |
||
258 |
(*Commutative law for addition*) |
|
259 |
lemma add_commute: "m #+ n = n #+ m" |
|
260 |
apply (subgoal_tac "natify(m) #+ natify(n) = natify(n) #+ natify(m) ") |
|
261 |
apply (rule_tac [2] n = "natify(m) " in nat_induct) |
|
262 |
apply auto |
|
263 |
done |
|
264 |
||
265 |
(*for a/c rewriting*) |
|
266 |
lemma add_left_commute: "m#+(n#+k)=n#+(m#+k)" |
|
267 |
apply (rule add_commute [THEN trans]) |
|
268 |
apply (rule add_assoc [THEN trans]) |
|
269 |
apply (rule add_commute [THEN subst_context]) |
|
270 |
done |
|
271 |
||
272 |
(*Addition is an AC-operator*) |
|
273 |
lemmas add_ac = add_assoc add_commute add_left_commute |
|
274 |
||
275 |
(*Cancellation law on the left*) |
|
276 |
lemma raw_add_left_cancel: |
|
277 |
"[| raw_add(k, m) = raw_add(k, n); k:nat |] ==> m=n" |
|
278 |
apply (erule rev_mp) |
|
279 |
apply (induct_tac "k", auto) |
|
280 |
done |
|
281 |
||
282 |
lemma add_left_cancel_natify: "k #+ m = k #+ n ==> natify(m) = natify(n)" |
|
283 |
apply (unfold add_def) |
|
284 |
apply (drule raw_add_left_cancel, auto) |
|
285 |
done |
|
286 |
||
287 |
lemma add_left_cancel: |
|
288 |
"[| i = j; i #+ m = j #+ n; m:nat; n:nat |] ==> m = n" |
|
289 |
by (force dest!: add_left_cancel_natify) |
|
290 |
||
291 |
(*Thanks to Sten Agerholm*) |
|
292 |
lemma add_le_elim1_natify: "k#+m le k#+n ==> natify(m) le natify(n)" |
|
293 |
apply (rule_tac P = "natify(k) #+m le natify(k) #+n" in rev_mp) |
|
294 |
apply (rule_tac [2] n = "natify(k) " in nat_induct) |
|
295 |
apply auto |
|
296 |
done |
|
297 |
||
298 |
lemma add_le_elim1: "[| k#+m le k#+n; m: nat; n: nat |] ==> m le n" |
|
299 |
by (drule add_le_elim1_natify, auto) |
|
300 |
||
301 |
lemma add_lt_elim1_natify: "k#+m < k#+n ==> natify(m) < natify(n)" |
|
302 |
apply (rule_tac P = "natify(k) #+m < natify(k) #+n" in rev_mp) |
|
303 |
apply (rule_tac [2] n = "natify(k) " in nat_induct) |
|
304 |
apply auto |
|
305 |
done |
|
306 |
||
307 |
lemma add_lt_elim1: "[| k#+m < k#+n; m: nat; n: nat |] ==> m < n" |
|
308 |
by (drule add_lt_elim1_natify, auto) |
|
309 |
||
310 |
||
13356 | 311 |
subsection{*Monotonicity of Addition*} |
13163 | 312 |
|
313 |
(*strict, in 1st argument; proof is by rule induction on 'less than'. |
|
314 |
Still need j:nat, for consider j = omega. Then we can have i<omega, |
|
315 |
which is the same as i:nat, but natify(j)=0, so the conclusion fails.*) |
|
316 |
lemma add_lt_mono1: "[| i<j; j:nat |] ==> i#+k < j#+k" |
|
317 |
apply (frule lt_nat_in_nat, assumption) |
|
318 |
apply (erule succ_lt_induct) |
|
319 |
apply (simp_all add: leI) |
|
320 |
done |
|
321 |
||
322 |
(*strict, in both arguments*) |
|
323 |
lemma add_lt_mono: |
|
324 |
"[| i<j; k<l; j:nat; l:nat |] ==> i#+k < j#+l" |
|
325 |
apply (rule add_lt_mono1 [THEN lt_trans], assumption+) |
|
326 |
apply (subst add_commute, subst add_commute, rule add_lt_mono1, assumption+) |
|
327 |
done |
|
328 |
||
329 |
(*A [clumsy] way of lifting < monotonicity to le monotonicity *) |
|
330 |
lemma Ord_lt_mono_imp_le_mono: |
|
331 |
assumes lt_mono: "!!i j. [| i<j; j:k |] ==> f(i) < f(j)" |
|
332 |
and ford: "!!i. i:k ==> Ord(f(i))" |
|
333 |
and leij: "i le j" |
|
334 |
and jink: "j:k" |
|
335 |
shows "f(i) le f(j)" |
|
336 |
apply (insert leij jink) |
|
337 |
apply (blast intro!: leCI lt_mono ford elim!: leE) |
|
338 |
done |
|
339 |
||
340 |
(*le monotonicity, 1st argument*) |
|
341 |
lemma add_le_mono1: "[| i le j; j:nat |] ==> i#+k le j#+k" |
|
342 |
apply (rule_tac f = "%j. j#+k" in Ord_lt_mono_imp_le_mono, typecheck) |
|
343 |
apply (blast intro: add_lt_mono1 add_type [THEN nat_into_Ord])+ |
|
344 |
done |
|
345 |
||
346 |
(* le monotonicity, BOTH arguments*) |
|
347 |
lemma add_le_mono: "[| i le j; k le l; j:nat; l:nat |] ==> i#+k le j#+l" |
|
348 |
apply (rule add_le_mono1 [THEN le_trans], assumption+) |
|
349 |
apply (subst add_commute, subst add_commute, rule add_le_mono1, assumption+) |
|
350 |
done |
|
351 |
||
352 |
(** Subtraction is the inverse of addition. **) |
|
353 |
||
354 |
lemma diff_add_inverse: "(n#+m) #- n = natify(m)" |
|
355 |
apply (subgoal_tac " (natify(n) #+ m) #- natify(n) = natify(m) ") |
|
356 |
apply (rule_tac [2] n = "natify(n) " in nat_induct) |
|
357 |
apply auto |
|
358 |
done |
|
359 |
||
360 |
lemma diff_add_inverse2: "(m#+n) #- n = natify(m)" |
|
361 |
by (simp add: add_commute [of m] diff_add_inverse) |
|
362 |
||
363 |
lemma diff_cancel: "(k#+m) #- (k#+n) = m #- n" |
|
364 |
apply (subgoal_tac "(natify(k) #+ natify(m)) #- (natify(k) #+ natify(n)) = |
|
365 |
natify(m) #- natify(n) ") |
|
366 |
apply (rule_tac [2] n = "natify(k) " in nat_induct) |
|
367 |
apply auto |
|
368 |
done |
|
369 |
||
370 |
lemma diff_cancel2: "(m#+k) #- (n#+k) = m #- n" |
|
371 |
by (simp add: add_commute [of _ k] diff_cancel) |
|
372 |
||
373 |
lemma diff_add_0: "n #- (n#+m) = 0" |
|
374 |
apply (subgoal_tac "natify(n) #- (natify(n) #+ natify(m)) = 0") |
|
375 |
apply (rule_tac [2] n = "natify(n) " in nat_induct) |
|
376 |
apply auto |
|
377 |
done |
|
378 |
||
13361 | 379 |
lemma pred_0 [simp]: "pred(0) = 0" |
380 |
by (simp add: pred_def) |
|
381 |
||
382 |
lemma eq_succ_imp_eq_m1: "[|i = succ(j); i\<in>nat|] ==> j = i #- 1 & j \<in>nat" |
|
383 |
by simp |
|
384 |
||
385 |
lemma pred_Un_distrib: |
|
386 |
"[|i\<in>nat; j\<in>nat|] ==> pred(i Un j) = pred(i) Un pred(j)" |
|
387 |
apply (erule_tac n=i in natE, simp) |
|
388 |
apply (erule_tac n=j in natE, simp) |
|
389 |
apply (simp add: succ_Un_distrib [symmetric]) |
|
390 |
done |
|
391 |
||
392 |
lemma pred_type [TC,simp]: |
|
393 |
"i \<in> nat ==> pred(i) \<in> nat" |
|
394 |
by (simp add: pred_def split: split_nat_case) |
|
395 |
||
396 |
lemma nat_diff_pred: "[|i\<in>nat; j\<in>nat|] ==> i #- succ(j) = pred(i #- j)"; |
|
397 |
apply (rule_tac m=i and n=j in diff_induct) |
|
398 |
apply (auto simp add: pred_def nat_imp_quasinat split: split_nat_case) |
|
399 |
done |
|
400 |
||
401 |
lemma diff_succ_eq_pred: "i #- succ(j) = pred(i #- j)"; |
|
402 |
apply (insert nat_diff_pred [of "natify(i)" "natify(j)"]) |
|
403 |
apply (simp add: natify_succ [symmetric]) |
|
404 |
done |
|
405 |
||
406 |
lemma nat_diff_Un_distrib: |
|
407 |
"[|i\<in>nat; j\<in>nat; k\<in>nat|] ==> (i Un j) #- k = (i#-k) Un (j#-k)" |
|
408 |
apply (rule_tac n=k in nat_induct) |
|
409 |
apply (simp_all add: diff_succ_eq_pred pred_Un_distrib) |
|
410 |
done |
|
411 |
||
412 |
lemma diff_Un_distrib: |
|
413 |
"[|i\<in>nat; j\<in>nat|] ==> (i Un j) #- k = (i#-k) Un (j#-k)" |
|
414 |
by (insert nat_diff_Un_distrib [of i j "natify(k)"], simp) |
|
415 |
||
416 |
text{*We actually prove @{term "i #- j #- k = i #- (j #+ k)"}*} |
|
417 |
lemma diff_diff_left [simplified]: |
|
418 |
"natify(i)#-natify(j)#-k = natify(i) #- (natify(j)#+k)"; |
|
419 |
by (rule_tac m="natify(i)" and n="natify(j)" in diff_induct, auto) |
|
420 |
||
13163 | 421 |
|
422 |
(** Lemmas for the CancelNumerals simproc **) |
|
423 |
||
424 |
lemma eq_add_iff: "(u #+ m = u #+ n) <-> (0 #+ m = natify(n))" |
|
425 |
apply auto |
|
426 |
apply (blast dest: add_left_cancel_natify) |
|
427 |
apply (simp add: add_def) |
|
428 |
done |
|
429 |
||
430 |
lemma less_add_iff: "(u #+ m < u #+ n) <-> (0 #+ m < natify(n))" |
|
431 |
apply (auto simp add: add_lt_elim1_natify) |
|
432 |
apply (drule add_lt_mono1) |
|
433 |
apply (auto simp add: add_commute [of u]) |
|
434 |
done |
|
435 |
||
436 |
lemma diff_add_eq: "((u #+ m) #- (u #+ n)) = ((0 #+ m) #- n)" |
|
437 |
by (simp add: diff_cancel) |
|
438 |
||
439 |
(*To tidy up the result of a simproc. Only the RHS will be simplified.*) |
|
440 |
lemma eq_cong2: "u = u' ==> (t==u) == (t==u')" |
|
441 |
by auto |
|
442 |
||
443 |
lemma iff_cong2: "u <-> u' ==> (t==u) == (t==u')" |
|
444 |
by auto |
|
445 |
||
446 |
||
13356 | 447 |
subsection{*Multiplication*} |
13163 | 448 |
|
449 |
lemma mult_0 [simp]: "0 #* m = 0" |
|
450 |
by (simp add: mult_def) |
|
451 |
||
452 |
lemma mult_succ [simp]: "succ(m) #* n = n #+ (m #* n)" |
|
453 |
by (simp add: add_def mult_def natify_succ raw_mult_type) |
|
454 |
||
455 |
(*right annihilation in product*) |
|
456 |
lemma mult_0_right [simp]: "m #* 0 = 0" |
|
457 |
apply (unfold mult_def) |
|
458 |
apply (rule_tac n = "natify(m) " in nat_induct) |
|
459 |
apply auto |
|
460 |
done |
|
461 |
||
462 |
(*right successor law for multiplication*) |
|
463 |
lemma mult_succ_right [simp]: "m #* succ(n) = m #+ (m #* n)" |
|
464 |
apply (subgoal_tac "natify(m) #* succ (natify(n)) = |
|
465 |
natify(m) #+ (natify(m) #* natify(n))") |
|
466 |
apply (simp (no_asm_use) add: natify_succ add_def mult_def) |
|
467 |
apply (rule_tac n = "natify(m) " in nat_induct) |
|
468 |
apply (simp_all add: add_ac) |
|
469 |
done |
|
470 |
||
471 |
lemma mult_1_natify [simp]: "1 #* n = natify(n)" |
|
472 |
by auto |
|
473 |
||
474 |
lemma mult_1_right_natify [simp]: "n #* 1 = natify(n)" |
|
475 |
by auto |
|
476 |
||
477 |
lemma mult_1: "n : nat ==> 1 #* n = n" |
|
478 |
by simp |
|
479 |
||
480 |
lemma mult_1_right: "n : nat ==> n #* 1 = n" |
|
481 |
by simp |
|
482 |
||
483 |
(*Commutative law for multiplication*) |
|
484 |
lemma mult_commute: "m #* n = n #* m" |
|
485 |
apply (subgoal_tac "natify(m) #* natify(n) = natify(n) #* natify(m) ") |
|
486 |
apply (rule_tac [2] n = "natify(m) " in nat_induct) |
|
487 |
apply auto |
|
488 |
done |
|
489 |
||
490 |
(*addition distributes over multiplication*) |
|
491 |
lemma add_mult_distrib: "(m #+ n) #* k = (m #* k) #+ (n #* k)" |
|
492 |
apply (subgoal_tac "(natify(m) #+ natify(n)) #* natify(k) = |
|
493 |
(natify(m) #* natify(k)) #+ (natify(n) #* natify(k))") |
|
494 |
apply (rule_tac [2] n = "natify(m) " in nat_induct) |
|
495 |
apply (simp_all add: add_assoc [symmetric]) |
|
496 |
done |
|
497 |
||
498 |
(*Distributive law on the left*) |
|
499 |
lemma add_mult_distrib_left: "k #* (m #+ n) = (k #* m) #+ (k #* n)" |
|
500 |
apply (subgoal_tac "natify(k) #* (natify(m) #+ natify(n)) = |
|
501 |
(natify(k) #* natify(m)) #+ (natify(k) #* natify(n))") |
|
502 |
apply (rule_tac [2] n = "natify(m) " in nat_induct) |
|
503 |
apply (simp_all add: add_ac) |
|
504 |
done |
|
505 |
||
506 |
(*Associative law for multiplication*) |
|
507 |
lemma mult_assoc: "(m #* n) #* k = m #* (n #* k)" |
|
508 |
apply (subgoal_tac "(natify(m) #* natify(n)) #* natify(k) = |
|
509 |
natify(m) #* (natify(n) #* natify(k))") |
|
510 |
apply (rule_tac [2] n = "natify(m) " in nat_induct) |
|
511 |
apply (simp_all add: add_mult_distrib) |
|
512 |
done |
|
513 |
||
514 |
(*for a/c rewriting*) |
|
515 |
lemma mult_left_commute: "m #* (n #* k) = n #* (m #* k)" |
|
516 |
apply (rule mult_commute [THEN trans]) |
|
517 |
apply (rule mult_assoc [THEN trans]) |
|
518 |
apply (rule mult_commute [THEN subst_context]) |
|
519 |
done |
|
520 |
||
521 |
lemmas mult_ac = mult_assoc mult_commute mult_left_commute |
|
522 |
||
523 |
||
524 |
lemma lt_succ_eq_0_disj: |
|
525 |
"[| m:nat; n:nat |] |
|
526 |
==> (m < succ(n)) <-> (m = 0 | (EX j:nat. m = succ(j) & j < n))" |
|
527 |
by (induct_tac "m", auto) |
|
528 |
||
529 |
lemma less_diff_conv [rule_format]: |
|
530 |
"[| j:nat; k:nat |] ==> ALL i:nat. (i < j #- k) <-> (i #+ k < j)" |
|
531 |
by (erule_tac m = "k" in diff_induct, auto) |
|
532 |
||
533 |
lemmas nat_typechecks = rec_type nat_0I nat_1I nat_succI Ord_nat |
|
534 |
||
535 |
ML |
|
536 |
{* |
|
537 |
val pred_def = thm "pred_def"; |
|
538 |
val raw_div_def = thm "raw_div_def"; |
|
539 |
val raw_mod_def = thm "raw_mod_def"; |
|
540 |
val div_def = thm "div_def"; |
|
541 |
val mod_def = thm "mod_def"; |
|
542 |
||
543 |
val zero_lt_natE = thm "zero_lt_natE"; |
|
544 |
val pred_succ_eq = thm "pred_succ_eq"; |
|
545 |
val natify_succ = thm "natify_succ"; |
|
546 |
val natify_0 = thm "natify_0"; |
|
547 |
val natify_non_succ = thm "natify_non_succ"; |
|
548 |
val natify_in_nat = thm "natify_in_nat"; |
|
549 |
val natify_ident = thm "natify_ident"; |
|
550 |
val natify_eqE = thm "natify_eqE"; |
|
551 |
val natify_idem = thm "natify_idem"; |
|
552 |
val add_natify1 = thm "add_natify1"; |
|
553 |
val add_natify2 = thm "add_natify2"; |
|
554 |
val mult_natify1 = thm "mult_natify1"; |
|
555 |
val mult_natify2 = thm "mult_natify2"; |
|
556 |
val diff_natify1 = thm "diff_natify1"; |
|
557 |
val diff_natify2 = thm "diff_natify2"; |
|
558 |
val mod_natify1 = thm "mod_natify1"; |
|
559 |
val mod_natify2 = thm "mod_natify2"; |
|
560 |
val div_natify1 = thm "div_natify1"; |
|
561 |
val div_natify2 = thm "div_natify2"; |
|
562 |
val raw_add_type = thm "raw_add_type"; |
|
563 |
val add_type = thm "add_type"; |
|
564 |
val raw_mult_type = thm "raw_mult_type"; |
|
565 |
val mult_type = thm "mult_type"; |
|
566 |
val raw_diff_type = thm "raw_diff_type"; |
|
567 |
val diff_type = thm "diff_type"; |
|
568 |
val diff_0_eq_0 = thm "diff_0_eq_0"; |
|
569 |
val diff_succ_succ = thm "diff_succ_succ"; |
|
570 |
val diff_0 = thm "diff_0"; |
|
571 |
val diff_le_self = thm "diff_le_self"; |
|
572 |
val add_0_natify = thm "add_0_natify"; |
|
573 |
val add_succ = thm "add_succ"; |
|
574 |
val add_0 = thm "add_0"; |
|
575 |
val add_assoc = thm "add_assoc"; |
|
576 |
val add_0_right_natify = thm "add_0_right_natify"; |
|
577 |
val add_succ_right = thm "add_succ_right"; |
|
578 |
val add_0_right = thm "add_0_right"; |
|
579 |
val add_commute = thm "add_commute"; |
|
580 |
val add_left_commute = thm "add_left_commute"; |
|
581 |
val raw_add_left_cancel = thm "raw_add_left_cancel"; |
|
582 |
val add_left_cancel_natify = thm "add_left_cancel_natify"; |
|
583 |
val add_left_cancel = thm "add_left_cancel"; |
|
584 |
val add_le_elim1_natify = thm "add_le_elim1_natify"; |
|
585 |
val add_le_elim1 = thm "add_le_elim1"; |
|
586 |
val add_lt_elim1_natify = thm "add_lt_elim1_natify"; |
|
587 |
val add_lt_elim1 = thm "add_lt_elim1"; |
|
588 |
val add_lt_mono1 = thm "add_lt_mono1"; |
|
589 |
val add_lt_mono = thm "add_lt_mono"; |
|
590 |
val Ord_lt_mono_imp_le_mono = thm "Ord_lt_mono_imp_le_mono"; |
|
591 |
val add_le_mono1 = thm "add_le_mono1"; |
|
592 |
val add_le_mono = thm "add_le_mono"; |
|
593 |
val diff_add_inverse = thm "diff_add_inverse"; |
|
594 |
val diff_add_inverse2 = thm "diff_add_inverse2"; |
|
595 |
val diff_cancel = thm "diff_cancel"; |
|
596 |
val diff_cancel2 = thm "diff_cancel2"; |
|
597 |
val diff_add_0 = thm "diff_add_0"; |
|
598 |
val eq_add_iff = thm "eq_add_iff"; |
|
599 |
val less_add_iff = thm "less_add_iff"; |
|
600 |
val diff_add_eq = thm "diff_add_eq"; |
|
601 |
val eq_cong2 = thm "eq_cong2"; |
|
602 |
val iff_cong2 = thm "iff_cong2"; |
|
603 |
val mult_0 = thm "mult_0"; |
|
604 |
val mult_succ = thm "mult_succ"; |
|
605 |
val mult_0_right = thm "mult_0_right"; |
|
606 |
val mult_succ_right = thm "mult_succ_right"; |
|
607 |
val mult_1_natify = thm "mult_1_natify"; |
|
608 |
val mult_1_right_natify = thm "mult_1_right_natify"; |
|
609 |
val mult_1 = thm "mult_1"; |
|
610 |
val mult_1_right = thm "mult_1_right"; |
|
611 |
val mult_commute = thm "mult_commute"; |
|
612 |
val add_mult_distrib = thm "add_mult_distrib"; |
|
613 |
val add_mult_distrib_left = thm "add_mult_distrib_left"; |
|
614 |
val mult_assoc = thm "mult_assoc"; |
|
615 |
val mult_left_commute = thm "mult_left_commute"; |
|
616 |
val lt_succ_eq_0_disj = thm "lt_succ_eq_0_disj"; |
|
617 |
val less_diff_conv = thm "less_diff_conv"; |
|
618 |
||
619 |
val add_ac = thms "add_ac"; |
|
620 |
val mult_ac = thms "mult_ac"; |
|
621 |
val nat_typechecks = thms "nat_typechecks"; |
|
622 |
*} |
|
9654
9754ba005b64
X-symbols for ordinal, cardinal, integer arithmetic
paulson
parents:
9492
diff
changeset
|
623 |
|
0 | 624 |
end |