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