src/HOL/Integ/IntDef.thy
changeset 20595 db6bedfba498
parent 20485 3078fd2eec7b
child 20713 823967ef47f1
equal deleted inserted replaced
20594:b80c4a5cd018 20595:db6bedfba498
   262 
   262 
   263 lemma zle_anti_sym: "[| z \<le> w; w \<le> z |] ==> z = (w::int)"
   263 lemma zle_anti_sym: "[| z \<le> w; w \<le> z |] ==> z = (w::int)"
   264 by (cases w, cases z, simp add: le)
   264 by (cases w, cases z, simp add: le)
   265 
   265 
   266 (* Axiom 'order_less_le' of class 'order': *)
   266 (* Axiom 'order_less_le' of class 'order': *)
   267 lemma zless_le: "((w::int) < z) = (w \<le> z & w \<noteq> z)"
   267 lemma zless_le [code func]: "((w::int) < z) = (w \<le> z & w \<noteq> z)"
   268 by (simp add: less_int_def)
   268 by (simp add: less_int_def)
   269 
   269 
   270 instance int :: order
   270 instance int :: order
   271   by intro_classes
   271   by intro_classes
   272     (assumption |
   272     (assumption |
   867 *}
   867 *}
   868 attach (test) {*
   868 attach (test) {*
   869 fun gen_int i = one_of [~1, 1] * random_range 0 i;
   869 fun gen_int i = one_of [~1, 1] * random_range 0 i;
   870 *}
   870 *}
   871 
   871 
   872 constdefs
   872 definition
   873   int_aux :: "int \<Rightarrow> nat \<Rightarrow> int"
   873   int_aux :: "int \<Rightarrow> nat \<Rightarrow> int"
   874   "int_aux i n == (i + int n)"
   874   "int_aux i n = (i + int n)"
   875   nat_aux :: "nat \<Rightarrow> int \<Rightarrow> nat"
   875   nat_aux :: "nat \<Rightarrow> int \<Rightarrow> nat"
   876   "nat_aux n i == (n + nat i)"
   876   "nat_aux n i = (n + nat i)"
   877 
   877 
   878 lemma [code]:
   878 lemma [code]:
   879   "int_aux i 0 = i"
   879   "int_aux i 0 = i"
   880   "int_aux i (Suc n) = int_aux (i + 1) n" -- {* tail recursive *}
   880   "int_aux i (Suc n) = int_aux (i + 1) n" -- {* tail recursive *}
   881   "int n = int_aux 0 n"
   881   "int n = int_aux 0 n"
   889   by (simp add: nat_aux_def)
   889   by (simp add: nat_aux_def)
   890 
   890 
   891 lemma [code inline]:
   891 lemma [code inline]:
   892   "neg k = (k < 0)"
   892   "neg k = (k < 0)"
   893   unfolding neg_def ..
   893   unfolding neg_def ..
       
   894 
       
   895 lemma [code func]:
       
   896   "\<bar>k\<Colon>int\<bar> = (if k \<le> 0 then - k else k)"
       
   897   unfolding zabs_def by auto
   894 
   898 
   895 consts_code
   899 consts_code
   896   "0" :: "int"                       ("0")
   900   "0" :: "int"                       ("0")
   897   "1" :: "int"                       ("1")
   901   "1" :: "int"                       ("1")
   898   "HOL.uminus" :: "int => int"       ("~")
   902   "HOL.uminus" :: "int => int"       ("~")
   900   "HOL.times" :: "int => int => int" ("(_ */ _)")
   904   "HOL.times" :: "int => int => int" ("(_ */ _)")
   901   "Orderings.less" :: "int => int => bool" ("(_ </ _)")
   905   "Orderings.less" :: "int => int => bool" ("(_ </ _)")
   902   "Orderings.less_eq" :: "int => int => bool" ("(_ <=/ _)")
   906   "Orderings.less_eq" :: "int => int => bool" ("(_ <=/ _)")
   903   "neg"                              ("(_ < 0)")
   907   "neg"                              ("(_ < 0)")
   904 
   908 
       
   909 instance int :: eq ..
       
   910 
   905 code_type int
   911 code_type int
   906   (SML target_atom "IntInf.int")
   912   (SML target_atom "IntInf.int")
   907   (Haskell target_atom "Integer")
   913   (Haskell target_atom "Integer")
   908 
   914 
   909 code_const "op + :: int \<Rightarrow> int \<Rightarrow> int"
   915 code_instance int :: eq
       
   916   (Haskell -)
       
   917 
       
   918 code_const "OperationalEquality.eq \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
       
   919   (SML "(op =) (_ : IntInf.int, _)")
       
   920   (Haskell infixl 4 "==")
       
   921 
       
   922 code_const "op <= \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
       
   923   (SML "IntInf.<= (_, _)")
       
   924   (Haskell infix 4 "<=")
       
   925 
       
   926 code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
       
   927   (SML "IntInf.< (_, _)")
       
   928   (Haskell infix 4 "<")
       
   929 
       
   930 code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
   910   (SML "IntInf.+ (_, _)")
   931   (SML "IntInf.+ (_, _)")
   911   (Haskell infixl 6 "+")
   932   (Haskell infixl 6 "+")
   912 
   933 
   913 code_const "op * :: int \<Rightarrow> int \<Rightarrow> int"
   934 code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
       
   935   (SML "IntInf.- (_, _)")
       
   936   (Haskell infixl 6 "-")
       
   937 
       
   938 code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
   914   (SML "IntInf.* (_, _)")
   939   (SML "IntInf.* (_, _)")
   915   (Haskell infixl 7 "*")
   940   (Haskell infixl 7 "*")
   916 
   941 
   917 code_const "uminus :: int \<Rightarrow> int"
   942 code_const "uminus \<Colon> int \<Rightarrow> int"
   918   (SML target_atom "IntInf.~")
   943   (SML target_atom "IntInf.~")
   919   (Haskell target_atom "negate")
   944   (Haskell target_atom "negate")
   920 
       
   921 code_const "op = :: int \<Rightarrow> int \<Rightarrow> bool"
       
   922   (SML "(op =) (_ : IntInf.int, _)")
       
   923   (Haskell infixl 4 "==")
       
   924 
       
   925 code_const "op <= :: int \<Rightarrow> int \<Rightarrow> bool"
       
   926   (SML "IntInf.<= (_, _)")
       
   927   (Haskell infix 4 "<=")
       
   928 
   945 
   929 ML {*
   946 ML {*
   930 fun number_of_codegen thy defs gr dep module b (Const ("Numeral.number_of",
   947 fun number_of_codegen thy defs gr dep module b (Const ("Numeral.number_of",
   931       Type ("fun", [_, T as Type ("IntDef.int", [])])) $ bin) =
   948       Type ("fun", [_, T as Type ("IntDef.int", [])])) $ bin) =
   932         (SOME (fst (Codegen.invoke_tycodegen thy defs dep module false (gr, T)),
   949         (SOME (fst (Codegen.invoke_tycodegen thy defs dep module false (gr, T)),