src/HOL/Word/BinOperations.thy
author haftmann
Tue, 21 Aug 2007 13:30:36 +0200
changeset 24380 c215e256beca
parent 24367 3e29eafabe16
child 24396 c1e20c65a3be
permissions -rw-r--r--
moved ordered_ab_semigroup_add to OrderedGroup.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     1
(* 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     2
  ID:     $Id$
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     3
  Author: Jeremy Dawson and Gerwin Klein, NICTA
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     4
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     5
  definition and basic theorems for bit-wise logical operations 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     6
  for integers expressed using Pls, Min, BIT,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     7
  and converting them to and from lists of bools
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     8
*) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     9
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
    10
header {* Bitwise Operations on Binary Integers *}
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
    11
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    12
theory BinOperations imports BinGeneral BitSyntax
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    13
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    14
begin
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    15
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
    16
subsection {* Logical operations *}
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    17
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    18
text "bit-wise logical operations on the int type"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    19
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    20
instance int :: bit
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    21
  int_not_def: "bitNOT \<equiv> bin_rec Numeral.Min Numeral.Pls 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    22
    (\<lambda>w b s. s BIT (NOT b))"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    23
  int_and_def: "bitAND \<equiv> bin_rec (\<lambda>x. Numeral.Pls) (\<lambda>y. y) 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    24
    (\<lambda>w b s y. s (bin_rest y) BIT (b AND bin_last y))"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    25
  int_or_def: "bitOR \<equiv> bin_rec (\<lambda>x. x) (\<lambda>y. Numeral.Min) 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    26
    (\<lambda>w b s y. s (bin_rest y) BIT (b OR bin_last y))"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    27
  int_xor_def: "bitXOR \<equiv> bin_rec (\<lambda>x. x) bitNOT 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    28
    (\<lambda>w b s y. s (bin_rest y) BIT (b XOR bin_last y))"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    29
  ..
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    30
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    31
lemma int_not_simps [simp]:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    32
  "NOT Numeral.Pls = Numeral.Min"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    33
  "NOT Numeral.Min = Numeral.Pls"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    34
  "NOT (w BIT b) = (NOT w) BIT (NOT b)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    35
  by (unfold int_not_def) (auto intro: bin_rec_simps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    36
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    37
lemma int_xor_Pls [simp]: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    38
  "Numeral.Pls XOR x = x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    39
  unfolding int_xor_def by (simp add: bin_rec_PM)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    40
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    41
lemma int_xor_Min [simp]: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    42
  "Numeral.Min XOR x = NOT x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    43
  unfolding int_xor_def by (simp add: bin_rec_PM)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    44
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    45
lemma int_xor_Bits [simp]: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    46
  "(x BIT b) XOR (y BIT c) = (x XOR y) BIT (b XOR c)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    47
  apply (unfold int_xor_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    48
  apply (rule bin_rec_simps (1) [THEN fun_cong, THEN trans])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    49
    apply (rule ext, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    50
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    51
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    52
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    53
  apply (simp add: int_not_simps [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    54
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    55
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    56
lemma int_xor_x_simps':
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    57
  "w XOR (Numeral.Pls BIT bit.B0) = w"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    58
  "w XOR (Numeral.Min BIT bit.B1) = NOT w"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    59
  apply (induct w rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    60
       apply simp_all[4]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    61
   apply (unfold int_xor_Bits)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    62
   apply clarsimp+
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    63
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    64
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    65
lemmas int_xor_extra_simps [simp] = int_xor_x_simps' [simplified arith_simps]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    66
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    67
lemma int_or_Pls [simp]: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    68
  "Numeral.Pls OR x = x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    69
  by (unfold int_or_def) (simp add: bin_rec_PM)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    70
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    71
lemma int_or_Min [simp]:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    72
  "Numeral.Min OR x = Numeral.Min"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    73
  by (unfold int_or_def) (simp add: bin_rec_PM)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    74
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    75
lemma int_or_Bits [simp]: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    76
  "(x BIT b) OR (y BIT c) = (x OR y) BIT (b OR c)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    77
  unfolding int_or_def by (simp add: bin_rec_simps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    78
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    79
lemma int_or_x_simps': 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    80
  "w OR (Numeral.Pls BIT bit.B0) = w"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    81
  "w OR (Numeral.Min BIT bit.B1) = Numeral.Min"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    82
  apply (induct w rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    83
       apply simp_all[4]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    84
   apply (unfold int_or_Bits)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    85
   apply clarsimp+
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    86
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    87
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    88
lemmas int_or_extra_simps [simp] = int_or_x_simps' [simplified arith_simps]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    89
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    90
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    91
lemma int_and_Pls [simp]:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    92
  "Numeral.Pls AND x = Numeral.Pls"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    93
  unfolding int_and_def by (simp add: bin_rec_PM)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    94
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    95
lemma int_and_Min [simp]:
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
    96
  "Numeral.Min AND x = x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    97
  unfolding int_and_def by (simp add: bin_rec_PM)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    98
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    99
lemma int_and_Bits [simp]: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   100
  "(x BIT b) AND (y BIT c) = (x AND y) BIT (b AND c)" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   101
  unfolding int_and_def by (simp add: bin_rec_simps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   102
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   103
lemma int_and_x_simps': 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   104
  "w AND (Numeral.Pls BIT bit.B0) = Numeral.Pls"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   105
  "w AND (Numeral.Min BIT bit.B1) = w"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   106
  apply (induct w rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   107
       apply simp_all[4]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   108
   apply (unfold int_and_Bits)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   109
   apply clarsimp+
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   110
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   111
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   112
lemmas int_and_extra_simps [simp] = int_and_x_simps' [simplified arith_simps]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   113
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   114
(* commutativity of the above *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   115
lemma bin_ops_comm:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   116
  shows
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   117
  int_and_comm: "!!y::int. x AND y = y AND x" and
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   118
  int_or_comm:  "!!y::int. x OR y = y OR x" and
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   119
  int_xor_comm: "!!y::int. x XOR y = y XOR x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   120
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   121
          apply simp_all[6]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   122
    apply (case_tac y rule: bin_exhaust, simp add: bit_ops_comm)+
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   123
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   124
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   125
lemma bin_ops_same [simp]:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   126
  "(x::int) AND x = x" 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   127
  "(x::int) OR x = x" 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   128
  "(x::int) XOR x = Numeral.Pls"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   129
  by (induct x rule: bin_induct) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   130
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   131
lemma int_not_not [simp]: "NOT (NOT (x::int)) = x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   132
  by (induct x rule: bin_induct) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   133
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   134
lemmas bin_log_esimps = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   135
  int_and_extra_simps  int_or_extra_simps  int_xor_extra_simps
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   136
  int_and_Pls int_and_Min  int_or_Pls int_or_Min  int_xor_Pls int_xor_Min
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   137
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   138
(* basic properties of logical (bit-wise) operations *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   139
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   140
lemma bbw_ao_absorb: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   141
  "!!y::int. x AND (y OR x) = x & x OR (y AND x) = x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   142
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   143
    apply auto 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   144
   apply (case_tac [!] y rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   145
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   146
   apply (case_tac [!] bit)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   147
     apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   148
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   149
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   150
lemma bbw_ao_absorbs_other:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   151
  "x AND (x OR y) = x \<and> (y AND x) OR x = (x::int)"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   152
  "(y OR x) AND x = x \<and> x OR (x AND y) = (x::int)"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   153
  "(x OR y) AND x = x \<and> (x AND y) OR x = (x::int)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   154
  apply (auto simp: bbw_ao_absorb int_or_comm)  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   155
      apply (subst int_or_comm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   156
    apply (simp add: bbw_ao_absorb)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   157
   apply (subst int_and_comm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   158
   apply (subst int_or_comm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   159
   apply (simp add: bbw_ao_absorb)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   160
  apply (subst int_and_comm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   161
  apply (simp add: bbw_ao_absorb)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   162
  done
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   163
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   164
lemmas bbw_ao_absorbs [simp] = bbw_ao_absorb bbw_ao_absorbs_other
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   165
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   166
lemma int_xor_not:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   167
  "!!y::int. (NOT x) XOR y = NOT (x XOR y) & 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   168
        x XOR (NOT y) = NOT (x XOR y)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   169
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   170
    apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   171
   apply (case_tac y rule: bin_exhaust, auto, 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   172
          case_tac b, auto)+
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   173
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   174
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   175
lemma bbw_assocs': 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   176
  "!!y z::int. (x AND y) AND z = x AND (y AND z) & 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   177
          (x OR y) OR z = x OR (y OR z) & 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   178
          (x XOR y) XOR z = x XOR (y XOR z)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   179
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   180
    apply (auto simp: int_xor_not)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   181
    apply (case_tac [!] y rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   182
    apply (case_tac [!] z rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   183
    apply (case_tac [!] bit)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   184
       apply (case_tac [!] b)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   185
             apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   186
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   187
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   188
lemma int_and_assoc:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   189
  "(x AND y) AND (z::int) = x AND (y AND z)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   190
  by (simp add: bbw_assocs')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   191
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   192
lemma int_or_assoc:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   193
  "(x OR y) OR (z::int) = x OR (y OR z)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   194
  by (simp add: bbw_assocs')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   195
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   196
lemma int_xor_assoc:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   197
  "(x XOR y) XOR (z::int) = x XOR (y XOR z)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   198
  by (simp add: bbw_assocs')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   199
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   200
lemmas bbw_assocs = int_and_assoc int_or_assoc int_xor_assoc
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   201
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   202
lemma bbw_lcs [simp]: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   203
  "(y::int) AND (x AND z) = x AND (y AND z)"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   204
  "(y::int) OR (x OR z) = x OR (y OR z)"
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   205
  "(y::int) XOR (x XOR z) = x XOR (y XOR z)" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   206
  apply (auto simp: bbw_assocs [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   207
  apply (auto simp: bin_ops_comm)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   208
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   209
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   210
lemma bbw_not_dist: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   211
  "!!y::int. NOT (x OR y) = (NOT x) AND (NOT y)" 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   212
  "!!y::int. NOT (x AND y) = (NOT x) OR (NOT y)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   213
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   214
       apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   215
   apply (case_tac [!] y rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   216
   apply (case_tac [!] bit, auto)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   217
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   218
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   219
lemma bbw_oa_dist: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   220
  "!!y z::int. (x AND y) OR z = 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   221
          (x OR z) AND (y OR z)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   222
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   223
    apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   224
  apply (case_tac y rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   225
  apply (case_tac z rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   226
  apply (case_tac ba, auto)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   227
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   228
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   229
lemma bbw_ao_dist: 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   230
  "!!y z::int. (x OR y) AND z = 
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   231
          (x AND z) OR (y AND z)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   232
   apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   233
    apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   234
  apply (case_tac y rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   235
  apply (case_tac z rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   236
  apply (case_tac ba, auto)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   237
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   238
24367
3e29eafabe16 AC rules for bitwise logical operators no longer declared simp
huffman
parents: 24366
diff changeset
   239
(*
3e29eafabe16 AC rules for bitwise logical operators no longer declared simp
huffman
parents: 24366
diff changeset
   240
Why were these declared simp???
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   241
declare bin_ops_comm [simp] bbw_assocs [simp] 
24367
3e29eafabe16 AC rules for bitwise logical operators no longer declared simp
huffman
parents: 24366
diff changeset
   242
*)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   243
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   244
lemma plus_and_or [rule_format]:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   245
  "ALL y::int. (x AND y) + (x OR y) = x + y"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   246
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   247
    apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   248
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   249
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   250
  apply (case_tac y rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   251
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   252
  apply (unfold Bit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   253
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   254
  apply (erule_tac x = "x" in allE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   255
  apply (simp split: bit.split)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   256
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   257
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   258
lemma le_int_or:
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   259
  "!!x.  bin_sign y = Numeral.Pls ==> x <= x OR y"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   260
  apply (induct y rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   261
    apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   262
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   263
  apply (case_tac x rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   264
  apply (case_tac b)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   265
   apply (case_tac [!] bit)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   266
     apply (auto simp: less_eq_numeral_code)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   267
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   268
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   269
lemmas int_and_le =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   270
  xtr3 [OF bbw_ao_absorbs (2) [THEN conjunct2, symmetric] le_int_or] ;
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   271
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   272
lemma bin_nth_ops:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   273
  "!!x y. bin_nth (x AND y) n = (bin_nth x n & bin_nth y n)" 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   274
  "!!x y. bin_nth (x OR y) n = (bin_nth x n | bin_nth y n)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   275
  "!!x y. bin_nth (x XOR y) n = (bin_nth x n ~= bin_nth y n)" 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   276
  "!!x. bin_nth (NOT x) n = (~ bin_nth x n)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   277
  apply (induct n)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   278
         apply safe
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   279
                         apply (case_tac [!] x rule: bin_exhaust)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   280
                         apply simp_all
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   281
                      apply (case_tac [!] y rule: bin_exhaust)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   282
                      apply simp_all
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   283
        apply (auto dest: not_B1_is_B0 intro: B1_ass_B0)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   284
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   285
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   286
(* interaction between bit-wise and arithmetic *)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   287
(* good example of bin_induction *)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   288
lemma bin_add_not: "x + NOT x = Numeral.Min"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   289
  apply (induct x rule: bin_induct)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   290
    apply clarsimp
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   291
   apply clarsimp
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   292
  apply (case_tac bit, auto)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   293
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   294
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   295
(* truncating results of bit-wise operations *)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   296
lemma bin_trunc_ao: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   297
  "!!x y. (bintrunc n x) AND (bintrunc n y) = bintrunc n (x AND y)" 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   298
  "!!x y. (bintrunc n x) OR (bintrunc n y) = bintrunc n (x OR y)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   299
  apply (induct n)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   300
      apply auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   301
      apply (case_tac [!] x rule: bin_exhaust)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   302
      apply (case_tac [!] y rule: bin_exhaust)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   303
      apply auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   304
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   305
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   306
lemma bin_trunc_xor: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   307
  "!!x y. bintrunc n (bintrunc n x XOR bintrunc n y) = 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   308
          bintrunc n (x XOR y)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   309
  apply (induct n)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   310
   apply auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   311
   apply (case_tac [!] x rule: bin_exhaust)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   312
   apply (case_tac [!] y rule: bin_exhaust)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   313
   apply auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   314
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   315
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   316
lemma bin_trunc_not: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   317
  "!!x. bintrunc n (NOT (bintrunc n x)) = bintrunc n (NOT x)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   318
  apply (induct n)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   319
   apply auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   320
   apply (case_tac [!] x rule: bin_exhaust)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   321
   apply auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   322
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   323
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   324
(* want theorems of the form of bin_trunc_xor *)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   325
lemma bintr_bintr_i:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   326
  "x = bintrunc n y ==> bintrunc n x = bintrunc n y"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   327
  by auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   328
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   329
lemmas bin_trunc_and = bin_trunc_ao(1) [THEN bintr_bintr_i]
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   330
lemmas bin_trunc_or = bin_trunc_ao(2) [THEN bintr_bintr_i]
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   331
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   332
subsection {* Setting and clearing bits *}
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   333
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   334
consts
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   335
  bin_sc :: "nat => bit => int => int"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   336
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   337
primrec
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   338
  Z : "bin_sc 0 b w = bin_rest w BIT b"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   339
  Suc :
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   340
    "bin_sc (Suc n) b w = bin_sc n b (bin_rest w) BIT bin_last w"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   341
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   342
(** nth bit, set/clear **)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   343
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   344
lemma bin_nth_sc [simp]: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   345
  "!!w. bin_nth (bin_sc n b w) n = (b = bit.B1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   346
  by (induct n)  auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   347
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   348
lemma bin_sc_sc_same [simp]: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   349
  "!!w. bin_sc n c (bin_sc n b w) = bin_sc n c w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   350
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   351
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   352
lemma bin_sc_sc_diff:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   353
  "!!w m. m ~= n ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   354
    bin_sc m c (bin_sc n b w) = bin_sc n b (bin_sc m c w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   355
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   356
   apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   357
   apply (case_tac [!] m)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   358
     apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   359
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   360
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   361
lemma bin_nth_sc_gen: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   362
  "!!w m. bin_nth (bin_sc n b w) m = (if m = n then b = bit.B1 else bin_nth w m)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   363
  by (induct n) (case_tac [!] m, auto)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   364
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   365
lemma bin_sc_nth [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   366
  "!!w. (bin_sc n (If (bin_nth w n) bit.B1 bit.B0) w) = w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   367
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   368
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   369
lemma bin_sign_sc [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   370
  "!!w. bin_sign (bin_sc n b w) = bin_sign w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   371
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   372
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   373
lemma bin_sc_bintr [simp]: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   374
  "!!w m. bintrunc m (bin_sc n x (bintrunc m (w))) = bintrunc m (bin_sc n x w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   375
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   376
   apply (case_tac [!] w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   377
   apply (case_tac [!] m, auto)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   378
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   379
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   380
lemma bin_clr_le:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   381
  "!!w. bin_sc n bit.B0 w <= w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   382
  apply (induct n) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   383
   apply (case_tac [!] w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   384
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   385
   apply (unfold Bit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   386
   apply (simp_all split: bit.split)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   387
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   388
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   389
lemma bin_set_ge:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   390
  "!!w. bin_sc n bit.B1 w >= w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   391
  apply (induct n) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   392
   apply (case_tac [!] w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   393
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   394
   apply (unfold Bit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   395
   apply (simp_all split: bit.split)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   396
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   397
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   398
lemma bintr_bin_clr_le:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   399
  "!!w m. bintrunc n (bin_sc m bit.B0 w) <= bintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   400
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   401
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   402
  apply (case_tac w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   403
  apply (case_tac m)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   404
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   405
   apply (unfold Bit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   406
   apply (simp_all split: bit.split)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   407
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   408
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   409
lemma bintr_bin_set_ge:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   410
  "!!w m. bintrunc n (bin_sc m bit.B1 w) >= bintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   411
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   412
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   413
  apply (case_tac w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   414
  apply (case_tac m)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   415
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   416
   apply (unfold Bit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   417
   apply (simp_all split: bit.split)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   418
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   419
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   420
lemma bin_sc_FP [simp]: "bin_sc n bit.B0 Numeral.Pls = Numeral.Pls"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   421
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   422
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   423
lemma bin_sc_TM [simp]: "bin_sc n bit.B1 Numeral.Min = Numeral.Min"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   424
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   425
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   426
lemmas bin_sc_simps = bin_sc.Z bin_sc.Suc bin_sc_TM bin_sc_FP
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   427
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   428
lemma bin_sc_minus:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   429
  "0 < n ==> bin_sc (Suc (n - 1)) b w = bin_sc n b w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   430
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   431
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   432
lemmas bin_sc_Suc_minus = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   433
  trans [OF bin_sc_minus [symmetric] bin_sc.Suc, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   434
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   435
lemmas bin_sc_Suc_pred [simp] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   436
  bin_sc_Suc_minus [of "number_of bin", simplified nobm1, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   437
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   438
subsection {* Operations on lists of booleans *}
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   439
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   440
consts
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   441
  bin_to_bl :: "nat => int => bool list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   442
  bin_to_bl_aux :: "nat => int => bool list => bool list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   443
  bl_to_bin :: "bool list => int"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   444
  bl_to_bin_aux :: "int => bool list => int"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   445
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   446
  bl_of_nth :: "nat => (nat => bool) => bool list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   447
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   448
primrec
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   449
  Nil : "bl_to_bin_aux w [] = w"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   450
  Cons : "bl_to_bin_aux w (b # bs) = 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   451
      bl_to_bin_aux (w BIT (if b then bit.B1 else bit.B0)) bs"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   452
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   453
primrec
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   454
  Z : "bin_to_bl_aux 0 w bl = bl"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   455
  Suc : "bin_to_bl_aux (Suc n) w bl =
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   456
    bin_to_bl_aux n (bin_rest w) ((bin_last w = bit.B1) # bl)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   457
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   458
defs
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   459
  bin_to_bl_def : "bin_to_bl n w == bin_to_bl_aux n w []"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   460
  bl_to_bin_def : "bl_to_bin bs == bl_to_bin_aux Numeral.Pls bs"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   461
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   462
primrec
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   463
  Suc : "bl_of_nth (Suc n) f = f n # bl_of_nth n f"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   464
  Z : "bl_of_nth 0 f = []"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   465
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   466
consts
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   467
  takefill :: "'a => nat => 'a list => 'a list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   468
  app2 :: "('a => 'b => 'c) => 'a list => 'b list => 'c list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   469
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   470
-- "takefill - like take but if argument list too short,"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   471
-- "extends result to get requested length"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   472
primrec
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   473
  Z : "takefill fill 0 xs = []"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   474
  Suc : "takefill fill (Suc n) xs = (
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   475
    case xs of [] => fill # takefill fill n xs
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   476
      | y # ys => y # takefill fill n ys)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   477
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   478
defs
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   479
  app2_def : "app2 f as bs == map (split f) (zip as bs)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   480
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   481
subsection {* Splitting and concatenation *}
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   482
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   483
-- "rcat and rsplit"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   484
consts
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   485
  bin_rcat :: "nat => int list => int"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   486
  bin_rsplit_aux :: "nat * int list * nat * int => int list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   487
  bin_rsplit :: "nat => (nat * int) => int list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   488
  bin_rsplitl_aux :: "nat * int list * nat * int => int list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   489
  bin_rsplitl :: "nat => (nat * int) => int list"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   490
  
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   491
recdef bin_rsplit_aux "measure (fst o snd o snd)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   492
  "bin_rsplit_aux (n, bs, (m, c)) =
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   493
    (if m = 0 | n = 0 then bs else
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   494
      let (a, b) = bin_split n c 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   495
      in bin_rsplit_aux (n, b # bs, (m - n, a)))"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   496
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   497
recdef bin_rsplitl_aux "measure (fst o snd o snd)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   498
  "bin_rsplitl_aux (n, bs, (m, c)) =
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   499
    (if m = 0 | n = 0 then bs else
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   500
      let (a, b) = bin_split (min m n) c 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   501
      in bin_rsplitl_aux (n, b # bs, (m - n, a)))"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   502
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   503
defs
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   504
  bin_rcat_def : "bin_rcat n bs == foldl (%u v. bin_cat u n v) Numeral.Pls bs"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   505
  bin_rsplit_def : "bin_rsplit n w == bin_rsplit_aux (n, [], w)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   506
  bin_rsplitl_def : "bin_rsplitl n w == bin_rsplitl_aux (n, [], w)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   507
     
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   508
 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   509
(* potential for looping *)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   510
declare bin_rsplit_aux.simps [simp del]
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   511
declare bin_rsplitl_aux.simps [simp del]
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   512
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   513
lemma bin_sign_cat: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   514
  "!!y. bin_sign (bin_cat x n y) = bin_sign x"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   515
  by (induct n) auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   516
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   517
lemma bin_cat_Suc_Bit:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   518
  "bin_cat w (Suc n) (v BIT b) = bin_cat w n v BIT b"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   519
  by auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   520
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   521
lemma bin_nth_cat: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   522
  "!!n y. bin_nth (bin_cat x k y) n = 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   523
    (if n < k then bin_nth y n else bin_nth x (n - k))"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   524
  apply (induct k)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   525
   apply clarsimp
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   526
  apply (case_tac n, auto)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   527
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   528
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   529
lemma bin_nth_split:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   530
  "!!b c. bin_split n c = (a, b) ==> 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   531
    (ALL k. bin_nth a k = bin_nth c (n + k)) & 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   532
    (ALL k. bin_nth b k = (k < n & bin_nth c k))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   533
  apply (induct n)
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   534
   apply clarsimp
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   535
  apply (clarsimp simp: Let_def split: ls_splits)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   536
  apply (case_tac k)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   537
  apply auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   538
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   539
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   540
lemma bin_cat_assoc: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   541
  "!!z. bin_cat (bin_cat x m y) n z = bin_cat x (m + n) (bin_cat y n z)" 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   542
  by (induct n) auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   543
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   544
lemma bin_cat_assoc_sym: "!!z m. 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   545
  bin_cat x m (bin_cat y n z) = bin_cat (bin_cat x (m - n) y) (min m n) z"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   546
  apply (induct n, clarsimp)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   547
  apply (case_tac m, auto)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   548
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   549
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   550
lemma bin_cat_Pls [simp]: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   551
  "!!w. bin_cat Numeral.Pls n w = bintrunc n w"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   552
  by (induct n) auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   553
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   554
lemma bintr_cat1: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   555
  "!!b. bintrunc (k + n) (bin_cat a n b) = bin_cat (bintrunc k a) n b"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   556
  by (induct n) auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   557
    
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   558
lemma bintr_cat: "bintrunc m (bin_cat a n b) = 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   559
    bin_cat (bintrunc (m - n) a) n (bintrunc (min m n) b)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   560
  by (rule bin_eqI) (auto simp: bin_nth_cat nth_bintr)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   561
    
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   562
lemma bintr_cat_same [simp]: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   563
  "bintrunc n (bin_cat a n b) = bintrunc n b"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   564
  by (auto simp add : bintr_cat)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   565
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   566
lemma cat_bintr [simp]: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   567
  "!!b. bin_cat a n (bintrunc n b) = bin_cat a n b"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   568
  by (induct n) auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   569
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   570
lemma split_bintrunc: 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   571
  "!!b c. bin_split n c = (a, b) ==> b = bintrunc n c"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   572
  by (induct n) (auto simp: Let_def split: ls_splits)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   573
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   574
lemma bin_cat_split:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   575
  "!!v w. bin_split n w = (u, v) ==> w = bin_cat u n v"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   576
  by (induct n) (auto simp: Let_def split: ls_splits)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   577
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   578
lemma bin_split_cat:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   579
  "!!w. bin_split n (bin_cat v n w) = (v, bintrunc n w)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   580
  by (induct n) auto
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   581
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   582
lemma bin_split_Pls [simp]:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   583
  "bin_split n Numeral.Pls = (Numeral.Pls, Numeral.Pls)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   584
  by (induct n) (auto simp: Let_def split: ls_splits)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   585
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   586
lemma bin_split_Min [simp]:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   587
  "bin_split n Numeral.Min = (Numeral.Min, bintrunc n Numeral.Min)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   588
  by (induct n) (auto simp: Let_def split: ls_splits)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   589
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   590
lemma bin_split_trunc:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   591
  "!!m b c. bin_split (min m n) c = (a, b) ==> 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   592
    bin_split n (bintrunc m c) = (bintrunc (m - n) a, b)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   593
  apply (induct n, clarsimp)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   594
  apply (simp add: bin_rest_trunc Let_def split: ls_splits)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   595
  apply (case_tac m)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   596
   apply (auto simp: Let_def split: ls_splits)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   597
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   598
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   599
lemma bin_split_trunc1:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   600
  "!!m b c. bin_split n c = (a, b) ==> 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   601
    bin_split n (bintrunc m c) = (bintrunc (m - n) a, bintrunc m b)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   602
  apply (induct n, clarsimp)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   603
  apply (simp add: bin_rest_trunc Let_def split: ls_splits)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   604
  apply (case_tac m)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   605
   apply (auto simp: Let_def split: ls_splits)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   606
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   607
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   608
lemma bin_cat_num:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   609
  "!!b. bin_cat a n b = a * 2 ^ n + bintrunc n b"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   610
  apply (induct n, clarsimp)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   611
  apply (simp add: Bit_def cong: number_of_False_cong)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   612
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   613
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   614
lemma bin_split_num:
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   615
  "!!b. bin_split n b = (b div 2 ^ n, b mod 2 ^ n)"
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   616
  apply (induct n, clarsimp)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   617
  apply (simp add: bin_rest_div zdiv_zmult2_eq)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   618
  apply (case_tac b rule: bin_exhaust)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   619
  apply simp
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   620
  apply (simp add: Bit_def zmod_zmult_zmult1 p1mod22k
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   621
              split: bit.split 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   622
              cong: number_of_False_cong)
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   623
  done 
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   624
31e359126ab6 reorganize into subsections
huffman
parents: 24353
diff changeset
   625
subsection {* Miscellaneous lemmas *}
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   626
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   627
lemma nth_2p_bin: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   628
  "!!m. bin_nth (2 ^ n) m = (m = n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   629
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   630
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   631
   apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   632
     apply (case_tac m) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   633
      apply (auto simp: trans [OF numeral_1_eq_1 [symmetric] number_of_eq])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   634
   apply (case_tac m) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   635
    apply (auto simp: Bit_B0_2t [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   636
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   637
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   638
(* for use when simplifying with bin_nth_Bit *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   639
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   640
lemma ex_eq_or:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   641
  "(EX m. n = Suc m & (m = k | P m)) = (n = Suc k | (EX m. n = Suc m & P m))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   642
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   643
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   644
end
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   645