src/HOL/Library/Code_Integer.thy
author haftmann
Tue, 16 Sep 2008 09:21:24 +0200
changeset 28228 7ebe8dc06cbb
parent 27487 c8a6ce181805
child 28346 b8390cd56b8f
permissions -rw-r--r--
evaluation using code generator
haftmann@24999
     1
(*  Title:      HOL/Library/Code_Integer.thy
haftmann@24999
     2
    ID:         $Id$
haftmann@24999
     3
    Author:     Florian Haftmann, TU Muenchen
haftmann@24999
     4
*)
haftmann@24999
     5
haftmann@24999
     6
header {* Pretty integer literals for code generation *}
haftmann@24999
     7
haftmann@24999
     8
theory Code_Integer
haftmann@28228
     9
imports Plain "~~/src/HOL/Code_Eval" "~~/src/HOL/Presburger"
haftmann@24999
    10
begin
haftmann@24999
    11
haftmann@24999
    12
text {*
haftmann@24999
    13
  HOL numeral expressions are mapped to integer literals
haftmann@24999
    14
  in target languages, using predefined target language
haftmann@24999
    15
  operations for abstract integer operations.
haftmann@24999
    16
*}
haftmann@24999
    17
haftmann@24999
    18
code_type int
haftmann@24999
    19
  (SML "IntInf.int")
haftmann@24999
    20
  (OCaml "Big'_int.big'_int")
haftmann@24999
    21
  (Haskell "Integer")
haftmann@24999
    22
haftmann@24999
    23
code_instance int :: eq
haftmann@24999
    24
  (Haskell -)
haftmann@24999
    25
haftmann@24999
    26
setup {*
haftmann@25928
    27
  fold (Numeral.add_code @{const_name number_int_inst.number_of_int}
haftmann@25928
    28
    true true) ["SML", "OCaml", "Haskell"]
haftmann@24999
    29
*}
haftmann@24999
    30
huffman@26086
    31
code_const "Int.Pls" and "Int.Min" and "Int.Bit0" and "Int.Bit1"
haftmann@24999
    32
  (SML "raise/ Fail/ \"Pls\""
haftmann@24999
    33
     and "raise/ Fail/ \"Min\""
huffman@26086
    34
     and "!((_);/ raise/ Fail/ \"Bit0\")"
huffman@26086
    35
     and "!((_);/ raise/ Fail/ \"Bit1\")")
haftmann@24999
    36
  (OCaml "failwith/ \"Pls\""
haftmann@24999
    37
     and "failwith/ \"Min\""
huffman@26086
    38
     and "!((_);/ failwith/ \"Bit0\")"
huffman@26086
    39
     and "!((_);/ failwith/ \"Bit1\")")
haftmann@24999
    40
  (Haskell "error/ \"Pls\""
haftmann@24999
    41
     and "error/ \"Min\""
huffman@26086
    42
     and "error/ \"Bit0\""
huffman@26086
    43
     and "error/ \"Bit1\"")
haftmann@24999
    44
haftmann@25919
    45
code_const Int.pred
haftmann@24999
    46
  (SML "IntInf.- ((_), 1)")
haftmann@24999
    47
  (OCaml "Big'_int.pred'_big'_int")
haftmann@24999
    48
  (Haskell "!(_/ -/ 1)")
haftmann@24999
    49
haftmann@25919
    50
code_const Int.succ
haftmann@24999
    51
  (SML "IntInf.+ ((_), 1)")
haftmann@24999
    52
  (OCaml "Big'_int.succ'_big'_int")
haftmann@24999
    53
  (Haskell "!(_/ +/ 1)")
haftmann@24999
    54
haftmann@24999
    55
code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@24999
    56
  (SML "IntInf.+ ((_), (_))")
haftmann@24999
    57
  (OCaml "Big'_int.add'_big'_int")
haftmann@24999
    58
  (Haskell infixl 6 "+")
haftmann@24999
    59
haftmann@24999
    60
code_const "uminus \<Colon> int \<Rightarrow> int"
haftmann@24999
    61
  (SML "IntInf.~")
haftmann@24999
    62
  (OCaml "Big'_int.minus'_big'_int")
haftmann@24999
    63
  (Haskell "negate")
haftmann@24999
    64
haftmann@24999
    65
code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@24999
    66
  (SML "IntInf.- ((_), (_))")
haftmann@24999
    67
  (OCaml "Big'_int.sub'_big'_int")
haftmann@24999
    68
  (Haskell infixl 6 "-")
haftmann@24999
    69
haftmann@24999
    70
code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@24999
    71
  (SML "IntInf.* ((_), (_))")
haftmann@24999
    72
  (OCaml "Big'_int.mult'_big'_int")
haftmann@24999
    73
  (Haskell infixl 7 "*")
haftmann@24999
    74
haftmann@24999
    75
code_const "op = \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@24999
    76
  (SML "!((_ : IntInf.int) = _)")
haftmann@24999
    77
  (OCaml "Big'_int.eq'_big'_int")
haftmann@24999
    78
  (Haskell infixl 4 "==")
haftmann@24999
    79
haftmann@24999
    80
code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@24999
    81
  (SML "IntInf.<= ((_), (_))")
haftmann@24999
    82
  (OCaml "Big'_int.le'_big'_int")
haftmann@24999
    83
  (Haskell infix 4 "<=")
haftmann@24999
    84
haftmann@24999
    85
code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@24999
    86
  (SML "IntInf.< ((_), (_))")
haftmann@24999
    87
  (OCaml "Big'_int.lt'_big'_int")
haftmann@24999
    88
  (Haskell infix 4 "<")
haftmann@24999
    89
haftmann@24999
    90
code_reserved SML IntInf
haftmann@24999
    91
code_reserved OCaml Big_int
haftmann@24999
    92
haftmann@28228
    93
text {* Evaluation *}
haftmann@28228
    94
haftmann@28228
    95
lemma [code func, code func del]:
haftmann@28228
    96
  "(Code_Eval.term_of \<Colon> int \<Rightarrow> term) = Code_Eval.term_of" ..
haftmann@28228
    97
haftmann@28228
    98
code_const "Code_Eval.term_of \<Colon> int \<Rightarrow> term"
haftmann@28228
    99
  (SML "HOLogic.mk'_number/ HOLogic.intT")
haftmann@28228
   100
haftmann@24999
   101
end