src/HOL/Code_Numeral.thy
changeset 31377 a48f9ef9de15
parent 31266 55e70b6d812e
child 31998 2c7a24f74db9
equal deleted inserted replaced
31376:4356b52b03f7 31377:a48f9ef9de15
   277 
   277 
   278 text {* Implementation of indices by bounded integers *}
   278 text {* Implementation of indices by bounded integers *}
   279 
   279 
   280 code_type code_numeral
   280 code_type code_numeral
   281   (SML "int")
   281   (SML "int")
   282   (OCaml "int")
   282   (OCaml "Big'_int.big'_int")
   283   (Haskell "Int")
   283   (Haskell "Int")
   284 
   284 
   285 code_instance code_numeral :: eq
   285 code_instance code_numeral :: eq
   286   (Haskell -)
   286   (Haskell -)
   287 
   287 
   288 setup {*
   288 setup {*
   289   fold (Numeral.add_code @{const_name number_code_numeral_inst.number_of_code_numeral}
   289   fold (Numeral.add_code @{const_name number_code_numeral_inst.number_of_code_numeral}
   290     false false) ["SML", "OCaml", "Haskell"]
   290     false false) ["SML", "Haskell"]
       
   291   #> Numeral.add_code @{const_name number_code_numeral_inst.number_of_code_numeral} false true "OCaml"
   291 *}
   292 *}
   292 
   293 
   293 code_reserved SML Int int
   294 code_reserved SML Int int
   294 code_reserved OCaml Pervasives int
   295 code_reserved OCaml Big_int
   295 
   296 
   296 code_const "op + \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"
   297 code_const "op + \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"
   297   (SML "Int.+/ ((_),/ (_))")
   298   (SML "Int.+/ ((_),/ (_))")
   298   (OCaml "Pervasives.( + )")
   299   (OCaml "Big'_int.add'_big'_int")
   299   (Haskell infixl 6 "+")
   300   (Haskell infixl 6 "+")
   300 
   301 
   301 code_const "subtract_code_numeral \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"
   302 code_const "subtract_code_numeral \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"
   302   (SML "Int.max/ (_/ -/ _,/ 0 : int)")
   303   (SML "Int.max/ (_/ -/ _,/ 0 : int)")
   303   (OCaml "Pervasives.max/ (_/ -/ _)/ (0 : int) ")
   304   (OCaml "Big'_int.max'_big'_int/ (Big'_int.sub'_big'_int/ _/ _)/ Big'_int.zero'_big'_int")
   304   (Haskell "max/ (_/ -/ _)/ (0 :: Int)")
   305   (Haskell "max/ (_/ -/ _)/ (0 :: Int)")
   305 
   306 
   306 code_const "op * \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"
   307 code_const "op * \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"
   307   (SML "Int.*/ ((_),/ (_))")
   308   (SML "Int.*/ ((_),/ (_))")
   308   (OCaml "Pervasives.( * )")
   309   (OCaml "Big'_int.mult'_big'_int")
   309   (Haskell infixl 7 "*")
   310   (Haskell infixl 7 "*")
   310 
   311 
   311 code_const div_mod_code_numeral
   312 code_const div_mod_code_numeral
   312   (SML "(fn n => fn m =>/ if m = 0/ then (0, n) else/ (n div m, n mod m))")
   313   (SML "(fn n => fn m =>/ if m = 0/ then (0, n) else/ (n div m, n mod m))")
   313   (OCaml "(fun n -> fun m ->/ if m = 0/ then (0, n) else/ (n '/ m, n mod m))")
   314   (OCaml "(fun k -> fun l ->/ Big'_int.quomod'_big'_int/ (Big'_int.abs'_big'_int k)/ (Big'_int.abs'_big'_int l))")
   314   (Haskell "divMod")
   315   (Haskell "divMod")
   315 
   316 
   316 code_const "eq_class.eq \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> bool"
   317 code_const "eq_class.eq \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> bool"
   317   (SML "!((_ : Int.int) = _)")
   318   (SML "!((_ : Int.int) = _)")
   318   (OCaml "!((_ : int) = _)")
   319   (OCaml "Big'_int.eq'_big'_int")
   319   (Haskell infixl 4 "==")
   320   (Haskell infixl 4 "==")
   320 
   321 
   321 code_const "op \<le> \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> bool"
   322 code_const "op \<le> \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> bool"
   322   (SML "Int.<=/ ((_),/ (_))")
   323   (SML "Int.<=/ ((_),/ (_))")
   323   (OCaml "!((_ : int) <= _)")
   324   (OCaml "Big'_int.le'_big'_int")
   324   (Haskell infix 4 "<=")
   325   (Haskell infix 4 "<=")
   325 
   326 
   326 code_const "op < \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> bool"
   327 code_const "op < \<Colon> code_numeral \<Rightarrow> code_numeral \<Rightarrow> bool"
   327   (SML "Int.</ ((_),/ (_))")
   328   (SML "Int.</ ((_),/ (_))")
   328   (OCaml "!((_ : int) < _)")
   329   (OCaml "Big'_int.lt'_big'_int")
   329   (Haskell infix 4 "<")
   330   (Haskell infix 4 "<")
   330 
   331 
   331 end
   332 end