276 then have "int (nat_of k) = int (nat_of k div 2) * 2 + int (nat_of k mod 2)" |
276 then have "int (nat_of k) = int (nat_of k div 2) * 2 + int (nat_of k mod 2)" |
277 unfolding int_mult zadd_int [symmetric] by simp |
277 unfolding int_mult zadd_int [symmetric] by simp |
278 then show ?thesis by (auto simp add: int_of_def mult_ac) |
278 then show ?thesis by (auto simp add: int_of_def mult_ac) |
279 qed |
279 qed |
280 |
280 |
281 hide (open) const of_nat nat_of int_of |
281 hide_const (open) of_nat nat_of int_of |
282 |
282 |
283 subsubsection {* Lazy Evaluation of an indexed function *} |
283 subsubsection {* Lazy Evaluation of an indexed function *} |
284 |
284 |
285 function iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a Predicate.pred" |
285 function iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a Predicate.pred" |
286 where |
286 where |
287 "iterate_upto f n m = Predicate.Seq (%u. if n > m then Predicate.Empty else Predicate.Insert (f n) (iterate_upto f (n + 1) m))" |
287 "iterate_upto f n m = Predicate.Seq (%u. if n > m then Predicate.Empty else Predicate.Insert (f n) (iterate_upto f (n + 1) m))" |
288 by pat_completeness auto |
288 by pat_completeness auto |
289 |
289 |
290 termination by (relation "measure (%(f, n, m). Code_Numeral.nat_of (m + 1 - n))") auto |
290 termination by (relation "measure (%(f, n, m). Code_Numeral.nat_of (m + 1 - n))") auto |
291 |
291 |
292 hide (open) const iterate_upto |
292 hide_const (open) iterate_upto |
293 |
293 |
294 subsection {* Code generator setup *} |
294 subsection {* Code generator setup *} |
295 |
295 |
296 text {* Implementation of indices by bounded integers *} |
296 text {* Implementation of indices by bounded integers *} |
297 |
297 |