src/HOL/Library/Efficient_Nat.thy
changeset 28694 4e9edaef64dc
parent 28683 59c01ec6cb8d
child 28969 4ed63cdda799
equal deleted inserted replaced
28693:a1294a197d12 28694:4e9edaef64dc
     4 *)
     4 *)
     5 
     5 
     6 header {* Implementation of natural numbers by target-language integers *}
     6 header {* Implementation of natural numbers by target-language integers *}
     7 
     7 
     8 theory Efficient_Nat
     8 theory Efficient_Nat
     9 imports Plain Code_Index Code_Integer
     9 imports Code_Index Code_Integer
    10 begin
    10 begin
    11 
    11 
    12 text {*
    12 text {*
    13   When generating code for functions on natural numbers, the
    13   When generating code for functions on natural numbers, the
    14   canonical representation using @{term "0::nat"} and
    14   canonical representation using @{term "0::nat"} and
    54   unfolding of_nat_mult [symmetric] by simp
    54   unfolding of_nat_mult [symmetric] by simp
    55 
    55 
    56 text {* Specialized @{term "op div \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"} 
    56 text {* Specialized @{term "op div \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"} 
    57   and @{term "op mod \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"} operations. *}
    57   and @{term "op mod \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"} operations. *}
    58 
    58 
    59 definition
    59 definition divmod_aux ::  "nat \<Rightarrow> nat \<Rightarrow> nat \<times> nat" where
    60   divmod_aux ::  "nat \<Rightarrow> nat \<Rightarrow> nat \<times> nat"
       
    61 where
       
    62   [code del]: "divmod_aux = divmod"
    60   [code del]: "divmod_aux = divmod"
    63 
    61 
    64 lemma [code]:
    62 lemma [code]:
    65   "divmod n m = (if m = 0 then (0, n) else divmod_aux n m)"
    63   "divmod n m = (if m = 0 then (0, n) else divmod_aux n m)"
    66   unfolding divmod_aux_def divmod_div_mod by simp
    64   unfolding divmod_aux_def divmod_div_mod by simp