src/HOL/Word/WordDefinition.thy
author haftmann
Tue, 15 Jan 2008 16:19:23 +0100
changeset 25919 8b1c0d434824
parent 25762 c03e9d04b3e4
child 26514 eff55c0a6d34
permissions -rw-r--r--
joined theories IntDef, Numeral, IntArith to theory Int
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
  Basic definition of word type and basic theorems following from 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     6
  the definition of the word type 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     7
*) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     8
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     9
header {* Definition of Word Type *}
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    10
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    11
theory WordDefinition imports Size BinBoolList TdThs begin
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    12
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    13
typedef (open word) 'a word
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    14
  = "{(0::int) ..< 2^len_of TYPE('a::len0)}" by auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    15
25762
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    16
instantiation word :: (len0) size
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    17
begin
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    18
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    19
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    20
  word_size: "size (w :: 'a word) = len_of TYPE('a)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    21
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    22
instance ..
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    23
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    24
end
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    25
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    26
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    27
  -- {* representation of words using unsigned or signed bins, 
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    28
        only difference in these is the type class *}
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    29
  word_of_int :: "int \<Rightarrow> 'a\<Colon>len0 word"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    30
where
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    31
  "word_of_int w = Abs_word (bintrunc (len_of TYPE ('a)) w)" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    32
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    33
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
    34
