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