src/HOL/Library/Word.thy
changeset 73788 35217bf33215
parent 73682 78044b2f001c
child 73789 aab7975fa070
equal deleted inserted replaced
73787:493b1ae188da 73788:35217bf33215
  2166     (ucast (drop_bit LENGTH('c) w) :: 'b::len word, ucast w :: 'c::len word)\<close>
  2166     (ucast (drop_bit LENGTH('c) w) :: 'b::len word, ucast w :: 'c::len word)\<close>
  2167 
  2167 
  2168 definition word_rcat :: \<open>'a::len word list \<Rightarrow> 'b::len word\<close>
  2168 definition word_rcat :: \<open>'a::len word list \<Rightarrow> 'b::len word\<close>
  2169   where \<open>word_rcat = word_of_int \<circ> horner_sum uint (2 ^ LENGTH('a)) \<circ> rev\<close>
  2169   where \<open>word_rcat = word_of_int \<circ> horner_sum uint (2 ^ LENGTH('a)) \<circ> rev\<close>
  2170 
  2170 
  2171 abbreviation (input) max_word :: \<open>'a::len word\<close>
       
  2172   \<comment> \<open>Largest representable machine integer.\<close>
       
  2173   where "max_word \<equiv> - 1"
       
  2174 
       
  2175 
  2171 
  2176 subsection \<open>More on conversions\<close>
  2172 subsection \<open>More on conversions\<close>
  2177 
  2173 
  2178 lemma int_word_sint:
  2174 lemma int_word_sint:
  2179   \<open>sint (word_of_int x :: 'a::len word) = (x + 2 ^ (LENGTH('a) - 1)) mod 2 ^ LENGTH('a) - 2 ^ (LENGTH('a) - 1)\<close>
  2175   \<open>sint (word_of_int x :: 'a::len word) = (x + 2 ^ (LENGTH('a) - 1)) mod 2 ^ LENGTH('a) - 2 ^ (LENGTH('a) - 1)\<close>
  4120 lemma word_nat_cases [cases type: word]:
  4116 lemma word_nat_cases [cases type: word]:
  4121   fixes x :: "'a::len word"
  4117   fixes x :: "'a::len word"
  4122   obtains n where "x = of_nat n" and "n < 2^LENGTH('a)"
  4118   obtains n where "x = of_nat n" and "n < 2^LENGTH('a)"
  4123   by (rule that [of \<open>unat x\<close>]) simp_all
  4119   by (rule that [of \<open>unat x\<close>]) simp_all
  4124 
  4120 
  4125 lemma max_word_max [intro!]: "n \<le> max_word"
  4121 lemma max_word_max [intro!]:
       
  4122   \<open>n \<le> - 1\<close> for n :: \<open>'a::len word\<close>
  4126   by (fact word_order.extremum)
  4123   by (fact word_order.extremum)
  4127 
  4124 
  4128 lemma word_of_int_2p_len: "word_of_int (2 ^ LENGTH('a)) = (0::'a::len word)"
  4125 lemma word_of_int_2p_len: "word_of_int (2 ^ LENGTH('a)) = (0::'a::len word)"
  4129   by simp
  4126   by simp
  4130 
  4127 
  4131 lemma word_pow_0: "(2::'a::len word) ^ LENGTH('a) = 0"
  4128 lemma word_pow_0: "(2::'a::len word) ^ LENGTH('a) = 0"
  4132   by (fact word_exp_length_eq_0)
  4129   by (fact word_exp_length_eq_0)
  4133 
  4130 
  4134 lemma max_word_wrap: "x + 1 = 0 \<Longrightarrow> x = max_word"
  4131 lemma max_word_wrap: 
       
  4132   \<open>x + 1 = 0 \<Longrightarrow> x = - 1\<close> for x :: \<open>'a::len word\<close>
  4135   by (simp add: eq_neg_iff_add_eq_0)
  4133   by (simp add: eq_neg_iff_add_eq_0)
  4136 
  4134 
  4137 lemma word_and_max: "x AND max_word = x"
  4135 lemma word_and_max:
       
  4136   \<open>x AND - 1 = x\<close> for x :: \<open>'a::len word\<close>
  4138   by (fact word_log_esimps)
  4137   by (fact word_log_esimps)
  4139 
  4138 
  4140 lemma word_or_max: "x OR max_word = max_word"
  4139 lemma word_or_max:
       
  4140   \<open>x OR - 1 = - 1\<close> for x :: \<open>'a::len word\<close>
  4141   by (fact word_log_esimps)
  4141   by (fact word_log_esimps)
  4142 
  4142 
  4143 lemma word_ao_dist2: "x AND (y OR z) = x AND y OR x AND z"
  4143 lemma word_ao_dist2: "x AND (y OR z) = x AND y OR x AND z"
  4144   for x y z :: "'a::len word"
  4144   for x y z :: "'a::len word"
  4145   by (fact bit.conj_disj_distrib)
  4145   by (fact bit.conj_disj_distrib)
  4150 
  4150 
  4151 lemma word_and_not [simp]: "x AND NOT x = 0"
  4151 lemma word_and_not [simp]: "x AND NOT x = 0"
  4152   for x :: "'a::len word"
  4152   for x :: "'a::len word"
  4153   by (fact bit.conj_cancel_right)
  4153   by (fact bit.conj_cancel_right)
  4154 
  4154 
  4155 lemma word_or_not [simp]: "x OR NOT x = max_word"
  4155 lemma word_or_not [simp]:
       
  4156   \<open>x OR NOT x = - 1\<close> for x :: \<open>'a::len word\<close>
  4156   by (fact bit.disj_cancel_right)
  4157   by (fact bit.disj_cancel_right)
  4157 
  4158 
  4158 lemma word_xor_and_or: "x XOR y = x AND NOT y OR NOT x AND y"
  4159 lemma word_xor_and_or: "x XOR y = x AND NOT y OR NOT x AND y"
  4159   for x y :: "'a::len word"
  4160   for x y :: "'a::len word"
  4160   by (fact bit.xor_def)
  4161   by (fact bit.xor_def)