src/HOL/Word/Word.thy
changeset 46010 ebbc2d5cd720
parent 46009 5cb7ef5bfef2
child 46011 96a5f44c22da
equal deleted inserted replaced
46009:5cb7ef5bfef2 46010:ebbc2d5cd720
   453   "of_bool False = 0"
   453   "of_bool False = 0"
   454 | "of_bool True = 1"
   454 | "of_bool True = 1"
   455 
   455 
   456 (* FIXME: only provide one theorem name *)
   456 (* FIXME: only provide one theorem name *)
   457 lemmas of_nth_def = word_set_bits_def
   457 lemmas of_nth_def = word_set_bits_def
       
   458 
       
   459 subsection {* Theorems about typedefs *}
   458 
   460 
   459 lemma sint_sbintrunc': 
   461 lemma sint_sbintrunc': 
   460   "sint (word_of_int bin :: 'a word) = 
   462   "sint (word_of_int bin :: 'a word) = 
   461     (sbintrunc (len_of TYPE ('a :: len) - 1) bin)"
   463     (sbintrunc (len_of TYPE ('a :: len) - 1) bin)"
   462   unfolding sint_uint 
   464   unfolding sint_uint 
   661   unfolding word_size by (rule less_le_trans [OF sint_lt])
   663   unfolding word_size by (rule less_le_trans [OF sint_lt])
   662 
   664 
   663 lemma sint_below_size:
   665 lemma sint_below_size:
   664   "x \<le> - (2 ^ (size (w::'a::len word) - 1)) \<Longrightarrow> x \<le> sint w"
   666   "x \<le> - (2 ^ (size (w::'a::len word) - 1)) \<Longrightarrow> x \<le> sint w"
   665   unfolding word_size by (rule order_trans [OF _ sint_ge])
   667   unfolding word_size by (rule order_trans [OF _ sint_ge])
       
   668 
       
   669 subsection {* Testing bits *}
   666 
   670 
   667 lemma test_bit_eq_iff: "(test_bit (u::'a::len0 word) = test_bit v) = (u = v)"
   671 lemma test_bit_eq_iff: "(test_bit (u::'a::len0 word) = test_bit v) = (u = v)"
   668   unfolding word_test_bit_def by (simp add: bin_nth_eq_iff)
   672   unfolding word_test_bit_def by (simp add: bin_nth_eq_iff)
   669 
   673 
   670 lemma test_bit_size [rule_format] : "(w::'a::len0 word) !! n --> n < size w"
   674 lemma test_bit_size [rule_format] : "(w::'a::len0 word) !! n --> n < size w"
  4133   word_rotl_dt [where w="number_of w", unfolded to_bl_no_bin] for w
  4137   word_rotl_dt [where w="number_of w", unfolded to_bl_no_bin] for w
  4134 
  4138 
  4135 declare word_roti_def [simp]
  4139 declare word_roti_def [simp]
  4136 
  4140 
  4137 
  4141 
  4138 subsection {* Miscellaneous  *}
  4142 subsection {* Maximum machine word *}
  4139 
  4143 
  4140 lemma word_int_cases:
  4144 lemma word_int_cases:
  4141   "\<lbrakk>\<And>n. \<lbrakk>(x ::'a::len0 word) = word_of_int n; 0 \<le> n; n < 2^len_of TYPE('a)\<rbrakk> \<Longrightarrow> P\<rbrakk>
  4145   "\<lbrakk>\<And>n. \<lbrakk>(x ::'a::len0 word) = word_of_int n; 0 \<le> n; n < 2^len_of TYPE('a)\<rbrakk> \<Longrightarrow> P\<rbrakk>
  4142    \<Longrightarrow> P"
  4146    \<Longrightarrow> P"
  4143   by (cases x rule: word_uint.Abs_cases) (simp add: uints_num)
  4147   by (cases x rule: word_uint.Abs_cases) (simp add: uints_num)
  4451 lemma word_induct2 [induct type]: 
  4455 lemma word_induct2 [induct type]: 
  4452   "\<lbrakk>P 0; \<And>n. \<lbrakk>1 + n \<noteq> 0; P n\<rbrakk> \<Longrightarrow> P (1 + n)\<rbrakk> \<Longrightarrow> P (n::'b::len word)"
  4456   "\<lbrakk>P 0; \<And>n. \<lbrakk>1 + n \<noteq> 0; P n\<rbrakk> \<Longrightarrow> P (1 + n)\<rbrakk> \<Longrightarrow> P (n::'b::len word)"
  4453   apply (rule word_induct, simp)
  4457   apply (rule word_induct, simp)
  4454   apply (case_tac "1+n = 0", auto)
  4458   apply (case_tac "1+n = 0", auto)
  4455   done
  4459   done
       
  4460 
       
  4461 subsection {* Recursion combinator for words *}
  4456 
  4462 
  4457 definition word_rec :: "'a \<Rightarrow> ('b::len word \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'b word \<Rightarrow> 'a" where
  4463 definition word_rec :: "'a \<Rightarrow> ('b::len word \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'b word \<Rightarrow> 'a" where
  4458   "word_rec forZero forSuc n = nat_rec forZero (forSuc \<circ> of_nat) (unat n)"
  4464   "word_rec forZero forSuc n = nat_rec forZero (forSuc \<circ> of_nat) (unat n)"
  4459 
  4465 
  4460 lemma word_rec_0: "word_rec z s 0 = z"
  4466 lemma word_rec_0: "word_rec z s 0 = z"