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