src/HOL/Word/Word.thy
changeset 41550 efa734d9b221
parent 41413 64cd30d6b0b8
child 42793 88bee9f6eec7
equal deleted inserted replaced
41549:2c65ad10bec8 41550:efa734d9b221
  2169   apply (clarsimp simp add : uno_simps)
  2169   apply (clarsimp simp add : uno_simps)
  2170   done
  2170   done
  2171 
  2171 
  2172 lemma word_of_int_power_hom: 
  2172 lemma word_of_int_power_hom: 
  2173   "word_of_int a ^ n = (word_of_int (a ^ n) :: 'a :: len word)"
  2173   "word_of_int a ^ n = (word_of_int (a ^ n) :: 'a :: len word)"
  2174   by (induct n) (simp_all add : word_of_int_hom_syms power_Suc)
  2174   by (induct n) (simp_all add: word_of_int_hom_syms)
  2175 
  2175 
  2176 lemma word_arith_power_alt: 
  2176 lemma word_arith_power_alt: 
  2177   "a ^ n = (word_of_int (uint a ^ n) :: 'a :: len word)"
  2177   "a ^ n = (word_of_int (uint a ^ n) :: 'a :: len word)"
  2178   by (simp add : word_of_int_power_hom [symmetric])
  2178   by (simp add : word_of_int_power_hom [symmetric])
  2179 
  2179 
  2365   fixes x :: "'a::len0 word"
  2365   fixes x :: "'a::len0 word"
  2366   shows "(x OR y) AND z = x AND z OR y AND z"
  2366   shows "(x OR y) AND z = x AND z OR y AND z"
  2367   using word_of_int_Ex [where x=x] 
  2367   using word_of_int_Ex [where x=x] 
  2368         word_of_int_Ex [where x=y] 
  2368         word_of_int_Ex [where x=y] 
  2369         word_of_int_Ex [where x=z]   
  2369         word_of_int_Ex [where x=z]   
  2370   by (auto simp: bwsimps bbw_ao_dist simp del: bin_ops_comm)
  2370   by (auto simp: bwsimps bbw_ao_dist)
  2371 
  2371 
  2372 lemma word_oa_dist:
  2372 lemma word_oa_dist:
  2373   fixes x :: "'a::len0 word"
  2373   fixes x :: "'a::len0 word"
  2374   shows "x AND y OR z = (x OR z) AND (y OR z)"
  2374   shows "x AND y OR z = (x OR z) AND (y OR z)"
  2375   using word_of_int_Ex [where x=x] 
  2375   using word_of_int_Ex [where x=x] 
  2376         word_of_int_Ex [where x=y] 
  2376         word_of_int_Ex [where x=y] 
  2377         word_of_int_Ex [where x=z]   
  2377         word_of_int_Ex [where x=z]   
  2378   by (auto simp: bwsimps bbw_oa_dist simp del: bin_ops_comm)
  2378   by (auto simp: bwsimps bbw_oa_dist)
  2379 
  2379 
  2380 lemma word_add_not [simp]: 
  2380 lemma word_add_not [simp]: 
  2381   fixes x :: "'a::len0 word"
  2381   fixes x :: "'a::len0 word"
  2382   shows "x + NOT x = -1"
  2382   shows "x + NOT x = -1"
  2383   using word_of_int_Ex [where x=x] 
  2383   using word_of_int_Ex [where x=x] 
  2569     
  2569     
  2570 lemma word_set_set_diff: 
  2570 lemma word_set_set_diff: 
  2571   fixes w :: "'a::len0 word"
  2571   fixes w :: "'a::len0 word"
  2572   assumes "m ~= n"
  2572   assumes "m ~= n"
  2573   shows "set_bit (set_bit w m x) n y = set_bit (set_bit w n y) m x" 
  2573   shows "set_bit (set_bit w m x) n y = set_bit (set_bit w n y) m x" 
  2574   by (rule word_eqI) (clarsimp simp add : test_bit_set_gen word_size prems)
  2574   by (rule word_eqI) (clarsimp simp add: test_bit_set_gen word_size assms)
  2575     
  2575     
  2576 lemma test_bit_no': 
  2576 lemma test_bit_no': 
  2577   fixes w :: "'a::len0 word"
  2577   fixes w :: "'a::len0 word"
  2578   shows "w = number_of bin \<Longrightarrow> test_bit w n = (n < size w & bin_nth bin n)"
  2578   shows "w = number_of bin \<Longrightarrow> test_bit w n = (n < size w & bin_nth bin n)"
  2579   unfolding word_test_bit_def word_number_of_def word_size
  2579   unfolding word_test_bit_def word_number_of_def word_size
  2621   apply (clarsimp simp add: word_size test_bit_no)
  2621   apply (clarsimp simp add: word_size test_bit_no)
  2622   apply (auto simp add: word_bl.Abs_inverse test_bit_bl word_size)
  2622   apply (auto simp add: word_bl.Abs_inverse test_bit_bl word_size)
  2623   done
  2623   done
  2624 
  2624 
  2625 lemma word_msb_n1: "msb (-1::'a::len word)"
  2625 lemma word_msb_n1: "msb (-1::'a::len word)"
  2626   unfolding word_msb_alt word_msb_alt to_bl_n1 by simp
  2626   unfolding word_msb_alt to_bl_n1 by simp
  2627 
  2627 
  2628 declare word_set_set_same [simp] word_set_nth [simp]
  2628 declare word_set_set_same [simp] word_set_nth [simp]
  2629   test_bit_no [simp] word_set_no [simp] nth_0 [simp]
  2629   test_bit_no [simp] word_set_no [simp] nth_0 [simp]
  2630   setBit_no [simp] clearBit_no [simp]
  2630   setBit_no [simp] clearBit_no [simp]
  2631   word_lsb_no [simp] word_msb_no [simp] word_msb_n1 [simp] word_lsb_1_0 [simp]
  2631   word_lsb_no [simp] word_msb_no [simp] word_msb_n1 [simp] word_lsb_1_0 [simp]
  3045   apply simp
  3045   apply simp
  3046   done
  3046   done
  3047 
  3047 
  3048 lemma shiftl_t2n: "shiftl (w :: 'a :: len word) n = 2 ^ n * w"
  3048 lemma shiftl_t2n: "shiftl (w :: 'a :: len word) n = 2 ^ n * w"
  3049   unfolding shiftl_def 
  3049   unfolding shiftl_def 
  3050   by (induct n) (auto simp: shiftl1_2t power_Suc)
  3050   by (induct n) (auto simp: shiftl1_2t)
  3051 
  3051 
  3052 lemma shiftr1_bintr [simp]:
  3052 lemma shiftr1_bintr [simp]:
  3053   "(shiftr1 (number_of w) :: 'a :: len0 word) = 
  3053   "(shiftr1 (number_of w) :: 'a :: len0 word) = 
  3054     number_of (bin_rest (bintrunc (len_of TYPE ('a)) w))" 
  3054     number_of (bin_rest (bintrunc (len_of TYPE ('a)) w))" 
  3055   unfolding shiftr1_def word_number_of_def
  3055   unfolding shiftr1_def word_number_of_def
  3938   apply (rule trans)
  3938   apply (rule trans)
  3939    apply (rule test_bit_rsplit_alt)
  3939    apply (rule test_bit_rsplit_alt)
  3940      apply (clarsimp simp: word_size)+
  3940      apply (clarsimp simp: word_size)+
  3941   apply (rule trans)
  3941   apply (rule trans)
  3942   apply (rule test_bit_rcat [OF refl refl])
  3942   apply (rule test_bit_rcat [OF refl refl])
  3943   apply (simp add : word_size msrevs)
  3943   apply (simp add: word_size msrevs)
  3944   apply (subst nth_rev)
  3944   apply (subst nth_rev)
  3945    apply arith
  3945    apply arith
  3946   apply (simp add : le0 [THEN [2] xtr7, THEN diff_Suc_less])
  3946   apply (simp add: le0 [THEN [2] xtr7, THEN diff_Suc_less])
  3947   apply safe
  3947   apply safe
  3948   apply (simp add : diff_mult_distrib)
  3948   apply (simp add: diff_mult_distrib)
  3949   apply (rule mpl_lem)
  3949   apply (rule mpl_lem)
  3950   apply (cases "size ws")
  3950   apply (cases "size ws")
  3951    apply simp_all
  3951    apply simp_all
  3952   done
  3952   done
  3953 
  3953