src/HOL/Library/Code_Target_Int.thy
changeset 60868 dd18c33c001e
parent 60500 903bb1495239
child 61275 053ec04ea866
equal deleted inserted replaced
60867:86e7560e07d0 60868:dd18c33c001e
    69 lemma [code]:
    69 lemma [code]:
    70   "k * l = int_of_integer (of_int k * of_int l)"
    70   "k * l = int_of_integer (of_int k * of_int l)"
    71   by simp
    71   by simp
    72 
    72 
    73 lemma [code]:
    73 lemma [code]:
    74   "Divides.divmod_abs k l = map_prod int_of_integer int_of_integer
       
    75     (Code_Numeral.divmod_abs (of_int k) (of_int l))"
       
    76   by (simp add: prod_eq_iff)
       
    77 
       
    78 lemma [code]:
       
    79   "k div l = int_of_integer (of_int k div of_int l)"
    74   "k div l = int_of_integer (of_int k div of_int l)"
    80   by simp
    75   by simp
    81 
    76 
    82 lemma [code]:
    77 lemma [code]:
    83   "k mod l = int_of_integer (of_int k mod of_int l)"
    78   "k mod l = int_of_integer (of_int k mod of_int l)"
    98 
    93 
    99 lemma (in ring_1) of_int_code_if:
    94 lemma (in ring_1) of_int_code_if:
   100   "of_int k = (if k = 0 then 0
    95   "of_int k = (if k = 0 then 0
   101      else if k < 0 then - of_int (- k)
    96      else if k < 0 then - of_int (- k)
   102      else let
    97      else let
   103        (l, j) = divmod_int k 2;
    98        l = 2 * of_int (k div 2);
   104        l' = 2 * of_int l
    99        j = k mod 2
   105      in if j = 0 then l' else l' + 1)"
   100      in if j = 0 then l else l + 1)"
   106 proof -
   101 proof -
   107   from mod_div_equality have *: "of_int k = of_int (k div 2 * 2 + k mod 2)" by simp
   102   from mod_div_equality have *: "of_int k = of_int (k div 2 * 2 + k mod 2)" by simp
   108   show ?thesis
   103   show ?thesis
   109     by (simp add: Let_def divmod_int_mod_div of_int_add [symmetric])
   104     by (simp add: Let_def of_int_add [symmetric]) (simp add: * mult.commute)
   110       (simp add: * mult.commute)
       
   111 qed
   105 qed
   112 
   106 
   113 declare of_int_code_if [code]
   107 declare of_int_code_if [code]
   114 
   108 
   115 lemma [code]:
   109 lemma [code]:
   119 code_identifier
   113 code_identifier
   120   code_module Code_Target_Int \<rightharpoonup>
   114   code_module Code_Target_Int \<rightharpoonup>
   121     (SML) Arith and (OCaml) Arith and (Haskell) Arith
   115     (SML) Arith and (OCaml) Arith and (Haskell) Arith
   122 
   116 
   123 end
   117 end
   124