src/HOL/Library/Code_Char_chr.thy
author Christian Urban <urbanc@in.tum.de>
Tue, 11 May 2010 07:45:47 +0100
changeset 36812 e090bdb4e1c5
parent 32069 6d28bbd33e2c
child 37222 4d984bc33c66
permissions -rw-r--r--
tuned proof so that no simplifier warning is printed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24999
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Library/Code_Char_chr.thy
haftmann
parents:
diff changeset
     2
    Author:     Florian Haftmann
haftmann
parents:
diff changeset
     3
*)
haftmann
parents:
diff changeset
     4
haftmann
parents:
diff changeset
     5
header {* Code generation of pretty characters with character codes *}
haftmann
parents:
diff changeset
     6
haftmann
parents:
diff changeset
     7
theory Code_Char_chr
30663
0b6aff7451b2 Main is (Complex_Main) base entry point in library theories
haftmann
parents: 28562
diff changeset
     8
imports Char_nat Code_Char Code_Integer Main
24999
haftmann
parents:
diff changeset
     9
begin
haftmann
parents:
diff changeset
    10
haftmann
parents:
diff changeset
    11
definition
haftmann
parents:
diff changeset
    12
  "int_of_char = int o nat_of_char"
haftmann
parents:
diff changeset
    13
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 27368
diff changeset
    14
lemma [code]:
24999
haftmann
parents:
diff changeset
    15
  "nat_of_char = nat o int_of_char"
haftmann
parents:
diff changeset
    16
  unfolding int_of_char_def by (simp add: expand_fun_eq)
haftmann
parents:
diff changeset
    17
haftmann
parents:
diff changeset
    18
definition
haftmann
parents:
diff changeset
    19
  "char_of_int = char_of_nat o nat"
haftmann
parents:
diff changeset
    20
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 27368
diff changeset
    21
lemma [code]:
24999
haftmann
parents:
diff changeset
    22
  "char_of_nat = char_of_int o int"
haftmann
parents:
diff changeset
    23
  unfolding char_of_int_def by (simp add: expand_fun_eq)
haftmann
parents:
diff changeset
    24
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 27368
diff changeset
    25
lemmas [code del] = char.recs char.cases char.size
24999
haftmann
parents:
diff changeset
    26
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
    27
lemma [code, code_unfold]:
24999
haftmann
parents:
diff changeset
    28
  "char_rec f c = split f (nibble_pair_of_nat (nat_of_char c))"
haftmann
parents:
diff changeset
    29
  by (cases c) (auto simp add: nibble_pair_of_nat_char)
haftmann
parents:
diff changeset
    30
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
    31
lemma [code, code_unfold]:
24999
haftmann
parents:
diff changeset
    32
  "char_case f c = split f (nibble_pair_of_nat (nat_of_char c))"
haftmann
parents:
diff changeset
    33
  by (cases c) (auto simp add: nibble_pair_of_nat_char)
haftmann
parents:
diff changeset
    34
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 27368
diff changeset
    35
lemma [code]:
24999
haftmann
parents:
diff changeset
    36
  "size (c\<Colon>char) = 0"
haftmann
parents:
diff changeset
    37
  by (cases c) auto
haftmann
parents:
diff changeset
    38
haftmann
parents:
diff changeset
    39
code_const int_of_char and char_of_int
haftmann
parents:
diff changeset
    40
  (SML "!(IntInf.fromInt o Char.ord)" and "!(Char.chr o IntInf.toInt)")
haftmann
parents:
diff changeset
    41
  (OCaml "Big'_int.big'_int'_of'_int (Char.code _)" and "Char.chr (Big'_int.int'_of'_big'_int _)")
haftmann
parents:
diff changeset
    42
  (Haskell "toInteger (fromEnum (_ :: Char))" and "!(let chr k | k < 256 = toEnum k :: Char in chr . fromInteger)")
haftmann
parents:
diff changeset
    43
haftmann
parents:
diff changeset
    44
end