equal
deleted
inserted
replaced
113 lemma nibble_of_nat_mod_16: |
113 lemma nibble_of_nat_mod_16: |
114 "nibble_of_nat (n mod 16) = nibble_of_nat n" |
114 "nibble_of_nat (n mod 16) = nibble_of_nat n" |
115 by (simp add: nibble_of_nat_def) |
115 by (simp add: nibble_of_nat_def) |
116 |
116 |
117 datatype char = Char nibble nibble |
117 datatype char = Char nibble nibble |
118 -- "Note: canonical order of character encoding coincides with standard term ordering" |
118 \<comment> "Note: canonical order of character encoding coincides with standard term ordering" |
119 |
119 |
120 syntax |
120 syntax |
121 "_Char" :: "str_position => char" ("CHR _") |
121 "_Char" :: "str_position => char" ("CHR _") |
122 |
122 |
123 type_synonym string = "char list" |
123 type_synonym string = "char list" |
279 then have "nibble_of_nat (nat_of_nibble y + nat_of_nibble x * 16) = y" |
279 then have "nibble_of_nat (nat_of_nibble y + nat_of_nibble x * 16) = y" |
280 by (simp only: nibble_of_nat_mod_16) |
280 by (simp only: nibble_of_nat_mod_16) |
281 with Char show ?thesis by (simp add: nat_of_char_def add.commute) |
281 with Char show ?thesis by (simp add: nat_of_char_def add.commute) |
282 qed |
282 qed |
283 |
283 |
284 code_datatype Char -- \<open>drop case certificate for char\<close> |
284 code_datatype Char \<comment> \<open>drop case certificate for char\<close> |
285 |
285 |
286 lemma case_char_code [code]: |
286 lemma case_char_code [code]: |
287 "case_char f c = (let n = nat_of_char c in f (nibble_of_nat (n div 16)) (nibble_of_nat n))" |
287 "case_char f c = (let n = nat_of_char c in f (nibble_of_nat (n div 16)) (nibble_of_nat n))" |
288 by (cases c) |
288 by (cases c) |
289 (simp only: Let_def nibble_of_nat_of_char_div_16 nibble_of_nat_nat_of_char char.case) |
289 (simp only: Let_def nibble_of_nat_of_char_div_16 nibble_of_nat_nat_of_char char.case) |