subsection "Type conversions and casting"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    35
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    36
constdefs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    37
  -- {* uint and sint cast a word to an integer,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    38
        uint treats the word as unsigned,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    39
        sint treats the most-significant-bit as a sign bit *}
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    40
  uint :: "'a :: len0 word => int"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    41
  "uint w == Rep_word w"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    42
  sint :: "'a :: len word => int"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    43
  sint_uint: "sint w == sbintrunc (len_of TYPE ('a) - 1) (uint w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    44
  unat :: "'a :: len0 word => nat"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    45
  "unat w == nat (uint w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    46
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    47
  -- "the sets of integers representing the words"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    48
  uints :: "nat => int set"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    49
  "uints n == range (bintrunc n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    50
  sints :: "nat => int set"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    51
  "sints n == range (sbintrunc (n - 1))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    52
  unats :: "nat => nat set"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    53
  "unats n == {i. i < 2 ^ n}"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    54
  norm_sint :: "nat => int => int"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    55
  "norm_sint n w == (w + 2 ^ (n - 1)) mod 2 ^ n - 2 ^ (n - 1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    56
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    57
  -- "cast a word to a different length"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    58
  scast :: "'a :: len word => 'b :: len word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    59
  "scast w == word_of_int (sint w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    60
  ucast :: "'a :: len0 word => 'b :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    61
  "ucast w == word_of_int (uint w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    62
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    63
  -- "whether a cast (or other) function is to a longer or shorter length"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    64
  source_size :: "('a :: len0 word => 'b) => nat"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    65
  "source_size c == let arb = arbitrary ; x = c arb in size arb"  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    66
  target_size :: "('a => 'b :: len0 word) => nat"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    67
  "target_size c == size (c arbitrary)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    68
  is_up :: "('a :: len0 word => 'b :: len0 word) => bool"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    69
  "is_up c == source_size c <= target_size c"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    70
  is_down :: "('a :: len0 word => 'b :: len0 word) => bool"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    71
  "is_down c == target_size c <= source_size c"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    72
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    73
constdefs
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    74
  of_bl :: "bool list => 'a :: len0 word" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    75
  "of_bl bl == word_of_int (bl_to_bin bl)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    76
  to_bl :: "'a :: len0 word => bool list"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    77
  "to_bl w == 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    78
  bin_to_bl (len_of TYPE ('a)) (uint w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    79
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    80
  word_reverse :: "'a :: len0 word => 'a word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    81
  "word_reverse w == of_bl (rev (to_bl w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    82
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    83
constdefs
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
    84
  word_int_case :: "(int => 'b) => ('a :: len0 word) => 'b"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    85
  "word_int_case f w == f (uint w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    86
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    87
syntax
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    88
  of_int :: "int => 'a"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    89
translations
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    90
  "case x of of_int y => b" == "word_int_case (%y. b) x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    91
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    92
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
    93
subsection  "Arithmetic operations"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    94
25762
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    95
instantiation word :: (len0) "{number, uminus, minus, plus, one, zero, times, Divides.div, power, ord, bit}"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    96
begin
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    97
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    98
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
    99
  word_0_wi: "0 = word_of_int 0"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   100
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   101
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   102
  word_1_wi: "1 = word_of_int 1"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   103
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   104
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   105
  word_add_def: "a + b = word_of_int (uint a + uint b)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   106
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   107
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   108
  word_sub_wi: "a - b = word_of_int (uint a - uint b)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   109
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   110
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   111
  word_minus_def: "- a = word_of_int (- uint a)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   112
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   113
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   114
  word_mult_def: "a * b = word_of_int (uint a * uint b)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   115
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   116
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   117
  word_div_def: "a div b = word_of_int (uint a div uint b)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   118
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   119
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   120
  word_mod_def: "a mod b = word_of_int (uint a mod uint b)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   121
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   122
primrec power_word where
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   123
  "(a\<Colon>'a word) ^ 0 = 1"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   124
  | "(a\<Colon>'a word) ^ Suc n = a * a ^ n"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   125
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   126
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   127
  word_number_of_def: "number_of w = word_of_int w"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   128
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   129
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   130
  word_le_def: "a \<le> b \<longleftrightarrow> uint a \<le> uint b"
24415
640b85390ba0 new instance proofs
huffman
parents: 24408
diff changeset
   131
25762
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   132
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   133
  word_less_def: "x < y \<longleftrightarrow> x \<le> y \<and> x \<noteq> (y \<Colon> 'a word)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   134
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   135
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   136
  word_and_def: 
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   137
  "(a::'a word) AND b = word_of_int (uint a AND uint b)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   138
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   139
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   140
  word_or_def:  
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   141
  "(a::'a word) OR b = word_of_int (uint a OR uint b)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   142
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   143
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   144
  word_xor_def: 
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   145
  "(a::'a word) XOR b = word_of_int (uint a XOR uint b)"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   146
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   147
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   148
  word_not_def: 
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   149
  "NOT (a::'a word) = word_of_int (NOT (uint a))"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   150
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   151
instance ..
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   152
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   153
end 
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   154
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   155
abbreviation
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   156
  word_power :: "'a\<Colon>len0 word \<Rightarrow> nat \<Rightarrow> 'a word"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   157
where
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   158
  "word_power == op ^"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   159
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   160
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   161
  word_succ :: "'a :: len0 word => 'a word"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   162
where
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25762
diff changeset
   163
  "word_succ a = word_of_int (Int.succ (uint a))"
25762
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   164
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   165
definition
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   166
  word_pred :: "'a :: len0 word => 'a word"
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   167
where
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25762
diff changeset
   168
  "word_pred a = word_of_int (Int.pred (uint a))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   169
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   170
constdefs
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   171
  udvd :: "'a::len word => 'a::len word => bool" (infixl "udvd" 50)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   172
  "a udvd b == EX n>=0. uint b = n * uint a"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   173
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   174
  word_sle :: "'a :: len word => 'a word => bool" ("(_/ <=s _)" [50, 51] 50)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   175
  "a <=s b == sint a <= sint b"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   176
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   177
  word_sless :: "'a :: len word => 'a word => bool" ("(_/ <s _)" [50, 51] 50)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   178
  "(x <s y) == (x <=s y & x ~= y)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   179
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   180
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
   181
subsection "Bit-wise operations"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   182
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   183
defs (overloaded)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   184
  word_test_bit_def: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   185
  "test_bit (a::'a::len0 word) == bin_nth (uint a)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   186
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   187
  word_set_bit_def: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   188
  "set_bit (a::'a::len0 word) n x == 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   189
   word_of_int (bin_sc n (If x bit.B1 bit.B0) (uint a))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   190
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   191
  word_set_bits_def:  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   192
  "(BITS n. f n)::'a::len0 word == of_bl (bl_of_nth (len_of TYPE ('a)) f)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   193
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   194
  word_lsb_def: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   195
  "lsb (a::'a::len0 word) == bin_last (uint a) = bit.B1"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   196
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   197
  word_msb_def: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25762
diff changeset
   198
  "msb (a::'a::len word) == bin_sign (sint a) = Int.Min"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   199
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   200
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   201
constdefs
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   202
  setBit :: "'a :: len0 word => nat => 'a word" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   203
  "setBit w n == set_bit w n True"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   204
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   205
  clearBit :: "'a :: len0 word => nat => 'a word" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   206
  "clearBit w n == set_bit w n False"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   207
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   208
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   209
subsection "Shift operations"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   210
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   211
constdefs
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   212
  shiftl1 :: "'a :: len0 word => 'a word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   213
  "shiftl1 w == word_of_int (uint w BIT bit.B0)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   214
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   215
  -- "shift right as unsigned or as signed, ie logical or arithmetic"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   216
  shiftr1 :: "'a :: len0 word => 'a word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   217
  "shiftr1 w == word_of_int (bin_rest (uint w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   218
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   219
  sshiftr1 :: "'a :: len word => 'a word" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   220
  "sshiftr1 w == word_of_int (bin_rest (sint w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   221
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   222
  bshiftr1 :: "bool => 'a :: len word => 'a word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   223
  "bshiftr1 b w == of_bl (b # butlast (to_bl w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   224
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   225
  sshiftr :: "'a :: len word => nat => 'a word" (infixl ">>>" 55)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   226
  "w >>> n == (sshiftr1 ^ n) w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   227
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   228
  mask :: "nat => 'a::len word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   229
  "mask n == (1 << n) - 1"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   230
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   231
  revcast :: "'a :: len0 word => 'b :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   232
  "revcast w ==  of_bl (takefill False (len_of TYPE('b)) (to_bl w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   233
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   234
  slice1 :: "nat => 'a :: len0 word => 'b :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   235
  "slice1 n w == of_bl (takefill False n (to_bl w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   236
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   237
  slice :: "nat => 'a :: len0 word => 'b :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   238
  "slice n w == slice1 (size w - n) w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   239
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   240
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   241
defs (overloaded)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   242
  shiftl_def: "(w::'a::len0 word) << n == (shiftl1 ^ n) w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   243
  shiftr_def: "(w::'a::len0 word) >> n == (shiftr1 ^ n) w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   244
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   245
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   246
subsection "Rotation"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   247
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   248
constdefs
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   249
  rotater1 :: "'a list => 'a list"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   250
  "rotater1 ys == 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   251
    case ys of [] => [] | x # xs => last ys # butlast ys"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   252
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   253
  rotater :: "nat => 'a list => 'a list"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   254
  "rotater n == rotater1 ^ n"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   255
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   256
  word_rotr :: "nat => 'a :: len0 word => 'a :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   257
  "word_rotr n w == of_bl (rotater n (to_bl w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   258
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   259
  word_rotl :: "nat => 'a :: len0 word => 'a :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   260
  "word_rotl n w == of_bl (rotate n (to_bl w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   261
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   262
  word_roti :: "int => 'a :: len0 word => 'a :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   263
  "word_roti i w == if i >= 0 then word_rotr (nat i) w
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   264
                    else word_rotl (nat (- i)) w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   265
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   266
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   267
subsection "Split and cat operations"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   268
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   269
constdefs
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   270
  word_cat :: "'a :: len0 word => 'b :: len0 word => 'c :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   271
  "word_cat a b == word_of_int (bin_cat (uint a) (len_of TYPE ('b)) (uint b))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   272
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   273
  word_split :: "'a :: len0 word => ('b :: len0 word) * ('c :: len0 word)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   274
  "word_split a == 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   275
   case bin_split (len_of TYPE ('c)) (uint a) of 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   276
     (u, v) => (word_of_int u, word_of_int v)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   277
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   278
  word_rcat :: "'a :: len0 word list => 'b :: len0 word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   279
  "word_rcat ws == 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   280
  word_of_int (bin_rcat (len_of TYPE ('a)) (map uint ws))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   281
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   282
  word_rsplit :: "'a :: len0 word => 'b :: len word list"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   283
  "word_rsplit w == 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   284
  map word_of_int (bin_rsplit (len_of TYPE ('b)) (len_of TYPE ('a), uint w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   285
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   286
constdefs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   287
  -- "Largest representable machine integer."
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   288
  max_word :: "'a::len word"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   289
  "max_word \<equiv> word_of_int (2^len_of TYPE('a) - 1)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   290
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   291
consts 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   292
  of_bool :: "bool \<Rightarrow> 'a::len word"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   293
primrec
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   294
  "of_bool False = 0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   295
  "of_bool True = 1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   296
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   297
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   298
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   299
lemmas of_nth_def = word_set_bits_def
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   300
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   301
lemmas word_size_gt_0 [iff] = 
25762
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   302
  xtr1 [OF word_size len_gt_0, standard]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   303
lemmas lens_gt_0 = word_size_gt_0 len_gt_0
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   304
lemmas lens_not_0 [iff] = lens_gt_0 [THEN gr_implies_not0, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   305
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   306
lemma uints_num: "uints n = {i. 0 \<le> i \<and> i < 2 ^ n}"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   307
  by (simp add: uints_def range_bintrunc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   308
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   309
lemma sints_num: "sints n = {i. - (2 ^ (n - 1)) \<le> i \<and> i < 2 ^ (n - 1)}"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   310
  by (simp add: sints_def range_sbintrunc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   311
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   312
lemmas atLeastLessThan_alt = atLeastLessThan_def [unfolded 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   313
  atLeast_def lessThan_def Collect_conj_eq [symmetric]]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   314
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   315
lemma mod_in_reps: "m > 0 ==> y mod m : {0::int ..< m}"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   316
  unfolding atLeastLessThan_alt by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   317
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   318
lemma 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   319
  Rep_word_0:"0 <= Rep_word x" and 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   320
  Rep_word_lt: "Rep_word (x::'a::len0 word) < 2 ^ len_of TYPE('a)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   321
  by (auto simp: Rep_word [simplified])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   322
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   323
lemma Rep_word_mod_same:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   324
  "Rep_word x mod 2 ^ len_of TYPE('a) = Rep_word (x::'a::len0 word)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   325
  by (simp add: int_mod_eq Rep_word_lt Rep_word_0)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   326
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   327
lemma td_ext_uint: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   328
  "td_ext (uint :: 'a word => int) word_of_int (uints (len_of TYPE('a::len0))) 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   329
    (%w::int. w mod 2 ^ len_of TYPE('a))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   330
  apply (unfold td_ext_def')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   331
  apply (simp add: uints_num uint_def word_of_int_def bintrunc_mod2p)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   332
  apply (simp add: Rep_word_mod_same Rep_word_0 Rep_word_lt
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   333
                   word.Rep_word_inverse word.Abs_word_inverse int_mod_lem)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   334
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   335
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   336
lemmas int_word_uint = td_ext_uint [THEN td_ext.eq_norm, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   337
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   338
interpretation word_uint: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   339
  td_ext ["uint::'a::len0 word \<Rightarrow> int" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   340
          word_of_int 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   341
          "uints (len_of TYPE('a::len0))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   342
          "\<lambda>w. w mod 2 ^ len_of TYPE('a::len0)"]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   343
  by (rule td_ext_uint)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   344
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   345
lemmas td_uint = word_uint.td_thm
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   346
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   347
lemmas td_ext_ubin = td_ext_uint 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   348
  [simplified len_gt_0 no_bintr_alt1 [symmetric]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   349
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   350
interpretation word_ubin:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   351
  td_ext ["uint::'a::len0 word \<Rightarrow> int" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   352
          word_of_int 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   353
          "uints (len_of TYPE('a::len0))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   354
          "bintrunc (len_of TYPE('a::len0))"]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   355
  by (rule td_ext_ubin)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   356
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   357
lemma sint_sbintrunc': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   358
  "sint (word_of_int bin :: 'a word) = 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   359
    (sbintrunc (len_of TYPE ('a :: len) - 1) bin)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   360
  unfolding sint_uint 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   361
  by (auto simp: word_ubin.eq_norm sbintrunc_bintrunc_lt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   362
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   363
lemma uint_sint: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   364
  "uint w = bintrunc (len_of TYPE('a)) (sint (w :: 'a :: len word))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   365
  unfolding sint_uint by (auto simp: bintrunc_sbintrunc_le)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   366
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   367
lemma bintr_uint': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   368
  "n >= size w ==> bintrunc n (uint w) = uint w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   369
  apply (unfold word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   370
  apply (subst word_ubin.norm_Rep [symmetric]) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   371
  apply (simp only: bintrunc_bintrunc_min word_size min_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   372
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   373
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   374
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   375
lemma wi_bintr': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   376
  "wb = word_of_int bin ==> n >= size wb ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   377
    word_of_int (bintrunc n bin) = wb"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   378
  unfolding word_size
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   379
  by (clarsimp simp add : word_ubin.norm_eq_iff [symmetric] min_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   380
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   381
lemmas bintr_uint = bintr_uint' [unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   382
lemmas wi_bintr = wi_bintr' [unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   383
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   384
lemma td_ext_sbin: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   385
  "td_ext (sint :: 'a word => int) word_of_int (sints (len_of TYPE('a::len))) 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   386
    (sbintrunc (len_of TYPE('a) - 1))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   387
  apply (unfold td_ext_def' sint_uint)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   388
  apply (simp add : word_ubin.eq_norm)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   389
  apply (cases "len_of TYPE('a)")
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   390
   apply (auto simp add : sints_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   391
  apply (rule sym [THEN trans])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   392
  apply (rule word_ubin.Abs_norm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   393
  apply (simp only: bintrunc_sbintrunc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   394
  apply (drule sym)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   395
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   396
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   397
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   398
lemmas td_ext_sint = td_ext_sbin 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   399
  [simplified len_gt_0 no_sbintr_alt2 Suc_pred' [symmetric]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   400
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   401
(* We do sint before sbin, before sint is the user version
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   402
   and interpretations do not produce thm duplicates. I.e. 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   403
   we get the name word_sint.Rep_eqD, but not word_sbin.Req_eqD,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   404
   because the latter is the same thm as the former *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   405
interpretation word_sint:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   406
  td_ext ["sint ::'a::len word => int" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   407
          word_of_int 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   408
          "sints (len_of TYPE('a::len))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   409
          "%w. (w + 2^(len_of TYPE('a::len) - 1)) mod 2^len_of TYPE('a::len) -
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   410
               2 ^ (len_of TYPE('a::len) - 1)"]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   411
  by (rule td_ext_sint)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   412
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   413
interpretation word_sbin:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   414
  td_ext ["sint ::'a::len word => int" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   415
          word_of_int 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   416
          "sints (len_of TYPE('a::len))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   417
          "sbintrunc (len_of TYPE('a::len) - 1)"]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   418
  by (rule td_ext_sbin)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   419
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   420
lemmas int_word_sint = td_ext_sint [THEN td_ext.eq_norm, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   421
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   422
lemmas td_sint = word_sint.td
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   423
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   424
lemma word_number_of_alt: "number_of b == word_of_int (number_of b)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   425
  unfolding word_number_of_def by (simp add: number_of_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   426
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   427
lemma word_no_wi: "number_of = word_of_int"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   428
  by (auto simp: word_number_of_def intro: ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   429
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   430
lemma to_bl_def': 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   431
  "(to_bl :: 'a :: len0 word => bool list) =
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   432
    bin_to_bl (len_of TYPE('a)) o uint"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   433
  by (auto simp: to_bl_def intro: ext)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   434
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25149
diff changeset
   435
lemmas word_reverse_no_def [simp] = word_reverse_def [of "number_of w", standard]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   436
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   437
lemmas uints_mod = uints_def [unfolded no_bintr_alt1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   438
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   439
lemma uint_bintrunc: "uint (number_of bin :: 'a word) = 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   440
    number_of (bintrunc (len_of TYPE ('a :: len0)) bin)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   441
  unfolding word_number_of_def number_of_eq
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   442
  by (auto intro: word_ubin.eq_norm) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   443
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   444
lemma sint_sbintrunc: "sint (number_of bin :: 'a word) = 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   445
    number_of (sbintrunc (len_of TYPE ('a :: len) - 1) bin)" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   446
  unfolding word_number_of_def number_of_eq
25149
776f985efa4c fixed proof: no one_is_Suc_zero;
wenzelm
parents: 24465
diff changeset
   447
  by (subst word_sbin.eq_norm) simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   448
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   449
lemma unat_bintrunc: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   450
  "unat (number_of bin :: 'a :: len0 word) =
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   451
    number_of (bintrunc (len_of TYPE('a)) bin)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   452
  unfolding unat_def nat_number_of_def 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   453
  by (simp only: uint_bintrunc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   454
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   455
(* WARNING - these may not always be helpful *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   456
declare 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   457
  uint_bintrunc [simp] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   458
  sint_sbintrunc [simp] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   459
  unat_bintrunc [simp]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   460
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   461
lemma size_0_eq: "size (w :: 'a :: len0 word) = 0 ==> v = w"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   462
  apply (unfold word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   463
  apply (rule word_uint.Rep_eqD)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   464
  apply (rule box_equals)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   465
    defer
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   466
    apply (rule word_ubin.norm_Rep)+
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   467
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   468
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   469
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   470
lemmas uint_lem = word_uint.Rep [unfolded uints_num mem_Collect_eq]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   471
lemmas sint_lem = word_sint.Rep [unfolded sints_num mem_Collect_eq]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   472
lemmas uint_ge_0 [iff] = uint_lem [THEN conjunct1, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   473
lemmas uint_lt2p [iff] = uint_lem [THEN conjunct2, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   474
lemmas sint_ge = sint_lem [THEN conjunct1, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   475
lemmas sint_lt = sint_lem [THEN conjunct2, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   476
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   477
lemma sign_uint_Pls [simp]: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25762
diff changeset
   478
  "bin_sign (uint x) = Int.Pls"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   479
  by (simp add: sign_Pls_ge_0 number_of_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   480
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   481
lemmas uint_m2p_neg = iffD2 [OF diff_less_0_iff_less uint_lt2p, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   482
lemmas uint_m2p_not_non_neg = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   483
  iffD2 [OF linorder_not_le uint_m2p_neg, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   484
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   485
lemma lt2p_lem:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   486
  "len_of TYPE('a) <= n ==> uint (w :: 'a :: len0 word) < 2 ^ n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   487
  by (rule xtr8 [OF _ uint_lt2p]) simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   488
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   489
lemmas uint_le_0_iff [simp] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   490
  uint_ge_0 [THEN leD, THEN linorder_antisym_conv1, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   491
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   492
lemma uint_nat: "uint w == int (unat w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   493
  unfolding unat_def by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   494
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   495
lemma uint_number_of:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   496
  "uint (number_of b :: 'a :: len0 word) = number_of b mod 2 ^ len_of TYPE('a)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   497
  unfolding word_number_of_alt
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   498
  by (simp only: int_word_uint)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   499
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   500
lemma unat_number_of: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25762
diff changeset
   501
  "bin_sign b = Int.Pls ==> 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   502
  unat (number_of b::'a::len0 word) = number_of b mod 2 ^ len_of TYPE ('a)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   503
  apply (unfold unat_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   504
  apply (clarsimp simp only: uint_number_of)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   505
  apply (rule nat_mod_distrib [THEN trans])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   506
    apply (erule sign_Pls_ge_0 [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   507
   apply (simp_all add: nat_power_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   508
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   509
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   510
lemma sint_number_of: "sint (number_of b :: 'a :: len word) = (number_of b + 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   511
    2 ^ (len_of TYPE('a) - 1)) mod 2 ^ len_of TYPE('a) -
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   512
    2 ^ (len_of TYPE('a) - 1)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   513
  unfolding word_number_of_alt by (rule int_word_sint)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   514
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   515
lemma word_of_int_bin [simp] : 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   516
  "(word_of_int (number_of bin) :: 'a :: len0 word) = (number_of bin)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   517
  unfolding word_number_of_alt by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   518
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   519
lemma word_int_case_wi: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   520
  "word_int_case f (word_of_int i :: 'b word) = 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   521
    f (i mod 2 ^ len_of TYPE('b::len0))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   522
  unfolding word_int_case_def by (simp add: word_uint.eq_norm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   523
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   524
lemma word_int_split: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   525
  "P (word_int_case f x) = 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   526
    (ALL i. x = (word_of_int i :: 'b :: len0 word) & 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   527
      0 <= i & i < 2 ^ len_of TYPE('b) --> P (f i))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   528
  unfolding word_int_case_def
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   529
  by (auto simp: word_uint.eq_norm int_mod_eq')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   530
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   531
lemma word_int_split_asm: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   532
  "P (word_int_case f x) = 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   533
    (~ (EX n. x = (word_of_int n :: 'b::len0 word) &
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   534
      0 <= n & n < 2 ^ len_of TYPE('b::len0) & ~ P (f n)))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   535
  unfolding word_int_case_def
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   536
  by (auto simp: word_uint.eq_norm int_mod_eq')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   537
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   538
lemmas uint_range' =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   539
  word_uint.Rep [unfolded uints_num mem_Collect_eq, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   540
lemmas sint_range' = word_sint.Rep [unfolded One_nat_def
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   541
  sints_num mem_Collect_eq, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   542
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   543
lemma uint_range_size: "0 <= uint w & uint w < 2 ^ size w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   544
  unfolding word_size by (rule uint_range')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   545
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   546
lemma sint_range_size:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   547
  "- (2 ^ (size w - Suc 0)) <= sint w & sint w < 2 ^ (size w - Suc 0)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   548
  unfolding word_size by (rule sint_range')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   549
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   550
lemmas sint_above_size = sint_range_size
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   551
  [THEN conjunct2, THEN [2] xtr8, folded One_nat_def, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   552
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   553
lemmas sint_below_size = sint_range_size
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   554
  [THEN conjunct1, THEN [2] order_trans, folded One_nat_def, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   555
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   556
lemma test_bit_eq_iff: "(test_bit (u::'a::len0 word) = test_bit v) = (u = v)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   557
  unfolding word_test_bit_def by (simp add: bin_nth_eq_iff)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   558
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   559
lemma test_bit_size [rule_format] : "(w::'a::len0 word) !! n --> n < size w"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   560
  apply (unfold word_test_bit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   561
  apply (subst word_ubin.norm_Rep [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   562
  apply (simp only: nth_bintr word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   563
  apply fast
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   564
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   565
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   566
lemma word_eqI [rule_format] : 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   567
  fixes u :: "'a::len0 word"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   568
  shows "(ALL n. n < size u --> u !! n = v !! n) ==> u = v"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   569
  apply (rule test_bit_eq_iff [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   570
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   571
  apply (erule allE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   572
  apply (erule impCE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   573
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   574
   apply assumption
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   575
  apply (auto dest!: test_bit_size simp add: word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   576
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   577
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   578
lemmas word_eqD = test_bit_eq_iff [THEN iffD2, THEN fun_cong, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   579
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   580
lemma test_bit_bin': "w !! n = (n < size w & bin_nth (uint w) n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   581
  unfolding word_test_bit_def word_size
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   582
  by (simp add: nth_bintr [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   583
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   584
lemmas test_bit_bin = test_bit_bin' [unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   585
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   586
lemma bin_nth_uint_imp': "bin_nth (uint w) n --> n < size w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   587
  apply (unfold word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   588
  apply (rule impI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   589
  apply (rule nth_bintr [THEN iffD1, THEN conjunct1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   590
  apply (subst word_ubin.norm_Rep)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   591
  apply assumption
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   592
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   593
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   594
lemma bin_nth_sint': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   595
  "n >= size w --> bin_nth (sint w) n = bin_nth (sint w) (size w - 1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   596
  apply (rule impI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   597
  apply (subst word_sbin.norm_Rep [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   598
  apply (simp add : nth_sbintr word_size)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   599
  apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   600
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   601
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   602
lemmas bin_nth_uint_imp = bin_nth_uint_imp' [rule_format, unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   603
lemmas bin_nth_sint = bin_nth_sint' [rule_format, unfolded word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   604
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   605
(* type definitions theorem for in terms of equivalent bool list *)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   606
lemma td_bl: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   607
  "type_definition (to_bl :: 'a::len0 word => bool list) 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   608
                   of_bl  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   609
                   {bl. length bl = len_of TYPE('a)}"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   610
  apply (unfold type_definition_def of_bl_def to_bl_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   611
  apply (simp add: word_ubin.eq_norm)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   612
  apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   613
  apply (drule sym)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   614
  apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   615
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   616
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   617
interpretation word_bl:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   618
  type_definition ["to_bl :: 'a::len0 word => bool list"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   619
                   of_bl  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   620
                   "{bl. length bl = len_of TYPE('a::len0)}"]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   621
  by (rule td_bl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   622
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   623
lemma word_size_bl: "size w == size (to_bl w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   624
  unfolding word_size by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   625
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   626
lemma to_bl_use_of_bl:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   627
  "(to_bl w = bl) = (w = of_bl bl \<and> length bl = length (to_bl w))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   628
  by (fastsimp elim!: word_bl.Abs_inverse [simplified])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   629
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   630
lemma to_bl_word_rev: "to_bl (word_reverse w) = rev (to_bl w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   631
  unfolding word_reverse_def by (simp add: word_bl.Abs_inverse)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   632
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   633
lemma word_rev_rev [simp] : "word_reverse (word_reverse w) = w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   634
  unfolding word_reverse_def by (simp add : word_bl.Abs_inverse)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   635
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   636
lemma word_rev_gal: "word_reverse w = u ==> word_reverse u = w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   637
  by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   638
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   639
lemmas word_rev_gal' = sym [THEN word_rev_gal, symmetric, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   640
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   641
lemmas length_bl_gt_0 [iff] = xtr1 [OF word_bl.Rep' len_gt_0, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   642
lemmas bl_not_Nil [iff] = 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   643
  length_bl_gt_0 [THEN length_greater_0_conv [THEN iffD1], standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   644
lemmas length_bl_neq_0 [iff] = length_bl_gt_0 [THEN gr_implies_not0]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   645
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25762
diff changeset
   646
lemma hd_bl_sign_sint: "hd (to_bl w) = (bin_sign (sint w) = Int.Min)"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   647
  apply (unfold to_bl_def sint_uint)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   648
  apply (rule trans [OF _ bl_sbin_sign])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   649
  apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   650
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   651
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   652
lemma of_bl_drop': 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   653
  "lend = length bl - len_of TYPE ('a :: len0) ==> 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   654
    of_bl (drop lend bl) = (of_bl bl :: 'a word)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   655
  apply (unfold of_bl_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   656
  apply (clarsimp simp add : trunc_bl2bin [symmetric])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   657
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   658
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   659
lemmas of_bl_no = of_bl_def [folded word_number_of_def]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   660
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   661
lemma test_bit_of_bl:  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   662
  "(of_bl bl::'a::len0 word) !! n = (rev bl ! n \<and> n < len_of TYPE('a) \<and> n < length bl)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   663
  apply (unfold of_bl_def word_test_bit_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   664
  apply (auto simp add: word_size word_ubin.eq_norm nth_bintr bin_nth_of_bl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   665
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   666
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   667
lemma no_of_bl: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   668
  "(number_of bin ::'a::len0 word) = of_bl (bin_to_bl (len_of TYPE ('a)) bin)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   669
  unfolding word_size of_bl_no by (simp add : word_number_of_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   670
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   671
lemma uint_bl: "to_bl w == bin_to_bl (size w) (uint w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   672
  unfolding word_size to_bl_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   673
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   674
lemma to_bl_bin: "bl_to_bin (to_bl w) = uint w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   675
  unfolding uint_bl by (simp add : word_size)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   676
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   677
lemma to_bl_of_bin: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   678
  "to_bl (word_of_int bin::'a::len0 word) = bin_to_bl (len_of TYPE('a)) bin"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   679
  unfolding uint_bl by (clarsimp simp add: word_ubin.eq_norm word_size)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   680
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   681
lemmas to_bl_no_bin [simp] = to_bl_of_bin [folded word_number_of_def]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   682
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   683
lemma to_bl_to_bin [simp] : "bl_to_bin (to_bl w) = uint w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   684
  unfolding uint_bl by (simp add : word_size)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   685
  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   686
lemmas uint_bl_bin [simp] = trans [OF bin_bl_bin word_ubin.norm_Rep, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   687
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   688
lemmas num_AB_u [simp] = word_uint.Rep_inverse 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   689
  [unfolded o_def word_number_of_def [symmetric], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   690
lemmas num_AB_s [simp] = word_sint.Rep_inverse 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   691
  [unfolded o_def word_number_of_def [symmetric], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   692
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   693
(* naturals *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   694
lemma uints_unats: "uints n = int ` unats n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   695
  apply (unfold unats_def uints_num)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   696
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   697
  apply (rule_tac image_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   698
  apply (erule_tac nat_0_le [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   699
  apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   700
  apply (erule_tac nat_less_iff [THEN iffD2])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   701
  apply (rule_tac [2] zless_nat_eq_int_zless [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   702
  apply (auto simp add : nat_power_eq int_power)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   703
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   704
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   705
lemma unats_uints: "unats n = nat ` uints n"
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25149
diff changeset
   706
  by (auto simp add : uints_unats image_iff)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   707
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   708
lemmas bintr_num = word_ubin.norm_eq_iff 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   709
  [symmetric, folded word_number_of_def, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   710
lemmas sbintr_num = word_sbin.norm_eq_iff 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   711
  [symmetric, folded word_number_of_def, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   712
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   713
lemmas num_of_bintr = word_ubin.Abs_norm [folded word_number_of_def, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   714
lemmas num_of_sbintr = word_sbin.Abs_norm [folded word_number_of_def, standard];
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   715
    
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   716
(* don't add these to simpset, since may want bintrunc n w to be simplified;
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   717
  may want these in reverse, but loop as simp rules, so use following *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   718
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   719
lemma num_of_bintr':
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   720
  "bintrunc (len_of TYPE('a :: len0)) a = b ==> 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   721
    number_of a = (number_of b :: 'a word)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   722
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   723
  apply (rule_tac num_of_bintr [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   724
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   725
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   726
lemma num_of_sbintr':
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   727
  "sbintrunc (len_of TYPE('a :: len) - 1) a = b ==> 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   728
    number_of a = (number_of b :: 'a word)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   729
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   730
  apply (rule_tac num_of_sbintr [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   731
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   732
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   733
lemmas num_abs_bintr = sym [THEN trans,
25762
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   734
  OF num_of_bintr word_number_of_def, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   735
lemmas num_abs_sbintr = sym [THEN trans,
25762
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25349
diff changeset
   736
  OF num_of_sbintr word_number_of_def, standard]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   737
  
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   738
(** cast - note, no arg for new length, as it's determined by type of result,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   739
  thus in "cast w = w, the type means cast to length of w! **)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   740
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   741
lemma ucast_id: "ucast w = w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   742
  unfolding ucast_def by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   743
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   744
lemma scast_id: "scast w = w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   745
  unfolding scast_def by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   746
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   747
lemma ucast_bl: "ucast w == of_bl (to_bl w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   748
  unfolding ucast_def of_bl_def uint_bl
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   749
  by (auto simp add : word_size)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   750
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   751
lemma nth_ucast: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   752
  "(ucast w::'a::len0 word) !! n = (w !! n & n < len_of TYPE('a))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   753
  apply (unfold ucast_def test_bit_bin)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   754
  apply (simp add: word_ubin.eq_norm nth_bintr word_size) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   755
  apply (fast elim!: bin_nth_uint_imp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   756
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   757
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   758
(* for literal u(s)cast *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   759
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   760
lemma ucast_bintr [simp]: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   761
  "ucast (number_of w ::'a::len0 word) = 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   762
   number_of (bintrunc (len_of TYPE('a)) w)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   763
  unfolding ucast_def by simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   764
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   765
lemma scast_sbintr [simp]: 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   766
  "scast (number_of w ::'a::len word) = 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   767
   number_of (sbintrunc (len_of TYPE('a) - Suc 0) w)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   768
  unfolding scast_def by simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   769
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   770
lemmas source_size = source_size_def [unfolded Let_def word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   771
lemmas target_size = target_size_def [unfolded Let_def word_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   772
lemmas is_down = is_down_def [unfolded source_size target_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   773
lemmas is_up = is_up_def [unfolded source_size target_size]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   774
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   775
lemmas is_up_down = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   776
  trans [OF is_up [THEN meta_eq_to_obj_eq] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   777
            is_down [THEN meta_eq_to_obj_eq, symmetric], 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   778
         standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   779
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   780
lemma down_cast_same': "uc = ucast ==> is_down uc ==> uc = scast"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   781
  apply (unfold is_down)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   782
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   783
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   784
  apply (unfold ucast_def scast_def uint_sint)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   785
  apply (rule word_ubin.norm_eq_iff [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   786
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   787
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   788
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   789
lemma word_rev_tf': 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   790
  "r = to_bl (of_bl bl) ==> r = rev (takefill False (length r) (rev bl))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   791
  unfolding of_bl_def uint_bl
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   792
  by (clarsimp simp add: bl_bin_bl_rtf word_ubin.eq_norm word_size)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   793
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   794
lemmas word_rev_tf = refl [THEN word_rev_tf', unfolded word_bl.Rep', standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   795
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   796
lemmas word_rep_drop = word_rev_tf [simplified takefill_alt,
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   797
  simplified, simplified rev_take, simplified]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   798
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   799
lemma to_bl_ucast: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   800
  "to_bl (ucast (w::'b::len0 word) ::'a::len0 word) = 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   801
   replicate (len_of TYPE('a) - len_of TYPE('b)) False @
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   802
   drop (len_of TYPE('b) - len_of TYPE('a)) (to_bl w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   803
  apply (unfold ucast_bl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   804
  apply (rule trans)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   805
   apply (rule word_rep_drop)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   806
  apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   807
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   808
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   809
lemma ucast_up_app': 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   810
  "uc = ucast ==> source_size uc + n = target_size uc ==> 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   811
    to_bl (uc w) = replicate n False @ (to_bl w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   812
  apply (auto simp add : source_size target_size to_bl_ucast)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   813
  apply (rule_tac f = "%n. replicate n False" in arg_cong)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   814
  apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   815
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   816
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   817
lemma ucast_down_drop': 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   818
  "uc = ucast ==> source_size uc = target_size uc + n ==> 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   819
    to_bl (uc w) = drop n (to_bl w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   820
  by (auto simp add : source_size target_size to_bl_ucast)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   821
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   822
lemma scast_down_drop': 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   823
  "sc = scast ==> source_size sc = target_size sc + n ==> 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   824
    to_bl (sc w) = drop n (to_bl w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   825
  apply (subgoal_tac "sc = ucast")
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   826
   apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   827
   apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   828
   apply (erule refl [THEN ucast_down_drop'])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   829
  apply (rule refl [THEN down_cast_same', symmetric])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   830
  apply (simp add : source_size target_size is_down)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   831
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   832
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   833
lemma sint_up_scast': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   834
  "sc = scast ==> is_up sc ==> sint (sc w) = sint w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   835
  apply (unfold is_up)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   836
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   837
  apply (simp add: scast_def word_sbin.eq_norm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   838
  apply (rule box_equals)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   839
    prefer 3
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   840
    apply (rule word_sbin.norm_Rep)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   841
   apply (rule sbintrunc_sbintrunc_l)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   842
   defer
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   843
   apply (subst word_sbin.norm_Rep)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   844
   apply (rule refl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   845
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   846
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   847
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   848
lemma uint_up_ucast':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   849
  "uc = ucast ==> is_up uc ==> uint (uc w) = uint w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   850
  apply (unfold is_up)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   851
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   852
  apply (rule bin_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   853
  apply (fold word_test_bit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   854
  apply (auto simp add: nth_ucast)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   855
  apply (auto simp add: test_bit_bin)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   856
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   857
    
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   858
lemmas down_cast_same = refl [THEN down_cast_same']
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   859
lemmas ucast_up_app = refl [THEN ucast_up_app']
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   860
lemmas ucast_down_drop = refl [THEN ucast_down_drop']
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   861
lemmas scast_down_drop = refl [THEN scast_down_drop']
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   862
lemmas uint_up_ucast = refl [THEN uint_up_ucast']
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   863
lemmas sint_up_scast = refl [THEN sint_up_scast']
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   864
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   865
lemma ucast_up_ucast': "uc = ucast ==> is_up uc ==> ucast (uc w) = ucast w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   866
  apply (simp (no_asm) add: ucast_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   867
  apply (clarsimp simp add: uint_up_ucast)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   868
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   869
    
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   870
lemma scast_up_scast': "sc = scast ==> is_up sc ==> scast (sc w) = scast w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   871
  apply (simp (no_asm) add: scast_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   872
  apply (clarsimp simp add: sint_up_scast)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   873
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   874
    
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   875
lemma ucast_of_bl_up': 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   876
  "w = of_bl bl ==> size bl <= size w ==> ucast w = of_bl bl"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   877
  by (auto simp add : nth_ucast word_size test_bit_of_bl intro!: word_eqI)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   878
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   879
lemmas ucast_up_ucast = refl [THEN ucast_up_ucast']
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   880
lemmas scast_up_scast = refl [THEN scast_up_scast']
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   881
lemmas ucast_of_bl_up = refl [THEN ucast_of_bl_up']
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   882
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   883
lemmas ucast_up_ucast_id = trans [OF ucast_up_ucast ucast_id]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   884
lemmas scast_up_scast_id = trans [OF scast_up_scast scast_id]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   885
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   886
lemmas isduu = is_up_down [where c = "ucast", THEN iffD2]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   887
lemmas isdus = is_up_down [where c = "scast", THEN iffD2]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   888
lemmas ucast_down_ucast_id = isduu [THEN ucast_up_ucast_id]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   889
lemmas scast_down_scast_id = isdus [THEN ucast_up_ucast_id]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   890
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   891
lemma up_ucast_surj:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   892
  "is_up (ucast :: 'b::len0 word => 'a::len0 word) ==> 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   893
   surj (ucast :: 'a word => 'b word)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   894
  by (rule surjI, erule ucast_up_ucast_id)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   895
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   896
lemma up_scast_surj:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   897
  "is_up (scast :: 'b::len word => 'a::len word) ==> 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   898
   surj (scast :: 'a word => 'b word)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   899
  by (rule surjI, erule scast_up_scast_id)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   900
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   901
lemma down_scast_inj:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   902
  "is_down (scast :: 'b::len word => 'a::len word) ==> 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   903
   inj_on (ucast :: 'a word => 'b word) A"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   904
  by (rule inj_on_inverseI, erule scast_down_scast_id)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   905
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   906
lemma down_ucast_inj:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   907
  "is_down (ucast :: 'b::len0 word => 'a::len0 word) ==> 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   908
   inj_on (ucast :: 'a word => 'b word) A"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   909
  by (rule inj_on_inverseI, erule ucast_down_ucast_id)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   910
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   911
lemma of_bl_append_same: "of_bl (X @ to_bl w) = w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   912
  by (rule word_bl.Rep_eqD) (simp add: word_rep_drop)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   913
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   914
lemma ucast_down_no': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   915
  "uc = ucast ==> is_down uc ==> uc (number_of bin) = number_of bin"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   916
  apply (unfold word_number_of_def is_down)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   917
  apply (clarsimp simp add: ucast_def word_ubin.eq_norm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   918
  apply (rule word_ubin.norm_eq_iff [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   919
  apply (erule bintrunc_bintrunc_ge)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   920
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   921
    
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   922
lemmas ucast_down_no = ucast_down_no' [OF refl]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   923
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   924
lemma ucast_down_bl': "uc = ucast ==> is_down uc ==> uc (of_bl bl) = of_bl bl"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   925
  unfolding of_bl_no by clarify (erule ucast_down_no)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   926
    
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   927
lemmas ucast_down_bl = ucast_down_bl' [OF refl]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   928
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   929
lemmas slice_def' = slice_def [unfolded word_size]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   930
lemmas test_bit_def' = word_test_bit_def [THEN meta_eq_to_obj_eq, THEN fun_cong]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   931
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   932
lemmas word_log_defs = word_and_def word_or_def word_xor_def word_not_def
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   933
lemmas word_log_bin_defs = word_log_defs
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24415
diff changeset
   934
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   935
end