src/HOL/Word/WordShift.thy
changeset 24374 bb0d3b49fef0
parent 24350 4d74f37c6367
child 24401 d9d2aa843a3b
     1.1 --- a/src/HOL/Word/WordShift.thy	Tue Aug 21 00:24:10 2007 +0200
     1.2 +++ b/src/HOL/Word/WordShift.thy	Tue Aug 21 01:07:05 2007 +0200
     1.3 @@ -11,6 +11,41 @@
     1.4  
     1.5  subsection "Bit shifting"
     1.6  
     1.7 +constdefs
     1.8 +  shiftl1 :: "'a :: len0 word => 'a word"
     1.9 +  "shiftl1 w == word_of_int (uint w BIT bit.B0)"
    1.10 +
    1.11 +  -- "shift right as unsigned or as signed, ie logical or arithmetic"
    1.12 +  shiftr1 :: "'a :: len0 word => 'a word"
    1.13 +  "shiftr1 w == word_of_int (bin_rest (uint w))"
    1.14 +
    1.15 +  sshiftr1 :: "'a :: len word => 'a word" 
    1.16 +  "sshiftr1 w == word_of_int (bin_rest (sint w))"
    1.17 +
    1.18 +  bshiftr1 :: "bool => 'a :: len word => 'a word"
    1.19 +  "bshiftr1 b w == of_bl (b # butlast (to_bl w))"
    1.20 +
    1.21 +  sshiftr :: "'a :: len word => nat => 'a word" (infixl ">>>" 55)
    1.22 +  "w >>> n == (sshiftr1 ^ n) w"
    1.23 +
    1.24 +  mask :: "nat => 'a::len word"
    1.25 +  "mask n == (1 << n) - 1"
    1.26 +
    1.27 +  revcast :: "'a :: len0 word => 'b :: len0 word"
    1.28 +  "revcast w ==  of_bl (takefill False (len_of TYPE('b)) (to_bl w))"
    1.29 +
    1.30 +  slice1 :: "nat => 'a :: len0 word => 'b :: len0 word"
    1.31 +  "slice1 n w == of_bl (takefill False n (to_bl w))"
    1.32 +
    1.33 +  slice :: "nat => 'a :: len0 word => 'b :: len0 word"
    1.34 +  "slice n w == slice1 (size w - n) w"
    1.35 +
    1.36 +defs (overloaded)
    1.37 +  shiftl_def: "(w::'a::len0 word) << n == (shiftl1 ^ n) w"
    1.38 +  shiftr_def: "(w::'a::len0 word) >> n == (shiftr1 ^ n) w"
    1.39 +
    1.40 +lemmas slice_def' = slice_def [unfolded word_size]
    1.41 +
    1.42  lemma shiftl1_number [simp] :
    1.43    "shiftl1 (number_of w) = number_of (w BIT bit.B0)"
    1.44    apply (unfold shiftl1_def word_number_of_def)
    1.45 @@ -862,6 +897,23 @@
    1.46  
    1.47  subsection "Split and cat"
    1.48  
    1.49 +constdefs
    1.50 +  word_cat :: "'a :: len0 word => 'b :: len0 word => 'c :: len0 word"
    1.51 +  "word_cat a b == word_of_int (bin_cat (uint a) (len_of TYPE ('b)) (uint b))"
    1.52 +
    1.53 +  word_split :: "'a :: len0 word => ('b :: len0 word) * ('c :: len0 word)"
    1.54 +  "word_split a == 
    1.55 +   case bin_split (len_of TYPE ('c)) (uint a) of 
    1.56 +     (u, v) => (word_of_int u, word_of_int v)"
    1.57 +
    1.58 +  word_rcat :: "'a :: len0 word list => 'b :: len0 word"
    1.59 +  "word_rcat ws == 
    1.60 +  word_of_int (bin_rcat (len_of TYPE ('a)) (map uint ws))"
    1.61 +
    1.62 +  word_rsplit :: "'a :: len0 word => 'b :: len word list"
    1.63 +  "word_rsplit w == 
    1.64 +  map word_of_int (bin_rsplit (len_of TYPE ('b)) (len_of TYPE ('a), uint w))"
    1.65 +
    1.66  lemmas word_split_bin' = word_split_def [THEN meta_eq_to_obj_eq, standard]
    1.67  lemmas word_cat_bin' = word_cat_def [THEN meta_eq_to_obj_eq, standard]
    1.68  
    1.69 @@ -1244,6 +1296,24 @@
    1.70  
    1.71  subsection "Rotation"
    1.72  
    1.73 +constdefs
    1.74 +  rotater1 :: "'a list => 'a list"
    1.75 +  "rotater1 ys == 
    1.76 +    case ys of [] => [] | x # xs => last ys # butlast ys"
    1.77 +
    1.78 +  rotater :: "nat => 'a list => 'a list"
    1.79 +  "rotater n == rotater1 ^ n"
    1.80 +
    1.81 +  word_rotr :: "nat => 'a :: len0 word => 'a :: len0 word"
    1.82 +  "word_rotr n w == of_bl (rotater n (to_bl w))"
    1.83 +
    1.84 +  word_rotl :: "nat => 'a :: len0 word => 'a :: len0 word"
    1.85 +  "word_rotl n w == of_bl (rotate n (to_bl w))"
    1.86 +
    1.87 +  word_roti :: "int => 'a :: len0 word => 'a :: len0 word"
    1.88 +  "word_roti i w == if i >= 0 then word_rotr (nat i) w
    1.89 +                    else word_rotl (nat (- i)) w"
    1.90 +
    1.91  lemmas rotater_0' [simp] = rotater_def [where n = "0", simplified]
    1.92  
    1.93  lemmas word_rot_defs = word_roti_def word_rotr_def word_rotl_def