160 by (simp add: min_def less_eq_int_def) |
160 by (simp add: min_def less_eq_int_def) |
161 |
161 |
162 lemma int_of_max [simp]: |
162 lemma int_of_max [simp]: |
163 "int_of (max k l) = max (int_of k) (int_of l)" |
163 "int_of (max k l) = max (int_of k) (int_of l)" |
164 by (simp add: max_def less_eq_int_def) |
164 by (simp add: max_def less_eq_int_def) |
|
165 |
|
166 lemma of_nat_nat_of [simp]: |
|
167 "of_nat (nat_of k) = max 0 k" |
|
168 by (simp add: nat_of_def Target_Numeral.int_eq_iff less_eq_int_def max_def) |
165 |
169 |
166 |
170 |
167 subsection {* Code theorems for target language numerals *} |
171 subsection {* Code theorems for target language numerals *} |
168 |
172 |
169 text {* Constructors *} |
173 text {* Constructors *} |
618 declare of_int_code [code] |
622 declare of_int_code [code] |
619 |
623 |
620 |
624 |
621 subsection {* Implementation for @{typ nat} *} |
625 subsection {* Implementation for @{typ nat} *} |
622 |
626 |
|
627 definition Nat :: "Target_Numeral.int \<Rightarrow> nat" where |
|
628 "Nat = Target_Numeral.nat_of" |
|
629 |
623 definition of_nat :: "nat \<Rightarrow> Target_Numeral.int" where |
630 definition of_nat :: "nat \<Rightarrow> Target_Numeral.int" where |
624 [code_abbrev]: "of_nat = Nat.of_nat" |
631 [code_abbrev]: "of_nat = Nat.of_nat" |
625 |
632 |
626 hide_const (open) of_nat |
633 hide_const (open) of_nat Nat |
627 |
634 |
628 lemma int_of_nat [simp]: |
635 lemma int_of_nat [simp]: |
629 "Target_Numeral.int_of (Target_Numeral.of_nat n) = of_nat n" |
636 "Target_Numeral.int_of (Target_Numeral.of_nat n) = of_nat n" |
630 by (simp add: of_nat_def) |
637 by (simp add: of_nat_def) |
631 |
638 |
632 lemma [code abstype]: |
639 lemma [code abstype]: |
633 "Target_Numeral.nat_of (Target_Numeral.of_nat n) = n" |
640 "Target_Numeral.Nat (Target_Numeral.of_nat n) = n" |
634 by (simp add: nat_of_def) |
641 by (simp add: Nat_def nat_of_def) |
|
642 |
|
643 lemma [code abstract]: |
|
644 "Target_Numeral.of_nat (Target_Numeral.nat_of k) = max 0 k" |
|
645 by (simp add: of_nat_def) |
635 |
646 |
636 lemma [code_abbrev]: |
647 lemma [code_abbrev]: |
637 "nat (Int.Pos k) = nat_of_num k" |
648 "nat (Int.Pos k) = nat_of_num k" |
638 by (simp add: nat_of_num_numeral) |
649 by (simp add: nat_of_num_numeral) |
639 |
650 |