24 using their counterparts on the integers: |
24 using their counterparts on the integers: |
25 *} |
25 *} |
26 |
26 |
27 code_datatype number_nat_inst.number_of_nat |
27 code_datatype number_nat_inst.number_of_nat |
28 |
28 |
29 lemma zero_nat_code [code, code_unfold_post]: |
29 lemma zero_nat_code [code, code_unfold]: |
30 "0 = (Numeral0 :: nat)" |
30 "0 = (Numeral0 :: nat)" |
31 by simp |
31 by simp |
32 |
32 |
33 lemma one_nat_code [code, code_unfold_post]: |
33 lemma one_nat_code [code, code_unfold]: |
34 "1 = (Numeral1 :: nat)" |
34 "1 = (Numeral1 :: nat)" |
35 by simp |
35 by simp |
36 |
36 |
37 lemma Suc_code [code]: |
37 lemma Suc_code [code]: |
38 "Suc n = n + 1" |
38 "Suc n = n + 1" |
284 |
284 |
285 text {* |
285 text {* |
286 Natural numerals. |
286 Natural numerals. |
287 *} |
287 *} |
288 |
288 |
289 lemma [code_unfold_post]: |
289 lemma [code_abbrev]: |
290 "nat (number_of i) = number_nat_inst.number_of_nat i" |
290 "number_nat_inst.number_of_nat i = nat (number_of i)" |
291 -- {* this interacts as desired with @{thm nat_number_of_def} *} |
291 -- {* this interacts as desired with @{thm nat_number_of_def} *} |
292 by (simp add: number_nat_inst.number_of_nat) |
292 by (simp add: number_nat_inst.number_of_nat) |
293 |
293 |
294 setup {* |
294 setup {* |
295 fold (Numeral.add_code @{const_name number_nat_inst.number_of_nat} |
295 fold (Numeral.add_code @{const_name number_nat_inst.number_of_nat} |
305 returns its input value, provided that it is non-negative, and otherwise |
305 returns its input value, provided that it is non-negative, and otherwise |
306 returns @{text "0"}. |
306 returns @{text "0"}. |
307 *} |
307 *} |
308 |
308 |
309 definition int :: "nat \<Rightarrow> int" where |
309 definition int :: "nat \<Rightarrow> int" where |
310 [code del]: "int = of_nat" |
310 [code del, code_abbrev]: "int = of_nat" |
311 |
311 |
312 lemma int_code' [code]: |
312 lemma int_code' [code]: |
313 "int (number_of l) = (if neg (number_of l \<Colon> int) then 0 else number_of l)" |
313 "int (number_of l) = (if neg (number_of l \<Colon> int) then 0 else number_of l)" |
314 unfolding int_nat_number_of [folded int_def] .. |
314 unfolding int_nat_number_of [folded int_def] .. |
315 |
315 |
316 lemma nat_code' [code]: |
316 lemma nat_code' [code]: |
317 "nat (number_of l) = (if neg (number_of l \<Colon> int) then 0 else number_of l)" |
317 "nat (number_of l) = (if neg (number_of l \<Colon> int) then 0 else number_of l)" |
318 unfolding nat_number_of_def number_of_is_id neg_def by simp |
318 unfolding nat_number_of_def number_of_is_id neg_def by simp |
319 |
319 |
320 lemma of_nat_int [code_unfold_post]: |
320 lemma of_nat_int: (* FIXME delete candidate *) |
321 "of_nat = int" by (simp add: int_def) |
321 "of_nat = int" by (simp add: int_def) |
322 |
322 |
323 lemma of_nat_aux_int [code_unfold]: |
323 lemma of_nat_aux_int [code_unfold]: |
324 "of_nat_aux (\<lambda>i. i + 1) k 0 = int k" |
324 "of_nat_aux (\<lambda>i. i + 1) k 0 = int k" |
325 by (simp add: int_def Nat.of_nat_code) |
325 by (simp add: int_def Nat.of_nat_code) |