src/HOL/Word/Bit_Representation.thy
author huffman
Thu, 22 Dec 2011 12:14:26 +0100
changeset 45952 ed9cc0634aaf
parent 45856 caa99836aed8
child 45953 1d6fcb19aa50
permissions -rw-r--r--
add lemma bin_nth_minus1
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: 44890
diff changeset
     4
  Basic definitions to do with integers, expressed using Pls, Min, BIT.
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     5
*) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     6
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     7
header {* Basic Definitions for Binary Integers *}
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     8
37658
df789294c77a more speaking names
haftmann
parents: 37654
diff changeset
     9
theory Bit_Representation
41413
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 37667
diff changeset
    10
imports Misc_Numeric "~~/src/HOL/Library/Bit"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    11
begin
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    12
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    13
subsection {* Further properties of numerals *}
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    14
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    15
definition bitval :: "bit \<Rightarrow> 'a\<Colon>zero_neq_one" where
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    16
  "bitval = bit_case 0 1"
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    17
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    18
lemma bitval_simps [simp]:
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    19
  "bitval 0 = 0"
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    20
  "bitval 1 = 1"
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    21
  by (simp_all add: bitval_def)
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    22
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
    23
definition Bit :: "int \<Rightarrow> bit \<Rightarrow> int" (infixl "BIT" 90) where
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    24
  "k BIT b = bitval b + k + k"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    25
45843
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    26
definition bin_last :: "int \<Rightarrow> bit" where
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    27
  "bin_last w = (if w mod 2 = 0 then (0::bit) else (1::bit))"
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    28
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    29
definition bin_rest :: "int \<Rightarrow> int" where
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    30
  "bin_rest w = w div 2"
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    31
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    32
lemma bin_rl_simp [simp]:
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    33
  "bin_rest w BIT bin_last w = w"
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    34
  unfolding bin_rest_def bin_last_def Bit_def
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    35
  using mod_div_equality [of w 2]
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    36
  by (cases "w mod 2 = 0", simp_all)
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    37
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    38
lemma bin_rest_BIT: "bin_rest (x BIT b) = x"
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    39
  unfolding bin_rest_def Bit_def
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    40
  by (cases b, simp_all)
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    41
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    42
lemma bin_last_BIT: "bin_last (x BIT b) = b"
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    43
  unfolding bin_last_def Bit_def
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    44
  by (cases b, simp_all add: z1pmod2)
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    45
45848
ec252975e82c declare BIT_eq_iff [iff]; remove unneeded lemmas
huffman
parents: 45847
diff changeset
    46
lemma BIT_eq_iff [iff]: "u BIT b = v BIT c \<longleftrightarrow> u = v \<and> b = c"
45843
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    47
  by (metis bin_rest_BIT bin_last_BIT)
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
    48
45849
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    49
lemma BIT_bin_simps [simp]:
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    50
  "number_of w BIT 0 = number_of (Int.Bit0 w)"
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    51
  "number_of w BIT 1 = number_of (Int.Bit1 w)"
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    52
  unfolding Bit_def number_of_is_id numeral_simps by simp_all
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    53
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    54
lemma BIT_special_simps [simp]:
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    55
  shows "0 BIT 0 = 0" and "0 BIT 1 = 1" and "1 BIT 0 = 2" and "1 BIT 1 = 3"
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    56
  unfolding Bit_def by simp_all
904d8e0eaec6 add simp rules for BIT applied to numerals
huffman
parents: 45848
diff changeset
    57
45851
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    58
lemma bin_last_numeral_simps [simp]:
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    59
  "bin_last 0 = 0"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    60
  "bin_last 1 = 1"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    61
  "bin_last -1 = 1"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    62
  "bin_last (number_of (Int.Bit0 w)) = 0"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    63
  "bin_last (number_of (Int.Bit1 w)) = 1"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    64
  unfolding bin_last_def by simp_all
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    65
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    66
lemma bin_rest_numeral_simps [simp]:
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    67
  "bin_rest 0 = 0"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    68
  "bin_rest 1 = 0"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    69
  "bin_rest -1 = -1"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    70
  "bin_rest (number_of (Int.Bit0 w)) = number_of w"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    71
  "bin_rest (number_of (Int.Bit1 w)) = number_of w"
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    72
  unfolding bin_rest_def by simp_all
19f7ac6cf3cc add simp rules for bin_rest and bin_last applied to numerals
huffman
parents: 45850
diff changeset
    73
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
    74
lemma BIT_B0_eq_Bit0: "w BIT 0 = Int.Bit0 w"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    75
  unfolding Bit_def Bit0_def by simp
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    76
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
    77
