src/HOL/Word/Bit_Int.thy
changeset 54427 783861a66a60
parent 54224 9fda41a04c32
child 54489 03ff4d1e6784
equal deleted inserted replaced
54426:edb87aac9cca 54427:783861a66a60
   630 
   630 
   631 lemma ex_eq_or:
   631 lemma ex_eq_or:
   632   "(EX m. n = Suc m & (m = k | P m)) = (n = Suc k | (EX m. n = Suc m & P m))"
   632   "(EX m. n = Suc m & (m = k | P m)) = (n = Suc k | (EX m. n = Suc m & P m))"
   633   by auto
   633   by auto
   634 
   634 
       
   635 lemma power_BIT: "2 ^ (Suc n) - 1 = (2 ^ n - 1) BIT 1"
       
   636   unfolding Bit_B1
       
   637   by (induct n) simp_all
       
   638 
       
   639 lemma mod_BIT:
       
   640   "bin BIT bit mod 2 ^ Suc n = (bin mod 2 ^ n) BIT bit"
       
   641 proof -
       
   642   have "bin mod 2 ^ n < 2 ^ n" by simp
       
   643   then have "bin mod 2 ^ n \<le> 2 ^ n - 1" by simp
       
   644   then have "2 * (bin mod 2 ^ n) \<le> 2 * (2 ^ n - 1)"
       
   645     by (rule mult_left_mono) simp
       
   646   then have "2 * (bin mod 2 ^ n) + 1 < 2 * 2 ^ n" by simp
       
   647   then show ?thesis
       
   648     by (auto simp add: Bit_def bitval_def mod_mult_mult1 mod_add_left_eq [of "2 * bin"]
       
   649       mod_pos_pos_trivial split add: bit.split)
       
   650 qed
       
   651 
       
   652 lemma AND_mod:
       
   653   fixes x :: int
       
   654   shows "x AND 2 ^ n - 1 = x mod 2 ^ n"
       
   655 proof (induct x arbitrary: n rule: bin_induct)
       
   656   case 1
       
   657   then show ?case
       
   658     by simp
       
   659 next
       
   660   case 2
       
   661   then show ?case
       
   662     by (simp, simp add: m1mod2k)
       
   663 next
       
   664   case (3 bin bit)
       
   665   show ?case
       
   666   proof (cases n)
       
   667     case 0
       
   668     then show ?thesis by (simp add: int_and_extra_simps)
       
   669   next
       
   670     case (Suc m)
       
   671     with 3 show ?thesis
       
   672       by (simp only: power_BIT mod_BIT int_and_Bits) simp
       
   673   qed
       
   674 qed
       
   675 
   635 end
   676 end
   636 
   677