src/HOL/Word/Word.thy
changeset 70191 bdc835d934b7
parent 70190 ff9efdc84289
child 70192 b4bf82ed0ad5
equal deleted inserted replaced
70190:ff9efdc84289 70191:bdc835d934b7
   356   where "x <s y \<longleftrightarrow> x <=s y \<and> x \<noteq> y"
   356   where "x <s y \<longleftrightarrow> x <=s y \<and> x \<noteq> y"
   357 
   357 
   358 
   358 
   359 subsection \<open>Bit-wise operations\<close>
   359 subsection \<open>Bit-wise operations\<close>
   360 
   360 
   361 instantiation word :: (len0) bits
   361 definition shiftl1 :: "'a::len0 word \<Rightarrow> 'a word"
       
   362   where "shiftl1 w = word_of_int (uint w BIT False)"
       
   363 
       
   364 definition shiftr1 :: "'a::len0 word \<Rightarrow> 'a word"
       
   365   \<comment> \<open>shift right as unsigned or as signed, ie logical or arithmetic\<close>
       
   366   where "shiftr1 w = word_of_int (bin_rest (uint w))"
       
   367 
       
   368 instantiation word :: (len0) bit_operations
   362 begin
   369 begin
   363 
   370 
   364 lift_definition bitNOT_word :: "'a word \<Rightarrow> 'a word" is bitNOT
   371 lift_definition bitNOT_word :: "'a word \<Rightarrow> 'a word" is bitNOT
   365   by (metis bin_trunc_not)
   372   by (metis bin_trunc_not)
   366 
   373 
   380 definition word_set_bits_def: "(BITS n. f n) = of_bl (bl_of_nth LENGTH('a) f)"
   387 definition word_set_bits_def: "(BITS n. f n) = of_bl (bl_of_nth LENGTH('a) f)"
   381 
   388 
   382 definition word_lsb_def: "lsb a \<longleftrightarrow> bin_last (uint a)"
   389 definition word_lsb_def: "lsb a \<longleftrightarrow> bin_last (uint a)"
   383 
   390 
   384 definition "msb a \<longleftrightarrow> bin_sign (sbintrunc (LENGTH('a) - 1) (uint a)) = - 1"
   391 definition "msb a \<longleftrightarrow> bin_sign (sbintrunc (LENGTH('a) - 1) (uint a)) = - 1"
   385 
       
   386 definition shiftl1 :: "'a word \<Rightarrow> 'a word"
       
   387   where "shiftl1 w = word_of_int (uint w BIT False)"
       
   388 
       
   389 definition shiftr1 :: "'a word \<Rightarrow> 'a word"
       
   390   \<comment> \<open>shift right as unsigned or as signed, ie logical or arithmetic\<close>
       
   391   where "shiftr1 w = word_of_int (bin_rest (uint w))"
       
   392 
   392 
   393 definition shiftl_def: "w << n = (shiftl1 ^^ n) w"
   393 definition shiftl_def: "w << n = (shiftl1 ^^ n) w"
   394 
   394 
   395 definition shiftr_def: "w >> n = (shiftr1 ^^ n) w"
   395 definition shiftr_def: "w >> n = (shiftr1 ^^ n) w"
   396 
   396