lemma BIT_B1_eq_Bit1: "w BIT 1 = Int.Bit1 w"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    78
  unfolding Bit_def Bit1_def by simp
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    79
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    80
lemmas BIT_simps = BIT_B0_eq_Bit0 BIT_B1_eq_Bit1
24384
0002537695df move BIT datatype stuff from Num_Lemmas to BinGeneral
huffman
parents: 24383
diff changeset
    81
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    82
lemma number_of_False_cong: 
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    83
  "False \<Longrightarrow> number_of x = number_of y"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    84
  by (rule FalseE)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    85
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    86
lemma less_Bits: 
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
    87
  "(v BIT b < w BIT c) = (v < w | v <= w & b = (0::bit) & c = (1::bit))"
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    88
  unfolding Bit_def by (auto simp add: bitval_def split: bit.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    89
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    90
lemma le_Bits: 
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
    91
  "(v BIT b <= w BIT c) = (v < w | v <= w & (b ~= (1::bit) | c ~= (0::bit)))" 
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
    92
  unfolding Bit_def by (auto simp add: bitval_def split: bit.split)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    93
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    94
lemma no_no [simp]: "number_of (number_of i) = i"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    95
  unfolding number_of_eq by simp
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    96
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    97
lemma Bit_B0:
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
    98
  "k BIT (0::bit) = k + k"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
    99
   by (unfold Bit_def) simp
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   100
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   101
lemma Bit_B1:
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   102
  "k BIT (1::bit) = k + k + 1"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   103
   by (unfold Bit_def) simp
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   104
  
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   105
lemma Bit_B0_2t: "k BIT (0::bit) = 2 * k"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   106
  by (rule trans, rule Bit_B0) simp
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   107
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   108
lemma Bit_B1_2t: "k BIT (1::bit) = 2 * k + 1"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   109
  by (rule trans, rule Bit_B1) simp
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   110
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   111
lemma B_mod_2': 
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   112
  "X = 2 ==> (w BIT (1::bit)) mod X = 1 & (w BIT (0::bit)) mod X = 0"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   113
  apply (simp (no_asm) only: Bit_B0 Bit_B1)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   114
  apply (simp add: z1pmod2)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   115
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   116
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   117
lemma B1_mod_2 [simp]: "(Int.Bit1 w) mod 2 = 1"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   118
  unfolding numeral_simps number_of_is_id by (simp add: z1pmod2)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   119
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   120
lemma B0_mod_2 [simp]: "(Int.Bit0 w) mod 2 = 0"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   121
  unfolding numeral_simps number_of_is_id by simp
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   122
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   123
lemma neB1E [elim!]:
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   124
  assumes ne: "y \<noteq> (1::bit)"
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   125
  assumes y: "y = (0::bit) \<Longrightarrow> P"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   126
  shows "P"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   127
  apply (rule y)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   128
  apply (cases y rule: bit.exhaust, simp)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   129
  apply (simp add: ne)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   130
  done
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   131
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   132
lemma bin_ex_rl: "EX w b. w BIT b = bin"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   133
  apply (unfold Bit_def)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   134
  apply (cases "even bin")
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   135
   apply (clarsimp simp: even_equiv_def)
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   136
   apply (auto simp: odd_equiv_def bitval_def split: bit.split)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   137
  done
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   138
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   139
lemma bin_exhaust:
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   140
  assumes Q: "\<And>x b. bin = x BIT b \<Longrightarrow> Q"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   141
  shows "Q"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   142
  apply (insert bin_ex_rl [of bin])  
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   143
  apply (erule exE)+
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   144
  apply (rule Q)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   145
  apply force
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   146
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   147
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   148
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   149
subsection {* Destructors for binary integers *}
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   150
37546
d1fa353e1c4a more direct definition simplifies proofs
haftmann
parents: 36176
diff changeset
   151
definition bin_rl :: "int \<Rightarrow> int \<times> bit" where 
d1fa353e1c4a more direct definition simplifies proofs
haftmann
parents: 36176
diff changeset
   152
  "bin_rl w = (bin_rest w, bin_last w)"
d1fa353e1c4a more direct definition simplifies proofs
haftmann
parents: 36176
diff changeset
   153
d1fa353e1c4a more direct definition simplifies proofs
haftmann
parents: 36176
diff changeset
   154
lemma bin_rl_char: "bin_rl w = (r, l) \<longleftrightarrow> r BIT l = w"
45843
c58ce659ce2a reorder some definitions and proofs, in preparation for new numeral representation
huffman
parents: 45604
diff changeset
   155
  unfolding bin_rl_def by (auto simp: bin_rest_BIT bin_last_BIT)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   156
26514
eff55c0a6d34 tuned towards code generation
haftmann
parents: 26294
diff changeset
   157
primrec bin_nth where
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   158
  Z: "bin_nth w 0 = (bin_last w = (1::bit))"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   159
  | Suc: "bin_nth w (Suc n) = bin_nth (bin_rest w) n"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   160
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   161
lemma bin_rl_simps [simp]:
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   162
  "bin_rl Int.Pls = (Int.Pls, (0::bit))"
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   163
  "bin_rl Int.Min = (Int.Min, (1::bit))"
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   164
  "bin_rl (Int.Bit0 r) = (r, (0::bit))"
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   165
  "bin_rl (Int.Bit1 r) = (r, (1::bit))"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   166
  "bin_rl (r BIT b) = (r, b)"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   167
  unfolding bin_rl_char by (simp_all add: BIT_simps)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   168
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   169
lemma bin_abs_lem:
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   170
  "bin = (w BIT b) ==> ~ bin = Int.Min --> ~ bin = Int.Pls -->
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   171
    nat (abs w) < nat (abs bin)"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   172
  apply (clarsimp simp add: bin_rl_char)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   173
  apply (unfold Pls_def Min_def Bit_def)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   174
  apply (cases b)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   175
   apply (clarsimp, arith)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   176
  apply (clarsimp, arith)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   177
  done
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   178
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   179
lemma bin_induct:
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   180
  assumes PPls: "P Int.Pls"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   181
    and PMin: "P Int.Min"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   182
    and PBit: "!!bin bit. P bin ==> P (bin BIT bit)"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   183
  shows "P bin"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   184
  apply (rule_tac P=P and a=bin and f1="nat o abs" 
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   185
                  in wf_measure [THEN wf_induct])
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   186
  apply (simp add: measure_def inv_image_def)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   187
  apply (case_tac x rule: bin_exhaust)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   188
  apply (frule bin_abs_lem)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   189
  apply (auto simp add : PPls PMin PBit)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   190
  done
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   191
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   192
lemma numeral_induct:
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   193
  assumes Pls: "P Int.Pls"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   194
  assumes Min: "P Int.Min"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   195
  assumes Bit0: "\<And>w. \<lbrakk>P w; w \<noteq> Int.Pls\<rbrakk> \<Longrightarrow> P (Int.Bit0 w)"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   196
  assumes Bit1: "\<And>w. \<lbrakk>P w; w \<noteq> Int.Min\<rbrakk> \<Longrightarrow> P (Int.Bit1 w)"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   197
  shows "P x"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   198
  apply (induct x rule: bin_induct)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   199
    apply (rule Pls)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   200
   apply (rule Min)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   201
  apply (case_tac bit)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   202
   apply (case_tac "bin = Int.Pls")
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   203
    apply (simp add: BIT_simps)
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   204
   apply (simp add: Bit0 BIT_simps)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   205
  apply (case_tac "bin = Int.Min")
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   206
   apply (simp add: BIT_simps)
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   207
  apply (simp add: Bit1 BIT_simps)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   208
  done
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   209
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   210
lemma bin_rest_simps [simp]: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   211
  "bin_rest Int.Pls = Int.Pls"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   212
  "bin_rest Int.Min = Int.Min"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   213
  "bin_rest (Int.Bit0 w) = w"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   214
  "bin_rest (Int.Bit1 w) = w"
26514
eff55c0a6d34 tuned towards code generation
haftmann
parents: 26294
diff changeset
   215
  "bin_rest (w BIT b) = w"
37546
d1fa353e1c4a more direct definition simplifies proofs
haftmann
parents: 36176
diff changeset
   216
  using bin_rl_simps bin_rl_def by auto
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   217
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   218
lemma bin_last_simps [simp]: 
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   219
  "bin_last Int.Pls = (0::bit)"
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   220
  "bin_last Int.Min = (1::bit)"
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   221
  "bin_last (Int.Bit0 w) = (0::bit)"
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   222
  "bin_last (Int.Bit1 w) = (1::bit)"
26514
eff55c0a6d34 tuned towards code generation
haftmann
parents: 26294
diff changeset
   223
  "bin_last (w BIT b) = b"
37546
d1fa353e1c4a more direct definition simplifies proofs
haftmann
parents: 36176
diff changeset
   224
  using bin_rl_simps bin_rl_def by auto
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   225
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   226
lemma Bit_div2 [simp]: "(w BIT b) div 2 = w"
45529
0e1037d4e049 remove redundant lemmas bin_last_mod and bin_rest_div, use bin_last_def and bin_rest_def instead
huffman
parents: 44939
diff changeset
   227
  unfolding bin_rest_def [symmetric] by auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   228
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   229
lemma Bit0_div2 [simp]: "(Int.Bit0 w) div 2 = w"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   230
  using Bit_div2 [where b="(0::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   231
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   232
lemma Bit1_div2 [simp]: "(Int.Bit1 w) div 2 = w"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   233
  using Bit_div2 [where b="(1::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   234
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   235
lemma bin_nth_lem [rule_format]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   236
  "ALL y. bin_nth x = bin_nth y --> x = y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   237
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   238
    apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   239
    apply (erule rev_mp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   240
    apply (induct_tac y rule: bin_induct)
26827
a62f8db42f4a Deleted subset_antisym in a few proofs, because it is
berghofe
parents: 26557
diff changeset
   241
      apply (safe del: subset_antisym)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   242
      apply (drule_tac x=0 in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   243
     apply (erule notE, rule ext, 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   244
            drule_tac x="Suc x" in fun_cong, force)
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   245
    apply (drule_tac x=0 in fun_cong, force simp: BIT_simps)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   246
   apply (erule rev_mp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   247
   apply (induct_tac y rule: bin_induct)
26827
a62f8db42f4a Deleted subset_antisym in a few proofs, because it is
berghofe
parents: 26557
diff changeset
   248
     apply (safe del: subset_antisym)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   249
     apply (drule_tac x=0 in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   250
    apply (erule notE, rule ext, 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   251
           drule_tac x="Suc x" in fun_cong, force)
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   252
   apply (drule_tac x=0 in fun_cong, force simp: BIT_simps)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   253
  apply (case_tac y rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   254
  apply clarify
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   255
  apply (erule allE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   256
  apply (erule impE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   257
   prefer 2
45848
ec252975e82c declare BIT_eq_iff [iff]; remove unneeded lemmas
huffman
parents: 45847
diff changeset
   258
   apply (erule conjI)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   259
   apply (drule_tac x=0 in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   260
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   261
  apply (drule_tac x="Suc ?x" in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   262
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   263
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   264
lemma bin_nth_eq_iff: "(bin_nth x = bin_nth y) = (x = y)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   265
  by (auto elim: bin_nth_lem)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   266
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   267
lemmas bin_eqI = ext [THEN bin_nth_eq_iff [THEN iffD1]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   268
45543
827bf668c822 HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents: 45529
diff changeset
   269
lemma bin_eq_iff: "x = y \<longleftrightarrow> (\<forall>n. bin_nth x n = bin_nth y n)"
827bf668c822 HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents: 45529
diff changeset
   270
  by (auto intro!: bin_nth_lem del: equalityI)
827bf668c822 HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents: 45529
diff changeset
   271
45853
cbb6f2243b52 add lemma bin_nth_zero
huffman
parents: 45852
diff changeset
   272
lemma bin_nth_zero [simp]: "\<not> bin_nth 0 n"
cbb6f2243b52 add lemma bin_nth_zero
huffman
parents: 45852
diff changeset
   273
  by (induct n) auto
cbb6f2243b52 add lemma bin_nth_zero
huffman
parents: 45852
diff changeset
   274
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   275
lemma bin_nth_Pls [simp]: "~ bin_nth Int.Pls n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   276
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   277
45952
ed9cc0634aaf add lemma bin_nth_minus1
huffman
parents: 45856
diff changeset
   278
lemma bin_nth_minus1 [simp]: "bin_nth -1 n"
ed9cc0634aaf add lemma bin_nth_minus1
huffman
parents: 45856
diff changeset
   279
  by (induct n) auto
ed9cc0634aaf add lemma bin_nth_minus1
huffman
parents: 45856
diff changeset
   280
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   281
lemma bin_nth_Min [simp]: "bin_nth Int.Min n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   282
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   283
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   284
lemma bin_nth_0_BIT: "bin_nth (w BIT b) 0 = (b = (1::bit))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   285
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   286
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   287
lemma bin_nth_Suc_BIT: "bin_nth (w BIT b) (Suc n) = bin_nth w n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   288
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   289
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   290
lemma bin_nth_minus [simp]: "0 < n ==> bin_nth (w BIT b) n = bin_nth w (n - 1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   291
  by (cases n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   292
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   293
lemma bin_nth_minus_Bit0 [simp]:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   294
  "0 < n ==> bin_nth (Int.Bit0 w) n = bin_nth w (n - 1)"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   295
  using bin_nth_minus [where b="(0::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   296
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   297
lemma bin_nth_minus_Bit1 [simp]:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   298
  "0 < n ==> bin_nth (Int.Bit1 w) n = bin_nth w (n - 1)"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   299
  using bin_nth_minus [where b="(1::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   300
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   301
lemmas bin_nth_0 = bin_nth.simps(1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   302
lemmas bin_nth_Suc = bin_nth.simps(2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   303
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   304
lemmas bin_nth_simps = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   305
  bin_nth_0 bin_nth_Suc bin_nth_Pls bin_nth_Min bin_nth_minus
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   306
  bin_nth_minus_Bit0 bin_nth_minus_Bit1
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   307
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   308
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   309
subsection {* Truncating binary integers *}
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   310
45846
518a245a1ab6 type signature for bin_sign
huffman
parents: 45845
diff changeset
   311
definition bin_sign :: "int \<Rightarrow> int" where
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   312
  bin_sign_def: "bin_sign k = (if k \<ge> 0 then 0 else - 1)"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   313
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   314
lemma bin_sign_simps [simp]:
45850
50488b8abd58 add simp rules for bin_sign applied to numerals
huffman
parents: 45849
diff changeset
   315
  "bin_sign 0 = 0"
50488b8abd58 add simp rules for bin_sign applied to numerals
huffman
parents: 45849
diff changeset
   316
  "bin_sign -1 = -1"
50488b8abd58 add simp rules for bin_sign applied to numerals
huffman
parents: 45849
diff changeset
   317
  "bin_sign (number_of (Int.Bit0 w)) = bin_sign (number_of w)"
50488b8abd58 add simp rules for bin_sign applied to numerals
huffman
parents: 45849
diff changeset
   318
  "bin_sign (number_of (Int.Bit1 w)) = bin_sign (number_of w)"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   319
  "bin_sign Int.Pls = Int.Pls"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   320
  "bin_sign Int.Min = Int.Min"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   321
  "bin_sign (Int.Bit0 w) = bin_sign w"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   322
  "bin_sign (Int.Bit1 w) = bin_sign w"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   323
  "bin_sign (w BIT b) = bin_sign w"
45850
50488b8abd58 add simp rules for bin_sign applied to numerals
huffman
parents: 45849
diff changeset
   324
  unfolding bin_sign_def numeral_simps Bit_def bitval_def number_of_is_id
50488b8abd58 add simp rules for bin_sign applied to numerals
huffman
parents: 45849
diff changeset
   325
  by (simp_all split: bit.split)
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   326
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   327
lemma bin_sign_rest [simp]: 
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   328
  "bin_sign (bin_rest w) = bin_sign w"
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   329
  by (cases w rule: bin_exhaust) auto
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   330
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   331
primrec bintrunc :: "nat \<Rightarrow> int \<Rightarrow> int" where
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   332
  Z : "bintrunc 0 bin = Int.Pls"
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   333
| Suc : "bintrunc (Suc n) bin = bintrunc n (bin_rest bin) BIT (bin_last bin)"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   334
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   335
primrec sbintrunc :: "nat => int => int" where
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   336
  Z : "sbintrunc 0 bin = 
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   337
    (case bin_last bin of (1::bit) => Int.Min | (0::bit) => Int.Pls)"
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   338
| Suc : "sbintrunc (Suc n) bin = sbintrunc n (bin_rest bin) BIT (bin_last bin)"
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   339
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   340
lemma [code]:
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   341
  "sbintrunc 0 bin = 
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   342
    (case bin_last bin of (1::bit) => - 1 | (0::bit) => 0)"
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   343
  "sbintrunc (Suc n) bin = sbintrunc n (bin_rest bin) BIT (bin_last bin)"
45845
4158f35a5c6f remove some unwanted numeral-representation-specific simp rules
huffman
parents: 45844
diff changeset
   344
  apply simp_all
4158f35a5c6f remove some unwanted numeral-representation-specific simp rules
huffman
parents: 45844
diff changeset
   345
  apply (simp only: Pls_def Min_def)
4158f35a5c6f remove some unwanted numeral-representation-specific simp rules
huffman
parents: 45844
diff changeset
   346
  done
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   347
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   348
lemma sign_bintr:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   349
  "!!w. bin_sign (bintrunc n w) = Int.Pls"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   350
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   351
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   352
lemma bintrunc_mod2p:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   353
  "!!w. bintrunc n w = (w mod 2 ^ n :: int)"
45845
4158f35a5c6f remove some unwanted numeral-representation-specific simp rules
huffman
parents: 45844
diff changeset
   354
  apply (induct n)
4158f35a5c6f remove some unwanted numeral-representation-specific simp rules
huffman
parents: 45844
diff changeset
   355
  apply (simp add: Pls_def)
45529
0e1037d4e049 remove redundant lemmas bin_last_mod and bin_rest_div, use bin_last_def and bin_rest_def instead
huffman
parents: 44939
diff changeset
   356
  apply (simp add: bin_last_def bin_rest_def Bit_def zmod_zmult2_eq
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   357
              cong: number_of_False_cong)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   358
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   359
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   360
lemma sbintrunc_mod2p:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   361
  "!!w. sbintrunc n w = ((w + 2 ^ n) mod 2 ^ (Suc n) - 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   362
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   363
   apply clarsimp
30034
60f64f112174 removed redundant thms
nipkow
parents: 29631
diff changeset
   364
   apply (subst mod_add_left_eq)
45529
0e1037d4e049 remove redundant lemmas bin_last_mod and bin_rest_div, use bin_last_def and bin_rest_def instead
huffman
parents: 44939
diff changeset
   365
   apply (simp add: bin_last_def)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   366
   apply (simp add: number_of_eq)
45845
4158f35a5c6f remove some unwanted numeral-representation-specific simp rules
huffman
parents: 45844
diff changeset
   367
  apply (simp add: Pls_def)
45529
0e1037d4e049 remove redundant lemmas bin_last_mod and bin_rest_div, use bin_last_def and bin_rest_def instead
huffman
parents: 44939
diff changeset
   368
  apply (simp add: bin_last_def bin_rest_def Bit_def 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   369
              cong: number_of_False_cong)
30940
663af91c0720 zmod_zmult_zmult1 now subsumed by mod_mult_mult1
haftmann
parents: 30034
diff changeset
   370
  apply (clarsimp simp: mod_mult_mult1 [symmetric] 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   371
         zmod_zdiv_equality [THEN diff_eq_eq [THEN iffD2 [THEN sym]]])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   372
  apply (rule trans [symmetric, OF _ emep1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   373
     apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   374
  apply (auto simp: even_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   375
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   376
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   377
subsection "Simplifications for (s)bintrunc"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   378
45852
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   379
lemma bintrunc_n_0 [simp]: "bintrunc n 0 = 0"
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   380
  by (induct n) (auto simp add: Int.Pls_def)
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   381
45855
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   382
lemma sbintrunc_n_0 [simp]: "sbintrunc n 0 = 0"
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   383
  by (induct n) (auto simp add: Int.Pls_def)
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   384
45856
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   385
lemma sbintrunc_n_minus1 [simp]: "sbintrunc n -1 = -1"
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   386
  by (induct n) (auto, simp add: number_of_is_id)
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   387
45852
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   388
lemma bintrunc_Suc_numeral:
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   389
  "bintrunc (Suc n) 1 = 1"
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   390
  "bintrunc (Suc n) -1 = bintrunc n -1 BIT 1"
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   391
  "bintrunc (Suc n) (number_of (Int.Bit0 w)) = bintrunc n (number_of w) BIT 0"
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   392
  "bintrunc (Suc n) (number_of (Int.Bit1 w)) = bintrunc n (number_of w) BIT 1"
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   393
  by simp_all
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   394
45856
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   395
lemma sbintrunc_0_numeral [simp]:
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   396
  "sbintrunc 0 1 = -1"
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   397
  "sbintrunc 0 (number_of (Int.Bit0 w)) = 0"
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   398
  "sbintrunc 0 (number_of (Int.Bit1 w)) = -1"
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   399
  by (simp_all, unfold Pls_def number_of_is_id, simp_all)
caa99836aed8 more simp rules for sbintrunc
huffman
parents: 45855
diff changeset
   400
45855
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   401
lemma sbintrunc_Suc_numeral:
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   402
  "sbintrunc (Suc n) 1 = 1"
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   403
  "sbintrunc (Suc n) (number_of (Int.Bit0 w)) = sbintrunc n (number_of w) BIT 0"
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   404
  "sbintrunc (Suc n) (number_of (Int.Bit1 w)) = sbintrunc n (number_of w) BIT 1"
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   405
  by simp_all
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   406
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   407
lemma bit_bool:
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   408
  "(b = (b' = (1::bit))) = (b' = (if b then (1::bit) else (0::bit)))"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   409
  by (cases b') auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   410
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   411
lemmas bit_bool1 [simp] = refl [THEN bit_bool [THEN iffD1], symmetric]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   412
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   413
lemma bin_sign_lem:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   414
  "!!bin. (bin_sign (sbintrunc n bin) = Int.Min) = bin_nth bin n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   415
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   416
   apply (case_tac bin rule: bin_exhaust, case_tac b, auto)+
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   417
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   418
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   419
lemma nth_bintr:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   420
  "!!w m. bin_nth (bintrunc m w) n = (n < m & bin_nth w n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   421
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   422
   apply (case_tac m, auto)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   423
  apply (case_tac m, auto)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   424
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   425
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   426
lemma nth_sbintr:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   427
  "!!w m. bin_nth (sbintrunc m w) n = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   428
          (if n < m then bin_nth w n else bin_nth w m)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   429
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   430
   apply (case_tac m, simp_all split: bit.splits)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   431
  apply (case_tac m, simp_all split: bit.splits)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   432
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   433
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   434
lemma bin_nth_Bit:
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   435
  "bin_nth (w BIT b) n = (n = 0 & b = (1::bit) | (EX m. n = Suc m & bin_nth w m))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   436
  by (cases n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   437
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   438
lemma bin_nth_Bit0:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   439
  "bin_nth (Int.Bit0 w) n = (EX m. n = Suc m & bin_nth w m)"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   440
  using bin_nth_Bit [where b="(0::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   441
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   442
lemma bin_nth_Bit1:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   443
  "bin_nth (Int.Bit1 w) n = (n = 0 | (EX m. n = Suc m & bin_nth w m))"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   444
  using bin_nth_Bit [where b="(1::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   445
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   446
lemma bintrunc_bintrunc_l:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   447
  "n <= m ==> (bintrunc m (bintrunc n w) = bintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   448
  by (rule bin_eqI) (auto simp add : nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   449
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   450
lemma sbintrunc_sbintrunc_l:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   451
  "n <= m ==> (sbintrunc m (sbintrunc n w) = sbintrunc n w)"
32439
7a91c7bcfe7e tuned proofs
nipkow
parents: 30971
diff changeset
   452
  by (rule bin_eqI) (auto simp: nth_sbintr)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   453
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   454
lemma bintrunc_bintrunc_ge:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   455
  "n <= m ==> (bintrunc n (bintrunc m w) = bintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   456
  by (rule bin_eqI) (auto simp: nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   457
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   458
lemma bintrunc_bintrunc_min [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   459
  "bintrunc m (bintrunc n w) = bintrunc (min m n) w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   460
  apply (rule bin_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   461
  apply (auto simp: nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   462
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   463
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   464
lemma sbintrunc_sbintrunc_min [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   465
  "sbintrunc m (sbintrunc n w) = sbintrunc (min m n) w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   466
  apply (rule bin_eqI)
32642
026e7c6a6d08 be more cautious wrt. simp rules: inf_absorb1, inf_absorb2, sup_absorb1, sup_absorb2 are no simp rules by default any longer
haftmann
parents: 32439
diff changeset
   467
  apply (auto simp: nth_sbintr min_max.inf_absorb1 min_max.inf_absorb2)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   468
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   469
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   470
lemmas bintrunc_Pls = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   471
  bintrunc.Suc [where bin="Int.Pls", simplified bin_last_simps bin_rest_simps]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   472
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   473
lemmas bintrunc_Min [simp] = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   474
  bintrunc.Suc [where bin="Int.Min", simplified bin_last_simps bin_rest_simps]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   475
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   476
lemmas bintrunc_BIT  [simp] = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   477
  bintrunc.Suc [where bin="w BIT b", simplified bin_last_simps bin_rest_simps] for w b
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   478
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   479
lemma bintrunc_Bit0 [simp]:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   480
  "bintrunc (Suc n) (Int.Bit0 w) = Int.Bit0 (bintrunc n w)"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   481
  using bintrunc_BIT [where b="(0::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   482
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   483
lemma bintrunc_Bit1 [simp]:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   484
  "bintrunc (Suc n) (Int.Bit1 w) = Int.Bit1 (bintrunc n w)"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   485
  using bintrunc_BIT [where b="(1::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   486
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   487
lemmas bintrunc_Sucs = bintrunc_Pls bintrunc_Min bintrunc_BIT
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   488
  bintrunc_Bit0 bintrunc_Bit1
45852
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   489
  bintrunc_Suc_numeral
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   490
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   491
lemmas sbintrunc_Suc_Pls = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   492
  sbintrunc.Suc [where bin="Int.Pls", simplified bin_last_simps bin_rest_simps]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   493
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   494
lemmas sbintrunc_Suc_Min = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   495
  sbintrunc.Suc [where bin="Int.Min", simplified bin_last_simps bin_rest_simps]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   496
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   497
lemmas sbintrunc_Suc_BIT [simp] = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   498
  sbintrunc.Suc [where bin="w BIT b", simplified bin_last_simps bin_rest_simps] for w b
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   499
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   500
lemma sbintrunc_Suc_Bit0 [simp]:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   501
  "sbintrunc (Suc n) (Int.Bit0 w) = Int.Bit0 (sbintrunc n w)"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   502
  using sbintrunc_Suc_BIT [where b="(0::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   503
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   504
lemma sbintrunc_Suc_Bit1 [simp]:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   505
  "sbintrunc (Suc n) (Int.Bit1 w) = Int.Bit1 (sbintrunc n w)"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   506
  using sbintrunc_Suc_BIT [where b="(1::bit)"] by (simp add: BIT_simps)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   507
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   508
lemmas sbintrunc_Sucs = sbintrunc_Suc_Pls sbintrunc_Suc_Min sbintrunc_Suc_BIT
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   509
  sbintrunc_Suc_Bit0 sbintrunc_Suc_Bit1
45855
b49cffac6c97 add simp rules for sbintrunc applied to numerals
huffman
parents: 45853
diff changeset
   510
  sbintrunc_Suc_numeral
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   511
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   512
lemmas sbintrunc_Pls = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   513
  sbintrunc.Z [where bin="Int.Pls", 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   514
               simplified bin_last_simps bin_rest_simps bit.simps]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   515
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   516
lemmas sbintrunc_Min = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   517
  sbintrunc.Z [where bin="Int.Min", 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   518
               simplified bin_last_simps bin_rest_simps bit.simps]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   519
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   520
lemmas sbintrunc_0_BIT_B0 [simp] = 
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   521
  sbintrunc.Z [where bin="w BIT (0::bit)", 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   522
               simplified bin_last_simps bin_rest_simps bit.simps] for w
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   523
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   524
lemmas sbintrunc_0_BIT_B1 [simp] = 
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   525
  sbintrunc.Z [where bin="w BIT (1::bit)", 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   526
               simplified bin_last_simps bin_rest_simps bit.simps] for w
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   527
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   528
lemma sbintrunc_0_Bit0 [simp]: "sbintrunc 0 (Int.Bit0 w) = Int.Pls"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   529
  using sbintrunc_0_BIT_B0 by simp
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   530
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   531
lemma sbintrunc_0_Bit1 [simp]: "sbintrunc 0 (Int.Bit1 w) = Int.Min"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   532
  using sbintrunc_0_BIT_B1 by simp
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   533
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   534
lemmas sbintrunc_0_simps =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   535
  sbintrunc_Pls sbintrunc_Min sbintrunc_0_BIT_B0 sbintrunc_0_BIT_B1
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   536
  sbintrunc_0_Bit0 sbintrunc_0_Bit1
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   537
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   538
lemmas bintrunc_simps = bintrunc.Z bintrunc_Sucs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   539
lemmas sbintrunc_simps = sbintrunc_0_simps sbintrunc_Sucs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   540
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   541
lemma bintrunc_minus:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   542
  "0 < n ==> bintrunc (Suc (n - 1)) w = bintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   543
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   544
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   545
lemma sbintrunc_minus:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   546
  "0 < n ==> sbintrunc (Suc (n - 1)) w = sbintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   547
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   548
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   549
lemmas bintrunc_minus_simps = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   550
  bintrunc_Sucs [THEN [2] bintrunc_minus [symmetric, THEN trans]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   551
lemmas sbintrunc_minus_simps = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   552
  sbintrunc_Sucs [THEN [2] sbintrunc_minus [symmetric, THEN trans]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   553
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   554
lemma bintrunc_n_Pls [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   555
  "bintrunc n Int.Pls = Int.Pls"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   556
  by (induct n) (auto simp: BIT_simps)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   557
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   558
lemma sbintrunc_n_PM [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   559
  "sbintrunc n Int.Pls = Int.Pls"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   560
  "sbintrunc n Int.Min = Int.Min"
45847
b4254b2e2b4a towards removing BIT_simps from the simpset
huffman
parents: 45846
diff changeset
   561
  by (induct n) (auto simp: BIT_simps)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   562
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   563
lemmas thobini1 = arg_cong [where f = "%w. w BIT b"] for b
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   564
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   565
lemmas bintrunc_BIT_I = trans [OF bintrunc_BIT thobini1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   566
lemmas bintrunc_Min_I = trans [OF bintrunc_Min thobini1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   567
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   568
lemmas bmsts = bintrunc_minus_simps(1-3) [THEN thobini1 [THEN [2] trans]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   569
lemmas bintrunc_Pls_minus_I = bmsts(1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   570
lemmas bintrunc_Min_minus_I = bmsts(2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   571
lemmas bintrunc_BIT_minus_I = bmsts(3)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   572
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   573
lemma bintrunc_0_Min: "bintrunc 0 Int.Min = Int.Pls"
45852
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   574
  by (fact bintrunc.Z) (* FIXME: delete *)
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   575
lemma bintrunc_0_BIT: "bintrunc 0 (w BIT b) = Int.Pls"
45852
24f563d94497 add simp rules for bintrunc applied to numerals
huffman
parents: 45851
diff changeset
   576
  by (fact bintrunc.Z) (* FIXME: delete *)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   577
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   578
lemma bintrunc_Suc_lem:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   579
  "bintrunc (Suc n) x = y ==> m = Suc n ==> bintrunc m x = y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   580
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   581
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   582
lemmas bintrunc_Suc_Ialts = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   583
  bintrunc_Min_I [THEN bintrunc_Suc_lem]
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   584
  bintrunc_BIT_I [THEN bintrunc_Suc_lem]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   585
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   586
lemmas sbintrunc_BIT_I = trans [OF sbintrunc_Suc_BIT thobini1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   587
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   588
lemmas sbintrunc_Suc_Is = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   589
  sbintrunc_Sucs(1-3) [THEN thobini1 [THEN [2] trans]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   590
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   591
lemmas sbintrunc_Suc_minus_Is = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   592
  sbintrunc_minus_simps(1-3) [THEN thobini1 [THEN [2] trans]]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   593
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   594
lemma sbintrunc_Suc_lem:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   595
  "sbintrunc (Suc n) x = y ==> m = Suc n ==> sbintrunc m x = y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   596
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   597
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   598
lemmas sbintrunc_Suc_Ialts = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   599
  sbintrunc_Suc_Is [THEN sbintrunc_Suc_lem]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   600
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   601
lemma sbintrunc_bintrunc_lt:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   602
  "m > n ==> sbintrunc n (bintrunc m w) = sbintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   603
  by (rule bin_eqI) (auto simp: nth_sbintr nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   604
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   605
lemma bintrunc_sbintrunc_le:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   606
  "m <= Suc n ==> bintrunc m (sbintrunc n w) = bintrunc m w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   607
  apply (rule bin_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   608
  apply (auto simp: nth_sbintr nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   609
   apply (subgoal_tac "x=n", safe, arith+)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   610
  apply (subgoal_tac "x=n", safe, arith+)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   611
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   612
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   613
lemmas bintrunc_sbintrunc [simp] = order_refl [THEN bintrunc_sbintrunc_le]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   614
lemmas sbintrunc_bintrunc [simp] = lessI [THEN sbintrunc_bintrunc_lt]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   615
lemmas bintrunc_bintrunc [simp] = order_refl [THEN bintrunc_bintrunc_l]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   616
lemmas sbintrunc_sbintrunc [simp] = order_refl [THEN sbintrunc_sbintrunc_l] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   617
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   618
lemma bintrunc_sbintrunc' [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   619
  "0 < n \<Longrightarrow> bintrunc n (sbintrunc (n - 1) w) = bintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   620
  by (cases n) (auto simp del: bintrunc.Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   621
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   622
lemma sbintrunc_bintrunc' [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   623
  "0 < n \<Longrightarrow> sbintrunc (n - 1) (bintrunc n w) = sbintrunc (n - 1) w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   624
  by (cases n) (auto simp del: bintrunc.Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   625
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   626
lemma bin_sbin_eq_iff: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   627
  "bintrunc (Suc n) x = bintrunc (Suc n) y <-> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   628
   sbintrunc n x = sbintrunc n y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   629
  apply (rule iffI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   630
   apply (rule box_equals [OF _ sbintrunc_bintrunc sbintrunc_bintrunc])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   631
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   632
  apply (rule box_equals [OF _ bintrunc_sbintrunc bintrunc_sbintrunc])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   633
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   634
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   635
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   636
lemma bin_sbin_eq_iff':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   637
  "0 < n \<Longrightarrow> bintrunc n x = bintrunc n y <-> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   638
            sbintrunc (n - 1) x = sbintrunc (n - 1) y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   639
  by (cases n) (simp_all add: bin_sbin_eq_iff del: bintrunc.Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   640
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   641
lemmas bintrunc_sbintruncS0 [simp] = bintrunc_sbintrunc' [unfolded One_nat_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   642
lemmas sbintrunc_bintruncS0 [simp] = sbintrunc_bintrunc' [unfolded One_nat_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   643
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   644
lemmas bintrunc_bintrunc_l' = le_add1 [THEN bintrunc_bintrunc_l]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   645
lemmas sbintrunc_sbintrunc_l' = le_add1 [THEN sbintrunc_sbintrunc_l]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   646
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   647
(* although bintrunc_minus_simps, if added to default simpset,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   648
  tends to get applied where it's not wanted in developing the theories,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   649
  we get a version for when the word length is given literally *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   650
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   651
lemmas nat_non0_gr = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   652
  trans [OF iszero_def [THEN Not_eq_iff [THEN iffD2]] refl]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   653
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   654
lemmas bintrunc_pred_simps [simp] = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   655
  bintrunc_minus_simps [of "number_of bin", simplified nobm1] for bin
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   656
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   657
lemmas sbintrunc_pred_simps [simp] = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   658
  sbintrunc_minus_simps [of "number_of bin", simplified nobm1] for bin
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   659
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   660
lemma no_bintr_alt:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   661
  "number_of (bintrunc n w) = w mod 2 ^ n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   662
  by (simp add: number_of_eq bintrunc_mod2p)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   663
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   664
lemma no_bintr_alt1: "bintrunc n = (%w. w mod 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   665
  by (rule ext) (rule bintrunc_mod2p)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   666
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   667
lemma range_bintrunc: "range (bintrunc n) = {i. 0 <= i & i < 2 ^ n}"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   668
  apply (unfold no_bintr_alt1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   669
  apply (auto simp add: image_iff)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   670
  apply (rule exI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   671
  apply (auto intro: int_mod_lem [THEN iffD1, symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   672
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   673
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   674
lemma no_bintr: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   675
  "number_of (bintrunc n w) = (number_of w mod 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   676
  by (simp add : bintrunc_mod2p number_of_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   677
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   678
lemma no_sbintr_alt2: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   679
  "sbintrunc n = (%w. (w + 2 ^ n) mod 2 ^ Suc n - 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   680
  by (rule ext) (simp add : sbintrunc_mod2p)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   681
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   682
lemma no_sbintr: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   683
  "number_of (sbintrunc n w) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   684
   ((number_of w + 2 ^ n) mod 2 ^ Suc n - 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   685
  by (simp add : no_sbintr_alt2 number_of_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   686
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   687
lemma range_sbintrunc: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   688
  "range (sbintrunc n) = {i. - (2 ^ n) <= i & i < 2 ^ n}"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   689
  apply (unfold no_sbintr_alt2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   690
  apply (auto simp add: image_iff eq_diff_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   691
  apply (rule exI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   692
  apply (auto intro: int_mod_lem [THEN iffD1, symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   693
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   694
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   695
lemma sb_inc_lem:
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   696
  "(a::int) + 2^k < 0 \<Longrightarrow> a + 2^k + 2^(Suc k) <= (a + 2^k) mod 2^(Suc k)"
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   697
  apply (erule int_mod_ge' [where n = "2 ^ (Suc k)" and b = "a + 2 ^ k", simplified zless2p])
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   698
  apply (rule TrueI)
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   699
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   700
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   701
lemma sb_inc_lem':
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   702
  "(a::int) < - (2^k) \<Longrightarrow> a + 2^k + 2^(Suc k) <= (a + 2^k) mod 2^(Suc k)"
35048
82ab78fff970 tuned proofs
haftmann
parents: 32642
diff changeset
   703
  by (rule sb_inc_lem) simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   704
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   705
lemma sbintrunc_inc:
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   706
  "x < - (2^n) ==> x + 2^(Suc n) <= sbintrunc n x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   707
  unfolding no_sbintr_alt2 by (drule sb_inc_lem') simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   708
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   709
lemma sb_dec_lem:
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   710
  "(0::int) <= - (2^k) + a ==> (a + 2^k) mod (2 * 2 ^ k) <= - (2 ^ k) + a"
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   711
  by (rule int_mod_le' [where n = "2 ^ (Suc k)" and b = "a + 2 ^ k",
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   712
    simplified zless2p, OF _ TrueI, simplified])
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   713
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   714
lemma sb_dec_lem':
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   715
  "(2::int) ^ k <= a ==> (a + 2 ^ k) mod (2 * 2 ^ k) <= - (2 ^ k) + a"
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   716
  by (rule iffD1 [OF diff_le_eq', THEN sb_dec_lem, simplified])
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   717
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   718
lemma sbintrunc_dec:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   719
  "x >= (2 ^ n) ==> x - 2 ^ (Suc n) >= sbintrunc n x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   720
  unfolding no_sbintr_alt2 by (drule sb_dec_lem') simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   721
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   722
lemmas zmod_uminus' = zmod_uminus [where b=c] for c
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   723
lemmas zpower_zmod' = zpower_zmod [where m=c and y=k] for c k
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   724
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   725
lemmas brdmod1s' [symmetric] = 
30034
60f64f112174 removed redundant thms
nipkow
parents: 29631
diff changeset
   726
  mod_add_left_eq mod_add_right_eq 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   727
  zmod_zsub_left_eq zmod_zsub_right_eq 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   728
  zmod_zmult1_eq zmod_zmult1_eq_rev 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   729
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   730
lemmas brdmods' [symmetric] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   731
  zpower_zmod' [symmetric]
30034
60f64f112174 removed redundant thms
nipkow
parents: 29631
diff changeset
   732
  trans [OF mod_add_left_eq mod_add_right_eq] 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   733
  trans [OF zmod_zsub_left_eq zmod_zsub_right_eq] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   734
  trans [OF zmod_zmult1_eq zmod_zmult1_eq_rev] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   735
  zmod_uminus' [symmetric]
30034
60f64f112174 removed redundant thms
nipkow
parents: 29631
diff changeset
   736
  mod_add_left_eq [where b = "1::int"]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   737
  zmod_zsub_left_eq [where b = "1"]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   738
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   739
lemmas bintr_arith1s =
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   740
  brdmod1s' [where c="2^n::int", folded pred_def succ_def bintrunc_mod2p] for n
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   741
lemmas bintr_ariths =
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   742
  brdmods' [where c="2^n::int", folded pred_def succ_def bintrunc_mod2p] for n
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   743
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   744
lemmas m2pths = pos_mod_sign pos_mod_bound [OF zless2p]
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   745
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   746
lemma bintr_ge0: "(0 :: int) <= number_of (bintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   747
  by (simp add : no_bintr m2pths)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   748
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   749
lemma bintr_lt2p: "number_of (bintrunc n w) < (2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   750
  by (simp add : no_bintr m2pths)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   751
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   752
lemma bintr_Min: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   753
  "number_of (bintrunc n Int.Min) = (2 ^ n :: int) - 1"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   754
  by (simp add : no_bintr m1mod2k)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   755
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   756
lemma sbintr_ge: "(- (2 ^ n) :: int) <= number_of (sbintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   757
  by (simp add : no_sbintr m2pths)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   758
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   759
lemma sbintr_lt: "number_of (sbintrunc n w) < (2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   760
  by (simp add : no_sbintr m2pths)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   761
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   762
lemma bintrunc_Suc:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   763
  "bintrunc (Suc n) bin = bintrunc n (bin_rest bin) BIT bin_last bin"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   764
  by (case_tac bin rule: bin_exhaust) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   765
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   766
lemma sign_Pls_ge_0: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   767
  "(bin_sign bin = Int.Pls) = (number_of bin >= (0 :: int))"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   768
  by (induct bin rule: numeral_induct) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   769
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   770
lemma sign_Min_lt_0: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   771
  "(bin_sign bin = Int.Min) = (number_of bin < (0 :: int))"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   772
  by (induct bin rule: numeral_induct) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   773
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   774
lemmas sign_Min_neg = trans [OF sign_Min_lt_0 neg_def [symmetric]] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   775
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   776
lemma bin_rest_trunc:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   777
  "!!bin. (bin_rest (bintrunc n bin)) = bintrunc (n - 1) (bin_rest bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   778
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   779
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   780
lemma bin_rest_power_trunc [rule_format] :
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30952
diff changeset
   781
  "(bin_rest ^^ k) (bintrunc n bin) = 
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30952
diff changeset
   782
    bintrunc (n - k) ((bin_rest ^^ k) bin)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   783
  by (induct k) (auto simp: bin_rest_trunc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   784
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   785
lemma bin_rest_trunc_i:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   786
  "bintrunc n (bin_rest bin) = bin_rest (bintrunc (Suc n) bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   787
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   788
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   789
lemma bin_rest_strunc:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   790
  "!!bin. bin_rest (sbintrunc (Suc n) bin) = sbintrunc n (bin_rest bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   791
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   792
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   793
lemma bintrunc_rest [simp]: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   794
  "!!bin. bintrunc n (bin_rest (bintrunc n bin)) = bin_rest (bintrunc n bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   795
  apply (induct n, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   796
  apply (case_tac bin rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   797
  apply (auto simp: bintrunc_bintrunc_l)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   798
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   799
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   800
lemma sbintrunc_rest [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   801
  "!!bin. sbintrunc n (bin_rest (sbintrunc n bin)) = bin_rest (sbintrunc n bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   802
  apply (induct n, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   803
  apply (case_tac bin rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   804
  apply (auto simp: bintrunc_bintrunc_l split: bit.splits)
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 bintrunc_rest':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   808
  "bintrunc n o bin_rest o bintrunc n = bin_rest o bintrunc n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   809
  by (rule ext) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   810
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   811
lemma sbintrunc_rest' :
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   812
  "sbintrunc n o bin_rest o sbintrunc n = bin_rest o sbintrunc n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   813
  by (rule ext) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   814
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   815
lemma rco_lem:
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30952
diff changeset
   816
  "f o g o f = g o f ==> f o (g o f) ^^ n = g ^^ n o f"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   817
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   818
  apply (induct_tac n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   819
   apply (simp_all (no_asm))
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   820
  apply (drule fun_cong)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   821
  apply (unfold o_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   822
  apply (erule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   823
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   824
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   825
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30952
diff changeset
   826
lemma rco_alt: "(f o g) ^^ n o f = f o (g o f) ^^ n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   827
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   828
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   829
   apply (simp_all add: o_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   830
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   831
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   832
lemmas rco_bintr = bintrunc_rest' 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   833
  [THEN rco_lem [THEN fun_cong], unfolded o_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   834
lemmas rco_sbintr = sbintrunc_rest' 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   835
  [THEN rco_lem [THEN fun_cong], unfolded o_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   836
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   837
subsection {* Splitting and concatenation *}
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   838
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   839
primrec bin_split :: "nat \<Rightarrow> int \<Rightarrow> int \<times> int" where
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   840
  Z: "bin_split 0 w = (w, Int.Pls)"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   841
  | Suc: "bin_split (Suc n) w = (let (w1, w2) = bin_split n (bin_rest w)
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   842
        in (w1, w2 BIT bin_last w))"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   843
37667
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   844
lemma [code]:
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   845
  "bin_split (Suc n) w = (let (w1, w2) = bin_split n (bin_rest w) in (w1, w2 BIT bin_last w))"
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   846
  "bin_split 0 w = (w, 0)"
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   847
  by (simp_all add: Pls_def)
41acc0fa6b6c avoid bitstrings in generated code
haftmann
parents: 37658
diff changeset
   848
26557
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   849
primrec bin_cat :: "int \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int" where
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   850
  Z: "bin_cat w 0 v = w"
9e7f95903b24 more new primrec
haftmann
parents: 26514
diff changeset
   851
  | Suc: "bin_cat w (Suc n) v = bin_cat w n (bin_rest v) BIT bin_last v"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   852
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   853
subsection {* Miscellaneous lemmas *}
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   854
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 30940
diff changeset
   855
lemma funpow_minus_simp:
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30952
diff changeset
   856
  "0 < n \<Longrightarrow> f ^^ n = f \<circ> f ^^ (n - 1)"
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 30940
diff changeset
   857
  by (cases n) simp_all
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   858
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   859
lemmas funpow_pred_simp [simp] =
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   860
  funpow_minus_simp [of "number_of bin", simplified nobm1] for bin
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   861
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   862
lemmas replicate_minus_simp = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   863
  trans [OF gen_minus [where f = "%n. replicate n x"] replicate.replicate_Suc] for x
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   864
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   865
lemmas replicate_pred_simp [simp] =
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   866
  replicate_minus_simp [of "number_of bin", simplified nobm1] for bin
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   867
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   868
lemmas power_Suc_no [simp] = power_Suc [of "number_of a"] for a
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   869
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   870
lemmas power_minus_simp = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   871
  trans [OF gen_minus [where f = "power f"] power_Suc] for f
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   872
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   873
lemmas power_pred_simp = 
45604
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   874
  power_minus_simp [of "number_of bin", simplified nobm1] for bin
29cf40fe8daf eliminated obsolete "standard";
wenzelm
parents: 45543
diff changeset
   875
lemmas power_pred_simp_no [simp] = power_pred_simp [where f= "number_of f"] for f
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   876
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   877
lemma list_exhaust_size_gt0:
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   878
  assumes y: "\<And>a list. y = a # list \<Longrightarrow> P"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   879
  shows "0 < length y \<Longrightarrow> P"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   880
  apply (cases y, simp)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   881
  apply (rule y)
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 41413
diff changeset
   882
  apply fastforce
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   883
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   884
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   885
lemma list_exhaust_size_eq0:
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   886
  assumes y: "y = [] \<Longrightarrow> P"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   887
  shows "length y = 0 \<Longrightarrow> P"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   888
  apply (cases y)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   889
   apply (rule y, simp)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   890
  apply simp
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   891
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   892
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   893
lemma size_Cons_lem_eq:
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   894
  "y = xa # list ==> size y = Suc k ==> size list = k"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   895
  by auto
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   896
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   897
lemma size_Cons_lem_eq_bin:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   898
  "y = xa # list ==> size y = number_of (Int.succ k) ==> 
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   899
    size list = number_of k"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   900
  by (auto simp: pred_def succ_def split add : split_if_asm)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   901
44939
5930d35c976d removed unused legacy lemma names, some comment cleanup.
kleing
parents: 44890
diff changeset
   902
lemmas ls_splits = prod.split prod.split_asm split_if_asm
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   903
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   904
lemma not_B1_is_B0: "y \<noteq> (1::bit) \<Longrightarrow> y = (0::bit)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   905
  by (cases y) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   906
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   907
lemma B1_ass_B0: 
37654
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   908
  assumes y: "y = (0::bit) \<Longrightarrow> y = (1::bit)"
8e33b9d04a82 use existing bit type from theory Bit
haftmann
parents: 37546
diff changeset
   909
  shows "y = (1::bit)"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   910
  apply (rule classical)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   911
  apply (drule not_B1_is_B0)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   912
  apply (erule y)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   913
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   914
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   915
-- "simplifications for specific word lengths"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   916
lemmas n2s_ths [THEN eq_reflection] = add_2_eq_Suc add_2_eq_Suc'
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   917
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   918
lemmas s2n_ths = n2s_ths [symmetric]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   919
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   920
end