src/HOL/Library/Code_Integer.thy
changeset 34899 8674bb6f727b
parent 32657 5f13912245ff
child 34944 970e1466028d
equal deleted inserted replaced
34898:62d70417f8ce 34899:8674bb6f727b
    16 
    16 
    17 code_type int
    17 code_type int
    18   (SML "IntInf.int")
    18   (SML "IntInf.int")
    19   (OCaml "Big'_int.big'_int")
    19   (OCaml "Big'_int.big'_int")
    20   (Haskell "Integer")
    20   (Haskell "Integer")
       
    21   (Scala "BigInt")
    21 
    22 
    22 code_instance int :: eq
    23 code_instance int :: eq
    23   (Haskell -)
    24   (Haskell -)
    24 
    25 
    25 setup {*
    26 setup {*
    26   fold (Numeral.add_code @{const_name number_int_inst.number_of_int}
    27   fold (Numeral.add_code @{const_name number_int_inst.number_of_int}
    27     true true) ["SML", "OCaml", "Haskell"]
    28     true true Code_Printer.str) ["SML", "OCaml", "Haskell", "Scala"]
       
    29   #> Numeral.add_code @{const_name number_int_inst.number_of_int}
       
    30     true true (fn s => (Pretty.block o map Code_Printer.str) ["BigInt", s]) "Scala"
    28 *}
    31 *}
    29 
    32 
    30 code_const "Int.Pls" and "Int.Min" and "Int.Bit0" and "Int.Bit1"
    33 code_const "Int.Pls" and "Int.Min" and "Int.Bit0" and "Int.Bit1"
    31   (SML "raise/ Fail/ \"Pls\""
    34   (SML "raise/ Fail/ \"Pls\""
    32      and "raise/ Fail/ \"Min\""
    35      and "raise/ Fail/ \"Min\""
    38      and "!((_);/ failwith/ \"Bit1\")")
    41      and "!((_);/ failwith/ \"Bit1\")")
    39   (Haskell "error/ \"Pls\""
    42   (Haskell "error/ \"Pls\""
    40      and "error/ \"Min\""
    43      and "error/ \"Min\""
    41      and "error/ \"Bit0\""
    44      and "error/ \"Bit0\""
    42      and "error/ \"Bit1\"")
    45      and "error/ \"Bit1\"")
       
    46   (Scala "!error(\"Pls\")"
       
    47      and "!error(\"Min\")"
       
    48      and "!error(\"Bit0\")"
       
    49      and "!error(\"Bit1\")")
       
    50 
    43 
    51 
    44 code_const Int.pred
    52 code_const Int.pred
    45   (SML "IntInf.- ((_), 1)")
    53   (SML "IntInf.- ((_), 1)")
    46   (OCaml "Big'_int.pred'_big'_int")
    54   (OCaml "Big'_int.pred'_big'_int")
    47   (Haskell "!(_/ -/ 1)")
    55   (Haskell "!(_/ -/ 1)")
       
    56   (Scala "!(_/ -/ 1)")
    48 
    57 
    49 code_const Int.succ
    58 code_const Int.succ
    50   (SML "IntInf.+ ((_), 1)")
    59   (SML "IntInf.+ ((_), 1)")
    51   (OCaml "Big'_int.succ'_big'_int")
    60   (OCaml "Big'_int.succ'_big'_int")
    52   (Haskell "!(_/ +/ 1)")
    61   (Haskell "!(_/ +/ 1)")
       
    62   (Scala "!(_/ +/ 1)")
    53 
    63 
    54 code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    64 code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    55   (SML "IntInf.+ ((_), (_))")
    65   (SML "IntInf.+ ((_), (_))")
    56   (OCaml "Big'_int.add'_big'_int")
    66   (OCaml "Big'_int.add'_big'_int")
    57   (Haskell infixl 6 "+")
    67   (Haskell infixl 6 "+")
       
    68   (Scala infixl 7 "+")
    58 
    69 
    59 code_const "uminus \<Colon> int \<Rightarrow> int"
    70 code_const "uminus \<Colon> int \<Rightarrow> int"
    60   (SML "IntInf.~")
    71   (SML "IntInf.~")
    61   (OCaml "Big'_int.minus'_big'_int")
    72   (OCaml "Big'_int.minus'_big'_int")
    62   (Haskell "negate")
    73   (Haskell "negate")
       
    74   (Scala "!(- _)")
    63 
    75 
    64 code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    76 code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    65   (SML "IntInf.- ((_), (_))")
    77   (SML "IntInf.- ((_), (_))")
    66   (OCaml "Big'_int.sub'_big'_int")
    78   (OCaml "Big'_int.sub'_big'_int")
    67   (Haskell infixl 6 "-")
    79   (Haskell infixl 6 "-")
       
    80   (Scala infixl 7 "-")
    68 
    81 
    69 code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    82 code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    70   (SML "IntInf.* ((_), (_))")
    83   (SML "IntInf.* ((_), (_))")
    71   (OCaml "Big'_int.mult'_big'_int")
    84   (OCaml "Big'_int.mult'_big'_int")
    72   (Haskell infixl 7 "*")
    85   (Haskell infixl 7 "*")
       
    86   (Scala infixl 8 "*")
    73 
    87 
    74 code_const pdivmod
    88 code_const pdivmod
    75   (SML "(fn k => fn l =>/ IntInf.divMod/ (IntInf.abs k,/ IntInf.abs l))")
    89   (SML "IntInf.divMod/ (IntInf.abs _,/ IntInf.abs _)")
    76   (OCaml "(fun k -> fun l ->/ Big'_int.quomod'_big'_int/ (Big'_int.abs'_big'_int k)/ (Big'_int.abs'_big'_int l))")
    90   (OCaml "Big'_int.quomod'_big'_int/ (Big'_int.abs'_big'_int _)/ (Big'_int.abs'_big'_int _)")
    77   (Haskell "(\\k l ->/ divMod/ (abs k)/ (abs l))")
    91   (Haskell "divMod/ (abs _)/ (abs _))")
       
    92   (Scala "!(_.abs '/% _.abs)")
    78 
    93 
    79 code_const "eq_class.eq \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
    94 code_const "eq_class.eq \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
    80   (SML "!((_ : IntInf.int) = _)")
    95   (SML "!((_ : IntInf.int) = _)")
    81   (OCaml "Big'_int.eq'_big'_int")
    96   (OCaml "Big'_int.eq'_big'_int")
    82   (Haskell infixl 4 "==")
    97   (Haskell infixl 4 "==")
       
    98   (Scala infixl 5 "==")
    83 
    99 
    84 code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
   100 code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
    85   (SML "IntInf.<= ((_), (_))")
   101   (SML "IntInf.<= ((_), (_))")
    86   (OCaml "Big'_int.le'_big'_int")
   102   (OCaml "Big'_int.le'_big'_int")
    87   (Haskell infix 4 "<=")
   103   (Haskell infix 4 "<=")
       
   104   (Scala infixl 4 "<=")
    88 
   105 
    89 code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
   106 code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
    90   (SML "IntInf.< ((_), (_))")
   107   (SML "IntInf.< ((_), (_))")
    91   (OCaml "Big'_int.lt'_big'_int")
   108   (OCaml "Big'_int.lt'_big'_int")
    92   (Haskell infix 4 "<")
   109   (Haskell infix 4 "<")
       
   110   (Scala infixl 4 "<=")
    93 
   111 
    94 code_const Code_Numeral.int_of
   112 code_const Code_Numeral.int_of
    95   (SML "IntInf.fromInt")
   113   (SML "IntInf.fromInt")
    96   (OCaml "_")
   114   (OCaml "_")
    97   (Haskell "toEnum")
   115   (Haskell "toEnum")
       
   116   (Scala "!BigInt(_)")
    98 
   117 
    99 code_reserved SML IntInf
   118 code_reserved SML IntInf
       
   119 code_reserved Scala BigInt
   100 
   120 
   101 text {* Evaluation *}
   121 text {* Evaluation *}
   102 
   122 
   103 code_const "Code_Evaluation.term_of \<Colon> int \<Rightarrow> term"
   123 code_const "Code_Evaluation.term_of \<Colon> int \<Rightarrow> term"
   104   (Eval "HOLogic.mk'_number/ HOLogic.intT")
   124   (Eval "HOLogic.mk'_number/ HOLogic.intT")