src/HOL/Num.thy
changeset 64178 12e6c3bbb488
parent 63913 6b886cadba7c
child 64238 b60a9752b6d0
equal deleted inserted replaced
64177:006f303fb173 64178:12e6c3bbb488
     4 *)
     4 *)
     5 
     5 
     6 section \<open>Binary Numerals\<close>
     6 section \<open>Binary Numerals\<close>
     7 
     7 
     8 theory Num
     8 theory Num
     9   imports BNF_Least_Fixpoint
     9   imports BNF_Least_Fixpoint Transfer
    10 begin
    10 begin
    11 
    11 
    12 subsection \<open>The \<open>num\<close> type\<close>
    12 subsection \<open>The \<open>num\<close> type\<close>
    13 
    13 
    14 datatype num = One | Bit0 num | Bit1 num
    14 datatype num = One | Bit0 num | Bit1 num
   533 subclass semiring_numeral ..
   533 subclass semiring_numeral ..
   534 
   534 
   535 lemma of_nat_numeral [simp]: "of_nat (numeral n) = numeral n"
   535 lemma of_nat_numeral [simp]: "of_nat (numeral n) = numeral n"
   536   by (induct n) (simp_all only: numeral.simps numeral_class.numeral.simps of_nat_add of_nat_1)
   536   by (induct n) (simp_all only: numeral.simps numeral_class.numeral.simps of_nat_add of_nat_1)
   537 
   537 
   538 end
   538 lemma numeral_unfold_funpow:
       
   539   "numeral k = (op + 1 ^^ numeral k) 0"
       
   540   unfolding of_nat_def [symmetric] by simp
       
   541 
       
   542 end
       
   543 
       
   544 lemma transfer_rule_numeral:
       
   545   fixes R :: "'a::semiring_1 \<Rightarrow> 'b::semiring_1 \<Rightarrow> bool"
       
   546   assumes [transfer_rule]: "R 0 0" "R 1 1"
       
   547     "rel_fun R (rel_fun R R) plus plus"
       
   548   shows "rel_fun HOL.eq R numeral numeral"
       
   549   apply (subst (2) numeral_unfold_funpow [abs_def])
       
   550   apply (subst (1) numeral_unfold_funpow [abs_def])
       
   551   apply transfer_prover
       
   552   done
   539 
   553 
   540 lemma nat_of_num_numeral [code_abbrev]: "nat_of_num = numeral"
   554 lemma nat_of_num_numeral [code_abbrev]: "nat_of_num = numeral"
   541 proof
   555 proof
   542   fix n
   556   fix n
   543   have "numeral n = nat_of_num n"
   557   have "numeral n = nat_of_num n"