| author | Andreas Lochbihler | 
| Tue, 01 Dec 2015 12:35:11 +0100 | |
| changeset 61766 | 507b39df1a57 | 
| parent 61275 | 053ec04ea866 | 
| child 61857 | 542f2c6da692 | 
| permissions | -rw-r--r-- | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 1 | (* Title: HOL/Code_Numeral.thy | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 2 | Author: Florian Haftmann, TU Muenchen | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 3 | *) | 
| 24999 | 4 | |
| 60758 | 5 | section \<open>Numeric types for code generation onto target language numerals only\<close> | 
| 24999 | 6 | |
| 31205 
98370b26c2ce
String.literal replaces message_string, code_numeral replaces (code_)index
 haftmann parents: 
31203diff
changeset | 7 | theory Code_Numeral | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 8 | imports Nat_Transfer Divides Lifting | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 9 | begin | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 10 | |
| 60758 | 11 | subsection \<open>Type of target language integers\<close> | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 12 | |
| 61076 | 13 | typedef integer = "UNIV :: int set" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 14 | morphisms int_of_integer integer_of_int .. | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 15 | |
| 59487 
adaa430fc0f7
default abstypes and default abstract equations make technical (no_code) annotation superfluous
 haftmann parents: 
58889diff
changeset | 16 | setup_lifting type_definition_integer | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 17 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 18 | lemma integer_eq_iff: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 19 | "k = l \<longleftrightarrow> int_of_integer k = int_of_integer l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 20 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 21 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 22 | lemma integer_eqI: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 23 | "int_of_integer k = int_of_integer l \<Longrightarrow> k = l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 24 | using integer_eq_iff [of k l] by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 25 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 26 | lemma int_of_integer_integer_of_int [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 27 | "int_of_integer (integer_of_int k) = k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 28 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 29 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 30 | lemma integer_of_int_int_of_integer [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 31 | "integer_of_int (int_of_integer k) = k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 32 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 33 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 34 | instantiation integer :: ring_1 | 
| 24999 | 35 | begin | 
| 36 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 37 | lift_definition zero_integer :: integer | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 38 | is "0 :: int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 39 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 40 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 41 | declare zero_integer.rep_eq [simp] | 
| 24999 | 42 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 43 | lift_definition one_integer :: integer | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 44 | is "1 :: int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 45 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 46 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 47 | declare one_integer.rep_eq [simp] | 
| 24999 | 48 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 49 | lift_definition plus_integer :: "integer \<Rightarrow> integer \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 50 | is "plus :: int \<Rightarrow> int \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 51 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 52 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 53 | declare plus_integer.rep_eq [simp] | 
| 24999 | 54 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 55 | lift_definition uminus_integer :: "integer \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 56 | is "uminus :: int \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 57 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 58 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 59 | declare uminus_integer.rep_eq [simp] | 
| 24999 | 60 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 61 | lift_definition minus_integer :: "integer \<Rightarrow> integer \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 62 | is "minus :: int \<Rightarrow> int \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 63 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 64 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 65 | declare minus_integer.rep_eq [simp] | 
| 24999 | 66 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 67 | lift_definition times_integer :: "integer \<Rightarrow> integer \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 68 | is "times :: int \<Rightarrow> int \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 69 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 70 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 71 | declare times_integer.rep_eq [simp] | 
| 28708 
a1a436f09ec6
explicit check for pattern discipline before code translation
 haftmann parents: 
28562diff
changeset | 72 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 73 | instance proof | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 74 | qed (transfer, simp add: algebra_simps)+ | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 75 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 76 | end | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 77 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 78 | lemma [transfer_rule]: | 
| 55945 | 79 | "rel_fun HOL.eq pcr_integer (of_nat :: nat \<Rightarrow> int) (of_nat :: nat \<Rightarrow> integer)" | 
| 51375 
d9e62d9c98de
patch Isabelle ditribution to conform to changes regarding the parametricity
 kuncar parents: 
51143diff
changeset | 80 | by (unfold of_nat_def [abs_def]) transfer_prover | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 81 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 82 | lemma [transfer_rule]: | 
| 55945 | 83 | "rel_fun HOL.eq pcr_integer (\<lambda>k :: int. k :: int) (of_int :: int \<Rightarrow> integer)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 84 | proof - | 
| 55945 | 85 | have "rel_fun HOL.eq pcr_integer (of_int :: int \<Rightarrow> int) (of_int :: int \<Rightarrow> integer)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 86 | by (unfold of_int_of_nat [abs_def]) transfer_prover | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 87 | then show ?thesis by (simp add: id_def) | 
| 24999 | 88 | qed | 
| 89 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 90 | lemma [transfer_rule]: | 
| 55945 | 91 | "rel_fun HOL.eq pcr_integer (numeral :: num \<Rightarrow> int) (numeral :: num \<Rightarrow> integer)" | 
| 26140 | 92 | proof - | 
| 55945 | 93 | have "rel_fun HOL.eq pcr_integer (numeral :: num \<Rightarrow> int) (\<lambda>n. of_int (numeral n))" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 94 | by transfer_prover | 
| 26140 | 95 | then show ?thesis by simp | 
| 96 | qed | |
| 97 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 98 | lemma [transfer_rule]: | 
| 55945 | 99 | "rel_fun HOL.eq (rel_fun HOL.eq pcr_integer) (Num.sub :: _ \<Rightarrow> _ \<Rightarrow> int) (Num.sub :: _ \<Rightarrow> _ \<Rightarrow> integer)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 100 | by (unfold Num.sub_def [abs_def]) transfer_prover | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 101 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 102 | lemma int_of_integer_of_nat [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 103 | "int_of_integer (of_nat n) = of_nat n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 104 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 105 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 106 | lift_definition integer_of_nat :: "nat \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 107 | is "of_nat :: nat \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 108 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 109 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 110 | lemma integer_of_nat_eq_of_nat [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 111 | "integer_of_nat = of_nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 112 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 113 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 114 | lemma int_of_integer_integer_of_nat [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 115 | "int_of_integer (integer_of_nat n) = of_nat n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 116 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 117 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 118 | lift_definition nat_of_integer :: "integer \<Rightarrow> nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 119 | is Int.nat | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 120 | . | 
| 26140 | 121 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 122 | lemma nat_of_integer_of_nat [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 123 | "nat_of_integer (of_nat n) = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 124 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 125 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 126 | lemma int_of_integer_of_int [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 127 | "int_of_integer (of_int k) = k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 128 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 129 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 130 | lemma nat_of_integer_integer_of_nat [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 131 | "nat_of_integer (integer_of_nat n) = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 132 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 133 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 134 | lemma integer_of_int_eq_of_int [simp, code_abbrev]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 135 | "integer_of_int = of_int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 136 | by transfer (simp add: fun_eq_iff) | 
| 26140 | 137 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 138 | lemma of_int_integer_of [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 139 | "of_int (int_of_integer k) = (k :: integer)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 140 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 141 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 142 | lemma int_of_integer_numeral [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 143 | "int_of_integer (numeral k) = numeral k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 144 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 145 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 146 | lemma int_of_integer_sub [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 147 | "int_of_integer (Num.sub k l) = Num.sub k l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 148 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 149 | |
| 61275 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 150 | lift_definition integer_of_num :: "num \<Rightarrow> integer" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 151 | is "numeral :: num \<Rightarrow> int" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 152 | . | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 153 | |
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 154 | lemma integer_of_num [code]: | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 155 | "integer_of_num num.One = 1" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 156 | "integer_of_num (num.Bit0 n) = (let k = integer_of_num n in k + k)" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 157 | "integer_of_num (num.Bit1 n) = (let k = integer_of_num n in k + k + 1)" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 158 | by (transfer, simp only: numeral.simps Let_def)+ | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 159 | |
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 160 | lemma numeral_unfold_integer_of_num: | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 161 | "numeral = integer_of_num" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 162 | by (simp add: integer_of_num_def map_fun_def fun_eq_iff) | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 163 | |
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 164 | lemma integer_of_num_triv: | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 165 | "integer_of_num Num.One = 1" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 166 | "integer_of_num (Num.Bit0 Num.One) = 2" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 167 | by (transfer, simp)+ | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 168 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 169 | instantiation integer :: "{ring_div, equal, linordered_idom}"
 | 
| 26140 | 170 | begin | 
| 171 | ||
| 60352 
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
 haftmann parents: 
59816diff
changeset | 172 | lift_definition divide_integer :: "integer \<Rightarrow> integer \<Rightarrow> integer" | 
| 
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
 haftmann parents: 
59816diff
changeset | 173 | is "divide :: int \<Rightarrow> int \<Rightarrow> int" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 174 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 175 | |
| 60352 
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
 haftmann parents: 
59816diff
changeset | 176 | declare divide_integer.rep_eq [simp] | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 177 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 178 | lift_definition mod_integer :: "integer \<Rightarrow> integer \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 179 | is "Divides.mod :: int \<Rightarrow> int \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 180 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 181 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 182 | declare mod_integer.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 183 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 184 | lift_definition abs_integer :: "integer \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 185 | is "abs :: int \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 186 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 187 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 188 | declare abs_integer.rep_eq [simp] | 
| 26140 | 189 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 190 | lift_definition sgn_integer :: "integer \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 191 | is "sgn :: int \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 192 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 193 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 194 | declare sgn_integer.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 195 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 196 | lift_definition less_eq_integer :: "integer \<Rightarrow> integer \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 197 | is "less_eq :: int \<Rightarrow> int \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 198 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 199 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 200 | lift_definition less_integer :: "integer \<Rightarrow> integer \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 201 | is "less :: int \<Rightarrow> int \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 202 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 203 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 204 | lift_definition equal_integer :: "integer \<Rightarrow> integer \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 205 | is "HOL.equal :: int \<Rightarrow> int \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 206 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 207 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 208 | instance proof | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 209 | qed (transfer, simp add: algebra_simps equal less_le_not_le [symmetric] mult_strict_right_mono linear)+ | 
| 26140 | 210 | |
| 211 | end | |
| 212 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 213 | lemma [transfer_rule]: | 
| 55945 | 214 | "rel_fun pcr_integer (rel_fun pcr_integer pcr_integer) (min :: _ \<Rightarrow> _ \<Rightarrow> int) (min :: _ \<Rightarrow> _ \<Rightarrow> integer)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 215 | by (unfold min_def [abs_def]) transfer_prover | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 216 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 217 | lemma [transfer_rule]: | 
| 55945 | 218 | "rel_fun pcr_integer (rel_fun pcr_integer pcr_integer) (max :: _ \<Rightarrow> _ \<Rightarrow> int) (max :: _ \<Rightarrow> _ \<Rightarrow> integer)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 219 | by (unfold max_def [abs_def]) transfer_prover | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 220 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 221 | lemma int_of_integer_min [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 222 | "int_of_integer (min k l) = min (int_of_integer k) (int_of_integer l)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 223 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 224 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 225 | lemma int_of_integer_max [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 226 | "int_of_integer (max k l) = max (int_of_integer k) (int_of_integer l)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 227 | by transfer rule | 
| 26140 | 228 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 229 | lemma nat_of_integer_non_positive [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 230 | "k \<le> 0 \<Longrightarrow> nat_of_integer k = 0" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 231 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 232 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 233 | lemma of_nat_of_integer [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 234 | "of_nat (nat_of_integer k) = max 0 k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 235 | by transfer auto | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 236 | |
| 61275 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 237 | instantiation integer :: semiring_numeral_div | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 238 | begin | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 239 | |
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 240 | definition divmod_integer :: "num \<Rightarrow> num \<Rightarrow> integer \<times> integer" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 241 | where | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 242 | divmod_integer'_def: "divmod_integer m n = (numeral m div numeral n, numeral m mod numeral n)" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 243 | |
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 244 | definition divmod_step_integer :: "num \<Rightarrow> integer \<times> integer \<Rightarrow> integer \<times> integer" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 245 | where | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 246 | "divmod_step_integer l qr = (let (q, r) = qr | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 247 | in if r \<ge> numeral l then (2 * q + 1, r - numeral l) | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 248 | else (2 * q, r))" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 249 | |
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 250 | instance proof | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 251 | show "divmod m n = (numeral m div numeral n :: integer, numeral m mod numeral n)" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 252 | for m n by (fact divmod_integer'_def) | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 253 | show "divmod_step l qr = (let (q, r) = qr | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 254 | in if r \<ge> numeral l then (2 * q + 1, r - numeral l) | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 255 | else (2 * q, r))" for l and qr :: "integer \<times> integer" | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 256 | by (fact divmod_step_integer_def) | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 257 | qed (transfer, | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 258 | fact le_add_diff_inverse2 | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 259 | semiring_numeral_div_class.div_less | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 260 | semiring_numeral_div_class.mod_less | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 261 | semiring_numeral_div_class.div_positive | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 262 | semiring_numeral_div_class.mod_less_eq_dividend | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 263 | semiring_numeral_div_class.pos_mod_bound | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 264 | semiring_numeral_div_class.pos_mod_sign | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 265 | semiring_numeral_div_class.mod_mult2_eq | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 266 | semiring_numeral_div_class.div_mult2_eq | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 267 | semiring_numeral_div_class.discrete)+ | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 268 | |
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 269 | end | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 270 | |
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 271 | declare divmod_algorithm_code [where ?'a = integer, | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 272 | unfolded numeral_unfold_integer_of_num, unfolded integer_of_num_triv, | 
| 
053ec04ea866
monomorphization of divmod wrt. code generation avoids costly dictionary unpacking at runtime
 haftmann parents: 
61274diff
changeset | 273 | code] | 
| 53069 
d165213e3924
execution of int division by class semiring_numeral_div, replacing pdivmod by divmod_abs
 haftmann parents: 
52435diff
changeset | 274 | |
| 55427 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 275 | lemma integer_of_nat_0: "integer_of_nat 0 = 0" | 
| 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 276 | by transfer simp | 
| 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 277 | |
| 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 278 | lemma integer_of_nat_1: "integer_of_nat 1 = 1" | 
| 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 279 | by transfer simp | 
| 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 280 | |
| 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 281 | lemma integer_of_nat_numeral: | 
| 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 282 | "integer_of_nat (numeral n) = numeral n" | 
| 
ff54d22fe357
make integer_of_char and char_of_integer work with NBE and code_simp
 Andreas Lochbihler parents: 
54489diff
changeset | 283 | by transfer simp | 
| 26140 | 284 | |
| 60758 | 285 | subsection \<open>Code theorems for target language integers\<close> | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 286 | |
| 60758 | 287 | text \<open>Constructors\<close> | 
| 26140 | 288 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 289 | definition Pos :: "num \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 290 | where | 
| 61274 
0261eec37233
more selective preprocessing allows bare "numeral" occurences to be retained as real function in generated code
 haftmann parents: 
61076diff
changeset | 291 | [simp, code_post]: "Pos = numeral" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 292 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 293 | lemma [transfer_rule]: | 
| 55945 | 294 | "rel_fun HOL.eq pcr_integer numeral Pos" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 295 | by simp transfer_prover | 
| 30245 
e67f42ac1157
consequent rewrite of index_size, size [index] to nat_of; support pseudo-primrec sepcifications with fun
 haftmann parents: 
29823diff
changeset | 296 | |
| 61274 
0261eec37233
more selective preprocessing allows bare "numeral" occurences to be retained as real function in generated code
 haftmann parents: 
61076diff
changeset | 297 | lemma Pos_fold [code_unfold]: | 
| 
0261eec37233
more selective preprocessing allows bare "numeral" occurences to be retained as real function in generated code
 haftmann parents: 
61076diff
changeset | 298 | "numeral Num.One = Pos Num.One" | 
| 
0261eec37233
more selective preprocessing allows bare "numeral" occurences to be retained as real function in generated code
 haftmann parents: 
61076diff
changeset | 299 | "numeral (Num.Bit0 k) = Pos (Num.Bit0 k)" | 
| 
0261eec37233
more selective preprocessing allows bare "numeral" occurences to be retained as real function in generated code
 haftmann parents: 
61076diff
changeset | 300 | "numeral (Num.Bit1 k) = Pos (Num.Bit1 k)" | 
| 
0261eec37233
more selective preprocessing allows bare "numeral" occurences to be retained as real function in generated code
 haftmann parents: 
61076diff
changeset | 301 | by simp_all | 
| 
0261eec37233
more selective preprocessing allows bare "numeral" occurences to be retained as real function in generated code
 haftmann parents: 
61076diff
changeset | 302 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 303 | definition Neg :: "num \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 304 | where | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
53069diff
changeset | 305 | [simp, code_abbrev]: "Neg n = - Pos n" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 306 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 307 | lemma [transfer_rule]: | 
| 55945 | 308 | "rel_fun HOL.eq pcr_integer (\<lambda>n. - numeral n) Neg" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
53069diff
changeset | 309 | by (simp add: Neg_def [abs_def]) transfer_prover | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 310 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 311 | code_datatype "0::integer" Pos Neg | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 312 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 313 | |
| 60758 | 314 | text \<open>Auxiliary operations\<close> | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 315 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 316 | lift_definition dup :: "integer \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 317 | is "\<lambda>k::int. k + k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 318 | . | 
| 26140 | 319 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 320 | lemma dup_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 321 | "dup 0 = 0" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 322 | "dup (Pos n) = Pos (Num.Bit0 n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 323 | "dup (Neg n) = Neg (Num.Bit0 n)" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
53069diff
changeset | 324 | by (transfer, simp only: numeral_Bit0 minus_add_distrib)+ | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 325 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 326 | lift_definition sub :: "num \<Rightarrow> num \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 327 | is "\<lambda>m n. numeral m - numeral n :: int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 328 | . | 
| 26140 | 329 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 330 | lemma sub_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 331 | "sub Num.One Num.One = 0" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 332 | "sub (Num.Bit0 m) Num.One = Pos (Num.BitM m)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 333 | "sub (Num.Bit1 m) Num.One = Pos (Num.Bit0 m)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 334 | "sub Num.One (Num.Bit0 n) = Neg (Num.BitM n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 335 | "sub Num.One (Num.Bit1 n) = Neg (Num.Bit0 n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 336 | "sub (Num.Bit0 m) (Num.Bit0 n) = dup (sub m n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 337 | "sub (Num.Bit1 m) (Num.Bit1 n) = dup (sub m n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 338 | "sub (Num.Bit1 m) (Num.Bit0 n) = dup (sub m n) + 1" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 339 | "sub (Num.Bit0 m) (Num.Bit1 n) = dup (sub m n) - 1" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 340 | by (transfer, simp add: dbl_def dbl_inc_def dbl_dec_def)+ | 
| 28351 | 341 | |
| 24999 | 342 | |
| 60758 | 343 | text \<open>Implementations\<close> | 
| 24999 | 344 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 345 | lemma one_integer_code [code, code_unfold]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 346 | "1 = Pos Num.One" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 347 | by simp | 
| 24999 | 348 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 349 | lemma plus_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 350 | "k + 0 = (k::integer)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 351 | "0 + l = (l::integer)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 352 | "Pos m + Pos n = Pos (m + n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 353 | "Pos m + Neg n = sub m n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 354 | "Neg m + Pos n = sub n m" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 355 | "Neg m + Neg n = Neg (m + n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 356 | by (transfer, simp)+ | 
| 24999 | 357 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 358 | lemma uminus_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 359 | "uminus 0 = (0::integer)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 360 | "uminus (Pos m) = Neg m" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 361 | "uminus (Neg m) = Pos m" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 362 | by simp_all | 
| 28708 
a1a436f09ec6
explicit check for pattern discipline before code translation
 haftmann parents: 
28562diff
changeset | 363 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 364 | lemma minus_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 365 | "k - 0 = (k::integer)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 366 | "0 - l = uminus (l::integer)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 367 | "Pos m - Pos n = sub m n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 368 | "Pos m - Neg n = Pos (m + n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 369 | "Neg m - Pos n = Neg (m + n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 370 | "Neg m - Neg n = sub n m" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 371 | by (transfer, simp)+ | 
| 46028 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45694diff
changeset | 372 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 373 | lemma abs_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 374 | "\<bar>k\<bar> = (if (k::integer) < 0 then - k else k)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 375 | by simp | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46664diff
changeset | 376 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 377 | lemma sgn_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 378 | "sgn k = (if k = 0 then 0 else if (k::integer) < 0 then - 1 else 1)" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46664diff
changeset | 379 | by simp | 
| 46028 
9f113cdf3d66
attribute code_abbrev superseedes code_unfold_post
 haftmann parents: 
45694diff
changeset | 380 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 381 | lemma times_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 382 | "k * 0 = (0::integer)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 383 | "0 * l = (0::integer)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 384 | "Pos m * Pos n = Pos (m * n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 385 | "Pos m * Neg n = Neg (m * n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 386 | "Neg m * Pos n = Neg (m * n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 387 | "Neg m * Neg n = Pos (m * n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 388 | by simp_all | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 389 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 390 | definition divmod_integer :: "integer \<Rightarrow> integer \<Rightarrow> integer \<times> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 391 | where | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 392 | "divmod_integer k l = (k div l, k mod l)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 393 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 394 | lemma fst_divmod [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 395 | "fst (divmod_integer k l) = k div l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 396 | by (simp add: divmod_integer_def) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 397 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 398 | lemma snd_divmod [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 399 | "snd (divmod_integer k l) = k mod l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 400 | by (simp add: divmod_integer_def) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 401 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 402 | definition divmod_abs :: "integer \<Rightarrow> integer \<Rightarrow> integer \<times> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 403 | where | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 404 | "divmod_abs k l = (\<bar>k\<bar> div \<bar>l\<bar>, \<bar>k\<bar> mod \<bar>l\<bar>)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 405 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 406 | lemma fst_divmod_abs [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 407 | "fst (divmod_abs k l) = \<bar>k\<bar> div \<bar>l\<bar>" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 408 | by (simp add: divmod_abs_def) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 409 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 410 | lemma snd_divmod_abs [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 411 | "snd (divmod_abs k l) = \<bar>k\<bar> mod \<bar>l\<bar>" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 412 | by (simp add: divmod_abs_def) | 
| 28708 
a1a436f09ec6
explicit check for pattern discipline before code translation
 haftmann parents: 
28562diff
changeset | 413 | |
| 53069 
d165213e3924
execution of int division by class semiring_numeral_div, replacing pdivmod by divmod_abs
 haftmann parents: 
52435diff
changeset | 414 | lemma divmod_abs_code [code]: | 
| 
d165213e3924
execution of int division by class semiring_numeral_div, replacing pdivmod by divmod_abs
 haftmann parents: 
52435diff
changeset | 415 | "divmod_abs (Pos k) (Pos l) = divmod k l" | 
| 
d165213e3924
execution of int division by class semiring_numeral_div, replacing pdivmod by divmod_abs
 haftmann parents: 
52435diff
changeset | 416 | "divmod_abs (Neg k) (Neg l) = divmod k l" | 
| 
d165213e3924
execution of int division by class semiring_numeral_div, replacing pdivmod by divmod_abs
 haftmann parents: 
52435diff
changeset | 417 | "divmod_abs (Neg k) (Pos l) = divmod k l" | 
| 
d165213e3924
execution of int division by class semiring_numeral_div, replacing pdivmod by divmod_abs
 haftmann parents: 
52435diff
changeset | 418 | "divmod_abs (Pos k) (Neg l) = divmod k l" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 419 | "divmod_abs j 0 = (0, \<bar>j\<bar>)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 420 | "divmod_abs 0 j = (0, 0)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 421 | by (simp_all add: prod_eq_iff) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 422 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 423 | lemma divmod_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 424 | "divmod_integer k l = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 425 | (if k = 0 then (0, 0) else if l = 0 then (0, k) else | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 426 | (apsnd \<circ> times \<circ> sgn) l (if sgn k = sgn l | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 427 | then divmod_abs k l | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 428 | else (let (r, s) = divmod_abs k l in | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 429 | if s = 0 then (- r, 0) else (- r - 1, \<bar>l\<bar> - s))))" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 430 | proof - | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 431 | have aux1: "\<And>k l::int. sgn k = sgn l \<longleftrightarrow> k = 0 \<and> l = 0 \<or> 0 < l \<and> 0 < k \<or> l < 0 \<and> k < 0" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 432 | by (auto simp add: sgn_if) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 433 | have aux2: "\<And>q::int. - int_of_integer k = int_of_integer l * q \<longleftrightarrow> int_of_integer k = int_of_integer l * - q" by auto | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 434 | show ?thesis | 
| 55414 
eab03e9cee8a
renamed '{prod,sum,bool,unit}_case' to 'case_...'
 blanchet parents: 
54489diff
changeset | 435 | by (simp add: prod_eq_iff integer_eq_iff case_prod_beta aux1) | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 436 | (auto simp add: zdiv_zminus1_eq_if zmod_zminus1_eq_if div_minus_right mod_minus_right aux2) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 437 | qed | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 438 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 439 | lemma div_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 440 | "k div l = fst (divmod_integer k l)" | 
| 28708 
a1a436f09ec6
explicit check for pattern discipline before code translation
 haftmann parents: 
28562diff
changeset | 441 | by simp | 
| 
a1a436f09ec6
explicit check for pattern discipline before code translation
 haftmann parents: 
28562diff
changeset | 442 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 443 | lemma mod_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 444 | "k mod l = snd (divmod_integer k l)" | 
| 25767 | 445 | by simp | 
| 24999 | 446 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 447 | lemma equal_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 448 | "HOL.equal 0 (0::integer) \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 449 | "HOL.equal 0 (Pos l) \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 450 | "HOL.equal 0 (Neg l) \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 451 | "HOL.equal (Pos k) 0 \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 452 | "HOL.equal (Pos k) (Pos l) \<longleftrightarrow> HOL.equal k l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 453 | "HOL.equal (Pos k) (Neg l) \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 454 | "HOL.equal (Neg k) 0 \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 455 | "HOL.equal (Neg k) (Pos l) \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 456 | "HOL.equal (Neg k) (Neg l) \<longleftrightarrow> HOL.equal k l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 457 | by (simp_all add: equal) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 458 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 459 | lemma equal_integer_refl [code nbe]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 460 | "HOL.equal (k::integer) k \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 461 | by (fact equal_refl) | 
| 31266 | 462 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 463 | lemma less_eq_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 464 | "0 \<le> (0::integer) \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 465 | "0 \<le> Pos l \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 466 | "0 \<le> Neg l \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 467 | "Pos k \<le> 0 \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 468 | "Pos k \<le> Pos l \<longleftrightarrow> k \<le> l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 469 | "Pos k \<le> Neg l \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 470 | "Neg k \<le> 0 \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 471 | "Neg k \<le> Pos l \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 472 | "Neg k \<le> Neg l \<longleftrightarrow> l \<le> k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 473 | by simp_all | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 474 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 475 | lemma less_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 476 | "0 < (0::integer) \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 477 | "0 < Pos l \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 478 | "0 < Neg l \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 479 | "Pos k < 0 \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 480 | "Pos k < Pos l \<longleftrightarrow> k < l" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 481 | "Pos k < Neg l \<longleftrightarrow> False" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 482 | "Neg k < 0 \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 483 | "Neg k < Pos l \<longleftrightarrow> True" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 484 | "Neg k < Neg l \<longleftrightarrow> l < k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 485 | by simp_all | 
| 26140 | 486 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 487 | lift_definition num_of_integer :: "integer \<Rightarrow> num" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 488 | is "num_of_nat \<circ> nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 489 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 490 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 491 | lemma num_of_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 492 | "num_of_integer k = (if k \<le> 1 then Num.One | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 493 | else let | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 494 | (l, j) = divmod_integer k 2; | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 495 | l' = num_of_integer l; | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 496 | l'' = l' + l' | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 497 | in if j = 0 then l'' else l'' + Num.One)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 498 | proof - | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 499 |   {
 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 500 | assume "int_of_integer k mod 2 = 1" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 501 | then have "nat (int_of_integer k mod 2) = nat 1" by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 502 | moreover assume *: "1 < int_of_integer k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 503 | ultimately have **: "nat (int_of_integer k) mod 2 = 1" by (simp add: nat_mod_distrib) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 504 | have "num_of_nat (nat (int_of_integer k)) = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 505 | num_of_nat (2 * (nat (int_of_integer k) div 2) + nat (int_of_integer k) mod 2)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 506 | by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 507 | then have "num_of_nat (nat (int_of_integer k)) = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 508 | num_of_nat (nat (int_of_integer k) div 2 + nat (int_of_integer k) div 2 + nat (int_of_integer k) mod 2)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 509 | by (simp add: mult_2) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 510 | with ** have "num_of_nat (nat (int_of_integer k)) = | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 511 | num_of_nat (nat (int_of_integer k) div 2 + nat (int_of_integer k) div 2 + 1)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 512 | by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 513 | } | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 514 | note aux = this | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 515 | show ?thesis | 
| 55414 
eab03e9cee8a
renamed '{prod,sum,bool,unit}_case' to 'case_...'
 blanchet parents: 
54489diff
changeset | 516 | by (auto simp add: num_of_integer_def nat_of_integer_def Let_def case_prod_beta | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 517 | not_le integer_eq_iff less_eq_integer_def | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 518 | nat_mult_distrib nat_div_distrib num_of_nat_One num_of_nat_plus_distrib | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 519 | mult_2 [where 'a=nat] aux add_One) | 
| 25918 | 520 | qed | 
| 521 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 522 | lemma nat_of_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 523 | "nat_of_integer k = (if k \<le> 0 then 0 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 524 | else let | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 525 | (l, j) = divmod_integer k 2; | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 526 | l' = nat_of_integer l; | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 527 | l'' = l' + l' | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 528 | in if j = 0 then l'' else l'' + 1)" | 
| 33340 
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
 haftmann parents: 
33318diff
changeset | 529 | proof - | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 530 | obtain j where "k = integer_of_int j" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 531 | proof | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 532 | show "k = integer_of_int (int_of_integer k)" by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 533 | qed | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 534 | moreover have "2 * (j div 2) = j - j mod 2" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
56846diff
changeset | 535 | by (simp add: zmult_div_cancel mult.commute) | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 536 | ultimately show ?thesis | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 537 | by (auto simp add: split_def Let_def mod_integer_def nat_of_integer_def not_le | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 538 | nat_add_distrib [symmetric] Suc_nat_eq_nat_zadd1) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 539 | (auto simp add: mult_2 [symmetric]) | 
| 33340 
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
 haftmann parents: 
33318diff
changeset | 540 | qed | 
| 28708 
a1a436f09ec6
explicit check for pattern discipline before code translation
 haftmann parents: 
28562diff
changeset | 541 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 542 | lemma int_of_integer_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 543 | "int_of_integer k = (if k < 0 then - (int_of_integer (- k)) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 544 | else if k = 0 then 0 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 545 | else let | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 546 | (l, j) = divmod_integer k 2; | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 547 | l' = 2 * int_of_integer l | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 548 | in if j = 0 then l' else l' + 1)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 549 | by (auto simp add: split_def Let_def integer_eq_iff zmult_div_cancel) | 
| 28708 
a1a436f09ec6
explicit check for pattern discipline before code translation
 haftmann parents: 
28562diff
changeset | 550 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 551 | lemma integer_of_int_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 552 | "integer_of_int k = (if k < 0 then - (integer_of_int (- k)) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 553 | else if k = 0 then 0 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 554 | else let | 
| 60868 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 555 | l = 2 * integer_of_int (k div 2); | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 556 | j = k mod 2 | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 557 | in if j = 0 then l else l + 1)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 558 | by (auto simp add: split_def Let_def integer_eq_iff zmult_div_cancel) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 559 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 560 | hide_const (open) Pos Neg sub dup divmod_abs | 
| 46547 
d1dcb91a512e
use qualified constant names instead of suffixes (from Florian Haftmann)
 huffman parents: 
46028diff
changeset | 561 | |
| 28708 
a1a436f09ec6
explicit check for pattern discipline before code translation
 haftmann parents: 
28562diff
changeset | 562 | |
| 60758 | 563 | subsection \<open>Serializer setup for target language integers\<close> | 
| 24999 | 564 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 565 | code_reserved Eval int Integer abs | 
| 25767 | 566 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 567 | code_printing | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 568 | type_constructor integer \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 569 | (SML) "IntInf.int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 570 | and (OCaml) "Big'_int.big'_int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 571 | and (Haskell) "Integer" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 572 | and (Scala) "BigInt" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 573 | and (Eval) "int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 574 | | class_instance integer :: equal \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 575 | (Haskell) - | 
| 24999 | 576 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 577 | code_printing | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 578 | constant "0::integer" \<rightharpoonup> | 
| 58400 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 haftmann parents: 
58399diff
changeset | 579 | (SML) "!(0/ :/ IntInf.int)" | 
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 580 | and (OCaml) "Big'_int.zero'_big'_int" | 
| 58400 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 haftmann parents: 
58399diff
changeset | 581 | and (Haskell) "!(0/ ::/ Integer)" | 
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 582 | and (Scala) "BigInt(0)" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46664diff
changeset | 583 | |
| 60758 | 584 | setup \<open> | 
| 58399 | 585 | fold (fn target => | 
| 586 |     Numeral.add_code @{const_name Code_Numeral.Pos} I Code_Printer.literal_numeral target
 | |
| 587 |     #> Numeral.add_code @{const_name Code_Numeral.Neg} (op ~) Code_Printer.literal_numeral target)
 | |
| 588 | ["SML", "OCaml", "Haskell", "Scala"] | |
| 60758 | 589 | \<close> | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 590 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 591 | code_printing | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 592 | constant "plus :: integer \<Rightarrow> _ \<Rightarrow> _" \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 593 | (SML) "IntInf.+ ((_), (_))" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 594 | and (OCaml) "Big'_int.add'_big'_int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 595 | and (Haskell) infixl 6 "+" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 596 | and (Scala) infixl 7 "+" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 597 | and (Eval) infixl 8 "+" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 598 | | constant "uminus :: integer \<Rightarrow> _" \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 599 | (SML) "IntInf.~" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 600 | and (OCaml) "Big'_int.minus'_big'_int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 601 | and (Haskell) "negate" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 602 | and (Scala) "!(- _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 603 | and (Eval) "~/ _" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 604 | | constant "minus :: integer \<Rightarrow> _" \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 605 | (SML) "IntInf.- ((_), (_))" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 606 | and (OCaml) "Big'_int.sub'_big'_int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 607 | and (Haskell) infixl 6 "-" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 608 | and (Scala) infixl 7 "-" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 609 | and (Eval) infixl 8 "-" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 610 | | constant Code_Numeral.dup \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 611 | (SML) "IntInf.*/ (2,/ (_))" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 612 | and (OCaml) "Big'_int.mult'_big'_int/ (Big'_int.big'_int'_of'_int/ 2)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 613 | and (Haskell) "!(2 * _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 614 | and (Scala) "!(2 * _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 615 | and (Eval) "!(2 * _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 616 | | constant Code_Numeral.sub \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 617 | (SML) "!(raise/ Fail/ \"sub\")" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 618 | and (OCaml) "failwith/ \"sub\"" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 619 | and (Haskell) "error/ \"sub\"" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 620 | and (Scala) "!sys.error(\"sub\")" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 621 | | constant "times :: integer \<Rightarrow> _ \<Rightarrow> _" \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 622 | (SML) "IntInf.* ((_), (_))" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 623 | and (OCaml) "Big'_int.mult'_big'_int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 624 | and (Haskell) infixl 7 "*" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 625 | and (Scala) infixl 8 "*" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 626 | and (Eval) infixl 9 "*" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 627 | | constant Code_Numeral.divmod_abs \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 628 | (SML) "IntInf.divMod/ (IntInf.abs _,/ IntInf.abs _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 629 | and (OCaml) "Big'_int.quomod'_big'_int/ (Big'_int.abs'_big'_int _)/ (Big'_int.abs'_big'_int _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 630 | and (Haskell) "divMod/ (abs _)/ (abs _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 631 | and (Scala) "!((k: BigInt) => (l: BigInt) =>/ if (l == 0)/ (BigInt(0), k) else/ (k.abs '/% l.abs))" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 632 | and (Eval) "Integer.div'_mod/ (abs _)/ (abs _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 633 | | constant "HOL.equal :: integer \<Rightarrow> _ \<Rightarrow> bool" \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 634 | (SML) "!((_ : IntInf.int) = _)" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 635 | and (OCaml) "Big'_int.eq'_big'_int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 636 | and (Haskell) infix 4 "==" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 637 | and (Scala) infixl 5 "==" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 638 | and (Eval) infixl 6 "=" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 639 | | constant "less_eq :: integer \<Rightarrow> _ \<Rightarrow> bool" \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 640 | (SML) "IntInf.<= ((_), (_))" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 641 | and (OCaml) "Big'_int.le'_big'_int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 642 | and (Haskell) infix 4 "<=" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 643 | and (Scala) infixl 4 "<=" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 644 | and (Eval) infixl 6 "<=" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 645 | | constant "less :: integer \<Rightarrow> _ \<Rightarrow> bool" \<rightharpoonup> | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 646 | (SML) "IntInf.< ((_), (_))" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 647 | and (OCaml) "Big'_int.lt'_big'_int" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 648 | and (Haskell) infix 4 "<" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 649 | and (Scala) infixl 4 "<" | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 650 | and (Eval) infixl 6 "<" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 651 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 652 | code_identifier | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51375diff
changeset | 653 | code_module Code_Numeral \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith | 
| 46547 
d1dcb91a512e
use qualified constant names instead of suffixes (from Florian Haftmann)
 huffman parents: 
46028diff
changeset | 654 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 655 | |
| 60758 | 656 | subsection \<open>Type of target language naturals\<close> | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 657 | |
| 61076 | 658 | typedef natural = "UNIV :: nat set" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 659 | morphisms nat_of_natural natural_of_nat .. | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 660 | |
| 59487 
adaa430fc0f7
default abstypes and default abstract equations make technical (no_code) annotation superfluous
 haftmann parents: 
58889diff
changeset | 661 | setup_lifting type_definition_natural | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 662 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 663 | lemma natural_eq_iff [termination_simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 664 | "m = n \<longleftrightarrow> nat_of_natural m = nat_of_natural n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 665 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 666 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 667 | lemma natural_eqI: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 668 | "nat_of_natural m = nat_of_natural n \<Longrightarrow> m = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 669 | using natural_eq_iff [of m n] by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 670 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 671 | lemma nat_of_natural_of_nat_inverse [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 672 | "nat_of_natural (natural_of_nat n) = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 673 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 674 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 675 | lemma natural_of_nat_of_natural_inverse [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 676 | "natural_of_nat (nat_of_natural n) = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 677 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 678 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 679 | instantiation natural :: "{comm_monoid_diff, semiring_1}"
 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 680 | begin | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 681 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 682 | lift_definition zero_natural :: natural | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 683 | is "0 :: nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 684 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 685 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 686 | declare zero_natural.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 687 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 688 | lift_definition one_natural :: natural | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 689 | is "1 :: nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 690 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 691 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 692 | declare one_natural.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 693 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 694 | lift_definition plus_natural :: "natural \<Rightarrow> natural \<Rightarrow> natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 695 | is "plus :: nat \<Rightarrow> nat \<Rightarrow> nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 696 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 697 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 698 | declare plus_natural.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 699 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 700 | lift_definition minus_natural :: "natural \<Rightarrow> natural \<Rightarrow> natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 701 | is "minus :: nat \<Rightarrow> nat \<Rightarrow> nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 702 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 703 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 704 | declare minus_natural.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 705 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 706 | lift_definition times_natural :: "natural \<Rightarrow> natural \<Rightarrow> natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 707 | is "times :: nat \<Rightarrow> nat \<Rightarrow> nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 708 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 709 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 710 | declare times_natural.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 711 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 712 | instance proof | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 713 | qed (transfer, simp add: algebra_simps)+ | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 714 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 715 | end | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 716 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 717 | lemma [transfer_rule]: | 
| 55945 | 718 | "rel_fun HOL.eq pcr_natural (\<lambda>n::nat. n) (of_nat :: nat \<Rightarrow> natural)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 719 | proof - | 
| 55945 | 720 | have "rel_fun HOL.eq pcr_natural (of_nat :: nat \<Rightarrow> nat) (of_nat :: nat \<Rightarrow> natural)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 721 | by (unfold of_nat_def [abs_def]) transfer_prover | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 722 | then show ?thesis by (simp add: id_def) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 723 | qed | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 724 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 725 | lemma [transfer_rule]: | 
| 55945 | 726 | "rel_fun HOL.eq pcr_natural (numeral :: num \<Rightarrow> nat) (numeral :: num \<Rightarrow> natural)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 727 | proof - | 
| 55945 | 728 | have "rel_fun HOL.eq pcr_natural (numeral :: num \<Rightarrow> nat) (\<lambda>n. of_nat (numeral n))" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 729 | by transfer_prover | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 730 | then show ?thesis by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 731 | qed | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 732 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 733 | lemma nat_of_natural_of_nat [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 734 | "nat_of_natural (of_nat n) = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 735 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 736 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 737 | lemma natural_of_nat_of_nat [simp, code_abbrev]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 738 | "natural_of_nat = of_nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 739 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 740 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 741 | lemma of_nat_of_natural [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 742 | "of_nat (nat_of_natural n) = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 743 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 744 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 745 | lemma nat_of_natural_numeral [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 746 | "nat_of_natural (numeral k) = numeral k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 747 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 748 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 749 | instantiation natural :: "{semiring_div, equal, linordered_semiring}"
 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 750 | begin | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 751 | |
| 60352 
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
 haftmann parents: 
59816diff
changeset | 752 | lift_definition divide_natural :: "natural \<Rightarrow> natural \<Rightarrow> natural" | 
| 
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
 haftmann parents: 
59816diff
changeset | 753 | is "divide :: nat \<Rightarrow> nat \<Rightarrow> nat" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 754 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 755 | |
| 60352 
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
 haftmann parents: 
59816diff
changeset | 756 | declare divide_natural.rep_eq [simp] | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 757 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 758 | lift_definition mod_natural :: "natural \<Rightarrow> natural \<Rightarrow> natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 759 | is "Divides.mod :: nat \<Rightarrow> nat \<Rightarrow> nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 760 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 761 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 762 | declare mod_natural.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 763 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 764 | lift_definition less_eq_natural :: "natural \<Rightarrow> natural \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 765 | is "less_eq :: nat \<Rightarrow> nat \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 766 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 767 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 768 | declare less_eq_natural.rep_eq [termination_simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 769 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 770 | lift_definition less_natural :: "natural \<Rightarrow> natural \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 771 | is "less :: nat \<Rightarrow> nat \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 772 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 773 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 774 | declare less_natural.rep_eq [termination_simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 775 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 776 | lift_definition equal_natural :: "natural \<Rightarrow> natural \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 777 | is "HOL.equal :: nat \<Rightarrow> nat \<Rightarrow> bool" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 778 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 779 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 780 | instance proof | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 781 | qed (transfer, simp add: algebra_simps equal less_le_not_le [symmetric] linear)+ | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 782 | |
| 24999 | 783 | end | 
| 46664 
1f6c140f9c72
moved predicate relations and conversion rules between set and predicate relations from Predicate.thy to Relation.thy; moved Predicate.thy upwards in theory hierarchy
 haftmann parents: 
46638diff
changeset | 784 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 785 | lemma [transfer_rule]: | 
| 55945 | 786 | "rel_fun pcr_natural (rel_fun pcr_natural pcr_natural) (min :: _ \<Rightarrow> _ \<Rightarrow> nat) (min :: _ \<Rightarrow> _ \<Rightarrow> natural)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 787 | by (unfold min_def [abs_def]) transfer_prover | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 788 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 789 | lemma [transfer_rule]: | 
| 55945 | 790 | "rel_fun pcr_natural (rel_fun pcr_natural pcr_natural) (max :: _ \<Rightarrow> _ \<Rightarrow> nat) (max :: _ \<Rightarrow> _ \<Rightarrow> natural)" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 791 | by (unfold max_def [abs_def]) transfer_prover | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 792 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 793 | lemma nat_of_natural_min [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 794 | "nat_of_natural (min k l) = min (nat_of_natural k) (nat_of_natural l)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 795 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 796 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 797 | lemma nat_of_natural_max [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 798 | "nat_of_natural (max k l) = max (nat_of_natural k) (nat_of_natural l)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 799 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 800 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 801 | lift_definition natural_of_integer :: "integer \<Rightarrow> natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 802 | is "nat :: int \<Rightarrow> nat" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 803 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 804 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 805 | lift_definition integer_of_natural :: "natural \<Rightarrow> integer" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 806 | is "of_nat :: nat \<Rightarrow> int" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 807 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 808 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 809 | lemma natural_of_integer_of_natural [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 810 | "natural_of_integer (integer_of_natural n) = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 811 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 812 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 813 | lemma integer_of_natural_of_integer [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 814 | "integer_of_natural (natural_of_integer k) = max 0 k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 815 | by transfer auto | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 816 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 817 | lemma int_of_integer_of_natural [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 818 | "int_of_integer (integer_of_natural n) = of_nat (nat_of_natural n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 819 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 820 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 821 | lemma integer_of_natural_of_nat [simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 822 | "integer_of_natural (of_nat n) = of_nat n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 823 | by transfer rule | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 824 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 825 | lemma [measure_function]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 826 | "is_measure nat_of_natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 827 | by (rule is_measure_trivial) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 828 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 829 | |
| 60758 | 830 | subsection \<open>Inductive representation of target language naturals\<close> | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 831 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 832 | lift_definition Suc :: "natural \<Rightarrow> natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 833 | is Nat.Suc | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 834 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 835 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 836 | declare Suc.rep_eq [simp] | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 837 | |
| 58306 
117ba6cbe414
renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
 blanchet parents: 
57512diff
changeset | 838 | old_rep_datatype "0::natural" Suc | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 839 | by (transfer, fact nat.induct nat.inject nat.distinct)+ | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 840 | |
| 55416 | 841 | lemma natural_cases [case_names nat, cases type: natural]: | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 842 | fixes m :: natural | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 843 | assumes "\<And>n. m = of_nat n \<Longrightarrow> P" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 844 | shows P | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 845 | using assms by transfer blast | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 846 | |
| 58390 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 847 | lemma [simp, code]: "size_natural = nat_of_natural" | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 848 | proof (rule ext) | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 849 | fix n | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 850 | show "size_natural n = nat_of_natural n" | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 851 | by (induct n) simp_all | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 852 | qed | 
| 58379 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 853 | |
| 58390 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 854 | lemma [simp, code]: "size = nat_of_natural" | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 855 | proof (rule ext) | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 856 | fix n | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 857 | show "size n = nat_of_natural n" | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 858 | by (induct n) simp_all | 
| 
b74d8470b98e
keep obsolete interpretations in Main, to avoid merge trouble
 blanchet parents: 
58379diff
changeset | 859 | qed | 
| 58379 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 860 | |
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 861 | lemma natural_decr [termination_simp]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 862 | "n \<noteq> 0 \<Longrightarrow> nat_of_natural n - Nat.Suc 0 < nat_of_natural n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 863 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 864 | |
| 58379 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 865 | lemma natural_zero_minus_one: "(0::natural) - 1 = 0" | 
| 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 866 | by (rule zero_diff) | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 867 | |
| 58379 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 868 | lemma Suc_natural_minus_one: "Suc n - 1 = n" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 869 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 870 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 871 | hide_const (open) Suc | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 872 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 873 | |
| 60758 | 874 | subsection \<open>Code refinement for target language naturals\<close> | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 875 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 876 | lift_definition Nat :: "integer \<Rightarrow> natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 877 | is nat | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 878 | . | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 879 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 880 | lemma [code_post]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 881 | "Nat 0 = 0" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 882 | "Nat 1 = 1" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 883 | "Nat (numeral k) = numeral k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 884 | by (transfer, simp)+ | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 885 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 886 | lemma [code abstype]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 887 | "Nat (integer_of_natural n) = n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 888 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 889 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 890 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 891 | "integer_of_natural (natural_of_nat n) = of_nat n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 892 | by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 893 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 894 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 895 | "integer_of_natural (natural_of_integer k) = max 0 k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 896 | by simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 897 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 898 | lemma [code_abbrev]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 899 | "natural_of_integer (Code_Numeral.Pos k) = numeral k" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 900 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 901 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 902 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 903 | "integer_of_natural 0 = 0" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 904 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 905 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 906 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 907 | "integer_of_natural 1 = 1" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 908 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 909 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 910 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 911 | "integer_of_natural (Code_Numeral.Suc n) = integer_of_natural n + 1" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 912 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 913 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 914 | lemma [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 915 | "nat_of_natural = nat_of_integer \<circ> integer_of_natural" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 916 | by transfer (simp add: fun_eq_iff) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 917 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 918 | lemma [code, code_unfold]: | 
| 55416 | 919 | "case_natural f g n = (if n = 0 then f else g (n - 1))" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 920 | by (cases n rule: natural.exhaust) (simp_all, simp add: Suc_def) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 921 | |
| 55642 
63beb38e9258
adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
 blanchet parents: 
55428diff
changeset | 922 | declare natural.rec [code del] | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 923 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 924 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 925 | "integer_of_natural (m + n) = integer_of_natural m + integer_of_natural n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 926 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 927 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 928 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 929 | "integer_of_natural (m - n) = max 0 (integer_of_natural m - integer_of_natural n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 930 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 931 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 932 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 933 | "integer_of_natural (m * n) = integer_of_natural m * integer_of_natural n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 934 | by transfer (simp add: of_nat_mult) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 935 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 936 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 937 | "integer_of_natural (m div n) = integer_of_natural m div integer_of_natural n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 938 | by transfer (simp add: zdiv_int) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 939 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 940 | lemma [code abstract]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 941 | "integer_of_natural (m mod n) = integer_of_natural m mod integer_of_natural n" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 942 | by transfer (simp add: zmod_int) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 943 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 944 | lemma [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 945 | "HOL.equal m n \<longleftrightarrow> HOL.equal (integer_of_natural m) (integer_of_natural n)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 946 | by transfer (simp add: equal) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 947 | |
| 58379 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 948 | lemma [code nbe]: "HOL.equal n (n::natural) \<longleftrightarrow> True" | 
| 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 949 | by (rule equal_class.equal_refl) | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 950 | |
| 58379 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 951 | lemma [code]: "m \<le> n \<longleftrightarrow> integer_of_natural m \<le> integer_of_natural n" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 952 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 953 | |
| 58379 
c044539a2bda
reintroduced an instantiation of 'size' for 'numerals'
 blanchet parents: 
58377diff
changeset | 954 | lemma [code]: "m < n \<longleftrightarrow> integer_of_natural m < integer_of_natural n" | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 955 | by transfer simp | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 956 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 957 | hide_const (open) Nat | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 958 | |
| 55736 
f1ed1e9cd080
unregister lifting setup following the best practice of Lifting
 kuncar parents: 
55642diff
changeset | 959 | lifting_update integer.lifting | 
| 
f1ed1e9cd080
unregister lifting setup following the best practice of Lifting
 kuncar parents: 
55642diff
changeset | 960 | lifting_forget integer.lifting | 
| 
f1ed1e9cd080
unregister lifting setup following the best practice of Lifting
 kuncar parents: 
55642diff
changeset | 961 | |
| 
f1ed1e9cd080
unregister lifting setup following the best practice of Lifting
 kuncar parents: 
55642diff
changeset | 962 | lifting_update natural.lifting | 
| 
f1ed1e9cd080
unregister lifting setup following the best practice of Lifting
 kuncar parents: 
55642diff
changeset | 963 | lifting_forget natural.lifting | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 964 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 965 | code_reflect Code_Numeral | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 966 | datatypes natural = _ | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 967 | functions integer_of_natural natural_of_integer | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 968 | |
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
49962diff
changeset | 969 | end |