equal
deleted
inserted
replaced
4 *) |
4 *) |
5 |
5 |
6 header {* Implementation of natural numbers by target-language integers *} |
6 header {* Implementation of natural numbers by target-language integers *} |
7 |
7 |
8 theory Efficient_Nat |
8 theory Efficient_Nat |
9 imports Plain Code_Index Code_Integer |
9 imports Code_Index Code_Integer |
10 begin |
10 begin |
11 |
11 |
12 text {* |
12 text {* |
13 When generating code for functions on natural numbers, the |
13 When generating code for functions on natural numbers, the |
14 canonical representation using @{term "0::nat"} and |
14 canonical representation using @{term "0::nat"} and |
54 unfolding of_nat_mult [symmetric] by simp |
54 unfolding of_nat_mult [symmetric] by simp |
55 |
55 |
56 text {* Specialized @{term "op div \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"} |
56 text {* Specialized @{term "op div \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"} |
57 and @{term "op mod \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"} operations. *} |
57 and @{term "op mod \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"} operations. *} |
58 |
58 |
59 definition |
59 definition divmod_aux :: "nat \<Rightarrow> nat \<Rightarrow> nat \<times> nat" where |
60 divmod_aux :: "nat \<Rightarrow> nat \<Rightarrow> nat \<times> nat" |
|
61 where |
|
62 [code del]: "divmod_aux = divmod" |
60 [code del]: "divmod_aux = divmod" |
63 |
61 |
64 lemma [code]: |
62 lemma [code]: |
65 "divmod n m = (if m = 0 then (0, n) else divmod_aux n m)" |
63 "divmod n m = (if m = 0 then (0, n) else divmod_aux n m)" |
66 unfolding divmod_aux_def divmod_div_mod by simp |
64 unfolding divmod_aux_def divmod_div_mod by simp |