src/HOL/Library/Pretty_Int.thy
author nipkow
Fri, 01 Jun 2007 22:09:16 +0200
changeset 23192 ec73b9707d48
parent 22949 997cef733bdd
child 23859 fc44fa554ca8
permissions -rw-r--r--
Moved list comprehension into List
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22803
5129e02f4df2 slightly tuned
haftmann
parents: 22767
diff changeset
     1
(*  Title:      HOL/Library/Pretty_Int.thy
5129e02f4df2 slightly tuned
haftmann
parents: 22767
diff changeset
     2
    ID:         $Id$
22767
125363bf7518 initial commit
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
125363bf7518 initial commit
haftmann
parents:
diff changeset
     4
*)
125363bf7518 initial commit
haftmann
parents:
diff changeset
     5
125363bf7518 initial commit
haftmann
parents:
diff changeset
     6
header {* Pretty integer literals for code generation *}
125363bf7518 initial commit
haftmann
parents:
diff changeset
     7
125363bf7518 initial commit
haftmann
parents:
diff changeset
     8
theory Pretty_Int
125363bf7518 initial commit
haftmann
parents:
diff changeset
     9
imports IntArith
125363bf7518 initial commit
haftmann
parents:
diff changeset
    10
begin
125363bf7518 initial commit
haftmann
parents:
diff changeset
    11
125363bf7518 initial commit
haftmann
parents:
diff changeset
    12
text {*
125363bf7518 initial commit
haftmann
parents:
diff changeset
    13
  HOL numeral expressions are mapped to integer literals
125363bf7518 initial commit
haftmann
parents:
diff changeset
    14
  in target languages, using predefined target language
125363bf7518 initial commit
haftmann
parents:
diff changeset
    15
  operations for abstract integer operations.
125363bf7518 initial commit
haftmann
parents:
diff changeset
    16
*}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    17
125363bf7518 initial commit
haftmann
parents:
diff changeset
    18
code_type int
125363bf7518 initial commit
haftmann
parents:
diff changeset
    19
  (SML "IntInf.int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    20
  (OCaml "Big'_int.big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    21
  (Haskell "Integer")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    22
22949
997cef733bdd fixed omission
haftmann
parents: 22803
diff changeset
    23
code_instance int :: eq
997cef733bdd fixed omission
haftmann
parents: 22803
diff changeset
    24
  (Haskell -)
997cef733bdd fixed omission
haftmann
parents: 22803
diff changeset
    25
22767
125363bf7518 initial commit
haftmann
parents:
diff changeset
    26
setup {*
125363bf7518 initial commit
haftmann
parents:
diff changeset
    27
  fold (fn target => CodegenSerializer.add_pretty_numeral target
125363bf7518 initial commit
haftmann
parents:
diff changeset
    28
    (@{const_name number_of}, @{typ "int \<Rightarrow> int"})
125363bf7518 initial commit
haftmann
parents:
diff changeset
    29
    @{const_name Numeral.B0} @{const_name Numeral.B1}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    30
    @{const_name Numeral.Pls} @{const_name Numeral.Min}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    31
    @{const_name Numeral.Bit}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    32
  ) ["SML", "OCaml", "Haskell"]
125363bf7518 initial commit
haftmann
parents:
diff changeset
    33
*}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    34
125363bf7518 initial commit
haftmann
parents:
diff changeset
    35
code_const "Numeral.Pls" and "Numeral.Min" and "Numeral.Bit"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    36
  (SML "raise/ Fail/ \"Pls\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    37
     and "raise/ Fail/ \"Min\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    38
     and "!((_);/ (_);/ raise/ Fail/ \"Bit\")")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    39
  (OCaml "failwith/ \"Pls\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    40
     and "failwith/ \"Min\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    41
     and "!((_);/ (_);/ failwith/ \"Bit\")")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    42
  (Haskell "error/ \"Pls\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    43
     and "error/ \"Min\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    44
     and "error/ \"Bit\"")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    45
125363bf7518 initial commit
haftmann
parents:
diff changeset
    46
code_const Numeral.pred
125363bf7518 initial commit
haftmann
parents:
diff changeset
    47
  (SML "IntInf.- ((_), 1)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    48
  (OCaml "Big'_int.pred'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    49
  (Haskell "!(_/ -/ 1)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    50
125363bf7518 initial commit
haftmann
parents:
diff changeset
    51
code_const Numeral.succ
125363bf7518 initial commit
haftmann
parents:
diff changeset
    52
  (SML "IntInf.+ ((_), 1)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    53
  (OCaml "Big'_int.succ'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    54
  (Haskell "!(_/ +/ 1)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    55
125363bf7518 initial commit
haftmann
parents:
diff changeset
    56
code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    57
  (SML "IntInf.+ ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    58
  (OCaml "Big'_int.add'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    59
  (Haskell infixl 6 "+")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    60
125363bf7518 initial commit
haftmann
parents:
diff changeset
    61
code_const "uminus \<Colon> int \<Rightarrow> int"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    62
  (SML "IntInf.~")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    63
  (OCaml "Big'_int.minus'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    64
  (Haskell "negate")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    65
125363bf7518 initial commit
haftmann
parents:
diff changeset
    66
code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    67
  (SML "IntInf.- ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    68
  (OCaml "Big'_int.sub'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    69
  (Haskell infixl 6 "-")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    70
125363bf7518 initial commit
haftmann
parents:
diff changeset
    71
code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    72
  (SML "IntInf.* ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    73
  (OCaml "Big'_int.mult'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    74
  (Haskell infixl 7 "*")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    75
125363bf7518 initial commit
haftmann
parents:
diff changeset
    76
code_const "op = \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    77
  (SML "!((_ : IntInf.int) = _)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    78
  (OCaml "Big'_int.eq'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    79
  (Haskell infixl 4 "==")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    80
125363bf7518 initial commit
haftmann
parents:
diff changeset
    81
code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    82
  (SML "IntInf.<= ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    83
  (OCaml "Big'_int.le'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    84
  (Haskell infix 4 "<=")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    85
125363bf7518 initial commit
haftmann
parents:
diff changeset
    86
code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    87
  (SML "IntInf.< ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    88
  (OCaml "Big'_int.lt'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    89
  (Haskell infix 4 "<")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    90
125363bf7518 initial commit
haftmann
parents:
diff changeset
    91
code_reserved SML IntInf
125363bf7518 initial commit
haftmann
parents:
diff changeset
    92
code_reserved OCaml Big_int
125363bf7518 initial commit
haftmann
parents:
diff changeset
    93
125363bf7518 initial commit
haftmann
parents:
diff changeset
    94
end