src/HOL/Word/WordBitwise.thy
author huffman
Wed, 22 Aug 2007 16:55:46 +0200
changeset 24401 d9d2aa843a3b
parent 24397 eaf37b780683
child 24408 058c5613a86f
permissions -rw-r--r--
move bool list operations from WordBitwise to WordBoolList
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     1
(* 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     2
    ID:         $Id$
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     3
    Author:     Jeremy Dawson and Gerwin Klein, NICTA
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     4
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     5
  contains theorems to do with bit-wise (logical) operations on words
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     6
*)
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     7
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     8
header {* Bitwise Operations on Words *}
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     9
24401
d9d2aa843a3b move bool list operations from WordBitwise to WordBoolList
huffman
parents: 24397
diff changeset
    10
theory WordBitwise imports WordArith begin
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    11
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    12
lemmas bin_log_bintrs = bin_trunc_not bin_trunc_xor bin_trunc_and bin_trunc_or
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    13
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    14
(* following definitions require both arithmetic and bit-wise word operations *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    15
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    16
(* to get word_no_log_defs from word_log_defs, using bin_log_bintrs *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    17
lemmas wils1 = bin_log_bintrs [THEN word_ubin.norm_eq_iff [THEN iffD1],
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    18
  folded word_ubin.eq_norm, THEN eq_reflection, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    19
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    20
(* the binary operations only *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    21
lemmas word_log_binary_defs = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    22
  word_and_def word_or_def word_xor_def
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    23
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    24
lemmas word_no_log_defs [simp] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    25
  word_not_def  [where a="number_of ?a", 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    26
                 unfolded word_no_wi wils1, folded word_no_wi]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    27
  word_log_binary_defs [where a="number_of ?a" and b="number_of ?b",
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    28
                        unfolded word_no_wi wils1, folded word_no_wi]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    29
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    30
lemmas word_wi_log_defs = word_no_log_defs [unfolded word_no_wi]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    31
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    32
lemma uint_or: "uint (x OR y) = (uint x) OR (uint y)"
24368
4c2e80f30aeb remove redundant lemma int_number_of
huffman
parents: 24367
diff changeset
    33
  by (simp add: word_or_def word_no_wi [symmetric] number_of_is_id
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    34
                bin_trunc_ao(2) [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    35
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    36
lemma uint_and: "uint (x AND y) = (uint x) AND (uint y)"
24368
4c2e80f30aeb remove redundant lemma int_number_of
huffman
parents: 24367
diff changeset
    37
  by (simp add: word_and_def number_of_is_id word_no_wi [symmetric]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    38
                bin_trunc_ao(1) [symmetric]) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    39
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    40
lemma word_ops_nth_size:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    41
  "n < size (x::'a::len0 word) ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    42
    (x OR y) !! n = (x !! n | y !! n) & 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    43
    (x AND y) !! n = (x !! n & y !! n) & 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    44
    (x XOR y) !! n = (x !! n ~= y !! n) & 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    45
    (NOT x) !! n = (~ x !! n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    46
  unfolding word_size word_no_wi word_test_bit_def word_log_defs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    47
  by (clarsimp simp add : word_ubin.eq_norm nth_bintr bin_nth_ops)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    48
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    49
lemma word_ao_nth:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    50
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    51
  shows "(x OR y) !! n = (x !! n | y !! n) & 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    52
         (x AND y) !! n = (x !! n & y !! n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    53
  apply (cases "n < size x")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    54
   apply (drule_tac y = "y" in word_ops_nth_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    55
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    56
  apply (simp add : test_bit_bin word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    57
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    58
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    59
(* get from commutativity, associativity etc of int_and etc
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    60
  to same for word_and etc *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    61
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    62
lemmas bwsimps = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    63
  word_of_int_homs(2) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    64
  word_0_wi_Pls
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    65
  word_m1_wi_Min
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    66
  word_wi_log_defs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    67
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    68
lemma word_bw_assocs:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    69
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    70
  shows
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    71
  "(x AND y) AND z = x AND y AND z"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    72
  "(x OR y) OR z = x OR y OR z"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    73
  "(x XOR y) XOR z = x XOR y XOR z"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    74
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    75
        word_of_int_Ex [where x=y] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    76
        word_of_int_Ex [where x=z]
24367
3e29eafabe16 AC rules for bitwise logical operators no longer declared simp
huffman
parents: 24353
diff changeset
    77
  by (auto simp: bwsimps bbw_assocs)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    78
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    79
lemma word_bw_comms:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    80
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    81
  shows
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    82
  "x AND y = y AND x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    83
  "x OR y = y OR x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    84
  "x XOR y = y XOR x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    85
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    86
        word_of_int_Ex [where x=y] 
24367
3e29eafabe16 AC rules for bitwise logical operators no longer declared simp
huffman
parents: 24353
diff changeset
    87
  by (auto simp: bwsimps bin_ops_comm)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    88
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    89
lemma word_bw_lcs:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    90
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    91
  shows
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    92
  "y AND x AND z = x AND y AND z"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    93
  "y OR x OR z = x OR y OR z"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    94
  "y XOR x XOR z = x XOR y XOR z"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    95
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    96
        word_of_int_Ex [where x=y] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    97
        word_of_int_Ex [where x=z]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    98
  by (auto simp: bwsimps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    99
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   100
lemma word_log_esimps [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   101
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   102
  shows
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   103
  "x AND 0 = 0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   104
  "x AND -1 = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   105
  "x OR 0 = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   106
  "x OR -1 = -1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   107
  "x XOR 0 = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   108
  "x XOR -1 = NOT x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   109
  "0 AND x = 0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   110
  "-1 AND x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   111
  "0 OR x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   112
  "-1 OR x = -1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   113
  "0 XOR x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   114
  "-1 XOR x = NOT x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   115
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   116
  by (auto simp: bwsimps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   117
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   118
lemma word_not_dist:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   119
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   120
  shows
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   121
  "NOT (x OR y) = NOT x AND NOT y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   122
  "NOT (x AND y) = NOT x OR NOT y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   123
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   124
        word_of_int_Ex [where x=y] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   125
  by (auto simp: bwsimps bbw_not_dist)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   126
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   127
lemma word_bw_same:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   128
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   129
  shows
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   130
  "x AND x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   131
  "x OR x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   132
  "x XOR x = 0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   133
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   134
  by (auto simp: bwsimps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   135
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   136
lemma word_ao_absorbs [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   137
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   138
  shows
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   139
  "x AND (y OR x) = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   140
  "x OR y AND x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   141
  "x AND (x OR y) = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   142
  "y AND x OR x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   143
  "(y OR x) AND x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   144
  "x OR x AND y = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   145
  "(x OR y) AND x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   146
  "x AND y OR x = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   147
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   148
        word_of_int_Ex [where x=y] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   149
  by (auto simp: bwsimps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   150
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   151
lemma word_not_not [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   152
  "NOT NOT (x::'a::len0 word) = x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   153
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   154
  by (auto simp: bwsimps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   155
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   156
lemma word_ao_dist:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   157
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   158
  shows "(x OR y) AND z = x AND z OR y AND z"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   159
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   160
        word_of_int_Ex [where x=y] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   161
        word_of_int_Ex [where x=z]   
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   162
  by (auto simp: bwsimps bbw_ao_dist simp del: bin_ops_comm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   163
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   164
lemma word_oa_dist:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   165
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   166
  shows "x AND y OR z = (x OR z) AND (y OR z)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   167
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   168
        word_of_int_Ex [where x=y] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   169
        word_of_int_Ex [where x=z]   
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   170
  by (auto simp: bwsimps bbw_oa_dist simp del: bin_ops_comm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   171
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   172
lemma word_add_not [simp]: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   173
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   174
  shows "x + NOT x = -1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   175
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   176
  by (auto simp: bwsimps bin_add_not)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   177
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   178
lemma word_plus_and_or [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   179
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   180
  shows "(x AND y) + (x OR y) = x + y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   181
  using word_of_int_Ex [where x=x] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   182
        word_of_int_Ex [where x=y] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   183
  by (auto simp: bwsimps plus_and_or)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   184
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   185
lemma leoa:   
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   186
  fixes x :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   187
  shows "(w = (x OR y)) ==> (y = (w AND y))" by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   188
lemma leao: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   189
  fixes x' :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   190
  shows "(w' = (x' AND y')) ==> (x' = (x' OR w'))" by auto 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   191
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   192
lemmas word_ao_equiv = leao [COMP leoa [COMP iffI]]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   193
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   194
lemma le_word_or2: "x <= x OR (y::'a::len0 word)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   195
  unfolding word_le_def uint_or
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   196
  by (auto intro: le_int_or) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   197
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   198
lemmas le_word_or1 = xtr3 [OF word_bw_comms (2) le_word_or2, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   199
lemmas word_and_le1 =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   200
  xtr3 [OF word_ao_absorbs (4) [symmetric] le_word_or2, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   201
lemmas word_and_le2 =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   202
  xtr3 [OF word_ao_absorbs (8) [symmetric] le_word_or2, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   203
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   204
lemma word_lsb_alt: "lsb (w::'a::len0 word) = test_bit w 0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   205
  by (auto simp: word_test_bit_def word_lsb_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   206
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   207
lemma word_lsb_1_0: "lsb (1::'a::len word) & ~ lsb (0::'b::len0 word)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   208
  unfolding word_lsb_def word_1_no word_0_no by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   209
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   210
lemma word_lsb_int: "lsb w = (uint w mod 2 = 1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   211
  unfolding word_lsb_def bin_last_mod by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   212
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   213
lemma word_msb_sint: "msb w = (sint w < 0)" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   214
  unfolding word_msb_def
24368
4c2e80f30aeb remove redundant lemma int_number_of
huffman
parents: 24367
diff changeset
   215
  by (simp add : sign_Min_lt_0 number_of_is_id)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   216
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   217
lemma word_msb_no': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   218
  "w = number_of bin ==> msb (w::'a::len word) = bin_nth bin (size w - 1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   219
  unfolding word_msb_def word_number_of_def
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   220
  by (clarsimp simp add: word_sbin.eq_norm word_size bin_sign_lem)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   221
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   222
lemmas word_msb_no = refl [THEN word_msb_no', unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   223
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   224
lemma word_msb_nth': "msb (w::'a::len word) = bin_nth (uint w) (size w - 1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   225
  apply (unfold word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   226
  apply (rule trans [OF _ word_msb_no])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   227
  apply (simp add : word_number_of_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   228
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   229
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   230
lemmas word_msb_nth = word_msb_nth' [unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   231
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   232
lemma word_set_nth:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   233
  "set_bit w n (test_bit w n) = (w::'a::len0 word)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   234
  unfolding word_test_bit_def word_set_bit_def by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   235
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   236
lemma test_bit_set: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   237
  fixes w :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   238
  shows "(set_bit w n x) !! n = (n < size w & x)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   239
  unfolding word_size word_test_bit_def word_set_bit_def
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   240
  by (clarsimp simp add : word_ubin.eq_norm nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   241
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   242
lemma test_bit_set_gen: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   243
  fixes w :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   244
  shows "test_bit (set_bit w n x) m = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   245
         (if m = n then n < size w & x else test_bit w m)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   246
  apply (unfold word_size word_test_bit_def word_set_bit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   247
  apply (clarsimp simp add: word_ubin.eq_norm nth_bintr bin_nth_sc_gen)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   248
  apply (auto elim!: test_bit_size [unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   249
              simp add: word_test_bit_def [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   250
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   251
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   252
lemma msb_nth':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   253
  fixes w :: "'a::len word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   254
  shows "msb w = w !! (size w - 1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   255
  unfolding word_msb_nth' word_test_bit_def by simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   256
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   257
lemmas msb_nth = msb_nth' [unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   258
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   259
lemmas msb0 = len_gt_0 [THEN diff_Suc_less, THEN
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   260
  word_ops_nth_size [unfolded word_size], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   261
lemmas msb1 = msb0 [where i = 0]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   262
lemmas word_ops_msb = msb1 [unfolded msb_nth [symmetric, unfolded One_nat_def]]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   263
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   264
lemmas lsb0 = len_gt_0 [THEN word_ops_nth_size [unfolded word_size], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   265
lemmas word_ops_lsb = lsb0 [unfolded word_lsb_alt]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   266
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   267
lemma word_set_set_same: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   268
  fixes w :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   269
  shows "set_bit (set_bit w n x) n y = set_bit w n y" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   270
  by (rule word_eqI) (simp add : test_bit_set_gen word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   271
    
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   272
lemma word_set_set_diff: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   273
  fixes w :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   274
  assumes "m ~= n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   275
  shows "set_bit (set_bit w m x) n y = set_bit (set_bit w n y) m x" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   276
  by (rule word_eqI) (clarsimp simp add : test_bit_set_gen word_size prems)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   277
    
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   278
lemma test_bit_no': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   279
  fixes w :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   280
  shows "w = number_of bin ==> test_bit w n = (n < size w & bin_nth bin n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   281
  unfolding word_test_bit_def word_number_of_def word_size
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   282
  by (simp add : nth_bintr [symmetric] word_ubin.eq_norm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   283
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   284
lemmas test_bit_no = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   285
  refl [THEN test_bit_no', unfolded word_size, THEN eq_reflection, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   286
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   287
lemma nth_0: "~ (0::'a::len0 word) !! n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   288
  unfolding test_bit_no word_0_no by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   289
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   290
lemma nth_sint: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   291
  fixes w :: "'a::len word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   292
  defines "l \<equiv> len_of TYPE ('a)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   293
  shows "bin_nth (sint w) n = (if n < l - 1 then w !! n else w !! (l - 1))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   294
  unfolding sint_uint l_def
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   295
  by (clarsimp simp add: nth_sbintr word_test_bit_def [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   296
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   297
lemma word_lsb_no: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   298
  "lsb (number_of bin :: 'a :: len word) = (bin_last bin = bit.B1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   299
  unfolding word_lsb_alt test_bit_no by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   300
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   301
lemma word_set_no: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   302
  "set_bit (number_of bin::'a::len0 word) n b = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   303
    number_of (bin_sc n (if b then bit.B1 else bit.B0) bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   304
  apply (unfold word_set_bit_def word_number_of_def [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   305
  apply (rule word_eqI)
24368
4c2e80f30aeb remove redundant lemma int_number_of
huffman
parents: 24367
diff changeset
   306
  apply (clarsimp simp: word_size bin_nth_sc_gen number_of_is_id 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   307
                        test_bit_no nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   308
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   309
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   310
lemmas setBit_no = setBit_def [THEN trans [OF meta_eq_to_obj_eq word_set_no],
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   311
  simplified if_simps, THEN eq_reflection, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   312
lemmas clearBit_no = clearBit_def [THEN trans [OF meta_eq_to_obj_eq word_set_no],
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   313
  simplified if_simps, THEN eq_reflection, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   314
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   315
lemma word_msb_n1: "msb (-1::'a::len word)"
24401
d9d2aa843a3b move bool list operations from WordBitwise to WordBoolList
huffman
parents: 24397
diff changeset
   316
  unfolding word_msb_def sint_sbintrunc number_of_is_id bin_sign_lem
d9d2aa843a3b move bool list operations from WordBitwise to WordBoolList
huffman
parents: 24397
diff changeset
   317
  by (rule bin_nth_Min)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   318
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   319
declare word_set_set_same [simp] word_set_nth [simp]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   320
  test_bit_no [simp] word_set_no [simp] nth_0 [simp]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   321
  setBit_no [simp] clearBit_no [simp]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   322
  word_lsb_no [simp] word_msb_no [simp] word_msb_n1 [simp] word_lsb_1_0 [simp]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   323
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   324
lemma word_set_nth_iff: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   325
  "(set_bit w n b = w) = (w !! n = b | n >= size (w::'a::len0 word))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   326
  apply (rule iffI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   327
   apply (rule disjCI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   328
   apply (drule word_eqD)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   329
   apply (erule sym [THEN trans])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   330
   apply (simp add: test_bit_set)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   331
  apply (erule disjE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   332
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   333
  apply (rule word_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   334
  apply (clarsimp simp add : test_bit_set_gen)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   335
  apply (drule test_bit_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   336
  apply force
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   337
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   338
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   339
lemma test_bit_2p': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   340
  "w = word_of_int (2 ^ n) ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   341
    w !! m = (m = n & m < size (w :: 'a :: len word))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   342
  unfolding word_test_bit_def word_size
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   343
  by (auto simp add: word_ubin.eq_norm nth_bintr nth_2p_bin)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   344
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   345
lemmas test_bit_2p = refl [THEN test_bit_2p', unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   346
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   347
lemmas nth_w2p = test_bit_2p [unfolded of_int_number_of_eq
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   348
  word_of_int [symmetric] of_int_power]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   349
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   350
lemma uint_2p: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   351
  "(0::'a::len word) < 2 ^ n ==> uint (2 ^ n::'a::len word) = 2 ^ n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   352
  apply (unfold word_arith_power_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   353
  apply (case_tac "len_of TYPE ('a)")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   354
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   355
  apply (case_tac "nat")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   356
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   357
   apply (case_tac "n")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   358
    apply (clarsimp simp add : word_1_wi [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   359
   apply (clarsimp simp add : word_0_wi [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   360
  apply (drule word_gt_0 [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   361
  apply (safe intro!: word_eqI bin_nth_lem ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   362
     apply (auto simp add: test_bit_2p nth_2p_bin word_test_bit_def [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   363
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   364
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   365
lemma word_of_int_2p: "(word_of_int (2 ^ n) :: 'a :: len word) = 2 ^ n" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   366
  apply (unfold word_arith_power_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   367
  apply (case_tac "len_of TYPE ('a)")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   368
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   369
  apply (case_tac "nat")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   370
   apply (rule word_ubin.norm_eq_iff [THEN iffD1]) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   371
   apply (rule box_equals) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   372
     apply (rule_tac [2] bintr_ariths (1))+ 
24368
4c2e80f30aeb remove redundant lemma int_number_of
huffman
parents: 24367
diff changeset
   373
   apply (clarsimp simp add : number_of_is_id)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   374
  apply simp 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   375
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   376
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   377
lemma bang_is_le: "x !! m ==> 2 ^ m <= (x :: 'a :: len word)" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   378
  apply (rule xtr3) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   379
  apply (rule_tac [2] y = "x" in le_word_or2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   380
  apply (rule word_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   381
  apply (auto simp add: word_ao_nth nth_w2p word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   382
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   383
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   384
lemma word_clr_le: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   385
  fixes w :: "'a::len0 word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   386
  shows "w >= set_bit w n False"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   387
  apply (unfold word_set_bit_def word_le_def word_ubin.eq_norm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   388
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   389
  apply (rule order_trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   390
   apply (rule bintr_bin_clr_le)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   391
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   392
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   393
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   394
lemma word_set_ge: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   395
  fixes w :: "'a::len word"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   396
  shows "w <= set_bit w n True"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   397
  apply (unfold word_set_bit_def word_le_def word_ubin.eq_norm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   398
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   399
  apply (rule order_trans [OF _ bintr_bin_set_ge])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   400
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   401
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   402
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   403
end
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   404