src/HOL/Word/Bool_List_Representation.thy
author haftmann
Tue, 13 Oct 2015 09:21:15 +0200
changeset 61424 c3658c18b7bc
parent 58874 7172c7ffb047
child 61799 4cf66f21b764
permissions -rw-r--r--
prod_case as canonical name for product type eliminator
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, NICTA
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     3
44939
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 41842
diff changeset
     4
  Theorems to do with integers, expressed using Pls, Min, BIT,
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     5
  theorems linking them to lists of booleans, and repeated splitting 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     6
  and concatenation.
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     7
*) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     8
58874
7172c7ffb047 modernized header;
wenzelm
parents: 58410
diff changeset
     9
section "Bool lists and integers"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    10
37658
df789294c77a more speaking names
haftmann
parents: 37657
diff changeset
    11
theory Bool_List_Representation
54874
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
    12
imports Main Bits_Int
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
    13
begin
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    14
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    15
definition map2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    16
where
61424
c3658c18b7bc prod_case as canonical name for product type eliminator
haftmann
parents: 58874
diff changeset
    17
  "map2 f as bs = map (case_prod f) (zip as bs)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    18
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    19
lemma map2_Nil [simp, code]:
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    20
  "map2 f [] ys = []"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    21
  unfolding map2_def by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    22
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    23
lemma map2_Nil2 [simp, code]:
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    24
  "map2 f xs [] = []"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    25
  unfolding map2_def by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    26
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    27
lemma map2_Cons [simp, code]:
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    28
  "map2 f (x # xs) (y # ys) = f x y # map2 f xs ys"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    29
  unfolding map2_def by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    30
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
    31
37657
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    32
subsection {* Operations on lists of booleans *}
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    33
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    34
primrec bl_to_bin_aux :: "bool list \<Rightarrow> int \<Rightarrow> int"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    35
where
37657
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    36
  Nil: "bl_to_bin_aux [] w = w"
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    37
  | Cons: "bl_to_bin_aux (b # bs) w = 
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
    38
      bl_to_bin_aux bs (w BIT b)"
