author | huffman |
Mon, 16 Feb 2009 13:14:36 -0800 | |
changeset 29944 | ca43d393c2f1 |
parent 29943 | 922b931fd2eb |
child 29945 | 75df553549b1 |
permissions | -rw-r--r-- |
28021 | 1 |
(* Title: HOL/ex/Numeral.thy |
2 |
ID: $Id$ |
|
3 |
Author: Florian Haftmann |
|
4 |
||
5 |
An experimental alternative numeral representation. |
|
6 |
*) |
|
7 |
||
8 |
theory Numeral |
|
9 |
imports Int Inductive |
|
10 |
begin |
|
11 |
||
12 |
subsection {* The @{text num} type *} |
|
13 |
||
29943 | 14 |
datatype num = One | Dig0 num | Dig1 num |
15 |
||
16 |
text {* Increment function for type @{typ num} *} |
|
17 |
||
18 |
primrec |
|
19 |
inc :: "num \<Rightarrow> num" |
|
20 |
where |
|
21 |
"inc One = Dig0 One" |
|
22 |
| "inc (Dig0 x) = Dig1 x" |
|
23 |
| "inc (Dig1 x) = Dig0 (inc x)" |
|
24 |
||
25 |
text {* Converting between type @{typ num} and type @{typ nat} *} |
|
26 |
||
27 |
primrec |
|
28 |
nat_of_num :: "num \<Rightarrow> nat" |
|
29 |
where |
|
30 |
"nat_of_num One = Suc 0" |
|
31 |
| "nat_of_num (Dig0 x) = nat_of_num x + nat_of_num x" |
|
32 |
| "nat_of_num (Dig1 x) = Suc (nat_of_num x + nat_of_num x)" |
|
33 |
||
34 |
primrec |
|
35 |
num_of_nat :: "nat \<Rightarrow> num" |
|
36 |
where |
|
37 |
"num_of_nat 0 = One" |
|
38 |
| "num_of_nat (Suc n) = (if 0 < n then inc (num_of_nat n) else One)" |
|
39 |
||
40 |
lemma nat_of_num_gt_0: "0 < nat_of_num x" |
|
41 |
by (induct x) simp_all |
|
42 |
||
43 |
lemma nat_of_num_neq_0: " nat_of_num x \<noteq> 0" |
|
44 |
by (induct x) simp_all |
|
45 |
||
46 |
lemma nat_of_num_inc: "nat_of_num (inc x) = Suc (nat_of_num x)" |
|
47 |
by (induct x) simp_all |
|
48 |
||
49 |
lemma num_of_nat_double: |
|
50 |
"0 < n \<Longrightarrow> num_of_nat (n + n) = Dig0 (num_of_nat n)" |
|
51 |
by (induct n) simp_all |
|
52 |
||
28021 | 53 |
text {* |
29943 | 54 |
Type @{typ num} is isomorphic to the strictly positive |
28021 | 55 |
natural numbers. |
56 |
*} |
|
57 |
||
29943 | 58 |
lemma nat_of_num_inverse: "num_of_nat (nat_of_num x) = x" |
59 |
by (induct x) (simp_all add: num_of_nat_double nat_of_num_gt_0) |
|
28021 | 60 |
|
29943 | 61 |
lemma num_of_nat_inverse: "0 < n \<Longrightarrow> nat_of_num (num_of_nat n) = n" |
62 |
by (induct n) (simp_all add: nat_of_num_inc) |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
63 |
|
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
64 |
lemma num_eq_iff: "x = y \<longleftrightarrow> nat_of_num x = nat_of_num y" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
65 |
apply safe |
29943 | 66 |
apply (drule arg_cong [where f=num_of_nat]) |
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
67 |
apply (simp add: nat_of_num_inverse) |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
68 |
done |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
69 |
|
29944 | 70 |
instantiation num :: "{plus,times}" |
28021 | 71 |
begin |
72 |
||
73 |
definition plus_num :: "num \<Rightarrow> num \<Rightarrow> num" where |
|
28562 | 74 |
[code del]: "m + n = num_of_nat (nat_of_num m + nat_of_num n)" |
28021 | 75 |
|
76 |
definition times_num :: "num \<Rightarrow> num \<Rightarrow> num" where |
|
28562 | 77 |
[code del]: "m * n = num_of_nat (nat_of_num m * nat_of_num n)" |
28021 | 78 |
|
29943 | 79 |
lemma nat_of_num_add: "nat_of_num (x + y) = nat_of_num x + nat_of_num y" |
80 |
unfolding plus_num_def |
|
81 |
by (intro num_of_nat_inverse add_pos_pos nat_of_num_gt_0) |
|
28021 | 82 |
|
29943 | 83 |
lemma nat_of_num_mult: "nat_of_num (x * y) = nat_of_num x * nat_of_num y" |
84 |
unfolding times_num_def |
|
85 |
by (intro num_of_nat_inverse mult_pos_pos nat_of_num_gt_0) |
|
28021 | 86 |
|
29944 | 87 |
instance .. |
28021 | 88 |
|
89 |
end |
|
90 |
||
29943 | 91 |
lemma num_induct [case_names One inc]: |
92 |
fixes P :: "num \<Rightarrow> bool" |
|
93 |
assumes One: "P One" |
|
94 |
and inc: "\<And>x. P x \<Longrightarrow> P (inc x)" |
|
95 |
shows "P x" |
|
96 |
proof - |
|
97 |
obtain n where n: "Suc n = nat_of_num x" |
|
98 |
by (cases "nat_of_num x", simp_all add: nat_of_num_neq_0) |
|
99 |
have "P (num_of_nat (Suc n))" |
|
100 |
proof (induct n) |
|
101 |
case 0 show ?case using One by simp |
|
28021 | 102 |
next |
29943 | 103 |
case (Suc n) |
104 |
then have "P (inc (num_of_nat (Suc n)))" by (rule inc) |
|
105 |
then show "P (num_of_nat (Suc (Suc n)))" by simp |
|
28021 | 106 |
qed |
29943 | 107 |
with n show "P x" |
108 |
by (simp add: nat_of_num_inverse) |
|
28021 | 109 |
qed |
110 |
||
111 |
text {* |
|
112 |
From now on, there are two possible models for @{typ num}: |
|
29943 | 113 |
as positive naturals (rule @{text "num_induct"}) |
28021 | 114 |
and as digit representation (rules @{text "num.induct"}, @{text "num.cases"}). |
115 |
||
116 |
It is not entirely clear in which context it is better to use |
|
117 |
the one or the other, or whether the construction should be reversed. |
|
118 |
*} |
|
119 |
||
120 |
||
121 |
subsection {* Binary numerals *} |
|
122 |
||
123 |
text {* |
|
124 |
We embed binary representations into a generic algebraic |
|
125 |
structure using @{text of_num} |
|
126 |
*} |
|
127 |
||
128 |
ML {* |
|
129 |
structure DigSimps = |
|
130 |
NamedThmsFun(val name = "numeral"; val description = "Simplification rules for numerals") |
|
131 |
*} |
|
132 |
||
133 |
setup DigSimps.setup |
|
134 |
||
135 |
class semiring_numeral = semiring + monoid_mult |
|
136 |
begin |
|
137 |
||
138 |
primrec of_num :: "num \<Rightarrow> 'a" where |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
139 |
of_num_one [numeral]: "of_num One = 1" |
28021 | 140 |
| "of_num (Dig0 n) = of_num n + of_num n" |
141 |
| "of_num (Dig1 n) = of_num n + of_num n + 1" |
|
142 |
||
29943 | 143 |
lemma of_num_inc: "of_num (inc x) = of_num x + 1" |
144 |
by (induct x) (simp_all add: add_ac) |
|
145 |
||
28021 | 146 |
declare of_num.simps [simp del] |
147 |
||
148 |
end |
|
149 |
||
150 |
text {* |
|
151 |
ML stuff and syntax. |
|
152 |
*} |
|
153 |
||
154 |
ML {* |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
155 |
fun mk_num 1 = @{term One} |
28021 | 156 |
| mk_num k = |
157 |
let |
|
158 |
val (l, b) = Integer.div_mod k 2; |
|
159 |
val bit = (if b = 0 then @{term Dig0} else @{term Dig1}); |
|
160 |
in bit $ (mk_num l) end; |
|
161 |
||
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
162 |
fun dest_num @{term One} = 1 |
28021 | 163 |
| dest_num (@{term Dig0} $ n) = 2 * dest_num n |
164 |
| dest_num (@{term Dig1} $ n) = 2 * dest_num n + 1; |
|
165 |
||
166 |
(*FIXME these have to gain proper context via morphisms phi*) |
|
167 |
||
168 |
fun mk_numeral T k = Const (@{const_name of_num}, @{typ num} --> T) |
|
169 |
$ mk_num k |
|
170 |
||
171 |
fun dest_numeral (Const (@{const_name of_num}, Type ("fun", [@{typ num}, T])) $ t) = |
|
172 |
(T, dest_num t) |
|
173 |
*} |
|
174 |
||
175 |
syntax |
|
176 |
"_Numerals" :: "xnum \<Rightarrow> 'a" ("_") |
|
177 |
||
178 |
parse_translation {* |
|
179 |
let |
|
180 |
fun num_of_int n = if n > 0 then case IntInf.quotRem (n, 2) |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
181 |
of (0, 1) => Const (@{const_name One}, dummyT) |
28021 | 182 |
| (n, 0) => Const (@{const_name Dig0}, dummyT) $ num_of_int n |
183 |
| (n, 1) => Const (@{const_name Dig1}, dummyT) $ num_of_int n |
|
184 |
else raise Match; |
|
185 |
fun numeral_tr [Free (num, _)] = |
|
186 |
let |
|
187 |
val {leading_zeros, value, ...} = Syntax.read_xnum num; |
|
188 |
val _ = leading_zeros = 0 andalso value > 0 |
|
189 |
orelse error ("Bad numeral: " ^ num); |
|
190 |
in Const (@{const_name of_num}, @{typ num} --> dummyT) $ num_of_int value end |
|
191 |
| numeral_tr ts = raise TERM ("numeral_tr", ts); |
|
192 |
in [("_Numerals", numeral_tr)] end |
|
193 |
*} |
|
194 |
||
195 |
typed_print_translation {* |
|
196 |
let |
|
197 |
fun dig b n = b + 2 * n; |
|
198 |
fun int_of_num' (Const (@{const_syntax Dig0}, _) $ n) = |
|
199 |
dig 0 (int_of_num' n) |
|
200 |
| int_of_num' (Const (@{const_syntax Dig1}, _) $ n) = |
|
201 |
dig 1 (int_of_num' n) |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
202 |
| int_of_num' (Const (@{const_syntax One}, _)) = 1; |
28021 | 203 |
fun num_tr' show_sorts T [n] = |
204 |
let |
|
205 |
val k = int_of_num' n; |
|
206 |
val t' = Syntax.const "_Numerals" $ Syntax.free ("#" ^ string_of_int k); |
|
207 |
in case T |
|
208 |
of Type ("fun", [_, T']) => |
|
209 |
if not (! show_types) andalso can Term.dest_Type T' then t' |
|
210 |
else Syntax.const Syntax.constrainC $ t' $ Syntax.term_of_typ show_sorts T' |
|
211 |
| T' => if T' = dummyT then t' else raise Match |
|
212 |
end; |
|
213 |
in [(@{const_syntax of_num}, num_tr')] end |
|
214 |
*} |
|
215 |
||
216 |
||
217 |
subsection {* Numeral operations *} |
|
218 |
||
219 |
text {* |
|
220 |
First, addition and multiplication on digits. |
|
221 |
*} |
|
222 |
||
223 |
lemma Dig_plus [numeral, simp, code]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
224 |
"One + One = Dig0 One" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
225 |
"One + Dig0 m = Dig1 m" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
226 |
"One + Dig1 m = Dig0 (m + One)" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
227 |
"Dig0 n + One = Dig1 n" |
28021 | 228 |
"Dig0 n + Dig0 m = Dig0 (n + m)" |
229 |
"Dig0 n + Dig1 m = Dig1 (n + m)" |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
230 |
"Dig1 n + One = Dig0 (n + One)" |
28021 | 231 |
"Dig1 n + Dig0 m = Dig1 (n + m)" |
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
232 |
"Dig1 n + Dig1 m = Dig0 (n + m + One)" |
29943 | 233 |
by (simp_all add: num_eq_iff nat_of_num_add) |
28021 | 234 |
|
235 |
lemma Dig_times [numeral, simp, code]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
236 |
"One * One = One" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
237 |
"One * Dig0 n = Dig0 n" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
238 |
"One * Dig1 n = Dig1 n" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
239 |
"Dig0 n * One = Dig0 n" |
28021 | 240 |
"Dig0 n * Dig0 m = Dig0 (n * Dig0 m)" |
241 |
"Dig0 n * Dig1 m = Dig0 (n * Dig1 m)" |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
242 |
"Dig1 n * One = Dig1 n" |
28021 | 243 |
"Dig1 n * Dig0 m = Dig0 (n * Dig0 m + m)" |
244 |
"Dig1 n * Dig1 m = Dig1 (n * Dig1 m + m)" |
|
29943 | 245 |
by (simp_all add: num_eq_iff nat_of_num_add nat_of_num_mult |
246 |
left_distrib right_distrib) |
|
28021 | 247 |
|
248 |
text {* |
|
249 |
@{const of_num} is a morphism. |
|
250 |
*} |
|
251 |
||
252 |
context semiring_numeral |
|
253 |
begin |
|
254 |
||
29943 | 255 |
abbreviation "Num1 \<equiv> of_num One" |
28021 | 256 |
|
257 |
text {* |
|
258 |
Alas, there is still the duplication of @{term 1}, |
|
259 |
thought the duplicated @{term 0} has disappeared. |
|
260 |
We could get rid of it by replacing the constructor |
|
261 |
@{term 1} in @{typ num} by two constructors |
|
262 |
@{text two} and @{text three}, resulting in a further |
|
263 |
blow-up. But it could be worth the effort. |
|
264 |
*} |
|
265 |
||
266 |
lemma of_num_plus_one [numeral]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
267 |
"of_num n + 1 = of_num (n + One)" |
29943 | 268 |
by (rule sym, induct n) (simp_all add: of_num.simps add_ac) |
28021 | 269 |
|
270 |
lemma of_num_one_plus [numeral]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
271 |
"1 + of_num n = of_num (n + One)" |
28021 | 272 |
unfolding of_num_plus_one [symmetric] add_commute .. |
273 |
||
29943 | 274 |
text {* Rules for addition in the One/inc view *} |
275 |
||
276 |
lemma add_One: "x + One = inc x" |
|
277 |
by (simp add: num_eq_iff nat_of_num_add nat_of_num_inc) |
|
278 |
||
279 |
lemma add_inc: "x + inc y = inc (x + y)" |
|
280 |
by (simp add: num_eq_iff nat_of_num_add nat_of_num_inc) |
|
281 |
||
282 |
text {* Rules for multiplication in the One/inc view *} |
|
283 |
||
284 |
lemma mult_One: "x * One = x" |
|
285 |
by (simp add: num_eq_iff nat_of_num_mult) |
|
286 |
||
287 |
lemma mult_inc: "x * inc y = x * y + x" |
|
288 |
by (simp add: num_eq_iff nat_of_num_mult nat_of_num_add nat_of_num_inc) |
|
289 |
||
28021 | 290 |
lemma of_num_plus [numeral]: |
291 |
"of_num m + of_num n = of_num (m + n)" |
|
292 |
by (induct n rule: num_induct) |
|
29943 | 293 |
(simp_all add: add_One add_inc of_num_one of_num_inc add_ac) |
28021 | 294 |
|
295 |
lemma of_num_times_one [numeral]: |
|
296 |
"of_num n * 1 = of_num n" |
|
297 |
by simp |
|
298 |
||
299 |
lemma of_num_one_times [numeral]: |
|
300 |
"1 * of_num n = of_num n" |
|
301 |
by simp |
|
302 |
||
303 |
lemma of_num_times [numeral]: |
|
304 |
"of_num m * of_num n = of_num (m * n)" |
|
305 |
by (induct n rule: num_induct) |
|
29943 | 306 |
(simp_all add: of_num_plus [symmetric] mult_One mult_inc |
307 |
semiring_class.right_distrib right_distrib of_num_one of_num_inc) |
|
28021 | 308 |
|
309 |
end |
|
310 |
||
311 |
text {* |
|
312 |
Structures with a @{term 0}. |
|
313 |
*} |
|
314 |
||
315 |
context semiring_1 |
|
316 |
begin |
|
317 |
||
318 |
subclass semiring_numeral .. |
|
319 |
||
320 |
lemma of_nat_of_num [numeral]: "of_nat (of_num n) = of_num n" |
|
321 |
by (induct n) |
|
322 |
(simp_all add: semiring_numeral_class.of_num.simps of_num.simps add_ac) |
|
323 |
||
324 |
declare of_nat_1 [numeral] |
|
325 |
||
326 |
lemma Dig_plus_zero [numeral]: |
|
327 |
"0 + 1 = 1" |
|
328 |
"0 + of_num n = of_num n" |
|
329 |
"1 + 0 = 1" |
|
330 |
"of_num n + 0 = of_num n" |
|
331 |
by simp_all |
|
332 |
||
333 |
lemma Dig_times_zero [numeral]: |
|
334 |
"0 * 1 = 0" |
|
335 |
"0 * of_num n = 0" |
|
336 |
"1 * 0 = 0" |
|
337 |
"of_num n * 0 = 0" |
|
338 |
by simp_all |
|
339 |
||
340 |
end |
|
341 |
||
342 |
lemma nat_of_num_of_num: "nat_of_num = of_num" |
|
343 |
proof |
|
344 |
fix n |
|
29943 | 345 |
have "of_num n = nat_of_num n" |
346 |
by (induct n) (simp_all add: of_num.simps) |
|
28021 | 347 |
then show "nat_of_num n = of_num n" by simp |
348 |
qed |
|
349 |
||
350 |
text {* |
|
351 |
Equality. |
|
352 |
*} |
|
353 |
||
354 |
context semiring_char_0 |
|
355 |
begin |
|
356 |
||
357 |
lemma of_num_eq_iff [numeral]: |
|
358 |
"of_num m = of_num n \<longleftrightarrow> m = n" |
|
359 |
unfolding of_nat_of_num [symmetric] nat_of_num_of_num [symmetric] |
|
29943 | 360 |
of_nat_eq_iff num_eq_iff .. |
28021 | 361 |
|
362 |
lemma of_num_eq_one_iff [numeral]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
363 |
"of_num n = 1 \<longleftrightarrow> n = One" |
28021 | 364 |
proof - |
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
365 |
have "of_num n = of_num One \<longleftrightarrow> n = One" unfolding of_num_eq_iff .. |
28021 | 366 |
then show ?thesis by (simp add: of_num_one) |
367 |
qed |
|
368 |
||
369 |
lemma one_eq_of_num_iff [numeral]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
370 |
"1 = of_num n \<longleftrightarrow> n = One" |
28021 | 371 |
unfolding of_num_eq_one_iff [symmetric] by auto |
372 |
||
373 |
end |
|
374 |
||
375 |
text {* |
|
376 |
Comparisons. Could be perhaps more general than here. |
|
377 |
*} |
|
378 |
||
379 |
lemma (in ordered_semidom) of_num_pos: "0 < of_num n" |
|
380 |
proof - |
|
381 |
have "(0::nat) < of_num n" |
|
382 |
by (induct n) (simp_all add: semiring_numeral_class.of_num.simps) |
|
383 |
then have "of_nat 0 \<noteq> of_nat (of_num n)" |
|
384 |
by (cases n) (simp_all only: semiring_numeral_class.of_num.simps of_nat_eq_iff) |
|
385 |
then have "0 \<noteq> of_num n" |
|
386 |
by (simp add: of_nat_of_num) |
|
387 |
moreover have "0 \<le> of_nat (of_num n)" by simp |
|
388 |
ultimately show ?thesis by (simp add: of_nat_of_num) |
|
389 |
qed |
|
390 |
||
29944 | 391 |
instantiation num :: ord |
28021 | 392 |
begin |
393 |
||
394 |
definition less_eq_num :: "num \<Rightarrow> num \<Rightarrow> bool" where |
|
28562 | 395 |
[code del]: "m \<le> n \<longleftrightarrow> nat_of_num m \<le> nat_of_num n" |
28021 | 396 |
|
397 |
definition less_num :: "num \<Rightarrow> num \<Rightarrow> bool" where |
|
28562 | 398 |
[code del]: "m < n \<longleftrightarrow> nat_of_num m < nat_of_num n" |
28021 | 399 |
|
29944 | 400 |
instance .. |
28021 | 401 |
|
402 |
end |
|
403 |
||
404 |
lemma less_eq_num_code [numeral, simp, code]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
405 |
"One \<le> n \<longleftrightarrow> True" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
406 |
"Dig0 m \<le> One \<longleftrightarrow> False" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
407 |
"Dig1 m \<le> One \<longleftrightarrow> False" |
28021 | 408 |
"Dig0 m \<le> Dig0 n \<longleftrightarrow> m \<le> n" |
409 |
"Dig0 m \<le> Dig1 n \<longleftrightarrow> m \<le> n" |
|
410 |
"Dig1 m \<le> Dig1 n \<longleftrightarrow> m \<le> n" |
|
411 |
"Dig1 m \<le> Dig0 n \<longleftrightarrow> m < n" |
|
412 |
using of_num_pos [of n, where ?'a = nat] of_num_pos [of m, where ?'a = nat] |
|
413 |
by (auto simp add: less_eq_num_def less_num_def nat_of_num_of_num of_num.simps) |
|
414 |
||
415 |
lemma less_num_code [numeral, simp, code]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
416 |
"m < One \<longleftrightarrow> False" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
417 |
"One < One \<longleftrightarrow> False" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
418 |
"One < Dig0 n \<longleftrightarrow> True" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
419 |
"One < Dig1 n \<longleftrightarrow> True" |
28021 | 420 |
"Dig0 m < Dig0 n \<longleftrightarrow> m < n" |
421 |
"Dig0 m < Dig1 n \<longleftrightarrow> m \<le> n" |
|
422 |
"Dig1 m < Dig1 n \<longleftrightarrow> m < n" |
|
423 |
"Dig1 m < Dig0 n \<longleftrightarrow> m < n" |
|
424 |
using of_num_pos [of n, where ?'a = nat] of_num_pos [of m, where ?'a = nat] |
|
425 |
by (auto simp add: less_eq_num_def less_num_def nat_of_num_of_num of_num.simps) |
|
426 |
||
427 |
context ordered_semidom |
|
428 |
begin |
|
429 |
||
430 |
lemma of_num_less_eq_iff [numeral]: "of_num m \<le> of_num n \<longleftrightarrow> m \<le> n" |
|
431 |
proof - |
|
432 |
have "of_nat (of_num m) \<le> of_nat (of_num n) \<longleftrightarrow> m \<le> n" |
|
433 |
unfolding less_eq_num_def nat_of_num_of_num of_nat_le_iff .. |
|
434 |
then show ?thesis by (simp add: of_nat_of_num) |
|
435 |
qed |
|
436 |
||
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
437 |
lemma of_num_less_eq_one_iff [numeral]: "of_num n \<le> 1 \<longleftrightarrow> n = One" |
28021 | 438 |
proof - |
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
439 |
have "of_num n \<le> of_num One \<longleftrightarrow> n = One" |
28021 | 440 |
by (cases n) (simp_all add: of_num_less_eq_iff) |
441 |
then show ?thesis by (simp add: of_num_one) |
|
442 |
qed |
|
443 |
||
444 |
lemma one_less_eq_of_num_iff [numeral]: "1 \<le> of_num n" |
|
445 |
proof - |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
446 |
have "of_num One \<le> of_num n" |
28021 | 447 |
by (cases n) (simp_all add: of_num_less_eq_iff) |
448 |
then show ?thesis by (simp add: of_num_one) |
|
449 |
qed |
|
450 |
||
451 |
lemma of_num_less_iff [numeral]: "of_num m < of_num n \<longleftrightarrow> m < n" |
|
452 |
proof - |
|
453 |
have "of_nat (of_num m) < of_nat (of_num n) \<longleftrightarrow> m < n" |
|
454 |
unfolding less_num_def nat_of_num_of_num of_nat_less_iff .. |
|
455 |
then show ?thesis by (simp add: of_nat_of_num) |
|
456 |
qed |
|
457 |
||
458 |
lemma of_num_less_one_iff [numeral]: "\<not> of_num n < 1" |
|
459 |
proof - |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
460 |
have "\<not> of_num n < of_num One" |
28021 | 461 |
by (cases n) (simp_all add: of_num_less_iff) |
462 |
then show ?thesis by (simp add: of_num_one) |
|
463 |
qed |
|
464 |
||
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
465 |
lemma one_less_of_num_iff [numeral]: "1 < of_num n \<longleftrightarrow> n \<noteq> One" |
28021 | 466 |
proof - |
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
467 |
have "of_num One < of_num n \<longleftrightarrow> n \<noteq> One" |
28021 | 468 |
by (cases n) (simp_all add: of_num_less_iff) |
469 |
then show ?thesis by (simp add: of_num_one) |
|
470 |
qed |
|
471 |
||
472 |
end |
|
473 |
||
474 |
text {* |
|
475 |
Structures with subtraction @{term "op -"}. |
|
476 |
*} |
|
477 |
||
29941 | 478 |
text {* A double-and-decrement function *} |
28021 | 479 |
|
29941 | 480 |
primrec DigM :: "num \<Rightarrow> num" where |
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
481 |
"DigM One = One" |
29941 | 482 |
| "DigM (Dig0 n) = Dig1 (DigM n)" |
483 |
| "DigM (Dig1 n) = Dig1 (Dig0 n)" |
|
28021 | 484 |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
485 |
lemma DigM_plus_one: "DigM n + One = Dig0 n" |
29941 | 486 |
by (induct n) simp_all |
28021 | 487 |
|
29944 | 488 |
lemma add_One_commute: "One + n = n + One" |
489 |
by (induct n) simp_all |
|
490 |
||
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
491 |
lemma one_plus_DigM: "One + DigM n = Dig0 n" |
29944 | 492 |
unfolding add_One_commute DigM_plus_one .. |
28021 | 493 |
|
494 |
class semiring_minus = semiring + minus + zero + |
|
495 |
assumes minus_inverts_plus1: "a + b = c \<Longrightarrow> c - b = a" |
|
496 |
assumes minus_minus_zero_inverts_plus1: "a + b = c \<Longrightarrow> b - c = 0 - a" |
|
497 |
begin |
|
498 |
||
499 |
lemma minus_inverts_plus2: "a + b = c \<Longrightarrow> c - a = b" |
|
500 |
by (simp add: add_ac minus_inverts_plus1 [of b a]) |
|
501 |
||
502 |
lemma minus_minus_zero_inverts_plus2: "a + b = c \<Longrightarrow> a - c = 0 - b" |
|
503 |
by (simp add: add_ac minus_minus_zero_inverts_plus1 [of b a]) |
|
504 |
||
505 |
end |
|
506 |
||
507 |
class semiring_1_minus = semiring_1 + semiring_minus |
|
508 |
begin |
|
509 |
||
510 |
lemma Dig_of_num_pos: |
|
511 |
assumes "k + n = m" |
|
512 |
shows "of_num m - of_num n = of_num k" |
|
513 |
using assms by (simp add: of_num_plus minus_inverts_plus1) |
|
514 |
||
515 |
lemma Dig_of_num_zero: |
|
516 |
shows "of_num n - of_num n = 0" |
|
517 |
by (rule minus_inverts_plus1) simp |
|
518 |
||
519 |
lemma Dig_of_num_neg: |
|
520 |
assumes "k + m = n" |
|
521 |
shows "of_num m - of_num n = 0 - of_num k" |
|
522 |
by (rule minus_minus_zero_inverts_plus1) (simp add: of_num_plus assms) |
|
523 |
||
524 |
lemmas Dig_plus_eval = |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
525 |
of_num_plus of_num_eq_iff Dig_plus refl [of One, THEN eqTrueI] num.inject |
28021 | 526 |
|
527 |
simproc_setup numeral_minus ("of_num m - of_num n") = {* |
|
528 |
let |
|
529 |
(*TODO proper implicit use of morphism via pattern antiquotations*) |
|
530 |
fun cdest_of_num ct = (snd o split_last o snd o Drule.strip_comb) ct; |
|
531 |
fun cdest_minus ct = case (rev o snd o Drule.strip_comb) ct of [n, m] => (m, n); |
|
532 |
fun attach_num ct = (dest_num (Thm.term_of ct), ct); |
|
533 |
fun cdifference t = (pairself (attach_num o cdest_of_num) o cdest_minus) t; |
|
534 |
val simplify = MetaSimplifier.rewrite false (map mk_meta_eq @{thms Dig_plus_eval}); |
|
535 |
fun cert ck cl cj = @{thm eqTrueE} OF [@{thm meta_eq_to_obj_eq} OF [simplify (Drule.list_comb (@{cterm "op = :: num \<Rightarrow> _"}, |
|
536 |
[Drule.list_comb (@{cterm "op + :: num \<Rightarrow> _"}, [ck, cl]), cj]))]]; |
|
537 |
in fn phi => fn _ => fn ct => case try cdifference ct |
|
538 |
of NONE => (NONE) |
|
539 |
| SOME ((k, ck), (l, cl)) => SOME (let val j = k - l in if j = 0 |
|
540 |
then MetaSimplifier.rewrite false [mk_meta_eq (Morphism.thm phi @{thm Dig_of_num_zero})] ct |
|
541 |
else mk_meta_eq (let |
|
542 |
val cj = Thm.cterm_of (Thm.theory_of_cterm ct) (mk_num (abs j)); |
|
543 |
in |
|
544 |
(if j > 0 then (Morphism.thm phi @{thm Dig_of_num_pos}) OF [cert cj cl ck] |
|
545 |
else (Morphism.thm phi @{thm Dig_of_num_neg}) OF [cert cj ck cl]) |
|
546 |
end) end) |
|
547 |
end |
|
548 |
*} |
|
549 |
||
550 |
lemma Dig_of_num_minus_zero [numeral]: |
|
551 |
"of_num n - 0 = of_num n" |
|
552 |
by (simp add: minus_inverts_plus1) |
|
553 |
||
554 |
lemma Dig_one_minus_zero [numeral]: |
|
555 |
"1 - 0 = 1" |
|
556 |
by (simp add: minus_inverts_plus1) |
|
557 |
||
558 |
lemma Dig_one_minus_one [numeral]: |
|
559 |
"1 - 1 = 0" |
|
560 |
by (simp add: minus_inverts_plus1) |
|
561 |
||
562 |
lemma Dig_of_num_minus_one [numeral]: |
|
29941 | 563 |
"of_num (Dig0 n) - 1 = of_num (DigM n)" |
28021 | 564 |
"of_num (Dig1 n) - 1 = of_num (Dig0 n)" |
29941 | 565 |
by (auto intro: minus_inverts_plus1 simp add: DigM_plus_one of_num.simps of_num_plus_one) |
28021 | 566 |
|
567 |
lemma Dig_one_minus_of_num [numeral]: |
|
29941 | 568 |
"1 - of_num (Dig0 n) = 0 - of_num (DigM n)" |
28021 | 569 |
"1 - of_num (Dig1 n) = 0 - of_num (Dig0 n)" |
29941 | 570 |
by (auto intro: minus_minus_zero_inverts_plus1 simp add: DigM_plus_one of_num.simps of_num_plus_one) |
28021 | 571 |
|
572 |
end |
|
573 |
||
574 |
context ring_1 |
|
575 |
begin |
|
576 |
||
577 |
subclass semiring_1_minus |
|
29667 | 578 |
proof qed (simp_all add: algebra_simps) |
28021 | 579 |
|
580 |
lemma Dig_zero_minus_of_num [numeral]: |
|
581 |
"0 - of_num n = - of_num n" |
|
582 |
by simp |
|
583 |
||
584 |
lemma Dig_zero_minus_one [numeral]: |
|
585 |
"0 - 1 = - 1" |
|
586 |
by simp |
|
587 |
||
588 |
lemma Dig_uminus_uminus [numeral]: |
|
589 |
"- (- of_num n) = of_num n" |
|
590 |
by simp |
|
591 |
||
592 |
lemma Dig_plus_uminus [numeral]: |
|
593 |
"of_num m + - of_num n = of_num m - of_num n" |
|
594 |
"- of_num m + of_num n = of_num n - of_num m" |
|
595 |
"- of_num m + - of_num n = - (of_num m + of_num n)" |
|
596 |
"of_num m - - of_num n = of_num m + of_num n" |
|
597 |
"- of_num m - of_num n = - (of_num m + of_num n)" |
|
598 |
"- of_num m - - of_num n = of_num n - of_num m" |
|
599 |
by (simp_all add: diff_minus add_commute) |
|
600 |
||
601 |
lemma Dig_times_uminus [numeral]: |
|
602 |
"- of_num n * of_num m = - (of_num n * of_num m)" |
|
603 |
"of_num n * - of_num m = - (of_num n * of_num m)" |
|
604 |
"- of_num n * - of_num m = of_num n * of_num m" |
|
605 |
by (simp_all add: minus_mult_left [symmetric] minus_mult_right [symmetric]) |
|
606 |
||
607 |
lemma of_int_of_num [numeral]: "of_int (of_num n) = of_num n" |
|
608 |
by (induct n) |
|
609 |
(simp_all only: of_num.simps semiring_numeral_class.of_num.simps of_int_add, simp_all) |
|
610 |
||
611 |
declare of_int_1 [numeral] |
|
612 |
||
613 |
end |
|
614 |
||
615 |
text {* |
|
616 |
Greetings to @{typ nat}. |
|
617 |
*} |
|
618 |
||
619 |
instance nat :: semiring_1_minus proof qed simp_all |
|
620 |
||
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
621 |
lemma Suc_of_num [numeral]: "Suc (of_num n) = of_num (n + One)" |
28021 | 622 |
unfolding of_num_plus_one [symmetric] by simp |
623 |
||
624 |
lemma nat_number: |
|
625 |
"1 = Suc 0" |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
626 |
"of_num One = Suc 0" |
29941 | 627 |
"of_num (Dig0 n) = Suc (of_num (DigM n))" |
28021 | 628 |
"of_num (Dig1 n) = Suc (of_num (Dig0 n))" |
29941 | 629 |
by (simp_all add: of_num.simps DigM_plus_one Suc_of_num) |
28021 | 630 |
|
631 |
declare diff_0_eq_0 [numeral] |
|
632 |
||
633 |
||
634 |
subsection {* Code generator setup for @{typ int} *} |
|
635 |
||
636 |
definition Pls :: "num \<Rightarrow> int" where |
|
637 |
[simp, code post]: "Pls n = of_num n" |
|
638 |
||
639 |
definition Mns :: "num \<Rightarrow> int" where |
|
640 |
[simp, code post]: "Mns n = - of_num n" |
|
641 |
||
642 |
code_datatype "0::int" Pls Mns |
|
643 |
||
644 |
lemmas [code inline] = Pls_def [symmetric] Mns_def [symmetric] |
|
645 |
||
646 |
definition sub :: "num \<Rightarrow> num \<Rightarrow> int" where |
|
28562 | 647 |
[simp, code del]: "sub m n = (of_num m - of_num n)" |
28021 | 648 |
|
649 |
definition dup :: "int \<Rightarrow> int" where |
|
28562 | 650 |
[code del]: "dup k = 2 * k" |
28021 | 651 |
|
652 |
lemma Dig_sub [code]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
653 |
"sub One One = 0" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
654 |
"sub (Dig0 m) One = of_num (DigM m)" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
655 |
"sub (Dig1 m) One = of_num (Dig0 m)" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
656 |
"sub One (Dig0 n) = - of_num (DigM n)" |
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
657 |
"sub One (Dig1 n) = - of_num (Dig0 n)" |
28021 | 658 |
"sub (Dig0 m) (Dig0 n) = dup (sub m n)" |
659 |
"sub (Dig1 m) (Dig1 n) = dup (sub m n)" |
|
660 |
"sub (Dig1 m) (Dig0 n) = dup (sub m n) + 1" |
|
661 |
"sub (Dig0 m) (Dig1 n) = dup (sub m n) - 1" |
|
29667 | 662 |
apply (simp_all add: dup_def algebra_simps) |
29941 | 663 |
apply (simp_all add: of_num_plus one_plus_DigM)[4] |
28021 | 664 |
apply (simp_all add: of_num.simps) |
665 |
done |
|
666 |
||
667 |
lemma dup_code [code]: |
|
668 |
"dup 0 = 0" |
|
669 |
"dup (Pls n) = Pls (Dig0 n)" |
|
670 |
"dup (Mns n) = Mns (Dig0 n)" |
|
671 |
by (simp_all add: dup_def of_num.simps) |
|
672 |
||
28562 | 673 |
lemma [code, code del]: |
28021 | 674 |
"(1 :: int) = 1" |
675 |
"(op + :: int \<Rightarrow> int \<Rightarrow> int) = op +" |
|
676 |
"(uminus :: int \<Rightarrow> int) = uminus" |
|
677 |
"(op - :: int \<Rightarrow> int \<Rightarrow> int) = op -" |
|
678 |
"(op * :: int \<Rightarrow> int \<Rightarrow> int) = op *" |
|
28367 | 679 |
"(eq_class.eq :: int \<Rightarrow> int \<Rightarrow> bool) = eq_class.eq" |
28021 | 680 |
"(op \<le> :: int \<Rightarrow> int \<Rightarrow> bool) = op \<le>" |
681 |
"(op < :: int \<Rightarrow> int \<Rightarrow> bool) = op <" |
|
682 |
by rule+ |
|
683 |
||
684 |
lemma one_int_code [code]: |
|
29942
31069b8d39df
replace 1::num with One; remove monoid_mult instance
huffman
parents:
29941
diff
changeset
|
685 |
"1 = Pls One" |
28021 | 686 |
by (simp add: of_num_one) |
687 |
||
688 |
lemma plus_int_code [code]: |
|
689 |
"k + 0 = (k::int)" |
|
690 |
"0 + l = (l::int)" |
|
691 |
"Pls m + Pls n = Pls (m + n)" |
|
692 |
"Pls m - Pls n = sub m n" |
|
693 |
"Mns m + Mns n = Mns (m + n)" |
|
694 |
"Mns m - Mns n = sub n m" |
|
695 |
by (simp_all add: of_num_plus [symmetric]) |
|
696 |
||
697 |
lemma uminus_int_code [code]: |
|
698 |
"uminus 0 = (0::int)" |
|
699 |
"uminus (Pls m) = Mns m" |
|
700 |
"uminus (Mns m) = Pls m" |
|
701 |
by simp_all |
|
702 |
||
703 |
lemma minus_int_code [code]: |
|
704 |
"k - 0 = (k::int)" |
|
705 |
"0 - l = uminus (l::int)" |
|
706 |
"Pls m - Pls n = sub m n" |
|
707 |
"Pls m - Mns n = Pls (m + n)" |
|
708 |
"Mns m - Pls n = Mns (m + n)" |
|
709 |
"Mns m - Mns n = sub n m" |
|
710 |
by (simp_all add: of_num_plus [symmetric]) |
|
711 |
||
712 |
lemma times_int_code [code]: |
|
713 |
"k * 0 = (0::int)" |
|
714 |
"0 * l = (0::int)" |
|
715 |
"Pls m * Pls n = Pls (m * n)" |
|
716 |
"Pls m * Mns n = Mns (m * n)" |
|
717 |
"Mns m * Pls n = Mns (m * n)" |
|
718 |
"Mns m * Mns n = Pls (m * n)" |
|
719 |
by (simp_all add: of_num_times [symmetric]) |
|
720 |
||
721 |
lemma eq_int_code [code]: |
|
28367 | 722 |
"eq_class.eq 0 (0::int) \<longleftrightarrow> True" |
723 |
"eq_class.eq 0 (Pls l) \<longleftrightarrow> False" |
|
724 |
"eq_class.eq 0 (Mns l) \<longleftrightarrow> False" |
|
725 |
"eq_class.eq (Pls k) 0 \<longleftrightarrow> False" |
|
726 |
"eq_class.eq (Pls k) (Pls l) \<longleftrightarrow> eq_class.eq k l" |
|
727 |
"eq_class.eq (Pls k) (Mns l) \<longleftrightarrow> False" |
|
728 |
"eq_class.eq (Mns k) 0 \<longleftrightarrow> False" |
|
729 |
"eq_class.eq (Mns k) (Pls l) \<longleftrightarrow> False" |
|
730 |
"eq_class.eq (Mns k) (Mns l) \<longleftrightarrow> eq_class.eq k l" |
|
28021 | 731 |
using of_num_pos [of l, where ?'a = int] of_num_pos [of k, where ?'a = int] |
28367 | 732 |
by (simp_all add: of_num_eq_iff eq) |
28021 | 733 |
|
734 |
lemma less_eq_int_code [code]: |
|
735 |
"0 \<le> (0::int) \<longleftrightarrow> True" |
|
736 |
"0 \<le> Pls l \<longleftrightarrow> True" |
|
737 |
"0 \<le> Mns l \<longleftrightarrow> False" |
|
738 |
"Pls k \<le> 0 \<longleftrightarrow> False" |
|
739 |
"Pls k \<le> Pls l \<longleftrightarrow> k \<le> l" |
|
740 |
"Pls k \<le> Mns l \<longleftrightarrow> False" |
|
741 |
"Mns k \<le> 0 \<longleftrightarrow> True" |
|
742 |
"Mns k \<le> Pls l \<longleftrightarrow> True" |
|
743 |
"Mns k \<le> Mns l \<longleftrightarrow> l \<le> k" |
|
744 |
using of_num_pos [of l, where ?'a = int] of_num_pos [of k, where ?'a = int] |
|
745 |
by (simp_all add: of_num_less_eq_iff) |
|
746 |
||
747 |
lemma less_int_code [code]: |
|
748 |
"0 < (0::int) \<longleftrightarrow> False" |
|
749 |
"0 < Pls l \<longleftrightarrow> True" |
|
750 |
"0 < Mns l \<longleftrightarrow> False" |
|
751 |
"Pls k < 0 \<longleftrightarrow> False" |
|
752 |
"Pls k < Pls l \<longleftrightarrow> k < l" |
|
753 |
"Pls k < Mns l \<longleftrightarrow> False" |
|
754 |
"Mns k < 0 \<longleftrightarrow> True" |
|
755 |
"Mns k < Pls l \<longleftrightarrow> True" |
|
756 |
"Mns k < Mns l \<longleftrightarrow> l < k" |
|
757 |
using of_num_pos [of l, where ?'a = int] of_num_pos [of k, where ?'a = int] |
|
758 |
by (simp_all add: of_num_less_iff) |
|
759 |
||
760 |
lemma [code inline del]: "(0::int) \<equiv> Numeral0" by simp |
|
761 |
lemma [code inline del]: "(1::int) \<equiv> Numeral1" by simp |
|
762 |
declare zero_is_num_zero [code inline del] |
|
763 |
declare one_is_num_one [code inline del] |
|
764 |
||
765 |
hide (open) const sub dup |
|
766 |
||
767 |
||
768 |
subsection {* Numeral equations as default simplification rules *} |
|
769 |
||
770 |
text {* TODO. Be more precise here with respect to subsumed facts. *} |
|
771 |
declare (in semiring_numeral) numeral [simp] |
|
772 |
declare (in semiring_1) numeral [simp] |
|
773 |
declare (in semiring_char_0) numeral [simp] |
|
774 |
declare (in ring_1) numeral [simp] |
|
775 |
thm numeral |
|
776 |
||
777 |
||
778 |
text {* Toy examples *} |
|
779 |
||
780 |
definition "bar \<longleftrightarrow> #4 * #2 + #7 = (#8 :: nat) \<and> #4 * #2 + #7 \<ge> (#8 :: int) - #3" |
|
781 |
code_thms bar |
|
782 |
export_code bar in Haskell file - |
|
783 |
export_code bar in OCaml module_name Foo file - |
|
784 |
ML {* @{code bar} *} |
|
785 |
||
786 |
end |