src/HOL/Word/BinGeneral.thy
author kleing
Mon, 17 Mar 2008 07:15:40 +0100
changeset 26294 c5fe289de634
parent 26086 3c243098b64a
child 26514 eff55c0a6d34
permissions -rw-r--r--
fixed broken bintrunc lemma
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     1
(* 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     2
  ID:     $Id$
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     3
  Author: Jeremy Dawson, NICTA
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     4
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     5
  contains basic definition to do with integers
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     6
  expressed using Pls, Min, BIT and important resulting theorems, 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     7
  in particular, bin_rec and related work
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     8
*) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     9
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
    10
header {* Basic Definitions for Binary Integers *}
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
    11
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    12
theory BinGeneral imports Num_Lemmas
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    13
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    14
begin
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    15
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    16
subsection {* Recursion combinator for binary integers *}
24384
0002537695df move BIT datatype stuff from Num_Lemmas to BinGeneral
huffman
parents: 24383
diff changeset
    17
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
    18
lemma brlem: "(bin = Int.Min) = (- bin + Int.pred 0 = 0)"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    19
  unfolding Min_def pred_def by arith
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
    20
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    21
function
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    22
  bin_rec' :: "int * 'a * 'a * (int => bit => 'a => 'a) => 'a"  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    23
  where 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
    24
  "bin_rec' (bin, f1, f2, f3) = (if bin = Int.Pls then f1 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
    25
    else if bin = Int.Min then f2
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    26
    else case bin_rl bin of (w, b) => f3 w b (bin_rec' (w, f1, f2, f3)))"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    27
  by pat_completeness auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    28
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    29
termination 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    30
  apply (relation "measure (nat o abs o fst)")
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    31
   apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    32
  apply (simp add: Pls_def brlem)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    33
  apply (clarsimp simp: bin_rl_char pred_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    34
  apply (frule thin_rl [THEN refl [THEN bin_abs_lem [rule_format]]]) 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    35
    apply (unfold Pls_def Min_def number_of_eq)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    36
    prefer 2
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    37
    apply (erule asm_rl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    38
   apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    39
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    40
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    41
constdefs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    42
  bin_rec :: "'a => 'a => (int => bit => 'a => 'a) => int => 'a"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    43
  "bin_rec f1 f2 f3 bin == bin_rec' (bin, f1, f2, f3)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    44
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    45
lemma bin_rec_PM:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
    46
  "f = bin_rec f1 f2 f3 ==> f Int.Pls = f1 & f Int.Min = f2"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    47
  apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    48
   apply (unfold bin_rec_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    49
   apply (auto intro: bin_rec'.simps [THEN trans])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    50
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    51
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    52
lemma bin_rec_Pls: "bin_rec f1 f2 f3 Int.Pls = f1"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    53
  unfolding bin_rec_def by simp
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    54
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    55
lemma bin_rec_Min: "bin_rec f1 f2 f3 Int.Min = f2"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    56
  unfolding bin_rec_def by simp
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    57
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    58
lemma bin_rec_Bit0:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    59
  "f3 Int.Pls bit.B0 f1 = f1 \<Longrightarrow>
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    60
    bin_rec f1 f2 f3 (Int.Bit0 w) = f3 w bit.B0 (bin_rec f1 f2 f3 w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    61
  apply (unfold bin_rec_def)
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    62
  apply (rule bin_rec'.simps [THEN trans])
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    63
  apply (fold bin_rec_def)
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    64
  apply (simp add: eq_Bit0_Pls eq_Bit0_Min bin_rec_Pls)
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    65
  done
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    66
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    67
lemma bin_rec_Bit1:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    68
  "f3 Int.Min bit.B1 f2 = f2 \<Longrightarrow>
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    69
    bin_rec f1 f2 f3 (Int.Bit1 w) = f3 w bit.B1 (bin_rec f1 f2 f3 w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    70
  apply (unfold bin_rec_def)
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    71
  apply (rule bin_rec'.simps [THEN trans])
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    72
  apply (fold bin_rec_def)
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    73
  apply (simp add: eq_Bit1_Pls eq_Bit1_Min bin_rec_Min)
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    74
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    75
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    76
lemma bin_rec_Bit:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
    77
  "f = bin_rec f1 f2 f3  ==> f3 Int.Pls bit.B0 f1 = f1 ==> 
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
    78
    f3 Int.Min bit.B1 f2 = f2 ==> f (w BIT b) = f3 w b (f w)"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    79
  by (cases b, simp add: bin_rec_Bit0, simp add: bin_rec_Bit1)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    80
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    81
lemmas bin_rec_simps = refl [THEN bin_rec_Bit] bin_rec_Pls bin_rec_Min
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
    82
  bin_rec_Bit0 bin_rec_Bit1
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    83
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    84
subsection {* Destructors for binary integers *}
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
    85
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
    86
consts
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    87
  -- "corresponding operations analysing bins"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    88
  bin_last :: "int => bit"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    89
  bin_rest :: "int => int"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
    90
  bin_sign :: "int => int"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    91
  bin_nth :: "int => nat => bool"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    92
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    93
primrec
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    94
  Z : "bin_nth w 0 = (bin_last w = bit.B1)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    95
  Suc : "bin_nth w (Suc n) = bin_nth (bin_rest w) n"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
    96
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
    97
defs  
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    98
  bin_rest_def : "bin_rest w == fst (bin_rl w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
    99
  bin_last_def : "bin_last w == snd (bin_rl w)"
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   100
  bin_sign_def : "bin_sign == bin_rec Int.Pls Int.Min (%w b s. s)"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   101
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   102
lemma bin_rl: "bin_rl w = (bin_rest w, bin_last w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   103
  unfolding bin_rest_def bin_last_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   104
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   105
lemmas bin_rl_simp [simp] = iffD1 [OF bin_rl_char bin_rl]
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   106
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   107
lemma bin_rest_simps [simp]: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   108
  "bin_rest Int.Pls = Int.Pls"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   109
  "bin_rest Int.Min = Int.Min"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   110
  "bin_rest (w BIT b) = w"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   111
  "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
   112
  "bin_rest (Int.Bit1 w) = w"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   113
  unfolding bin_rest_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   114
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   115
lemma bin_last_simps [simp]: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   116
  "bin_last Int.Pls = bit.B0"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   117
  "bin_last Int.Min = bit.B1"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   118
  "bin_last (w BIT b) = b"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   119
  "bin_last (Int.Bit0 w) = bit.B0"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   120
  "bin_last (Int.Bit1 w) = bit.B1"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   121
  unfolding bin_last_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
   122
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   123
lemma bin_sign_simps [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   124
  "bin_sign Int.Pls = Int.Pls"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   125
  "bin_sign Int.Min = Int.Min"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   126
  "bin_sign (w BIT b) = bin_sign w"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   127
  "bin_sign (Int.Bit0 w) = bin_sign w"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   128
  "bin_sign (Int.Bit1 w) = bin_sign w"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   129
  unfolding bin_sign_def by (auto simp: bin_rec_simps)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   130
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   131
lemma bin_r_l_extras [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   132
  "bin_last 0 = bit.B0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   133
  "bin_last (- 1) = bit.B1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   134
  "bin_last -1 = bit.B1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   135
  "bin_last 1 = bit.B1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   136
  "bin_rest 1 = 0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   137
  "bin_rest 0 = 0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   138
  "bin_rest (- 1) = - 1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   139
  "bin_rest -1 = -1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   140
  apply (unfold number_of_Min)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   141
  apply (unfold Pls_def [symmetric] Min_def [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   142
  apply (unfold numeral_1_eq_1 [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   143
  apply (auto simp: number_of_eq) 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   144
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   145
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   146
lemma bin_last_mod: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   147
  "bin_last w = (if w mod 2 = 0 then bit.B0 else bit.B1)"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   148
  apply (case_tac w rule: bin_exhaust)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   149
  apply (case_tac b)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   150
   apply auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   151
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   152
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   153
lemma bin_rest_div: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   154
  "bin_rest w = w div 2"
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   155
  apply (case_tac w rule: bin_exhaust)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   156
  apply (rule trans)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   157
   apply clarsimp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   158
   apply (rule refl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   159
  apply (drule trans)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   160
   apply (rule Bit_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   161
  apply (simp add: z1pdiv2 split: bit.split)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   162
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   163
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   164
lemma Bit_div2 [simp]: "(w BIT b) div 2 = w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   165
  unfolding bin_rest_div [symmetric] by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   166
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   167
lemma Bit0_div2 [simp]: "(Int.Bit0 w) div 2 = w"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   168
  using Bit_div2 [where b=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
   169
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   170
lemma Bit1_div2 [simp]: "(Int.Bit1 w) div 2 = w"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   171
  using Bit_div2 [where b=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
   172
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   173
lemma bin_nth_lem [rule_format]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   174
  "ALL y. bin_nth x = bin_nth y --> x = y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   175
  apply (induct x rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   176
    apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   177
    apply (erule rev_mp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   178
    apply (induct_tac y rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   179
      apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   180
      apply (drule_tac x=0 in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   181
     apply (erule notE, rule ext, 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   182
            drule_tac x="Suc x" in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   183
    apply (drule_tac x=0 in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   184
   apply (erule rev_mp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   185
   apply (induct_tac y rule: bin_induct)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   186
     apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   187
     apply (drule_tac x=0 in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   188
    apply (erule notE, rule ext, 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   189
           drule_tac x="Suc x" in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   190
   apply (drule_tac x=0 in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   191
  apply (case_tac y rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   192
  apply clarify
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   193
  apply (erule allE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   194
  apply (erule impE)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   195
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   196
   apply (erule BIT_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   197
   apply (drule_tac x=0 in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   198
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   199
  apply (drule_tac x="Suc ?x" in fun_cong, force)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   200
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   201
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   202
lemma bin_nth_eq_iff: "(bin_nth x = bin_nth y) = (x = y)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   203
  by (auto elim: bin_nth_lem)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   204
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   205
lemmas bin_eqI = ext [THEN bin_nth_eq_iff [THEN iffD1], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   206
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   207
lemma bin_nth_Pls [simp]: "~ bin_nth Int.Pls n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   208
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   209
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   210
lemma bin_nth_Min [simp]: "bin_nth Int.Min n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   211
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   212
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   213
lemma bin_nth_0_BIT: "bin_nth (w BIT b) 0 = (b = bit.B1)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   214
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   215
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   216
lemma bin_nth_Suc_BIT: "bin_nth (w BIT b) (Suc n) = bin_nth w n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   217
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   218
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   219
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
   220
  by (cases n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   221
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   222
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
   223
  "0 < n ==> bin_nth (Int.Bit0 w) n = bin_nth w (n - 1)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   224
  using bin_nth_minus [where b=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
   225
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   226
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
   227
  "0 < n ==> bin_nth (Int.Bit1 w) n = bin_nth w (n - 1)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   228
  using bin_nth_minus [where b=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
   229
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   230
lemmas bin_nth_0 = bin_nth.simps(1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   231
lemmas bin_nth_Suc = bin_nth.simps(2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   232
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   233
lemmas bin_nth_simps = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   234
  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
   235
  bin_nth_minus_Bit0 bin_nth_minus_Bit1
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   236
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   237
lemma bin_sign_rest [simp]: 
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   238
  "bin_sign (bin_rest w) = (bin_sign w)"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   239
  by (case_tac w rule: bin_exhaust) auto
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   240
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   241
subsection {* Truncating binary integers *}
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   242
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   243
consts
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   244
  bintrunc :: "nat => int => int"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   245
primrec 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   246
  Z : "bintrunc 0 bin = Int.Pls"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   247
  Suc : "bintrunc (Suc n) bin = bintrunc n (bin_rest bin) BIT (bin_last bin)"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   248
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   249
consts
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   250
  sbintrunc :: "nat => int => int" 
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   251
primrec 
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   252
  Z : "sbintrunc 0 bin = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   253
    (case bin_last bin of bit.B1 => Int.Min | bit.B0 => Int.Pls)"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   254
  Suc : "sbintrunc (Suc n) bin = sbintrunc n (bin_rest bin) BIT (bin_last bin)"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   255
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   256
lemma sign_bintr:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   257
  "!!w. bin_sign (bintrunc n w) = Int.Pls"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   258
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   259
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   260
lemma bintrunc_mod2p:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   261
  "!!w. bintrunc n w = (w mod 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   262
  apply (induct n, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   263
  apply (simp add: bin_last_mod bin_rest_div Bit_def zmod_zmult2_eq
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   264
              cong: number_of_False_cong)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   265
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   266
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   267
lemma sbintrunc_mod2p:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   268
  "!!w. sbintrunc n w = ((w + 2 ^ n) mod 2 ^ (Suc n) - 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   269
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   270
   apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   271
   apply (subst zmod_zadd_left_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   272
   apply (simp add: bin_last_mod)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   273
   apply (simp add: number_of_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   274
  apply clarsimp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   275
  apply (simp add: bin_last_mod bin_rest_div Bit_def 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   276
              cong: number_of_False_cong)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   277
  apply (clarsimp simp: zmod_zmult_zmult1 [symmetric] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   278
         zmod_zdiv_equality [THEN diff_eq_eq [THEN iffD2 [THEN sym]]])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   279
  apply (rule trans [symmetric, OF _ emep1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   280
     apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   281
  apply (auto simp: even_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   282
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   283
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   284
subsection "Simplifications for (s)bintrunc"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   285
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   286
lemma bit_bool:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   287
  "(b = (b' = bit.B1)) = (b' = (if b then bit.B1 else bit.B0))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   288
  by (cases b') auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   289
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24419
diff changeset
   290
lemmas bit_bool1 [simp] = refl [THEN bit_bool [THEN iffD1], symmetric]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   291
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   292
lemma bin_sign_lem:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   293
  "!!bin. (bin_sign (sbintrunc n bin) = Int.Min) = bin_nth bin n"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   294
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   295
   apply (case_tac bin rule: bin_exhaust, case_tac b, auto)+
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   296
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   297
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   298
lemma nth_bintr:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   299
  "!!w m. bin_nth (bintrunc m w) n = (n < m & bin_nth w n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   300
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   301
   apply (case_tac m, auto)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   302
  apply (case_tac m, auto)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   303
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   304
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   305
lemma nth_sbintr:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   306
  "!!w m. bin_nth (sbintrunc m w) n = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   307
          (if n < m then bin_nth w n else bin_nth w m)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   308
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   309
   apply (case_tac m, simp_all split: bit.splits)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   310
  apply (case_tac m, simp_all split: bit.splits)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   311
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   312
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   313
lemma bin_nth_Bit:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   314
  "bin_nth (w BIT b) n = (n = 0 & b = bit.B1 | (EX m. n = Suc m & bin_nth w m))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   315
  by (cases n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   316
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   317
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
   318
  "bin_nth (Int.Bit0 w) n = (EX m. n = Suc m & bin_nth w m)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   319
  using bin_nth_Bit [where b=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
   320
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   321
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
   322
  "bin_nth (Int.Bit1 w) n = (n = 0 | (EX m. n = Suc m & bin_nth w m))"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   323
  using bin_nth_Bit [where b=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
   324
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   325
lemma bintrunc_bintrunc_l:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   326
  "n <= m ==> (bintrunc m (bintrunc n w) = bintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   327
  by (rule bin_eqI) (auto simp add : nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   328
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   329
lemma sbintrunc_sbintrunc_l:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   330
  "n <= m ==> (sbintrunc m (sbintrunc n w) = sbintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   331
  by (rule bin_eqI) (auto simp: nth_sbintr min_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   332
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   333
lemma bintrunc_bintrunc_ge:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   334
  "n <= m ==> (bintrunc n (bintrunc m w) = bintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   335
  by (rule bin_eqI) (auto simp: nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   336
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   337
lemma bintrunc_bintrunc_min [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   338
  "bintrunc m (bintrunc n w) = bintrunc (min m n) w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   339
  apply (unfold min_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   340
  apply (rule bin_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   341
  apply (auto simp: nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   342
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   343
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   344
lemma sbintrunc_sbintrunc_min [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   345
  "sbintrunc m (sbintrunc n w) = sbintrunc (min m n) w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   346
  apply (unfold min_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   347
  apply (rule bin_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   348
  apply (auto simp: nth_sbintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   349
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   350
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   351
lemmas bintrunc_Pls = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   352
  bintrunc.Suc [where bin="Int.Pls", simplified bin_last_simps bin_rest_simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   353
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   354
lemmas bintrunc_Min [simp] = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   355
  bintrunc.Suc [where bin="Int.Min", simplified bin_last_simps bin_rest_simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   356
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   357
lemmas bintrunc_BIT  [simp] = 
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   358
  bintrunc.Suc [where bin="w BIT b", simplified bin_last_simps bin_rest_simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   359
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   360
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
   361
  "bintrunc (Suc n) (Int.Bit0 w) = Int.Bit0 (bintrunc n w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   362
  using bintrunc_BIT [where b=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
   363
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   364
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
   365
  "bintrunc (Suc n) (Int.Bit1 w) = Int.Bit1 (bintrunc n w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   366
  using bintrunc_BIT [where b=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
   367
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   368
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
   369
  bintrunc_Bit0 bintrunc_Bit1
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   370
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   371
lemmas sbintrunc_Suc_Pls = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   372
  sbintrunc.Suc [where bin="Int.Pls", simplified bin_last_simps bin_rest_simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   373
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   374
lemmas sbintrunc_Suc_Min = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   375
  sbintrunc.Suc [where bin="Int.Min", simplified bin_last_simps bin_rest_simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   376
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   377
lemmas sbintrunc_Suc_BIT [simp] = 
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   378
  sbintrunc.Suc [where bin="w BIT b", simplified bin_last_simps bin_rest_simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   379
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   380
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
   381
  "sbintrunc (Suc n) (Int.Bit0 w) = Int.Bit0 (sbintrunc n w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   382
  using sbintrunc_Suc_BIT [where b=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
   383
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   384
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
   385
  "sbintrunc (Suc n) (Int.Bit1 w) = Int.Bit1 (sbintrunc n w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   386
  using sbintrunc_Suc_BIT [where b=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
   387
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   388
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
   389
  sbintrunc_Suc_Bit0 sbintrunc_Suc_Bit1
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   390
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   391
lemmas sbintrunc_Pls = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   392
  sbintrunc.Z [where bin="Int.Pls", 
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   393
               simplified bin_last_simps bin_rest_simps bit.simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   394
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   395
lemmas sbintrunc_Min = 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   396
  sbintrunc.Z [where bin="Int.Min", 
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   397
               simplified bin_last_simps bin_rest_simps bit.simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   398
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   399
lemmas sbintrunc_0_BIT_B0 [simp] = 
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   400
  sbintrunc.Z [where bin="w BIT bit.B0", 
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   401
               simplified bin_last_simps bin_rest_simps bit.simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   402
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   403
lemmas sbintrunc_0_BIT_B1 [simp] = 
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   404
  sbintrunc.Z [where bin="w BIT bit.B1", 
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   405
               simplified bin_last_simps bin_rest_simps bit.simps, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   406
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   407
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
   408
  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
   409
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   410
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
   411
  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
   412
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   413
lemmas sbintrunc_0_simps =
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   414
  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
   415
  sbintrunc_0_Bit0 sbintrunc_0_Bit1
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   416
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   417
lemmas bintrunc_simps = bintrunc.Z bintrunc_Sucs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   418
lemmas sbintrunc_simps = sbintrunc_0_simps sbintrunc_Sucs
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   419
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   420
lemma bintrunc_minus:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   421
  "0 < n ==> bintrunc (Suc (n - 1)) w = bintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   422
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   423
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   424
lemma sbintrunc_minus:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   425
  "0 < n ==> sbintrunc (Suc (n - 1)) w = sbintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   426
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   427
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   428
lemmas bintrunc_minus_simps = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   429
  bintrunc_Sucs [THEN [2] bintrunc_minus [symmetric, THEN trans], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   430
lemmas sbintrunc_minus_simps = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   431
  sbintrunc_Sucs [THEN [2] sbintrunc_minus [symmetric, THEN trans], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   432
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   433
lemma bintrunc_n_Pls [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   434
  "bintrunc n Int.Pls = Int.Pls"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   435
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   436
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   437
lemma sbintrunc_n_PM [simp]:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   438
  "sbintrunc n Int.Pls = Int.Pls"
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   439
  "sbintrunc n Int.Min = Int.Min"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   440
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   441
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   442
lemmas thobini1 = arg_cong [where f = "%w. w BIT b", standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   443
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   444
lemmas bintrunc_BIT_I = trans [OF bintrunc_BIT thobini1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   445
lemmas bintrunc_Min_I = trans [OF bintrunc_Min thobini1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   446
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   447
lemmas bmsts = bintrunc_minus_simps(1-3) [THEN thobini1 [THEN [2] trans], standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   448
lemmas bintrunc_Pls_minus_I = bmsts(1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   449
lemmas bintrunc_Min_minus_I = bmsts(2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   450
lemmas bintrunc_BIT_minus_I = bmsts(3)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   451
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   452
lemma bintrunc_0_Min: "bintrunc 0 Int.Min = Int.Pls"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   453
  by auto
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   454
lemma bintrunc_0_BIT: "bintrunc 0 (w BIT b) = Int.Pls"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   455
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   456
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   457
lemma bintrunc_Suc_lem:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   458
  "bintrunc (Suc n) x = y ==> m = Suc n ==> bintrunc m x = y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   459
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   460
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   461
lemmas bintrunc_Suc_Ialts = 
26294
c5fe289de634 fixed broken bintrunc lemma
kleing
parents: 26086
diff changeset
   462
  bintrunc_Min_I [THEN bintrunc_Suc_lem, standard]
c5fe289de634 fixed broken bintrunc lemma
kleing
parents: 26086
diff changeset
   463
  bintrunc_BIT_I [THEN bintrunc_Suc_lem, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   464
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   465
lemmas sbintrunc_BIT_I = trans [OF sbintrunc_Suc_BIT thobini1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   466
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   467
lemmas sbintrunc_Suc_Is = 
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   468
  sbintrunc_Sucs(1-3) [THEN thobini1 [THEN [2] trans], standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   469
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   470
lemmas sbintrunc_Suc_minus_Is = 
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25919
diff changeset
   471
  sbintrunc_minus_simps(1-3) [THEN thobini1 [THEN [2] trans], standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   472
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   473
lemma sbintrunc_Suc_lem:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   474
  "sbintrunc (Suc n) x = y ==> m = Suc n ==> sbintrunc m x = y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   475
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   476
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   477
lemmas sbintrunc_Suc_Ialts = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   478
  sbintrunc_Suc_Is [THEN sbintrunc_Suc_lem, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   479
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   480
lemma sbintrunc_bintrunc_lt:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   481
  "m > n ==> sbintrunc n (bintrunc m w) = sbintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   482
  by (rule bin_eqI) (auto simp: nth_sbintr nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   483
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   484
lemma bintrunc_sbintrunc_le:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   485
  "m <= Suc n ==> bintrunc m (sbintrunc n w) = bintrunc m w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   486
  apply (rule bin_eqI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   487
  apply (auto simp: nth_sbintr nth_bintr)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   488
   apply (subgoal_tac "x=n", safe, arith+)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   489
  apply (subgoal_tac "x=n", safe, arith+)[1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   490
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   491
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   492
lemmas bintrunc_sbintrunc [simp] = order_refl [THEN bintrunc_sbintrunc_le]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   493
lemmas sbintrunc_bintrunc [simp] = lessI [THEN sbintrunc_bintrunc_lt]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   494
lemmas bintrunc_bintrunc [simp] = order_refl [THEN bintrunc_bintrunc_l]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   495
lemmas sbintrunc_sbintrunc [simp] = order_refl [THEN sbintrunc_sbintrunc_l] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   496
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   497
lemma bintrunc_sbintrunc' [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   498
  "0 < n \<Longrightarrow> bintrunc n (sbintrunc (n - 1) w) = bintrunc n w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   499
  by (cases n) (auto simp del: bintrunc.Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   500
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   501
lemma sbintrunc_bintrunc' [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   502
  "0 < n \<Longrightarrow> sbintrunc (n - 1) (bintrunc n w) = sbintrunc (n - 1) w"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   503
  by (cases n) (auto simp del: bintrunc.Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   504
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   505
lemma bin_sbin_eq_iff: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   506
  "bintrunc (Suc n) x = bintrunc (Suc n) y <-> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   507
   sbintrunc n x = sbintrunc n y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   508
  apply (rule iffI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   509
   apply (rule box_equals [OF _ sbintrunc_bintrunc sbintrunc_bintrunc])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   510
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   511
  apply (rule box_equals [OF _ bintrunc_sbintrunc bintrunc_sbintrunc])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   512
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   513
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   514
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   515
lemma bin_sbin_eq_iff':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   516
  "0 < n \<Longrightarrow> bintrunc n x = bintrunc n y <-> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   517
            sbintrunc (n - 1) x = sbintrunc (n - 1) y"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   518
  by (cases n) (simp_all add: bin_sbin_eq_iff del: bintrunc.Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   519
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   520
lemmas bintrunc_sbintruncS0 [simp] = bintrunc_sbintrunc' [unfolded One_nat_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   521
lemmas sbintrunc_bintruncS0 [simp] = sbintrunc_bintrunc' [unfolded One_nat_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   522
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   523
lemmas bintrunc_bintrunc_l' = le_add1 [THEN bintrunc_bintrunc_l]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   524
lemmas sbintrunc_sbintrunc_l' = le_add1 [THEN sbintrunc_sbintrunc_l]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   525
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   526
(* although bintrunc_minus_simps, if added to default simpset,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   527
  tends to get applied where it's not wanted in developing the theories,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   528
  we get a version for when the word length is given literally *)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   529
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   530
lemmas nat_non0_gr = 
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 24465
diff changeset
   531
  trans [OF iszero_def [THEN Not_eq_iff [THEN iffD2]] refl, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   532
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   533
lemmas bintrunc_pred_simps [simp] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   534
  bintrunc_minus_simps [of "number_of bin", simplified nobm1, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   535
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   536
lemmas sbintrunc_pred_simps [simp] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   537
  sbintrunc_minus_simps [of "number_of bin", simplified nobm1, standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   538
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   539
lemma no_bintr_alt:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   540
  "number_of (bintrunc n w) = w mod 2 ^ n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   541
  by (simp add: number_of_eq bintrunc_mod2p)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   542
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   543
lemma no_bintr_alt1: "bintrunc n = (%w. w mod 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   544
  by (rule ext) (rule bintrunc_mod2p)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   545
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   546
lemma range_bintrunc: "range (bintrunc n) = {i. 0 <= i & i < 2 ^ n}"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   547
  apply (unfold no_bintr_alt1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   548
  apply (auto simp add: image_iff)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   549
  apply (rule exI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   550
  apply (auto intro: int_mod_lem [THEN iffD1, symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   551
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   552
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   553
lemma no_bintr: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   554
  "number_of (bintrunc n w) = (number_of w mod 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   555
  by (simp add : bintrunc_mod2p number_of_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   556
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   557
lemma no_sbintr_alt2: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   558
  "sbintrunc n = (%w. (w + 2 ^ n) mod 2 ^ Suc n - 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   559
  by (rule ext) (simp add : sbintrunc_mod2p)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   560
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   561
lemma no_sbintr: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   562
  "number_of (sbintrunc n w) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   563
   ((number_of w + 2 ^ n) mod 2 ^ Suc n - 2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   564
  by (simp add : no_sbintr_alt2 number_of_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   565
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   566
lemma range_sbintrunc: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   567
  "range (sbintrunc n) = {i. - (2 ^ n) <= i & i < 2 ^ n}"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   568
  apply (unfold no_sbintr_alt2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   569
  apply (auto simp add: image_iff eq_diff_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   570
  apply (rule exI)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   571
  apply (auto intro: int_mod_lem [THEN iffD1, symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   572
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   573
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   574
lemma sb_inc_lem:
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   575
  "(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
   576
  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
   577
  apply (rule TrueI)
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   578
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   579
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   580
lemma sb_inc_lem':
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   581
  "(a::int) < - (2^k) \<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
   582
  by (rule iffD1 [OF less_diff_eq, THEN sb_inc_lem, simplified OrderedGroup.diff_0])
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   583
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   584
lemma sbintrunc_inc:
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   585
  "x < - (2^n) ==> x + 2^(Suc n) <= sbintrunc n x"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   586
  unfolding no_sbintr_alt2 by (drule sb_inc_lem') simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   587
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   588
lemma sb_dec_lem:
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   589
  "(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
   590
  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
   591
    simplified zless2p, OF _ TrueI, simplified])
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   592
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   593
lemma sb_dec_lem':
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   594
  "(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
   595
  by (rule iffD1 [OF diff_le_eq', THEN sb_dec_lem, simplified])
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   596
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   597
lemma sbintrunc_dec:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   598
  "x >= (2 ^ n) ==> x - 2 ^ (Suc n) >= sbintrunc n x"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   599
  unfolding no_sbintr_alt2 by (drule sb_dec_lem') simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   600
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   601
lemmas zmod_uminus' = zmod_uminus [where b="c", standard]
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   602
lemmas zpower_zmod' = zpower_zmod [where m="c" and y="k", standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   603
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   604
lemmas brdmod1s' [symmetric] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   605
  zmod_zadd_left_eq zmod_zadd_right_eq 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   606
  zmod_zsub_left_eq zmod_zsub_right_eq 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   607
  zmod_zmult1_eq zmod_zmult1_eq_rev 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   608
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   609
lemmas brdmods' [symmetric] = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   610
  zpower_zmod' [symmetric]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   611
  trans [OF zmod_zadd_left_eq zmod_zadd_right_eq] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   612
  trans [OF zmod_zsub_left_eq zmod_zsub_right_eq] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   613
  trans [OF zmod_zmult1_eq zmod_zmult1_eq_rev] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   614
  zmod_uminus' [symmetric]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   615
  zmod_zadd_left_eq [where b = "1"]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   616
  zmod_zsub_left_eq [where b = "1"]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   617
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   618
lemmas bintr_arith1s =
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   619
  brdmod1s' [where c="2^n", folded pred_def succ_def bintrunc_mod2p, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   620
lemmas bintr_ariths =
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   621
  brdmods' [where c="2^n", folded pred_def succ_def bintrunc_mod2p, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   622
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   623
lemmas m2pths = pos_mod_sign pos_mod_bound [OF zless2p, standard] 
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   624
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   625
lemma bintr_ge0: "(0 :: int) <= number_of (bintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   626
  by (simp add : no_bintr m2pths)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   627
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   628
lemma bintr_lt2p: "number_of (bintrunc n w) < (2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   629
  by (simp add : no_bintr m2pths)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   630
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   631
lemma bintr_Min: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   632
  "number_of (bintrunc n Int.Min) = (2 ^ n :: int) - 1"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   633
  by (simp add : no_bintr m1mod2k)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   634
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   635
lemma sbintr_ge: "(- (2 ^ n) :: int) <= number_of (sbintrunc n w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   636
  by (simp add : no_sbintr m2pths)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   637
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   638
lemma sbintr_lt: "number_of (sbintrunc n w) < (2 ^ n :: int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   639
  by (simp add : no_sbintr m2pths)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   640
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   641
lemma bintrunc_Suc:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   642
  "bintrunc (Suc n) bin = bintrunc n (bin_rest bin) BIT bin_last bin"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   643
  by (case_tac bin rule: bin_exhaust) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   644
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   645
lemma sign_Pls_ge_0: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   646
  "(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
   647
  by (induct bin rule: numeral_induct) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   648
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   649
lemma sign_Min_lt_0: 
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   650
  "(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
   651
  by (induct bin rule: numeral_induct) auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   652
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   653
lemmas sign_Min_neg = trans [OF sign_Min_lt_0 neg_def [symmetric]] 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   654
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   655
lemma bin_rest_trunc:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   656
  "!!bin. (bin_rest (bintrunc n bin)) = bintrunc (n - 1) (bin_rest bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   657
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   658
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   659
lemma bin_rest_power_trunc [rule_format] :
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   660
  "(bin_rest ^ k) (bintrunc n bin) = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   661
    bintrunc (n - k) ((bin_rest ^ k) bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   662
  by (induct k) (auto simp: bin_rest_trunc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   663
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   664
lemma bin_rest_trunc_i:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   665
  "bintrunc n (bin_rest bin) = bin_rest (bintrunc (Suc n) bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   666
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   667
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   668
lemma bin_rest_strunc:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   669
  "!!bin. bin_rest (sbintrunc (Suc n) bin) = sbintrunc n (bin_rest bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   670
  by (induct n) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   671
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   672
lemma bintrunc_rest [simp]: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   673
  "!!bin. bintrunc n (bin_rest (bintrunc n bin)) = bin_rest (bintrunc n bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   674
  apply (induct n, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   675
  apply (case_tac bin rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   676
  apply (auto simp: bintrunc_bintrunc_l)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   677
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   678
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   679
lemma sbintrunc_rest [simp]:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   680
  "!!bin. sbintrunc n (bin_rest (sbintrunc n bin)) = bin_rest (sbintrunc n bin)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   681
  apply (induct n, simp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   682
  apply (case_tac bin rule: bin_exhaust)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   683
  apply (auto simp: bintrunc_bintrunc_l split: bit.splits)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   684
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   685
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   686
lemma bintrunc_rest':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   687
  "bintrunc n o bin_rest o bintrunc n = bin_rest o bintrunc n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   688
  by (rule ext) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   689
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   690
lemma sbintrunc_rest' :
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   691
  "sbintrunc n o bin_rest o sbintrunc n = bin_rest o sbintrunc n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   692
  by (rule ext) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   693
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   694
lemma rco_lem:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   695
  "f o g o f = g o f ==> f o (g o f) ^ n = g ^ n o f"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   696
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   697
  apply (induct_tac n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   698
   apply (simp_all (no_asm))
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   699
  apply (drule fun_cong)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   700
  apply (unfold o_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   701
  apply (erule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   702
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   703
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   704
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   705
lemma rco_alt: "(f o g) ^ n o f = f o (g o f) ^ n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   706
  apply (rule ext)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   707
  apply (induct n)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   708
   apply (simp_all add: o_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   709
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   710
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   711
lemmas rco_bintr = bintrunc_rest' 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   712
  [THEN rco_lem [THEN fun_cong], unfolded o_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   713
lemmas rco_sbintr = sbintrunc_rest' 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   714
  [THEN rco_lem [THEN fun_cong], unfolded o_def]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   715
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   716
subsection {* Splitting and concatenation *}
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   717
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   718
consts
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   719
  bin_split :: "nat => int => int * int"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   720
primrec
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   721
  Z : "bin_split 0 w = (w, Int.Pls)"
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   722
  Suc : "bin_split (Suc n) w = (let (w1, w2) = bin_split n (bin_rest w)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   723
    in (w1, w2 BIT bin_last w))"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   724
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   725
consts
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   726
  bin_cat :: "int => nat => int => int"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   727
primrec
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   728
  Z : "bin_cat w 0 v = w"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   729
  Suc : "bin_cat w (Suc n) v = bin_cat w n (bin_rest v) BIT bin_last v"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   730
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   731
subsection {* Miscellaneous lemmas *}
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   732
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   733
lemmas funpow_minus_simp = 
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   734
  trans [OF gen_minus [where f = "power f"] funpow_Suc, standard]
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   735
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   736
lemmas funpow_pred_simp [simp] =
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   737
  funpow_minus_simp [of "number_of bin", simplified nobm1, standard]
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   738
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   739
lemmas replicate_minus_simp = 
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   740
  trans [OF gen_minus [where f = "%n. replicate n x"] replicate.replicate_Suc,
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   741
         standard]
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   742
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   743
lemmas replicate_pred_simp [simp] =
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   744
  replicate_minus_simp [of "number_of bin", simplified nobm1, standard]
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   745
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   746
lemmas power_Suc_no [simp] = power_Suc [of "number_of a", standard]
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   747
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   748
lemmas power_minus_simp = 
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   749
  trans [OF gen_minus [where f = "power f"] power_Suc, standard]
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   750
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   751
lemmas power_pred_simp = 
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   752
  power_minus_simp [of "number_of bin", simplified nobm1, standard]
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 25134
diff changeset
   753
lemmas power_pred_simp_no [simp] = power_pred_simp [where f= "number_of f", standard]
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   754
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   755
lemma list_exhaust_size_gt0:
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   756
  assumes y: "\<And>a list. y = a # list \<Longrightarrow> P"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   757
  shows "0 < length y \<Longrightarrow> P"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   758
  apply (cases y, simp)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   759
  apply (rule y)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   760
  apply fastsimp
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   761
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   762
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   763
lemma list_exhaust_size_eq0:
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   764
  assumes y: "y = [] \<Longrightarrow> P"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   765
  shows "length y = 0 \<Longrightarrow> P"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   766
  apply (cases y)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   767
   apply (rule y, simp)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   768
  apply simp
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   769
  done
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   770
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   771
lemma size_Cons_lem_eq:
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   772
  "y = xa # list ==> size y = Suc k ==> size list = k"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   773
  by auto
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   774
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   775
lemma size_Cons_lem_eq_bin:
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25349
diff changeset
   776
  "y = xa # list ==> size y = number_of (Int.succ k) ==> 
24364
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   777
    size list = number_of k"
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   778
  by (auto simp: pred_def succ_def split add : split_if_asm)
31e359126ab6 reorganize into subsections
huffman
parents: 24350
diff changeset
   779
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   780
lemmas ls_splits = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   781
  prod.split split_split prod.split_asm split_split_asm split_if_asm
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   782
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   783
lemma not_B1_is_B0: "y \<noteq> bit.B1 \<Longrightarrow> y = bit.B0"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   784
  by (cases y) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   785
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   786
lemma B1_ass_B0: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   787
  assumes y: "y = bit.B0 \<Longrightarrow> y = bit.B1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   788
  shows "y = bit.B1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   789
  apply (rule classical)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   790
  apply (drule not_B1_is_B0)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   791
  apply (erule y)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   792
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   793
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   794
-- "simplifications for specific word lengths"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   795
lemmas n2s_ths [THEN eq_reflection] = add_2_eq_Suc add_2_eq_Suc'
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   796
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   797
lemmas s2n_ths = n2s_ths [symmetric]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   798
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   799
end