37657
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    39
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    40
definition bl_to_bin :: "bool list \<Rightarrow> int"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    41
where
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
    42
  bl_to_bin_def: "bl_to_bin bs = bl_to_bin_aux bs 0"
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    43
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    44
primrec bin_to_bl_aux :: "nat \<Rightarrow> int \<Rightarrow> bool list \<Rightarrow> bool list"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    45
where
37657
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    46
  Z: "bin_to_bl_aux 0 w bl = bl"
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    47
  | Suc: "bin_to_bl_aux (Suc n) w bl =
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
    48
      bin_to_bl_aux n (bin_rest w) ((bin_last w) # bl)"
37657
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    49
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    50
definition bin_to_bl :: "nat \<Rightarrow> int \<Rightarrow> bool list"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    51
where
37657
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    52
  bin_to_bl_def : "bin_to_bl n w = bin_to_bl_aux n w []"
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    53
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    54
primrec bl_of_nth :: "nat \<Rightarrow> (nat \<Rightarrow> bool) \<Rightarrow> bool list"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    55
where
37657
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    56
  Suc: "bl_of_nth (Suc n) f = f n # bl_of_nth n f"
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    57
  | Z: "bl_of_nth 0 f = []"
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    58
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    59
primrec takefill :: "'a \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    60
where
37657
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    61
  Z: "takefill fill 0 xs = []"
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    62
  | Suc: "takefill fill (Suc n) xs = (
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    63
      case xs of [] => fill # takefill fill n xs
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    64
        | y # ys => y # takefill fill n ys)"
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    65
17e1085d07b2 moved specific operations here
haftmann
parents: 37654
diff changeset
    66
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    67
subsection "Arithmetic in terms of bool lists"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    68
44939
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 41842
diff changeset
    69
text {* 
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 41842
diff changeset
    70
  Arithmetic operations in terms of the reversed bool list,
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 41842
diff changeset
    71
  assuming input list(s) the same length, and don't extend them. 
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 41842
diff changeset
    72
*}
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    73
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    74
primrec rbl_succ :: "bool list => bool list"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    75
where
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    76
  Nil: "rbl_succ Nil = Nil"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
    77
  | Cons: "rbl_succ (x # xs) = (if x then False # rbl_succ xs else True # xs)"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    78
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    79
primrec rbl_pred :: "bool list => bool list"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    80
where
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
    81
  Nil: "rbl_pred Nil = Nil"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
    82
  | Cons: "rbl_pred (x # xs) = (if x then False # xs else True # rbl_pred xs)"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    83
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    84
primrec rbl_add :: "bool list => bool list => bool list"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    85
where
44939
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 41842
diff changeset
    86
  -- "result is length of first arg, second arg may be longer"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
    87
  Nil: "rbl_add Nil x = Nil"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
    88
  | Cons: "rbl_add (y # ys) x = (let ws = rbl_add ys (tl x) in 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    89
    (y ~= hd x) # (if hd x & y then rbl_succ ws else ws))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    90
54848
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    91
primrec rbl_mult :: "bool list => bool list => bool list"
a303daddebbf syntactically tuned
haftmann
parents: 54847
diff changeset
    92
where
44939
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 41842
diff changeset
    93
  -- "result is length of first arg, second arg may be longer"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
    94
  Nil: "rbl_mult Nil x = Nil"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
    95
  | Cons: "rbl_mult (y # ys) x = (let ws = False # rbl_mult ys x in 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
    96
    if y then rbl_add ws x else ws)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    97
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    98
lemma butlast_power:
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30952
diff changeset
    99
  "(butlast ^^ n) bl = take (length bl - n) bl"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   100
  by (induct n) (auto simp: butlast_take)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   101
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   102
lemma bin_to_bl_aux_zero_minus_simp [simp]:
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   103
  "0 < n \<Longrightarrow> bin_to_bl_aux n 0 bl = 
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   104
    bin_to_bl_aux (n - 1) 0 (False # bl)"
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   105
  by (cases n) auto
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   106
46617
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   107
lemma bin_to_bl_aux_minus1_minus_simp [simp]:
58410
6d46ad54a2ab explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents: 57514
diff changeset
   108
  "0 < n ==> bin_to_bl_aux n (- 1) bl = 
6d46ad54a2ab explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents: 57514
diff changeset
   109
    bin_to_bl_aux (n - 1) (- 1) (True # bl)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   110
  by (cases n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   111
46617
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   112
lemma bin_to_bl_aux_one_minus_simp [simp]:
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   113
  "0 < n \<Longrightarrow> bin_to_bl_aux n 1 bl = 
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   114
    bin_to_bl_aux (n - 1) 0 (True # bl)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   115
  by (cases n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   116
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26008
diff changeset
   117
lemma bin_to_bl_aux_Bit_minus_simp [simp]:
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   118
  "0 < n ==> bin_to_bl_aux n (w BIT b) bl = 
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
   119
    bin_to_bl_aux (n - 1) w (b # bl)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   120
  by (cases n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   121
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26008
diff changeset
   122
lemma bin_to_bl_aux_Bit0_minus_simp [simp]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   123
  "0 < n ==> bin_to_bl_aux n (numeral (Num.Bit0 w)) bl = 
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   124
    bin_to_bl_aux (n - 1) (numeral w) (False # bl)"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26008
diff changeset
   125
  by (cases n) auto
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26008
diff changeset
   126
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26008
diff changeset
   127
lemma bin_to_bl_aux_Bit1_minus_simp [simp]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   128
  "0 < n ==> bin_to_bl_aux n (numeral (Num.Bit1 w)) bl = 
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   129
    bin_to_bl_aux (n - 1) (numeral w) (True # bl)"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26008
diff changeset
   130
  by (cases n) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   131
44939
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 41842
diff changeset
   132
text {* Link between bin and bool list. *}
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   133
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   134
lemma bl_to_bin_aux_append: 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   135
  "bl_to_bin_aux (bs @ cs) w = bl_to_bin_aux cs (bl_to_bin_aux bs w)"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   136
  by (induct bs arbitrary: w) auto
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   137
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   138
lemma bin_to_bl_aux_append: 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   139
  "bin_to_bl_aux n w bs @ cs = bin_to_bl_aux n w (bs @ cs)"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   140
  by (induct n arbitrary: w bs) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   141
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   142
lemma bl_to_bin_append: 
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   143
  "bl_to_bin (bs @ cs) = bl_to_bin_aux cs (bl_to_bin bs)"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   144
  unfolding bl_to_bin_def by (rule bl_to_bin_aux_append)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   145
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   146
lemma bin_to_bl_aux_alt: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   147
  "bin_to_bl_aux n w bs = bin_to_bl n w @ bs" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   148
  unfolding bin_to_bl_def by (simp add : bin_to_bl_aux_append)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   149
45996
e69d631fe9af declare simp rules immediately, instead of using 'declare' commands
huffman
parents: 45854
diff changeset
   150
lemma bin_to_bl_0 [simp]: "bin_to_bl 0 bs = []"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   151
  unfolding bin_to_bl_def by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   152
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   153
lemma size_bin_to_bl_aux: 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   154
  "size (bin_to_bl_aux n w bs) = n + length bs"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   155
  by (induct n arbitrary: w bs) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   156
45996
e69d631fe9af declare simp rules immediately, instead of using 'declare' commands
huffman
parents: 45854
diff changeset
   157
lemma size_bin_to_bl [simp]: "size (bin_to_bl n w) = n" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   158
  unfolding bin_to_bl_def by (simp add : size_bin_to_bl_aux)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   159
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   160
lemma bin_bl_bin': 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   161
  "bl_to_bin (bin_to_bl_aux n w bs) = 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   162
    bl_to_bin_aux bs (bintrunc n w)"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   163
  by (induct n arbitrary: w bs) (auto simp add : bl_to_bin_def)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   164
45996
e69d631fe9af declare simp rules immediately, instead of using 'declare' commands
huffman
parents: 45854
diff changeset
   165
lemma bin_bl_bin [simp]: "bl_to_bin (bin_to_bl n w) = bintrunc n w"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   166
  unfolding bin_to_bl_def bin_bl_bin' by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   167
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   168
lemma bl_bin_bl':
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   169
  "bin_to_bl (n + length bs) (bl_to_bin_aux bs w) = 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   170
    bin_to_bl_aux n w bs"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   171
  apply (induct bs arbitrary: w n)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   172
   apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   173
    apply (simp_all only : add_Suc [symmetric])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   174
    apply (auto simp add : bin_to_bl_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   175
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   176
45996
e69d631fe9af declare simp rules immediately, instead of using 'declare' commands
huffman
parents: 45854
diff changeset
   177
lemma bl_bin_bl [simp]: "bin_to_bl (length bs) (bl_to_bin bs) = bs"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   178
  unfolding bl_to_bin_def
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   179
  apply (rule box_equals)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   180
    apply (rule bl_bin_bl')
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   181
   prefer 2
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   182
   apply (rule bin_to_bl_aux.Z)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   183
  apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   184
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   185
  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   186
lemma bl_to_bin_inj:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   187
  "bl_to_bin bs = bl_to_bin cs ==> length bs = length cs ==> bs = cs"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   188
  apply (rule_tac box_equals)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   189
    defer
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   190
    apply (rule bl_bin_bl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   191
   apply (rule bl_bin_bl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   192
  apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   193
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   194
45996
e69d631fe9af declare simp rules immediately, instead of using 'declare' commands
huffman
parents: 45854
diff changeset
   195
lemma bl_to_bin_False [simp]: "bl_to_bin (False # bl) = bl_to_bin bl"
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   196
  unfolding bl_to_bin_def by auto
45996
e69d631fe9af declare simp rules immediately, instead of using 'declare' commands
huffman
parents: 45854
diff changeset
   197
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   198
lemma bl_to_bin_Nil [simp]: "bl_to_bin [] = 0"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   199
  unfolding bl_to_bin_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   200
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   201
lemma bin_to_bl_zero_aux: 
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   202
  "bin_to_bl_aux n 0 bl = replicate n False @ bl"
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   203
  by (induct n arbitrary: bl) (auto simp: replicate_app_Cons_same)
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   204
46617
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   205
lemma bin_to_bl_zero: "bin_to_bl n 0 = replicate n False"
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   206
  unfolding bin_to_bl_def by (simp add: bin_to_bl_zero_aux)
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   207
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   208
lemma bin_to_bl_minus1_aux:
58410
6d46ad54a2ab explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents: 57514
diff changeset
   209
  "bin_to_bl_aux n (- 1) bl = replicate n True @ bl"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   210
  by (induct n arbitrary: bl) (auto simp: replicate_app_Cons_same)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   211
58410
6d46ad54a2ab explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents: 57514
diff changeset
   212
lemma bin_to_bl_minus1: "bin_to_bl n (- 1) = replicate n True"
46617
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   213
  unfolding bin_to_bl_def by (simp add: bin_to_bl_minus1_aux)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   214
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   215
lemma bl_to_bin_rep_F: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   216
  "bl_to_bin (replicate n False @ bl) = bl_to_bin bl"
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   217
  apply (simp add: bin_to_bl_zero_aux [symmetric] bin_bl_bin')
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   218
  apply (simp add: bl_to_bin_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   219
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   220
45996
e69d631fe9af declare simp rules immediately, instead of using 'declare' commands
huffman
parents: 45854
diff changeset
   221
lemma bin_to_bl_trunc [simp]:
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   222
  "n <= m ==> bin_to_bl n (bintrunc m w) = bin_to_bl n w"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   223
  by (auto intro: bl_to_bin_inj)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   224
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   225
lemma bin_to_bl_aux_bintr:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   226
  "bin_to_bl_aux n (bintrunc m bin) bl = 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   227
    replicate (n - m) False @ bin_to_bl_aux (min n m) bin bl"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   228
  apply (induct n arbitrary: m bin bl)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   229
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   230
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   231
  apply (case_tac "m")
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   232
   apply (clarsimp simp: bin_to_bl_zero_aux) 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   233
   apply (erule thin_rl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   234
   apply (induct_tac n)   
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   235
    apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   236
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   237
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   238
lemma bin_to_bl_bintr:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   239
  "bin_to_bl n (bintrunc m bin) =
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   240
    replicate (n - m) False @ bin_to_bl (min n m) bin"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   241
  unfolding bin_to_bl_def by (rule bin_to_bl_aux_bintr)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   242
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   243
lemma bl_to_bin_rep_False: "bl_to_bin (replicate n False) = 0"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   244
  by (induct n) auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   245
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   246
lemma len_bin_to_bl_aux: 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   247
  "length (bin_to_bl_aux n w bs) = n + length bs"
54869
0046711700c8 tuned proofs and declarations
haftmann
parents: 54863
diff changeset
   248
  by (fact size_bin_to_bl_aux)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   249
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   250
lemma len_bin_to_bl [simp]: "length (bin_to_bl n w) = n"
46617
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   251
  by (fact size_bin_to_bl) (* FIXME: duplicate *)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   252
  
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   253
lemma sign_bl_bin': 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   254
  "bin_sign (bl_to_bin_aux bs w) = bin_sign w"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   255
  by (induct bs arbitrary: w) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   256
  
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   257
lemma sign_bl_bin: "bin_sign (bl_to_bin bs) = 0"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   258
  unfolding bl_to_bin_def by (simp add : sign_bl_bin')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   259
  
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   260
lemma bl_sbin_sign_aux: 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   261
  "hd (bin_to_bl_aux (Suc n) w bs) = 
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   262
    (bin_sign (sbintrunc n w) = -1)"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   263
  apply (induct n arbitrary: w bs)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   264
   apply clarsimp
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   265
   apply (cases w rule: bin_exhaust)
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
   266
   apply simp
24333
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
lemma bl_sbin_sign: 
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   270
  "hd (bin_to_bl (Suc n) w) = (bin_sign (sbintrunc n w) = -1)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   271
  unfolding bin_to_bl_def by (rule bl_sbin_sign_aux)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   272
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   273
lemma bin_nth_of_bl_aux:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   274
  "bin_nth (bl_to_bin_aux bl w) n = 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   275
    (n < size bl & rev bl ! n | n >= length bl & bin_nth w (n - size bl))"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   276
  apply (induct bl arbitrary: w)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   277
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   278
  apply clarsimp
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   279
  apply (cut_tac x=n and y="size bl" in linorder_less_linear)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   280
  apply (erule disjE, simp add: nth_append)+
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   281
  apply auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   282
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   283
45475
b2b087c20e45 removed some old-style semicolons
huffman
parents: 44939
diff changeset
   284
lemma bin_nth_of_bl: "bin_nth (bl_to_bin bl) n = (n < length bl & rev bl ! n)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   285
  unfolding bl_to_bin_def by (simp add : bin_nth_of_bl_aux)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   286
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   287
lemma bin_nth_bl: "n < m \<Longrightarrow> bin_nth w n = nth (rev (bin_to_bl m w)) n"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   288
  apply (induct n arbitrary: m w)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   289
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   290
   apply (case_tac m, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   291
   apply (clarsimp simp: bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   292
   apply (simp add: bin_to_bl_aux_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   293
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   294
  apply (case_tac m, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   295
  apply (clarsimp simp: bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   296
  apply (simp add: bin_to_bl_aux_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   297
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   298
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   299
lemma nth_rev:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   300
  "n < length xs \<Longrightarrow> rev xs ! n = xs ! (length xs - 1 - n)"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   301
  apply (induct xs)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   302
   apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   303
  apply (clarsimp simp add : nth_append nth.simps split add : nat.split)
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   304
  apply (rule_tac f = "\<lambda>n. xs ! n" in arg_cong)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   305
  apply arith
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   306
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   307
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   308
lemma nth_rev_alt: "n < length ys \<Longrightarrow> ys ! n = rev ys ! (length ys - Suc n)"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   309
  by (simp add: nth_rev)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   310
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   311
lemma nth_bin_to_bl_aux:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   312
  "n < m + length bl \<Longrightarrow> (bin_to_bl_aux m w bl) ! n = 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   313
    (if n < m then bin_nth w (m - 1 - n) else bl ! (n - m))"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   314
  apply (induct m arbitrary: w n bl)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   315
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   316
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   317
  apply (case_tac w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   318
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   319
  done
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   320
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   321
lemma nth_bin_to_bl: "n < m ==> (bin_to_bl m w) ! n = bin_nth w (m - Suc n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   322
  unfolding bin_to_bl_def by (simp add : nth_bin_to_bl_aux)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   323
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   324
lemma bl_to_bin_lt2p_aux:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   325
  "bl_to_bin_aux bs w < (w + 1) * (2 ^ length bs)"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   326
  apply (induct bs arbitrary: w)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   327
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   328
  apply clarsimp
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
   329
  apply (drule meta_spec, erule xtrans(8) [rotated], simp add: Bit_def)+
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   330
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   331
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   332
lemma bl_to_bin_lt2p: "bl_to_bin bs < (2 ^ length bs)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   333
  apply (unfold bl_to_bin_def)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
   334
  apply (rule xtrans(1))
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   335
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   336
   apply (rule bl_to_bin_lt2p_aux)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   337
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   338
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   339
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   340
lemma bl_to_bin_ge2p_aux:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   341
  "bl_to_bin_aux bs w >= w * (2 ^ length bs)"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   342
  apply (induct bs arbitrary: w)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   343
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   344
  apply clarsimp
46652
bec50f8b3727 avoid using BIT_simps in proofs
huffman
parents: 46645
diff changeset
   345
   apply (drule meta_spec, erule order_trans [rotated],
bec50f8b3727 avoid using BIT_simps in proofs
huffman
parents: 46645
diff changeset
   346
          simp add: Bit_B0_2t Bit_B1_2t algebra_simps)+
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
   347
   apply (simp add: Bit_def)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   348
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   349
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   350
lemma bl_to_bin_ge0: "bl_to_bin bs >= 0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   351
  apply (unfold bl_to_bin_def)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
   352
  apply (rule xtrans(4))
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   353
   apply (rule bl_to_bin_ge2p_aux)
46617
8c5d10d41391 make bool list functions respect int/bin distinction
huffman
parents: 46240
diff changeset
   354
  apply simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   355
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   356
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   357
lemma butlast_rest_bin: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   358
  "butlast (bin_to_bl n w) = bin_to_bl (n - 1) (bin_rest w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   359
  apply (unfold bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   360
  apply (cases w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   361
  apply (cases n, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   362
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   363
  apply (auto simp add: bin_to_bl_aux_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   364
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   365
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   366
lemma butlast_bin_rest:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   367
  "butlast bl = bin_to_bl (length bl - Suc 0) (bin_rest (bl_to_bin bl))"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   368
  using butlast_rest_bin [where w="bl_to_bin bl" and n="length bl"] by simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   369
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   370
lemma butlast_rest_bl2bin_aux:
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   371
  "bl ~= [] \<Longrightarrow>
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   372
    bl_to_bin_aux (butlast bl) w = bin_rest (bl_to_bin_aux bl w)"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   373
  by (induct bl arbitrary: w) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   374
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   375
lemma butlast_rest_bl2bin: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   376
  "bl_to_bin (butlast bl) = bin_rest (bl_to_bin bl)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   377
  apply (unfold bl_to_bin_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   378
  apply (cases bl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   379
   apply (auto simp add: butlast_rest_bl2bin_aux)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   380
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   381
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   382
lemma trunc_bl2bin_aux:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   383
  "bintrunc m (bl_to_bin_aux bl w) = 
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   384
    bl_to_bin_aux (drop (length bl - m) bl) (bintrunc (m - length bl) w)"
53438
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   385
proof (induct bl arbitrary: w)
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   386
  case Nil show ?case by simp
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   387
next
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   388
  case (Cons b bl) show ?case
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   389
  proof (cases "m - length bl")
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   390
    case 0 then have "Suc (length bl) - m = Suc (length bl - m)" by simp
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   391
    with Cons show ?thesis by simp
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   392
  next
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   393
    case (Suc n) then have *: "m - Suc (length bl) = n" by simp
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   394
    with Suc Cons show ?thesis by simp
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   395
  qed
6301ed01e34d slight cleanup of lemma locations; tuned proof
haftmann
parents: 53062
diff changeset
   396
qed
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   397
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   398
lemma trunc_bl2bin: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   399
  "bintrunc m (bl_to_bin bl) = bl_to_bin (drop (length bl - m) bl)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   400
  unfolding bl_to_bin_def by (simp add : trunc_bl2bin_aux)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   401
  
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   402
lemma trunc_bl2bin_len [simp]:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   403
  "bintrunc (length bl) (bl_to_bin bl) = bl_to_bin bl"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   404
  by (simp add: trunc_bl2bin)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   405
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   406
lemma bl2bin_drop: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   407
  "bl_to_bin (drop k bl) = bintrunc (length bl - k) (bl_to_bin bl)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   408
  apply (rule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   409
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   410
   apply (rule trunc_bl2bin [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   411
  apply (cases "k <= length bl")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   412
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   413
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   414
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   415
lemma nth_rest_power_bin:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   416
  "bin_nth ((bin_rest ^^ k) w) n = bin_nth w (n + k)"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   417
  apply (induct k arbitrary: n, clarsimp)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   418
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   419
  apply (simp only: bin_nth.Suc [symmetric] add_Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   420
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   421
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   422
lemma take_rest_power_bin:
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30952
diff changeset
   423
  "m <= n ==> take m (bin_to_bl n w) = bin_to_bl m ((bin_rest ^^ (n - m)) w)" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   424
  apply (rule nth_equalityI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   425
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   426
  apply (clarsimp simp add: nth_bin_to_bl nth_rest_power_bin)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   427
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   428
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   429
lemma hd_butlast: "size xs > 1 ==> hd (butlast xs) = hd xs"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   430
  by (cases xs) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   431
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   432
lemma last_bin_last': 
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
   433
  "size xs > 0 \<Longrightarrow> last xs \<longleftrightarrow> bin_last (bl_to_bin_aux xs w)" 
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   434
  by (induct xs arbitrary: w) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   435
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   436
lemma last_bin_last: 
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
   437
  "size xs > 0 ==> last xs \<longleftrightarrow> bin_last (bl_to_bin xs)" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   438
  unfolding bl_to_bin_def by (erule last_bin_last')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   439
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   440
lemma bin_last_last: 
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
   441
  "bin_last w \<longleftrightarrow> last (bin_to_bl (Suc n) w)" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   442
  apply (unfold bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   443
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   444
  apply (auto simp add: bin_to_bl_aux_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   445
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   446
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   447
(** links between bit-wise operations and operations on bool lists **)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   448
    
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   449
lemma bl_xor_aux_bin:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   450
  "map2 (%x y. x ~= y) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   451
    bin_to_bl_aux n (v XOR w) (map2 (%x y. x ~= y) bs cs)"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   452
  apply (induct n arbitrary: v w bs cs)
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   453
   apply simp
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   454
  apply (case_tac v rule: bin_exhaust)
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   455
  apply (case_tac w rule: bin_exhaust)
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   456
  apply clarsimp
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   457
  apply (case_tac b)
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
   458
  apply auto
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   459
  done
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   460
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   461
lemma bl_or_aux_bin:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   462
  "map2 (op | ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   463
    bin_to_bl_aux n (v OR w) (map2 (op | ) bs cs)"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   464
  apply (induct n arbitrary: v w bs cs)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   465
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   466
  apply (case_tac v rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   467
  apply (case_tac w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   468
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   469
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   470
    
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   471
lemma bl_and_aux_bin:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   472
  "map2 (op & ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   473
    bin_to_bl_aux n (v AND w) (map2 (op & ) bs cs)" 
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   474
  apply (induct n arbitrary: v w bs cs)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   475
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   476
  apply (case_tac v rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   477
  apply (case_tac w rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   478
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   479
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   480
    
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   481
lemma bl_not_aux_bin:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   482
  "map Not (bin_to_bl_aux n w cs) = 
24353
9a7a9b19e925 use overloaded bitwise operators at type int
huffman
parents: 24350
diff changeset
   483
    bin_to_bl_aux n (NOT w) (map Not cs)"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   484
  apply (induct n arbitrary: w cs)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   485
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   486
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   487
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   488
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   489
lemma bl_not_bin: "map Not (bin_to_bl n w) = bin_to_bl n (NOT w)"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   490
  unfolding bin_to_bl_def by (simp add: bl_not_aux_bin)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   491
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   492
lemma bl_and_bin:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   493
  "map2 (op \<and>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v AND w)"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   494
  unfolding bin_to_bl_def by (simp add: bl_and_aux_bin)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   495
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   496
lemma bl_or_bin:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   497
  "map2 (op \<or>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v OR w)"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   498
  unfolding bin_to_bl_def by (simp add: bl_or_aux_bin)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   499
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   500
lemma bl_xor_bin:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   501
  "map2 (\<lambda>x y. x \<noteq> y) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v XOR w)"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   502
  unfolding bin_to_bl_def by (simp only: bl_xor_aux_bin map2_Nil)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   503
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   504
lemma drop_bin2bl_aux:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   505
  "drop m (bin_to_bl_aux n bin bs) = 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   506
    bin_to_bl_aux (n - m) bin (drop (m - n) bs)"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   507
  apply (induct n arbitrary: m bin bs, clarsimp)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   508
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   509
  apply (case_tac bin rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   510
  apply (case_tac "m <= n", simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   511
  apply (case_tac "m - n", simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   512
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   513
  apply (rule_tac f = "%nat. drop nat bs" in arg_cong) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   514
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   515
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   516
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   517
lemma drop_bin2bl: "drop m (bin_to_bl n bin) = bin_to_bl (n - m) bin"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   518
  unfolding bin_to_bl_def by (simp add : drop_bin2bl_aux)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   519
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   520
lemma take_bin2bl_lem1:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   521
  "take m (bin_to_bl_aux m w bs) = bin_to_bl m w"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   522
  apply (induct m arbitrary: w bs, clarsimp)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   523
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   524
  apply (simp add: bin_to_bl_aux_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   525
  apply (simp add: bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   526
  apply (simp add: bin_to_bl_aux_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   527
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   528
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   529
lemma take_bin2bl_lem:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   530
  "take m (bin_to_bl_aux (m + n) w bs) = 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   531
    take m (bin_to_bl (m + n) w)"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   532
  apply (induct n arbitrary: w bs)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   533
   apply (simp_all (no_asm) add: bin_to_bl_def take_bin2bl_lem1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   534
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   535
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   536
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   537
lemma bin_split_take:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   538
  "bin_split n c = (a, b) \<Longrightarrow>
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   539
    bin_to_bl m a = take m (bin_to_bl (m + n) c)"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   540
  apply (induct n arbitrary: b c)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   541
   apply clarsimp
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
   542
  apply (clarsimp simp: Let_def split: prod.split_asm)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   543
  apply (simp add: bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   544
  apply (simp add: take_bin2bl_lem)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   545
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   546
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   547
lemma bin_split_take1: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   548
  "k = m + n ==> bin_split n c = (a, b) ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   549
    bin_to_bl m a = take m (bin_to_bl k c)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   550
  by (auto elim: bin_split_take)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   551
  
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   552
lemma nth_takefill: "m < n \<Longrightarrow>
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   553
    takefill fill n l ! m = (if m < length l then l ! m else fill)"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   554
  apply (induct n arbitrary: m l, clarsimp)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   555
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   556
  apply (case_tac m)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   557
   apply (simp split: list.split)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   558
  apply (simp split: list.split)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   559
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   560
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   561
lemma takefill_alt:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   562
  "takefill fill n l = take n l @ replicate (n - length l) fill"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   563
  by (induct n arbitrary: l) (auto split: list.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   564
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   565
lemma takefill_replicate [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   566
  "takefill fill n (replicate m fill) = replicate n fill"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   567
  by (simp add : takefill_alt replicate_add [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   568
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   569
lemma takefill_le':
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   570
  "n = m + k \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   571
  by (induct m arbitrary: l n) (auto split: list.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   572
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   573
lemma length_takefill [simp]: "length (takefill fill n l) = n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   574
  by (simp add : takefill_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   575
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   576
lemma take_takefill':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   577
  "!!w n.  n = k + m ==> take k (takefill fill n w) = takefill fill k w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   578
  by (induct k) (auto split add : list.split) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   579
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   580
lemma drop_takefill:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   581
  "!!w. drop k (takefill fill (m + k) w) = takefill fill m (drop k w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   582
  by (induct k) (auto split add : list.split) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   583
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   584
lemma takefill_le [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   585
  "m \<le> n \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   586
  by (auto simp: le_iff_add takefill_le')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   587
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   588
lemma take_takefill [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   589
  "m \<le> n \<Longrightarrow> take m (takefill fill n w) = takefill fill m w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   590
  by (auto simp: le_iff_add take_takefill')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   591
 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   592
lemma takefill_append:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   593
  "takefill fill (m + length xs) (xs @ w) = xs @ (takefill fill m w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   594
  by (induct xs) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   595
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   596
lemma takefill_same': 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   597
  "l = length xs ==> takefill fill l xs = xs"
57492
74bf65a1910a Hypsubst preserves equality hypotheses
Thomas Sewell <thomas.sewell@nicta.com.au>
parents: 56073
diff changeset
   598
  by (induct xs arbitrary: l, auto)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   599
 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   600
lemmas takefill_same [simp] = takefill_same' [OF refl]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   601
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   602
lemma takefill_bintrunc:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   603
  "takefill False n bl = rev (bin_to_bl n (bl_to_bin (rev bl)))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   604
  apply (rule nth_equalityI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   605
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   606
  apply (clarsimp simp: nth_takefill nth_rev nth_bin_to_bl bin_nth_of_bl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   607
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   608
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   609
lemma bl_bin_bl_rtf:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   610
  "bin_to_bl n (bl_to_bin bl) = rev (takefill False n (rev bl))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   611
  by (simp add : takefill_bintrunc)
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   612
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   613
lemma bl_bin_bl_rep_drop:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   614
  "bin_to_bl n (bl_to_bin bl) =
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   615
    replicate (n - length bl) False @ drop (length bl - n) bl"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   616
  by (simp add: bl_bin_bl_rtf takefill_alt rev_take)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   617
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   618
lemma tf_rev:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   619
  "n + k = m + length bl ==> takefill x m (rev (takefill y n bl)) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   620
    rev (takefill y m (rev (takefill x k (rev bl))))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   621
  apply (rule nth_equalityI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   622
   apply (auto simp add: nth_takefill nth_rev)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   623
  apply (rule_tac f = "%n. bl ! n" in arg_cong) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   624
  apply arith 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   625
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   626
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   627
lemma takefill_minus:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   628
  "0 < n ==> takefill fill (Suc (n - 1)) w = takefill fill n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   629
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   630
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   631
lemmas takefill_Suc_cases = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   632
  list.cases [THEN takefill.Suc [THEN trans]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   633
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   634
lemmas takefill_Suc_Nil = takefill_Suc_cases (1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   635
lemmas takefill_Suc_Cons = takefill_Suc_cases (2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   636
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   637
lemmas takefill_minus_simps = takefill_Suc_cases [THEN [2] 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   638
  takefill_minus [symmetric, THEN trans]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   639
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   640
lemma takefill_numeral_Nil [simp]:
47219
172c031ad743 restate various simp rules for word operations using pred_numeral
huffman
parents: 47108
diff changeset
   641
  "takefill fill (numeral k) [] = fill # takefill fill (pred_numeral k) []"
172c031ad743 restate various simp rules for word operations using pred_numeral
huffman
parents: 47108
diff changeset
   642
  by (simp add: numeral_eq_Suc)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   643
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   644
lemma takefill_numeral_Cons [simp]:
47219
172c031ad743 restate various simp rules for word operations using pred_numeral
huffman
parents: 47108
diff changeset
   645
  "takefill fill (numeral k) (x # xs) = x # takefill fill (pred_numeral k) xs"
172c031ad743 restate various simp rules for word operations using pred_numeral
huffman
parents: 47108
diff changeset
   646
  by (simp add: numeral_eq_Suc)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   647
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   648
(* links with function bl_to_bin *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   649
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   650
lemma bl_to_bin_aux_cat: 
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   651
  "!!nv v. bl_to_bin_aux bs (bin_cat w nv v) = 
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   652
    bin_cat w (nv + length bs) (bl_to_bin_aux bs v)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   653
  apply (induct bs)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   654
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   655
  apply (simp add: bin_cat_Suc_Bit [symmetric] del: bin_cat.simps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   656
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   657
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   658
lemma bin_to_bl_aux_cat: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   659
  "!!w bs. bin_to_bl_aux (nv + nw) (bin_cat v nw w) bs = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   660
    bin_to_bl_aux nv v (bin_to_bl_aux nw w bs)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   661
  by (induct nw) auto 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   662
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   663
lemma bl_to_bin_aux_alt:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   664
  "bl_to_bin_aux bs w = bin_cat w (length bs) (bl_to_bin bs)"
46001
0b562d564d5f redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents: 45997
diff changeset
   665
  using bl_to_bin_aux_cat [where nv = "0" and v = "0"]
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   666
  unfolding bl_to_bin_def [symmetric] by simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   667
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   668
lemma bin_to_bl_cat:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   669
  "bin_to_bl (nv + nw) (bin_cat v nw w) =
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   670
    bin_to_bl_aux nv v (bin_to_bl nw w)"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   671
  unfolding bin_to_bl_def by (simp add: bin_to_bl_aux_cat)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   672
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   673
lemmas bl_to_bin_aux_app_cat = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   674
  trans [OF bl_to_bin_aux_append bl_to_bin_aux_alt]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   675
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   676
lemmas bin_to_bl_aux_cat_app =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   677
  trans [OF bin_to_bl_aux_cat bin_to_bl_aux_alt]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   678
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   679
lemma bl_to_bin_app_cat:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   680
  "bl_to_bin (bsa @ bs) = bin_cat (bl_to_bin bsa) (length bs) (bl_to_bin bs)"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   681
  by (simp only: bl_to_bin_aux_app_cat bl_to_bin_def)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   682
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   683
lemma bin_to_bl_cat_app:
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   684
  "bin_to_bl (n + nw) (bin_cat w nw wa) = bin_to_bl n w @ bin_to_bl nw wa"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   685
  by (simp only: bin_to_bl_def bin_to_bl_aux_cat_app)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   686
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   687
(* bl_to_bin_app_cat_alt and bl_to_bin_app_cat are easily interderivable *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   688
lemma bl_to_bin_app_cat_alt: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   689
  "bin_cat (bl_to_bin cs) n w = bl_to_bin (cs @ bin_to_bl n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   690
  by (simp add : bl_to_bin_app_cat)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   691
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   692
lemma mask_lem: "(bl_to_bin (True # replicate n False)) = 
46645
573aff6b9b0a adapt lemma mask_lem to respect int/bin distinction
huffman
parents: 46617
diff changeset
   693
    (bl_to_bin (replicate n True)) + 1"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   694
  apply (unfold bl_to_bin_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   695
  apply (induct n)
46645
573aff6b9b0a adapt lemma mask_lem to respect int/bin distinction
huffman
parents: 46617
diff changeset
   696
   apply simp
31790
05c92381363c corrected and unified thm names
nipkow
parents: 30971
diff changeset
   697
  apply (simp only: Suc_eq_plus1 replicate_add
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   698
                    append_Cons [symmetric] bl_to_bin_aux_append)
46645
573aff6b9b0a adapt lemma mask_lem to respect int/bin distinction
huffman
parents: 46617
diff changeset
   699
  apply (simp add: Bit_B0_2t Bit_B1_2t)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   700
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   701
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24399
diff changeset
   702
(* function bl_of_nth *)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   703
lemma length_bl_of_nth [simp]: "length (bl_of_nth n f) = n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   704
  by (induct n)  auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   705
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   706
lemma nth_bl_of_nth [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   707
  "m < n \<Longrightarrow> rev (bl_of_nth n f) ! m = f m"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   708
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   709
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   710
  apply (clarsimp simp add : nth_append)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   711
  apply (rule_tac f = "f" in arg_cong) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   712
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   713
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   714
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   715
lemma bl_of_nth_inj: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   716
  "(!!k. k < n ==> f k = g k) ==> bl_of_nth n f = bl_of_nth n g"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   717
  by (induct n)  auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   718
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   719
lemma bl_of_nth_nth_le:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   720
  "n \<le> length xs \<Longrightarrow> bl_of_nth n (nth (rev xs)) = drop (length xs - n) xs"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   721
  apply (induct n arbitrary: xs, clarsimp)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   722
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   723
  apply (rule trans [OF _ hd_Cons_tl])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   724
   apply (frule Suc_le_lessD)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   725
   apply (simp add: nth_rev trans [OF drop_Suc drop_tl, symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   726
   apply (subst hd_drop_conv_nth)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   727
     apply force
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   728
    apply simp_all
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   729
  apply (rule_tac f = "%n. drop n xs" in arg_cong) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   730
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   731
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   732
45854
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   733
lemma bl_of_nth_nth [simp]: "bl_of_nth (length xs) (op ! (rev xs)) = xs"
40554613b4f0 replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents: 45847
diff changeset
   734
  by (simp add: bl_of_nth_nth_le)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   735
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   736
lemma size_rbl_pred: "length (rbl_pred bl) = length bl"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   737
  by (induct bl) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   738
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   739
lemma size_rbl_succ: "length (rbl_succ bl) = length bl"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   740
  by (induct bl) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   741
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   742
lemma size_rbl_add:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   743
  "!!cl. length (rbl_add bl cl) = length bl"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   744
  by (induct bl) (auto simp: Let_def size_rbl_succ)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   745
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   746
lemma size_rbl_mult: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   747
  "!!cl. length (rbl_mult bl cl) = length bl"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   748
  by (induct bl) (auto simp add : Let_def size_rbl_add)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   749
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   750
lemmas rbl_sizes [simp] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   751
  size_rbl_pred size_rbl_succ size_rbl_add size_rbl_mult
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   752
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   753
lemmas rbl_Nils =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   754
  rbl_pred.Nil rbl_succ.Nil rbl_add.Nil rbl_mult.Nil
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   755
46653
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   756
lemma rbl_pred:
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   757
  "rbl_pred (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin - 1))"
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   758
  apply (induct n arbitrary: bin, simp)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   759
  apply (unfold bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   760
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   761
  apply (case_tac bin rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   762
  apply (case_tac b)
46653
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   763
   apply (clarsimp simp: bin_to_bl_aux_alt)+
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   764
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   765
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   766
lemma rbl_succ: 
46653
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   767
  "rbl_succ (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin + 1))"
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   768
  apply (induct n arbitrary: bin, simp)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   769
  apply (unfold bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   770
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   771
  apply (case_tac bin rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   772
  apply (case_tac b)
46653
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   773
   apply (clarsimp simp: bin_to_bl_aux_alt)+
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   774
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   775
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   776
lemma rbl_add: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   777
  "!!bina binb. rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   778
    rev (bin_to_bl n (bina + binb))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   779
  apply (induct n, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   780
  apply (unfold bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   781
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   782
  apply (case_tac bina rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   783
  apply (case_tac binb rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   784
  apply (case_tac b)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   785
   apply (case_tac [!] "ba")
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57492
diff changeset
   786
     apply (auto simp: rbl_succ bin_to_bl_aux_alt Let_def ac_simps)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   787
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   788
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   789
lemma rbl_add_app2: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   790
  "!!blb. length blb >= length bla ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   791
    rbl_add bla (blb @ blc) = rbl_add bla blb"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   792
  apply (induct bla, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   793
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   794
  apply (case_tac blb, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   795
  apply (clarsimp simp: Let_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   796
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   797
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   798
lemma rbl_add_take2: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   799
  "!!blb. length blb >= length bla ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   800
    rbl_add bla (take (length bla) blb) = rbl_add bla blb"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   801
  apply (induct bla, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   802
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   803
  apply (case_tac blb, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   804
  apply (clarsimp simp: Let_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   805
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   806
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   807
lemma rbl_add_long: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   808
  "m >= n ==> rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   809
    rev (bin_to_bl n (bina + binb))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   810
  apply (rule box_equals [OF _ rbl_add_take2 rbl_add])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   811
   apply (rule_tac f = "rbl_add (rev (bin_to_bl n bina))" in arg_cong) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   812
   apply (rule rev_swap [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   813
   apply (simp add: rev_take drop_bin2bl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   814
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   815
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   816
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   817
lemma rbl_mult_app2:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   818
  "!!blb. length blb >= length bla ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   819
    rbl_mult bla (blb @ blc) = rbl_mult bla blb"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   820
  apply (induct bla, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   821
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   822
  apply (case_tac blb, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   823
  apply (clarsimp simp: Let_def rbl_add_app2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   824
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   825
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   826
lemma rbl_mult_take2: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   827
  "length blb >= length bla ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   828
    rbl_mult bla (take (length bla) blb) = rbl_mult bla blb"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   829
  apply (rule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   830
   apply (rule rbl_mult_app2 [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   831
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   832
  apply (rule_tac f = "rbl_mult bla" in arg_cong) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   833
  apply (rule append_take_drop_id)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   834
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   835
    
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   836
lemma rbl_mult_gt1: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   837
  "m >= length bl ==> rbl_mult bl (rev (bin_to_bl m binb)) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   838
    rbl_mult bl (rev (bin_to_bl (length bl) binb))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   839
  apply (rule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   840
   apply (rule rbl_mult_take2 [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   841
   apply simp_all
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   842
  apply (rule_tac f = "rbl_mult bl" in arg_cong) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   843
  apply (rule rev_swap [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   844
  apply (simp add: rev_take drop_bin2bl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   845
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   846
    
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   847
lemma rbl_mult_gt: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   848
  "m > n ==> rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   849
    rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   850
  by (auto intro: trans [OF rbl_mult_gt1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   851
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   852
lemmas rbl_mult_Suc = lessI [THEN rbl_mult_gt]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   853
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   854
lemma rbbl_Cons: 
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 53438
diff changeset
   855
  "b # rev (bin_to_bl n x) = rev (bin_to_bl (Suc n) (x BIT b))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   856
  apply (unfold bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   857
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   858
  apply (simp add: bin_to_bl_aux_alt)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   859
  done
46653
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   860
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   861
lemma rbl_mult: "!!bina binb. 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   862
    rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   863
    rev (bin_to_bl n (bina * binb))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   864
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   865
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   866
  apply (unfold bin_to_bl_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   867
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   868
  apply (case_tac bina rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   869
  apply (case_tac binb rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   870
  apply (case_tac b)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   871
   apply (case_tac [!] "ba")
46653
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   872
     apply (auto simp: bin_to_bl_aux_alt Let_def)
a557db8f2fbf avoid using BIT_simps in proofs;
huffman
parents: 46652
diff changeset
   873
     apply (auto simp: rbbl_Cons rbl_mult_Suc rbl_add)
24333
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 rbl_add_split: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   877
  "P (rbl_add (y # ys) (x # xs)) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   878
    (ALL ws. length ws = length ys --> ws = rbl_add ys xs --> 
26008
24c82bef5696 eliminated escaped white space;
wenzelm
parents: 25919
diff changeset
   879
    (y --> ((x --> P (False # rbl_succ ws)) & (~ x -->  P (True # ws)))) &
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   880
    (~ y --> P (x # ws)))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   881
  apply (auto simp add: Let_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   882
   apply (case_tac [!] "y")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   883
     apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   884
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   885
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   886
lemma rbl_mult_split: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   887
  "P (rbl_mult (y # ys) xs) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   888
    (ALL ws. length ws = Suc (length ys) --> ws = False # rbl_mult ys xs --> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   889
    (y --> P (rbl_add ws xs)) & (~ y -->  P ws))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   890
  by (clarsimp simp add : Let_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   891
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   892
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
   893
subsection "Repeated splitting or concatenation"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   894
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   895
lemma sclem:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   896
  "size (concat (map (bin_to_bl n) xs)) = length xs * n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   897
  by (induct xs) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   898
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   899
lemma bin_cat_foldl_lem:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   900
  "foldl (%u. bin_cat u n) x xs = 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   901
    bin_cat x (size xs * n) (foldl (%u. bin_cat u n) y xs)"
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   902
  apply (induct xs arbitrary: x)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   903
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   904
  apply (simp (no_asm))
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   905
  apply (frule asm_rl)
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   906
  apply (drule meta_spec)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   907
  apply (erule trans)
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   908
  apply (drule_tac x = "bin_cat y n a" in meta_spec)
54863
82acc20ded73 prefer more canonical names for lemmas on min/max
haftmann
parents: 54854
diff changeset
   909
  apply (simp add : bin_cat_assoc_sym min.absorb2)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   910
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   911
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   912
lemma bin_rcat_bl:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   913
  "(bin_rcat n wl) = bl_to_bin (concat (map (bin_to_bl n) wl))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   914
  apply (unfold bin_rcat_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   915
  apply (rule sym)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   916
  apply (induct wl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   917
   apply (auto simp add : bl_to_bin_append)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   918
  apply (simp add : bl_to_bin_aux_alt sclem)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   919
  apply (simp add : bin_cat_foldl_lem [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   920
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   921
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   922
lemmas bin_rsplit_aux_simps = bin_rsplit_aux.simps bin_rsplitl_aux.simps
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   923
lemmas rsplit_aux_simps = bin_rsplit_aux_simps
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   924
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   925
lemmas th_if_simp1 = split_if [where P = "op = l", THEN iffD1, THEN conjunct1, THEN mp] for l
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   926
lemmas th_if_simp2 = split_if [where P = "op = l", THEN iffD1, THEN conjunct2, THEN mp] for l
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   927
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   928
lemmas rsplit_aux_simp1s = rsplit_aux_simps [THEN th_if_simp1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   929
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   930
lemmas rsplit_aux_simp2ls = rsplit_aux_simps [THEN th_if_simp2]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   931
(* these safe to [simp add] as require calculating m - n *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   932
lemmas bin_rsplit_aux_simp2s [simp] = rsplit_aux_simp2ls [unfolded Let_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   933
lemmas rbscl = bin_rsplit_aux_simp2s (2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   934
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   935
lemmas rsplit_aux_0_simps [simp] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   936
  rsplit_aux_simp1s [OF disjI1] rsplit_aux_simp1s [OF disjI2]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   937
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   938
lemma bin_rsplit_aux_append:
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   939
  "bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   940
  apply (induct n m c bs rule: bin_rsplit_aux.induct)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   941
  apply (subst bin_rsplit_aux.simps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   942
  apply (subst bin_rsplit_aux.simps)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
   943
  apply (clarsimp split: prod.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   944
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   945
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   946
lemma bin_rsplitl_aux_append:
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   947
  "bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   948
  apply (induct n m c bs rule: bin_rsplitl_aux.induct)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   949
  apply (subst bin_rsplitl_aux.simps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   950
  apply (subst bin_rsplitl_aux.simps)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
   951
  apply (clarsimp split: prod.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   952
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   953
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   954
lemmas rsplit_aux_apps [where bs = "[]"] =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   955
  bin_rsplit_aux_append bin_rsplitl_aux_append
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   956
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   957
lemmas rsplit_def_auxs = bin_rsplit_def bin_rsplitl_def
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   958
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   959
lemmas rsplit_aux_alts = rsplit_aux_apps 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   960
  [unfolded append_Nil rsplit_def_auxs [symmetric]]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   961
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   962
lemma bin_split_minus: "0 < n ==> bin_split (Suc (n - 1)) w = bin_split n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   963
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   964
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   965
lemmas bin_split_minus_simp =
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   966
  bin_split.Suc [THEN [2] bin_split_minus [symmetric, THEN trans]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   967
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   968
lemma bin_split_pred_simp [simp]: 
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   969
  "(0::nat) < numeral bin \<Longrightarrow>
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   970
  bin_split (numeral bin) w =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   971
  (let (w1, w2) = bin_split (numeral bin - 1) (bin_rest w)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   972
   in (w1, w2 BIT bin_last w))" 
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46655
diff changeset
   973
  by (simp only: bin_split_minus_simp)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   974
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   975
lemma bin_rsplit_aux_simp_alt:
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   976
  "bin_rsplit_aux n m c bs =
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   977
   (if m = 0 \<or> n = 0 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   978
   then bs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   979
   else let (a, b) = bin_split n c in bin_rsplit n (m - n, a) @ b # bs)"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   980
  unfolding bin_rsplit_aux.simps [of n m c bs]
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   981
  apply simp
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   982
  apply (subst rsplit_aux_alts)
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
   983
  apply (simp add: bin_rsplit_def)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   984
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   985
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   986
lemmas bin_rsplit_simp_alt = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   987
  trans [OF bin_rsplit_def bin_rsplit_aux_simp_alt]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   988
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   989
lemmas bthrs = bin_rsplit_simp_alt [THEN [2] trans]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   990
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   991
lemma bin_rsplit_size_sign' [rule_format] : 
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   992
  "\<lbrakk>n > 0; rev sw = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> 
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   993
    (ALL v: set sw. bintrunc n v = v)"
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
   994
  apply (induct sw arbitrary: nw w v)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   995
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   996
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   997
  apply (drule bthrs)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
   998
  apply (simp (no_asm_use) add: Let_def split: prod.split_asm split_if_asm)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   999
  apply clarify
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1000
  apply (drule split_bintrunc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1001
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1002
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1003
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1004
lemmas bin_rsplit_size_sign = bin_rsplit_size_sign' [OF asm_rl 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
  1005
  rev_rev_ident [THEN trans] set_rev [THEN equalityD2 [THEN subsetD]]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1006
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1007
lemma bin_nth_rsplit [rule_format] :
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1008
  "n > 0 ==> m < n ==> (ALL w k nw. rev sw = bin_rsplit n (nw, w) --> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1009
       k < size sw --> bin_nth (sw ! k) m = bin_nth w (k * n + m))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1010
  apply (induct sw)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1011
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1012
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1013
  apply (drule bthrs)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
  1014
  apply (simp (no_asm_use) add: Let_def split: prod.split_asm split_if_asm)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1015
  apply clarify
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1016
  apply (erule allE, erule impE, erule exI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1017
  apply (case_tac k)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1018
   apply clarsimp   
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1019
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1020
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1021
   apply (erule allE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1022
   apply (erule (1) impE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1023
   apply (drule bin_nth_split, erule conjE, erule allE,
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57492
diff changeset
  1024
          erule trans, simp add : ac_simps)+
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1025
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1026
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1027
lemma bin_rsplit_all:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1028
  "0 < nw ==> nw <= n ==> bin_rsplit n (nw, w) = [bintrunc n w]"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1029
  unfolding bin_rsplit_def
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
  1030
  by (clarsimp dest!: split_bintrunc simp: rsplit_aux_simp2ls split: prod.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1031
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1032
lemma bin_rsplit_l [rule_format] :
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1033
  "ALL bin. bin_rsplitl n (m, bin) = bin_rsplit n (m, bintrunc m bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1034
  apply (rule_tac a = "m" in wf_less_than [THEN wf_induct])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1035
  apply (simp (no_asm) add : bin_rsplitl_def bin_rsplit_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1036
  apply (rule allI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1037
  apply (subst bin_rsplitl_aux.simps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1038
  apply (subst bin_rsplit_aux.simps)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
  1039
  apply (clarsimp simp: Let_def split: prod.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1040
  apply (drule bin_split_trunc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1041
  apply (drule sym [THEN trans], assumption)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1042
  apply (subst rsplit_aux_alts(1))
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1043
  apply (subst rsplit_aux_alts(2))
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1044
  apply clarsimp
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1045
  unfolding bin_rsplit_def bin_rsplitl_def
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1046
  apply simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1047
  done
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1048
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1049
lemma bin_rsplit_rcat [rule_format] :
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1050
  "n > 0 --> bin_rsplit n (n * size ws, bin_rcat n ws) = map (bintrunc n) ws"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1051
  apply (unfold bin_rsplit_def bin_rcat_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1052
  apply (rule_tac xs = "ws" in rev_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1053
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1054
  apply clarsimp
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1055
  apply (subst rsplit_aux_alts)
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1056
  unfolding bin_split_cat
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1057
  apply simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1058
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1059
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1060
lemma bin_rsplit_aux_len_le [rule_format] :
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1061
  "\<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow>
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1062
    length ws \<le> m \<longleftrightarrow> nw + length bs * n \<le> m * n"
54871
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1063
proof -
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1064
  { fix i j j' k k' m :: nat and R
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1065
    assume d: "(i::nat) \<le> j \<or> m < j'"
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1066
    assume R1: "i * k \<le> j * k \<Longrightarrow> R"
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1067
    assume R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1068
    have "R" using d
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1069
      apply safe
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1070
       apply (rule R1, erule mult_le_mono1)
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1071
      apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1072
      done
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1073
  } note A = this
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1074
  { fix sc m n lb :: nat
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1075
    have "(0::nat) < sc \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n \<longleftrightarrow> sc + lb * n \<le> m * n"
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1076
      apply safe
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1077
       apply arith
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1078
      apply (case_tac "sc >= n")
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1079
       apply arith
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1080
      apply (insert linorder_le_less_linear [of m lb])
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1081
      apply (erule_tac k2=n and k'2=n in A)
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1082
       apply arith
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1083
      apply simp
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1084
      done
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1085
  } note B = this
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1086
  show ?thesis
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1087
    apply (induct n nw w bs rule: bin_rsplit_aux.induct)
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1088
    apply (subst bin_rsplit_aux.simps)
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1089
    apply (simp add: B Let_def split: prod.split)
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1090
    done
51612b889361 cleanup
haftmann
parents: 54869
diff changeset
  1091
qed
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1092
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1093
lemma bin_rsplit_len_le: 
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
  1094
  "n \<noteq> 0 --> ws = bin_rsplit n (nw, w) --> (length ws <= m) = (nw <= m * n)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1095
  unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len_le)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1096
 
45997
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
  1097
lemma bin_rsplit_aux_len:
13392893ea12 use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents: 45996
diff changeset
  1098
  "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n nw w cs) =
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1099
    (nw + n - 1) div n + length cs"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1100
  apply (induct n nw w cs rule: bin_rsplit_aux.induct)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1101
  apply (subst bin_rsplit_aux.simps)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
  1102
  apply (clarsimp simp: Let_def split: prod.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1103
  apply (erule thin_rl)
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 27105
diff changeset
  1104
  apply (case_tac m)
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 27105
diff changeset
  1105
  apply simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1106
  apply (case_tac "m <= n")
27677
646ea25ff59d (re-)added simp rules for (_ + _) div/mod _
haftmann
parents: 27651
diff changeset
  1107
  apply auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1108
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1109
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1110
lemma bin_rsplit_len: 
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
  1111
  "n\<noteq>0 ==> length (bin_rsplit n (nw, w)) = (nw + n - 1) div n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1112
  unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1113
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1114
lemma bin_rsplit_aux_len_indep:
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1115
  "n \<noteq> 0 \<Longrightarrow> length bs = length cs \<Longrightarrow>
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1116
    length (bin_rsplit_aux n nw v bs) =
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1117
    length (bin_rsplit_aux n nw w cs)"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1118
proof (induct n nw w cs arbitrary: v bs rule: bin_rsplit_aux.induct)
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1119
  case (1 n m w cs v bs) show ?case
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1120
  proof (cases "m = 0")
28298
3eb2855e5402 avoid using implicit assumptions
huffman
parents: 28059
diff changeset
  1121
    case True then show ?thesis using `length bs = length cs` by simp
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1122
  next
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1123
    case False
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1124
    from "1.hyps" `m \<noteq> 0` `n \<noteq> 0` have hyp: "\<And>v bs. length bs = Suc (length cs) \<Longrightarrow>
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1125
      length (bin_rsplit_aux n (m - n) v bs) =
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1126
      length (bin_rsplit_aux n (m - n) (fst (bin_split n w)) (snd (bin_split n w) # cs))"
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1127
    by auto
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1128
    show ?thesis using `length bs = length cs` `n \<noteq> 0`
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1129
      by (auto simp add: bin_rsplit_aux_simp_alt Let_def bin_rsplit_len
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents: 47219
diff changeset
  1130
        split: prod.split)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1131
  qed
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1132
qed
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1133
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1134
lemma bin_rsplit_len_indep: 
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
  1135
  "n\<noteq>0 ==> length (bin_rsplit n (nw, v)) = length (bin_rsplit n (nw, w))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1136
  apply (unfold bin_rsplit_def)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26086
diff changeset
  1137
  apply (simp (no_asm))
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1138
  apply (erule bin_rsplit_aux_len_indep)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1139
  apply (rule refl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1140
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1141
54874
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1142
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1143
text {* Even more bit operations *}
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1144
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1145
instantiation int :: bitss
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1146
begin
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1147
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1148
definition [iff]:
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1149
  "i !! n \<longleftrightarrow> bin_nth i n"
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1150
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1151
definition
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1152
  "lsb i = (i :: int) !! 0"
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1153
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1154
definition
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1155
  "set_bit i n b = bin_sc n b i"
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1156
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1157
definition
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1158
  "set_bits f =
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1159
  (if \<exists>n. \<forall>n'\<ge>n. \<not> f n' then 
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1160
     let n = LEAST n. \<forall>n'\<ge>n. \<not> f n'
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1161
     in bl_to_bin (rev (map f [0..<n]))
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1162
   else if \<exists>n. \<forall>n'\<ge>n. f n' then
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1163
     let n = LEAST n. \<forall>n'\<ge>n. f n'
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1164
     in sbintrunc n (bl_to_bin (True # rev (map f [0..<n])))
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1165
   else 0 :: int)"
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1166
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1167
definition
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1168
  "shiftl x n = (x :: int) * 2 ^ n"
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1169
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1170
definition
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1171
  "shiftr x n = (x :: int) div 2 ^ n"
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1172
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1173
definition
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1174
  "msb x \<longleftrightarrow> (x :: int) < 0"
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1175
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1176
instance ..
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1177
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
  1178
end
54874
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1179
c55c5dacd6a1 move instantiation here from AFP/Native_Word
haftmann
parents: 54871
diff changeset
  1180
end