src/HOL/Word/Word_Bitwise.thy
author haftmann
Thu, 18 Jun 2020 09:07:30 +0000
changeset 71954 13bb3f5cdc5b
parent 71941 49af3d9a818c
child 71957 3e162c63371a
permissions -rw-r--r--
pragmatically ruled out word types of length zero: a bit string with no bits is not bit string at all
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
70173
c2786fe88064 tuned theory names
haftmann
parents: 69597
diff changeset
     1
(*  Title:      HOL/Word/Word_Bitwise.thy
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
     2
    Authors:    Thomas Sewell, NICTA and Sascha Boehme, TU Muenchen
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
     3
*)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
     4
70173
c2786fe88064 tuned theory names
haftmann
parents: 69597
diff changeset
     5
theory Word_Bitwise
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
     6
  imports Word
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
     7
begin
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
     8
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61144
diff changeset
     9
text \<open>Helper constants used in defining addition\<close>
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    10
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    11
definition xor3 :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    12
  where "xor3 a b c = (a = (b = c))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    13
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    14
definition carry :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    15
  where "carry a b c = ((a \<and> (b \<or> c)) \<or> (b \<and> c))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    16
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    17
lemma carry_simps:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    18
  "carry True a b = (a \<or> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    19
  "carry a True b = (a \<or> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    20
  "carry a b True = (a \<or> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    21
  "carry False a b = (a \<and> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    22
  "carry a False b = (a \<and> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    23
  "carry a b False = (a \<and> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    24
  by (auto simp add: carry_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    25
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    26
lemma xor3_simps:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    27
  "xor3 True a b = (a = b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    28
  "xor3 a True b = (a = b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    29
  "xor3 a b True = (a = b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    30
  "xor3 False a b = (a \<noteq> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    31
  "xor3 a False b = (a \<noteq> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    32
  "xor3 a b False = (a \<noteq> b)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    33
  by (simp_all add: xor3_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    34
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61144
diff changeset
    35
text \<open>Breaking up word equalities into equalities on their
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    36
  bit lists. Equalities are generated and manipulated in the
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
    37
  reverse order to \<^const>\<open>to_bl\<close>.\<close>
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    38
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    39
lemma bl_word_sub: "to_bl (x - y) = to_bl (x + (- y))"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 51717
diff changeset
    40
  by simp
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    41
71954
13bb3f5cdc5b pragmatically ruled out word types of length zero: a bit string with no bits is not bit string at all
haftmann
parents: 71941
diff changeset
    42
lemma rbl_word_1: "rev (to_bl (1 :: 'a::len word)) = takefill False (LENGTH('a)) [True]"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    43
  apply (rule_tac s="rev (to_bl (word_succ (0 :: 'a word)))" in trans)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    44
   apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    45
  apply (simp only: rtb_rbl_ariths(1)[OF refl])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    46
  apply simp
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
    47
  apply (case_tac "LENGTH('a)")
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    48
   apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    49
  apply (simp add: takefill_alt)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    50
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    51
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    52
lemma rbl_word_if: "rev (to_bl (if P then x else y)) = map2 (If P) (rev (to_bl x)) (rev (to_bl y))"
70193
49a65e3f04c9 consolidated map2 clones
haftmann
parents: 70190
diff changeset
    53
  by (simp add: split_def)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    54
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    55
lemma rbl_add_carry_Cons:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    56
  "(if car then rbl_succ else id) (rbl_add (x # xs) (y # ys)) =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    57
    xor3 x y car # (if carry x y car then rbl_succ else id) (rbl_add xs ys)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    58
  by (simp add: carry_def xor3_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    59
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    60
lemma rbl_add_suc_carry_fold:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    61
  "length xs = length ys \<Longrightarrow>
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    62
    \<forall>car. (if car then rbl_succ else id) (rbl_add xs ys) =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    63
      (foldr (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car)) (zip xs ys) (\<lambda>_. [])) car"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    64
  apply (erule list_induct2)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    65
   apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    66
  apply (simp only: rbl_add_carry_Cons)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    67
  apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    68
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    69
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    70
lemma to_bl_plus_carry:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    71
  "to_bl (x + y) =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    72
    rev (foldr (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car))
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    73
      (rev (zip (to_bl x) (to_bl y))) (\<lambda>_. []) False)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    74
  using rbl_add_suc_carry_fold[where xs="rev (to_bl x)" and ys="rev (to_bl y)"]
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    75
  apply (simp add: word_add_rbl[OF refl refl])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    76
  apply (drule_tac x=False in spec)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    77
  apply (simp add: zip_rev)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    78
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    79
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    80
definition "rbl_plus cin xs ys =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    81
  foldr (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car)) (zip xs ys) (\<lambda>_. []) cin"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    82
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    83
lemma rbl_plus_simps:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    84
  "rbl_plus cin (x # xs) (y # ys) = xor3 x y cin # rbl_plus (carry x y cin) xs ys"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    85
  "rbl_plus cin [] ys = []"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    86
  "rbl_plus cin xs [] = []"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    87
  by (simp_all add: rbl_plus_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    88
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    89
lemma rbl_word_plus: "rev (to_bl (x + y)) = rbl_plus False (rev (to_bl x)) (rev (to_bl y))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    90
  by (simp add: rbl_plus_def to_bl_plus_carry zip_rev)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    91
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    92
definition "rbl_succ2 b xs = (if b then rbl_succ xs else xs)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    93
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    94
lemma rbl_succ2_simps:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    95
  "rbl_succ2 b [] = []"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    96
  "rbl_succ2 b (x # xs) = (b \<noteq> x) # rbl_succ2 (x \<and> b) xs"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    97
  by (simp_all add: rbl_succ2_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
    98
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
    99
lemma twos_complement: "- x = word_succ (NOT x)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   100
  using arg_cong[OF word_add_not[where x=x], where f="\<lambda>a. a - x + 1"]
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   101
  by (simp add: word_succ_p1 word_sp_01[unfolded word_succ_p1] del: word_add_not)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   102
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   103
lemma rbl_word_neg: "rev (to_bl (- x)) = rbl_succ2 True (map Not (rev (to_bl x)))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   104
  by (simp add: twos_complement word_succ_rbl[OF refl] bl_word_not rev_map rbl_succ2_def)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   105
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   106
lemma rbl_word_cat:
71954
13bb3f5cdc5b pragmatically ruled out word types of length zero: a bit string with no bits is not bit string at all
haftmann
parents: 71941
diff changeset
   107
  "rev (to_bl (word_cat x y :: 'a::len word)) =
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   108
    takefill False (LENGTH('a)) (rev (to_bl y) @ rev (to_bl x))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   109
  by (simp add: word_cat_bl word_rev_tf)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   110
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   111
lemma rbl_word_slice:
71954
13bb3f5cdc5b pragmatically ruled out word types of length zero: a bit string with no bits is not bit string at all
haftmann
parents: 71941
diff changeset
   112
  "rev (to_bl (slice n w :: 'a::len word)) =
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   113
    takefill False (LENGTH('a)) (drop n (rev (to_bl w)))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   114
  apply (simp add: slice_take word_rev_tf rev_take)
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   115
  apply (cases "n < LENGTH('b)", simp_all)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   116
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   117
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   118
lemma rbl_word_ucast:
71954
13bb3f5cdc5b pragmatically ruled out word types of length zero: a bit string with no bits is not bit string at all
haftmann
parents: 71941
diff changeset
   119
  "rev (to_bl (ucast x :: 'a::len word)) = takefill False (LENGTH('a)) (rev (to_bl x))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   120
  apply (simp add: to_bl_ucast takefill_alt)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   121
  apply (simp add: rev_drop)
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   122
  apply (cases "LENGTH('a) < LENGTH('b)")
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   123
   apply simp_all
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   124
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   125
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   126
lemma rbl_shiftl:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   127
  "rev (to_bl (w << n)) = takefill False (size w) (replicate n False @ rev (to_bl w))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   128
  by (simp add: bl_shiftl takefill_alt word_size rev_drop)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   129
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   130
lemma rbl_shiftr:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   131
  "rev (to_bl (w >> n)) = takefill False (size w) (drop n (rev (to_bl w)))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   132
  by (simp add: shiftr_slice rbl_word_slice word_size)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   133
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   134
definition "drop_nonempty v n xs = (if n < length xs then drop n xs else [last (v # xs)])"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   135
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   136
lemma drop_nonempty_simps:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   137
  "drop_nonempty v (Suc n) (x # xs) = drop_nonempty x n xs"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   138
  "drop_nonempty v 0 (x # xs) = (x # xs)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   139
  "drop_nonempty v n [] = [v]"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   140
  by (simp_all add: drop_nonempty_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   141
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   142
definition "takefill_last x n xs = takefill (last (x # xs)) n xs"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   143
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   144
lemma takefill_last_simps:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   145
  "takefill_last z (Suc n) (x # xs) = x # takefill_last x n xs"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   146
  "takefill_last z 0 xs = []"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   147
  "takefill_last z n [] = replicate n z"
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   148
  by (simp_all add: takefill_last_def) (simp_all add: takefill_alt)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   149
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   150
lemma rbl_sshiftr:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   151
  "rev (to_bl (w >>> n)) = takefill_last False (size w) (drop_nonempty False n (rev (to_bl w)))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   152
  apply (cases "n < size w")
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   153
   apply (simp add: bl_sshiftr takefill_last_def word_size
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   154
      takefill_alt rev_take last_rev
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   155
      drop_nonempty_def)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   156
  apply (subgoal_tac "(w >>> n) = of_bl (replicate (size w) (msb w))")
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   157
   apply (simp add: word_size takefill_last_def takefill_alt
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   158
      last_rev word_msb_alt word_rev_tf
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   159
      drop_nonempty_def take_Cons')
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   160
   apply (case_tac "LENGTH('a)", simp_all)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   161
  apply (rule word_eqI)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   162
  apply (simp add: nth_sshiftr word_size test_bit_of_bl
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   163
      msb_nth)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   164
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   165
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   166
lemma nth_word_of_int:
71954
13bb3f5cdc5b pragmatically ruled out word types of length zero: a bit string with no bits is not bit string at all
haftmann
parents: 71941
diff changeset
   167
  "(word_of_int x :: 'a::len word) !! n = (n < LENGTH('a) \<and> bin_nth x n)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   168
  apply (simp add: test_bit_bl word_size to_bl_of_bin)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   169
  apply (subst conj_cong[OF refl], erule bin_nth_bl)
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   170
  apply auto
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   171
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   172
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   173
lemma nth_scast:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   174
  "(scast (x :: 'a::len word) :: 'b::len word) !! n =
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   175
    (n < LENGTH('b) \<and>
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   176
    (if n < LENGTH('a) - 1 then x !! n
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   177
     else x !! (LENGTH('a) - 1)))"
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   178
  by (simp add: scast_def nth_sint)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   179
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   180
lemma rbl_word_scast:
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   181
  "rev (to_bl (scast x :: 'a::len word)) = takefill_last False (LENGTH('a)) (rev (to_bl x))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   182
  apply (rule nth_equalityI)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   183
   apply (simp add: word_size takefill_last_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   184
  apply (clarsimp simp: nth_scast takefill_last_def
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   185
      nth_takefill word_size nth_rev to_bl_nth)
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   186
  apply (cases "LENGTH('b)")
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   187
   apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   188
  apply (clarsimp simp: less_Suc_eq_le linorder_not_less
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   189
      last_rev word_msb_alt[symmetric]
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   190
      msb_nth)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   191
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   192
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   193
definition rbl_mul :: "bool list \<Rightarrow> bool list \<Rightarrow> bool list"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67121
diff changeset
   194
  where "rbl_mul xs ys = foldr (\<lambda>x sm. rbl_plus False (map ((\<and>) x) ys) (False # sm)) xs []"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   195
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   196
lemma rbl_mul_simps:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67121
diff changeset
   197
  "rbl_mul (x # xs) ys = rbl_plus False (map ((\<and>) x) ys) (False # rbl_mul xs ys)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   198
  "rbl_mul [] ys = []"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   199
  by (simp_all add: rbl_mul_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   200
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   201
lemma takefill_le2: "length xs \<le> n \<Longrightarrow> takefill x m (takefill x n xs) = takefill x m xs"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   202
  by (simp add: takefill_alt replicate_add[symmetric])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   203
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   204
lemma take_rbl_plus: "\<forall>n b. take n (rbl_plus b xs ys) = rbl_plus b (take n xs) (take n ys)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   205
  apply (simp add: rbl_plus_def take_zip[symmetric])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   206
  apply (rule_tac list="zip xs ys" in list.induct)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   207
   apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   208
  apply (clarsimp simp: split_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   209
  apply (case_tac n, simp_all)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   210
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   211
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   212
lemma word_rbl_mul_induct:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   213
  "length xs \<le> size y \<Longrightarrow>
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   214
    rbl_mul xs (rev (to_bl y)) = take (length xs) (rev (to_bl (of_bl (rev xs) * y)))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   215
  for y :: "'a::len word"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   216
proof (induct xs)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   217
  case Nil
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   218
  show ?case by (simp add: rbl_mul_simps)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   219
next
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   220
  case (Cons z zs)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   221
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   222
  have rbl_word_plus': "to_bl (x + y) = rev (rbl_plus False (rev (to_bl x)) (rev (to_bl y)))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   223
    for x y :: "'a word"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   224
    by (simp add: rbl_word_plus[symmetric])
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   225
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67121
diff changeset
   226
  have mult_bit: "to_bl (of_bl [z] * y) = map ((\<and>) z) (to_bl y)"
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   227
    by (cases z) (simp cong: map_cong, simp add: map_replicate_const cong: map_cong)
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   228
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   229
  have shiftl: "of_bl xs * 2 * y = (of_bl xs * y) << 1" for xs
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   230
    by (simp add: shiftl_t2n)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   231
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   232
  have zip_take_triv: "\<And>xs ys n. n = length ys \<Longrightarrow> zip (take n xs) ys = zip xs ys"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   233
    by (rule nth_equalityI) simp_all
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   234
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   235
  from Cons show ?case
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55465
diff changeset
   236
    apply (simp add: trans [OF of_bl_append add.commute]
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   237
        rbl_mul_simps rbl_word_plus' distrib_right mult_bit shiftl rbl_shiftl)
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   238
    apply (simp add: takefill_alt word_size rev_map take_rbl_plus min_def)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   239
    apply (simp add: rbl_plus_def zip_take_triv)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   240
    done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   241
qed
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   242
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   243
lemma rbl_word_mul: "rev (to_bl (x * y)) = rbl_mul (rev (to_bl x)) (rev (to_bl y))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   244
  for x :: "'a::len word"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   245
  using word_rbl_mul_induct[where xs="rev (to_bl x)" and y=y] by (simp add: word_size)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   246
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61144
diff changeset
   247
text \<open>Breaking up inequalities into bitlist properties.\<close>
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   248
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   249
definition
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   250
  "rev_bl_order F xs ys =
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   251
     (length xs = length ys \<and>
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   252
       ((xs = ys \<and> F)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   253
          \<or> (\<exists>n < length xs. drop (Suc n) xs = drop (Suc n) ys
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   254
                   \<and> \<not> xs ! n \<and> ys ! n)))"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   255
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   256
lemma rev_bl_order_simps:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   257
  "rev_bl_order F [] [] = F"
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   258
  "rev_bl_order F (x # xs) (y # ys) = rev_bl_order ((y \<and> \<not> x) \<or> ((y \<or> \<not> x) \<and> F)) xs ys"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   259
   apply (simp_all add: rev_bl_order_def)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   260
  apply (rule conj_cong[OF refl])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   261
  apply (cases "xs = ys")
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   262
   apply (simp add: nth_Cons')
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   263
   apply blast
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   264
  apply (simp add: nth_Cons')
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   265
  apply safe
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   266
   apply (rule_tac x="n - 1" in exI)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   267
   apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   268
  apply (rule_tac x="Suc n" in exI)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   269
  apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   270
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   271
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   272
lemma rev_bl_order_rev_simp:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   273
  "length xs = length ys \<Longrightarrow>
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   274
   rev_bl_order F (xs @ [x]) (ys @ [y]) = ((y \<and> \<not> x) \<or> ((y \<or> \<not> x) \<and> rev_bl_order F xs ys))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   275
  by (induct arbitrary: F rule: list_induct2) (auto simp: rev_bl_order_simps)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   276
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   277
lemma rev_bl_order_bl_to_bin:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   278
  "length xs = length ys \<Longrightarrow>
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   279
    rev_bl_order True xs ys = (bl_to_bin (rev xs) \<le> bl_to_bin (rev ys)) \<and>
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   280
    rev_bl_order False xs ys = (bl_to_bin (rev xs) < bl_to_bin (rev ys))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   281
  apply (induct xs ys rule: list_induct2)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   282
   apply (simp_all add: rev_bl_order_simps bl_to_bin_app_cat)
54847
d6cf9a5b9be9 prefer plain bool over dedicated type for binary digits
haftmann
parents: 54489
diff changeset
   283
  apply (auto simp add: bl_to_bin_def Bit_B0 Bit_B1 add1_zle_eq Bit_def)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   284
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   285
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   286
lemma word_le_rbl: "x \<le> y \<longleftrightarrow> rev_bl_order True (rev (to_bl x)) (rev (to_bl y))"
71954
13bb3f5cdc5b pragmatically ruled out word types of length zero: a bit string with no bits is not bit string at all
haftmann
parents: 71941
diff changeset
   287
  for x y :: "'a::len word"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   288
  by (simp add: rev_bl_order_bl_to_bin word_le_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   289
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   290
lemma word_less_rbl: "x < y \<longleftrightarrow> rev_bl_order False (rev (to_bl x)) (rev (to_bl y))"
71954
13bb3f5cdc5b pragmatically ruled out word types of length zero: a bit string with no bits is not bit string at all
haftmann
parents: 71941
diff changeset
   291
  for x y :: "'a::len word"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   292
  by (simp add: word_less_alt rev_bl_order_bl_to_bin)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   293
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   294
lemma word_sint_msb_eq: "sint x = uint x - (if msb x then 2 ^ size x else 0)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   295
  apply (cases "msb x")
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   296
   apply (rule word_sint.Abs_eqD[where 'a='a], simp_all)
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   297
    apply (simp add: word_size wi_hom_syms word_of_int_2p_len)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   298
   apply (simp add: sints_num word_size)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   299
   apply (rule conjI)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   300
    apply (simp add: le_diff_eq')
70185
ac1706cdde25 clarified notation
haftmann
parents: 70173
diff changeset
   301
    apply (rule order_trans[where y="2 ^ (LENGTH('a) - 1)"])
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   302
     apply (simp add: power_Suc[symmetric])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   303
    apply (simp add: linorder_not_less[symmetric] mask_eq_iff[symmetric])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   304
    apply (rule notI, drule word_eqD[where x="size x - 1"])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   305
    apply (simp add: msb_nth word_ops_nth_size word_size)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   306
   apply (simp add: order_less_le_trans[where y=0])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   307
  apply (rule word_uint.Abs_eqD[where 'a='a], simp_all)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   308
  apply (simp add: linorder_not_less uints_num word_msb_sint)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   309
  apply (rule order_less_le_trans[OF sint_lt])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   310
  apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   311
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   312
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   313
lemma word_sle_msb_le: "x <=s y \<longleftrightarrow> (msb y \<longrightarrow> msb x) \<and> ((msb x \<and> \<not> msb y) \<or> x \<le> y)"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   314
  apply (simp add: word_sle_def word_sint_msb_eq word_size word_le_def)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   315
  apply safe
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   316
   apply (rule order_trans[OF _ uint_ge_0])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   317
   apply (simp add: order_less_imp_le)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   318
  apply (erule notE[OF leD])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   319
  apply (rule order_less_le_trans[OF _ uint_ge_0])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   320
  apply simp
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   321
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   322
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   323
lemma word_sless_msb_less: "x <s y \<longleftrightarrow> (msb y \<longrightarrow> msb x) \<and> ((msb x \<and> \<not> msb y) \<or> x < y)"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   324
  by (auto simp add: word_sless_def word_sle_msb_le)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   325
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   326
definition "map_last f xs = (if xs = [] then [] else butlast xs @ [f (last xs)])"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   327
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   328
lemma map_last_simps:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   329
  "map_last f [] = []"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   330
  "map_last f [x] = [f x]"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   331
  "map_last f (x # y # zs) = x # map_last f (y # zs)"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   332
  by (simp_all add: map_last_def)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   333
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   334
lemma word_sle_rbl:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   335
  "x <=s y \<longleftrightarrow> rev_bl_order True (map_last Not (rev (to_bl x))) (map_last Not (rev (to_bl y)))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   336
  using word_msb_alt[where w=x] word_msb_alt[where w=y]
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   337
  apply (simp add: word_sle_msb_le word_le_rbl)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   338
  apply (subgoal_tac "length (to_bl x) = length (to_bl y)")
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   339
   apply (cases "to_bl x", simp)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   340
   apply (cases "to_bl y", simp)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   341
   apply (clarsimp simp: map_last_def rev_bl_order_rev_simp)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   342
   apply auto
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   343
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   344
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   345
lemma word_sless_rbl:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   346
  "x <s y \<longleftrightarrow> rev_bl_order False (map_last Not (rev (to_bl x))) (map_last Not (rev (to_bl y)))"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   347
  using word_msb_alt[where w=x] word_msb_alt[where w=y]
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   348
  apply (simp add: word_sless_msb_less word_less_rbl)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   349
  apply (subgoal_tac "length (to_bl x) = length (to_bl y)")
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   350
   apply (cases "to_bl x", simp)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   351
   apply (cases "to_bl y", simp)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   352
   apply (clarsimp simp: map_last_def rev_bl_order_rev_simp)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   353
   apply auto
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   354
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   355
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   356
text \<open>Lemmas for unpacking \<^term>\<open>rev (to_bl n)\<close> for numerals n and also
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   357
  for irreducible values and expressions.\<close>
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   358
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   359
lemma rev_bin_to_bl_simps:
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   360
  "rev (bin_to_bl 0 x) = []"
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   361
  "rev (bin_to_bl (Suc n) (numeral (num.Bit0 nm))) = False # rev (bin_to_bl n (numeral nm))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   362
  "rev (bin_to_bl (Suc n) (numeral (num.Bit1 nm))) = True # rev (bin_to_bl n (numeral nm))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   363
  "rev (bin_to_bl (Suc n) (numeral (num.One))) = True # replicate n False"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   364
  "rev (bin_to_bl (Suc n) (- numeral (num.Bit0 nm))) = False # rev (bin_to_bl n (- numeral nm))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   365
  "rev (bin_to_bl (Suc n) (- numeral (num.Bit1 nm))) =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   366
    True # rev (bin_to_bl n (- numeral (nm + num.One)))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   367
  "rev (bin_to_bl (Suc n) (- numeral (num.One))) = True # replicate n True"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   368
  "rev (bin_to_bl (Suc n) (- numeral (num.Bit0 nm + num.One))) =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   369
    True # rev (bin_to_bl n (- numeral (nm + num.One)))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   370
  "rev (bin_to_bl (Suc n) (- numeral (num.Bit1 nm + num.One))) =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   371
    False # rev (bin_to_bl n (- numeral (nm + num.One)))"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   372
  "rev (bin_to_bl (Suc n) (- numeral (num.One + num.One))) =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   373
    False # rev (bin_to_bl n (- numeral num.One))"
71941
49af3d9a818c replaced mere alias by input abbreviation
haftmann
parents: 70193
diff changeset
   374
  by (simp_all add: bin_to_bl_aux_append bin_to_bl_zero_aux bin_to_bl_minus1_aux replicate_append_same)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   375
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67121
diff changeset
   376
lemma to_bl_upt: "to_bl x = rev (map ((!!) x) [0 ..< size x])"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   377
  apply (rule nth_equalityI)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   378
   apply (simp add: word_size)
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   379
  apply (auto simp: to_bl_nth word_size nth_rev)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   380
  done
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   381
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67121
diff changeset
   382
lemma rev_to_bl_upt: "rev (to_bl x) = map ((!!) x) [0 ..< size x]"
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   383
  by (simp add: to_bl_upt)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   384
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   385
lemma upt_eq_list_intros:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   386
  "j \<le> i \<Longrightarrow> [i ..< j] = []"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   387
  "i = x \<Longrightarrow> x < j \<Longrightarrow> [x + 1 ..< j] = xs \<Longrightarrow> [i ..< j] = (x # xs)"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   388
  by (simp_all add: upt_eq_Cons_conv)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   389
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   390
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   391
subsection \<open>Tactic definition\<close>
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   392
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61144
diff changeset
   393
ML \<open>
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 59643
diff changeset
   394
structure Word_Bitwise_Tac =
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 59643
diff changeset
   395
struct
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   396
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   397
val word_ss = simpset_of \<^theory_context>\<open>Word\<close>;
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   398
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   399
fun mk_nat_clist ns =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   400
  fold_rev (Thm.mk_binop \<^cterm>\<open>Cons :: nat \<Rightarrow> _\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   401
    ns \<^cterm>\<open>[] :: nat list\<close>;
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   402
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   403
fun upt_conv ctxt ct =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59498
diff changeset
   404
  case Thm.term_of ct of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   405
    (\<^const>\<open>upt\<close> $ n $ m) =>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   406
      let
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 57512
diff changeset
   407
        val (i, j) = apply2 (snd o HOLogic.dest_number) (n, m);
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   408
        val ns = map (Numeral.mk_cnumber \<^ctyp>\<open>nat\<close>) (i upto (j - 1))
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   409
          |> mk_nat_clist;
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   410
        val prop =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   411
          Thm.mk_binop \<^cterm>\<open>(=) :: nat list \<Rightarrow> _\<close> ct ns
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   412
          |> Thm.apply \<^cterm>\<open>Trueprop\<close>;
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   413
      in
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   414
        try (fn () =>
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 62913
diff changeset
   415
          Goal.prove_internal ctxt [] prop
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59058
diff changeset
   416
            (K (REPEAT_DETERM (resolve_tac ctxt @{thms upt_eq_list_intros} 1
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   417
                ORELSE simp_tac (put_simpset word_ss ctxt) 1))) |> mk_meta_eq) ()
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   418
      end
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   419
  | _ => NONE;
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   420
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 59643
diff changeset
   421
val expand_upt_simproc =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   422
  Simplifier.make_simproc \<^context> "expand_upt"
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   423
   {lhss = [\<^term>\<open>upt x y\<close>], proc = K upt_conv};
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   424
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   425
fun word_len_simproc_fn ctxt ct =
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   426
  (case Thm.term_of ct of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   427
    Const (\<^const_name>\<open>len_of\<close>, _) $ t =>
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   428
     (let
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   429
        val T = fastype_of t |> dest_Type |> snd |> the_single
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   430
        val n = Numeral.mk_cnumber \<^ctyp>\<open>nat\<close> (Word_Lib.dest_binT T);
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   431
        val prop =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   432
          Thm.mk_binop \<^cterm>\<open>(=) :: nat \<Rightarrow> _\<close> ct n
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   433
          |> Thm.apply \<^cterm>\<open>Trueprop\<close>;
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   434
      in
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   435
        Goal.prove_internal ctxt [] prop (K (simp_tac (put_simpset word_ss ctxt) 1))
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   436
        |> mk_meta_eq |> SOME
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   437
      end handle TERM _ => NONE | TYPE _ => NONE)
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   438
  | _ => NONE);
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   439
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 59643
diff changeset
   440
val word_len_simproc =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   441
  Simplifier.make_simproc \<^context> "word_len"
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   442
   {lhss = [\<^term>\<open>len_of x\<close>], proc = K word_len_simproc_fn};
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   443
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   444
(* convert 5 or nat 5 to Suc 4 when n_sucs = 1, Suc (Suc 4) when n_sucs = 2,
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   445
   or just 5 (discarding nat) when n_sucs = 0 *)
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   446
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   447
fun nat_get_Suc_simproc_fn n_sucs ctxt ct =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   448
  let
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59498
diff changeset
   449
    val (f $ arg) = Thm.term_of ct;
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   450
    val n =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   451
      (case arg of \<^term>\<open>nat\<close> $ n => n | n => n)
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   452
      |> HOLogic.dest_number |> snd;
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   453
    val (i, j) = if n > n_sucs then (n_sucs, n - n_sucs) else (n, 0);
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   454
    val arg' = funpow i HOLogic.mk_Suc (HOLogic.mk_number \<^typ>\<open>nat\<close> j);
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   455
    val _ = if arg = arg' then raise TERM ("", []) else ();
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   456
    fun propfn g =
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   457
      HOLogic.mk_eq (g arg, g arg')
59643
f3be9235503d clarified context;
wenzelm
parents: 59621
diff changeset
   458
      |> HOLogic.mk_Trueprop |> Thm.cterm_of ctxt;
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   459
    val eq1 =
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   460
      Goal.prove_internal ctxt [] (propfn I)
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   461
        (K (simp_tac (put_simpset word_ss ctxt) 1));
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   462
  in
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67399
diff changeset
   463
    Goal.prove_internal ctxt [] (propfn (curry (op $) f))
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   464
      (K (simp_tac (put_simpset HOL_ss ctxt addsimps [eq1]) 1))
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   465
    |> mk_meta_eq |> SOME
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66446
diff changeset
   466
  end handle TERM _ => NONE;
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   467
61144
5e94dfead1c2 simplified simproc programming interfaces;
wenzelm
parents: 59643
diff changeset
   468
fun nat_get_Suc_simproc n_sucs ts =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   469
  Simplifier.make_simproc \<^context> "nat_get_Suc"
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   470
   {lhss = map (fn t => t $ \<^term>\<open>n :: nat\<close>) ts,
62913
13252110a6fe eliminated unused simproc identifier;
wenzelm
parents: 62390
diff changeset
   471
    proc = K (nat_get_Suc_simproc_fn n_sucs)};
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   472
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   473
val no_split_ss =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   474
  simpset_of (put_simpset HOL_ss \<^context>
62390
842917225d56 more canonical names
nipkow
parents: 61799
diff changeset
   475
    |> Splitter.del_split @{thm if_split});
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   476
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   477
val expand_word_eq_sss =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   478
  (simpset_of (put_simpset HOL_basic_ss \<^context> addsimps
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   479
       @{thms word_eq_rbl_eq word_le_rbl word_less_rbl word_sle_rbl word_sless_rbl}),
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   480
  map simpset_of [
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   481
   put_simpset no_split_ss \<^context> addsimps
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   482
    @{thms rbl_word_plus rbl_word_and rbl_word_or rbl_word_not
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   483
                                rbl_word_neg bl_word_sub rbl_word_xor
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   484
                                rbl_word_cat rbl_word_slice rbl_word_scast
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   485
                                rbl_word_ucast rbl_shiftl rbl_shiftr rbl_sshiftr
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   486
                                rbl_word_if},
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   487
   put_simpset no_split_ss \<^context> addsimps
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   488
    @{thms to_bl_numeral to_bl_neg_numeral to_bl_0 rbl_word_1},
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   489
   put_simpset no_split_ss \<^context> addsimps
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   490
    @{thms rev_rev_ident rev_replicate rev_map to_bl_upt word_size}
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   491
          addsimprocs [word_len_simproc],
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   492
   put_simpset no_split_ss \<^context> addsimps
55465
0d31c0546286 merged 'List.map' and 'List.list.map'
blanchet
parents: 54883
diff changeset
   493
    @{thms list.simps split_conv replicate.simps list.map
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   494
                                zip_Cons_Cons zip_Nil drop_Suc_Cons drop_0 drop_Nil
70193
49a65e3f04c9 consolidated map2 clones
haftmann
parents: 70190
diff changeset
   495
                                foldr.simps list.map zip.simps(1) zip_Nil zip_Cons_Cons takefill_Suc_Cons
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   496
                                takefill_Suc_Nil takefill.Z rbl_succ2_simps
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   497
                                rbl_plus_simps rev_bin_to_bl_simps append.simps
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   498
                                takefill_last_simps drop_nonempty_simps
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   499
                                rev_bl_order_simps}
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   500
          addsimprocs [expand_upt_simproc,
54883
dd04a8b654fc proper context for norm_hhf and derived operations;
wenzelm
parents: 54847
diff changeset
   501
                       nat_get_Suc_simproc 4
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   502
                         [\<^term>\<open>replicate\<close>, \<^term>\<open>takefill x\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   503
                          \<^term>\<open>drop\<close>, \<^term>\<open>bin_to_bl\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   504
                          \<^term>\<open>takefill_last x\<close>,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   505
                          \<^term>\<open>drop_nonempty x\<close>]],
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67405
diff changeset
   506
    put_simpset no_split_ss \<^context> addsimps @{thms xor3_simps carry_simps if_bool_simps}
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   507
  ])
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   508
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   509
fun tac ctxt =
50107
289181e3e524 tuned signature;
wenzelm
parents: 49962
diff changeset
   510
  let
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   511
    val (ss, sss) = expand_word_eq_sss;
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   512
  in
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67399
diff changeset
   513
    foldr1 (op THEN_ALL_NEW)
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   514
      ((CHANGED o safe_full_simp_tac (put_simpset ss ctxt)) ::
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   515
        map (fn ss => safe_full_simp_tac (put_simpset ss ctxt)) sss)
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51686
diff changeset
   516
  end;
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   517
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   518
end
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61144
diff changeset
   519
\<close>
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   520
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   521
method_setup word_bitwise =
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61144
diff changeset
   522
  \<open>Scan.succeed (fn ctxt => Method.SIMPLE_METHOD (Word_Bitwise_Tac.tac ctxt 1))\<close>
47567
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   523
  "decomposer for word equalities and inequalities into bit propositions"
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   524
407cabf66f21 New tactic "word_bitwise" expands word equalities/inequalities into logic.
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
diff changeset
   525
end