| author | chaieb |
| Wed, 22 Aug 2007 17:13:41 +0200 | |
| changeset 24403 | b7c3ee2ca184 |
| parent 24401 | d9d2aa843a3b |
| child 24408 | 058c5613a86f |
| permissions | -rw-r--r-- |
|
24397
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
1 |
(* |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
2 |
ID: $Id$ |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
3 |
Author: Jeremy Dawson and Gerwin Klein, NICTA |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
4 |
*) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
5 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
6 |
header {* Bool Lists and Words *}
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
7 |
|
|
24401
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
8 |
theory WordBoolList imports BinBoolList WordBitwise begin |
|
24397
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
9 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
10 |
constdefs |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
11 |
of_bl :: "bool list => 'a :: len0 word" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
12 |
"of_bl bl == word_of_int (bl_to_bin bl)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
13 |
to_bl :: "'a :: len0 word => bool list" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
14 |
"to_bl w == |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
15 |
bin_to_bl (len_of TYPE ('a)) (uint w)"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
16 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
17 |
word_reverse :: "'a :: len0 word => 'a word" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
18 |
"word_reverse w == of_bl (rev (to_bl w))" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
19 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
20 |
defs (overloaded) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
21 |
word_set_bits_def: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
22 |
"(BITS n. f n)::'a::len0 word == of_bl (bl_of_nth (len_of TYPE ('a)) f)"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
23 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
24 |
lemmas of_nth_def = word_set_bits_def |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
25 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
26 |
lemma to_bl_def': |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
27 |
"(to_bl :: 'a :: len0 word => bool list) = |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
28 |
bin_to_bl (len_of TYPE('a)) o uint"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
29 |
by (auto simp: to_bl_def intro: ext) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
30 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
31 |
lemmas word_reverse_no_def [simp] = word_reverse_def [of "number_of ?w"] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
32 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
33 |
(* type definitions theorem for in terms of equivalent bool list *) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
34 |
lemma td_bl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
35 |
"type_definition (to_bl :: 'a::len0 word => bool list) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
36 |
of_bl |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
37 |
{bl. length bl = len_of TYPE('a)}"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
38 |
apply (unfold type_definition_def of_bl_def to_bl_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
39 |
apply (simp add: word_ubin.eq_norm) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
40 |
apply safe |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
41 |
apply (drule sym) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
42 |
apply simp |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
43 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
44 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
45 |
interpretation word_bl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
46 |
type_definition ["to_bl :: 'a::len0 word => bool list" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
47 |
of_bl |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
48 |
"{bl. length bl = len_of TYPE('a::len0)}"]
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
49 |
by (rule td_bl) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
50 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
51 |
lemma word_size_bl: "size w == size (to_bl w)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
52 |
unfolding word_size by auto |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
53 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
54 |
lemma to_bl_use_of_bl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
55 |
"(to_bl w = bl) = (w = of_bl bl \<and> length bl = length (to_bl w))" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
56 |
by (fastsimp elim!: word_bl.Abs_inverse [simplified]) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
57 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
58 |
lemma to_bl_word_rev: "to_bl (word_reverse w) = rev (to_bl w)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
59 |
unfolding word_reverse_def by (simp add: word_bl.Abs_inverse) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
60 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
61 |
lemma word_rev_rev [simp] : "word_reverse (word_reverse w) = w" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
62 |
unfolding word_reverse_def by (simp add : word_bl.Abs_inverse) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
63 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
64 |
lemma word_rev_gal: "word_reverse w = u ==> word_reverse u = w" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
65 |
by auto |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
66 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
67 |
lemmas word_rev_gal' = sym [THEN word_rev_gal, symmetric, standard] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
68 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
69 |
lemmas length_bl_gt_0 [iff] = xtr1 [OF word_bl.Rep' len_gt_0, standard] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
70 |
lemmas bl_not_Nil [iff] = |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
71 |
length_bl_gt_0 [THEN length_greater_0_conv [THEN iffD1], standard] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
72 |
lemmas length_bl_neq_0 [iff] = length_bl_gt_0 [THEN gr_implies_not0] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
73 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
74 |
lemma hd_bl_sign_sint: "hd (to_bl w) = (bin_sign (sint w) = Numeral.Min)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
75 |
apply (unfold to_bl_def sint_uint) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
76 |
apply (rule trans [OF _ bl_sbin_sign]) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
77 |
apply simp |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
78 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
79 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
80 |
lemma of_bl_drop': |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
81 |
"lend = length bl - len_of TYPE ('a :: len0) ==>
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
82 |
of_bl (drop lend bl) = (of_bl bl :: 'a word)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
83 |
apply (unfold of_bl_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
84 |
apply (clarsimp simp add : trunc_bl2bin [symmetric]) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
85 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
86 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
87 |
lemmas of_bl_no = of_bl_def [folded word_number_of_def] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
88 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
89 |
lemma test_bit_of_bl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
90 |
"(of_bl bl::'a::len0 word) !! n = (rev bl ! n \<and> n < len_of TYPE('a) \<and> n < length bl)"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
91 |
apply (unfold of_bl_def word_test_bit_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
92 |
apply (auto simp add: word_size word_ubin.eq_norm nth_bintr bin_nth_of_bl) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
93 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
94 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
95 |
lemma no_of_bl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
96 |
"(number_of bin ::'a::len0 word) = of_bl (bin_to_bl (len_of TYPE ('a)) bin)"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
97 |
unfolding word_size of_bl_no by (simp add : word_number_of_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
98 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
99 |
lemma uint_bl: "to_bl w == bin_to_bl (size w) (uint w)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
100 |
unfolding word_size to_bl_def by auto |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
101 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
102 |
lemma to_bl_bin: "bl_to_bin (to_bl w) = uint w" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
103 |
unfolding uint_bl by (simp add : word_size) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
104 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
105 |
lemma to_bl_of_bin: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
106 |
"to_bl (word_of_int bin::'a::len0 word) = bin_to_bl (len_of TYPE('a)) bin"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
107 |
unfolding uint_bl by (clarsimp simp add: word_ubin.eq_norm word_size) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
108 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
109 |
lemmas to_bl_no_bin [simp] = to_bl_of_bin [folded word_number_of_def] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
110 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
111 |
lemma to_bl_to_bin [simp] : "bl_to_bin (to_bl w) = uint w" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
112 |
unfolding uint_bl by (simp add : word_size) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
113 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
114 |
lemmas uint_bl_bin [simp] = trans [OF bin_bl_bin word_ubin.norm_Rep, standard] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
115 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
116 |
lemma word_rev_tf': |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
117 |
"r = to_bl (of_bl bl) ==> r = rev (takefill False (length r) (rev bl))" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
118 |
unfolding of_bl_def uint_bl |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
119 |
by (clarsimp simp add: bl_bin_bl_rtf word_ubin.eq_norm word_size) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
120 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
121 |
lemmas word_rev_tf = refl [THEN word_rev_tf', unfolded word_bl.Rep', standard] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
122 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
123 |
lemmas word_rep_drop = word_rev_tf [simplified takefill_alt, |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
124 |
simplified, simplified rev_take, simplified] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
125 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
126 |
lemma of_bl_append_same: "of_bl (X @ to_bl w) = w" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
127 |
by (rule word_bl.Rep_eqD) (simp add: word_rep_drop) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
128 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
129 |
lemma ucast_bl: "ucast w == of_bl (to_bl w)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
130 |
unfolding ucast_def of_bl_def uint_bl |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
131 |
by (auto simp add : word_size) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
132 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
133 |
lemma to_bl_ucast: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
134 |
"to_bl (ucast (w::'b::len0 word) ::'a::len0 word) = |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
135 |
replicate (len_of TYPE('a) - len_of TYPE('b)) False @
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
136 |
drop (len_of TYPE('b) - len_of TYPE('a)) (to_bl w)"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
137 |
apply (unfold ucast_bl) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
138 |
apply (rule trans) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
139 |
apply (rule word_rep_drop) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
140 |
apply simp |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
141 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
142 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
143 |
lemma ucast_up_app': |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
144 |
"uc = ucast ==> source_size uc + n = target_size uc ==> |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
145 |
to_bl (uc w) = replicate n False @ (to_bl w)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
146 |
apply (auto simp add : source_size target_size to_bl_ucast) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
147 |
apply (rule_tac f = "%n. replicate n False" in arg_cong) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
148 |
apply simp |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
149 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
150 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
151 |
lemma ucast_down_drop': |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
152 |
"uc = ucast ==> source_size uc = target_size uc + n ==> |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
153 |
to_bl (uc w) = drop n (to_bl w)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
154 |
by (auto simp add : source_size target_size to_bl_ucast) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
155 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
156 |
lemma scast_down_drop': |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
157 |
"sc = scast ==> source_size sc = target_size sc + n ==> |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
158 |
to_bl (sc w) = drop n (to_bl w)" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
159 |
apply (subgoal_tac "sc = ucast") |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
160 |
apply safe |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
161 |
apply simp |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
162 |
apply (erule refl [THEN ucast_down_drop']) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
163 |
apply (rule refl [THEN down_cast_same', symmetric]) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
164 |
apply (simp add : source_size target_size is_down) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
165 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
166 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
167 |
lemmas ucast_up_app = refl [THEN ucast_up_app'] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
168 |
lemmas ucast_down_drop = refl [THEN ucast_down_drop'] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
169 |
lemmas scast_down_drop = refl [THEN scast_down_drop'] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
170 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
171 |
lemma ucast_of_bl_up': |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
172 |
"w = of_bl bl ==> size bl <= size w ==> ucast w = of_bl bl" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
173 |
by (auto simp add : nth_ucast word_size test_bit_of_bl intro!: word_eqI) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
174 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
175 |
lemmas ucast_of_bl_up = refl [THEN ucast_of_bl_up'] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
176 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
177 |
lemma ucast_down_bl': "uc = ucast ==> is_down uc ==> uc (of_bl bl) = of_bl bl" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
178 |
unfolding of_bl_no by clarify (erule ucast_down_no) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
179 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
180 |
lemmas ucast_down_bl = ucast_down_bl' [OF refl] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
181 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
182 |
lemma word_0_bl: "of_bl [] = 0" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
183 |
unfolding word_0_wi of_bl_def by (simp add : Pls_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
184 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
185 |
lemma word_1_bl: "of_bl [True] = 1" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
186 |
unfolding word_1_wi of_bl_def |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
187 |
by (simp add : bl_to_bin_def Bit_def Pls_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
188 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
189 |
lemma of_bl_0 [simp] : "of_bl (replicate n False) = 0" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
190 |
by (simp add : word_0_wi of_bl_def bl_to_bin_rep_False Pls_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
191 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
192 |
lemma to_bl_0: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
193 |
"to_bl (0::'a::len0 word) = replicate (len_of TYPE('a)) False"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
194 |
unfolding uint_bl |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
195 |
by (simp add : word_size bin_to_bl_Pls Pls_def [symmetric]) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
196 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
197 |
(* links with rbl operations *) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
198 |
lemma word_succ_rbl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
199 |
"to_bl w = bl ==> to_bl (word_succ w) = (rev (rbl_succ (rev bl)))" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
200 |
apply (unfold word_succ_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
201 |
apply clarify |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
202 |
apply (simp add: to_bl_of_bin) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
203 |
apply (simp add: to_bl_def rbl_succ) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
204 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
205 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
206 |
lemma word_pred_rbl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
207 |
"to_bl w = bl ==> to_bl (word_pred w) = (rev (rbl_pred (rev bl)))" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
208 |
apply (unfold word_pred_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
209 |
apply clarify |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
210 |
apply (simp add: to_bl_of_bin) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
211 |
apply (simp add: to_bl_def rbl_pred) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
212 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
213 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
214 |
lemma word_add_rbl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
215 |
"to_bl v = vbl ==> to_bl w = wbl ==> |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
216 |
to_bl (v + w) = (rev (rbl_add (rev vbl) (rev wbl)))" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
217 |
apply (unfold word_add_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
218 |
apply clarify |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
219 |
apply (simp add: to_bl_of_bin) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
220 |
apply (simp add: to_bl_def rbl_add) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
221 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
222 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
223 |
lemma word_mult_rbl: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
224 |
"to_bl v = vbl ==> to_bl w = wbl ==> |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
225 |
to_bl (v * w) = (rev (rbl_mult (rev vbl) (rev wbl)))" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
226 |
apply (unfold word_mult_def) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
227 |
apply clarify |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
228 |
apply (simp add: to_bl_of_bin) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
229 |
apply (simp add: to_bl_def rbl_mult) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
230 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
231 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
232 |
lemma rtb_rbl_ariths: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
233 |
"rev (to_bl w) = ys \<Longrightarrow> rev (to_bl (word_succ w)) = rbl_succ ys" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
234 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
235 |
"rev (to_bl w) = ys \<Longrightarrow> rev (to_bl (word_pred w)) = rbl_pred ys" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
236 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
237 |
"[| rev (to_bl v) = ys; rev (to_bl w) = xs |] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
238 |
==> rev (to_bl (v * w)) = rbl_mult ys xs" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
239 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
240 |
"[| rev (to_bl v) = ys; rev (to_bl w) = xs |] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
241 |
==> rev (to_bl (v + w)) = rbl_add ys xs" |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
242 |
by (auto simp: rev_swap [symmetric] word_succ_rbl |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
243 |
word_pred_rbl word_mult_rbl word_add_rbl) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
244 |
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
245 |
lemma of_bl_length_less: |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
246 |
"length x = k ==> k < len_of TYPE('a) ==> (of_bl x :: 'a :: len word) < 2 ^ k"
|
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
247 |
apply (unfold of_bl_no [unfolded word_number_of_def] |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
248 |
word_less_alt word_number_of_alt) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
249 |
apply safe |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
250 |
apply (simp (no_asm) add: word_of_int_power_hom word_uint.eq_norm |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
251 |
del: word_of_int_bin) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
252 |
apply (simp add: mod_pos_pos_trivial) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
253 |
apply (subst mod_pos_pos_trivial) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
254 |
apply (rule bl_to_bin_ge0) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
255 |
apply (rule order_less_trans) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
256 |
apply (rule bl_to_bin_lt2p) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
257 |
apply simp |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
258 |
apply (rule bl_to_bin_lt2p) |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
259 |
done |
|
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
260 |
|
|
24401
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
261 |
subsection "Bitwise operations on bool lists" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
262 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
263 |
lemma bl_word_not: "to_bl (NOT w) = map Not (to_bl w)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
264 |
unfolding to_bl_def word_log_defs |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
265 |
by (simp add: bl_not_bin number_of_is_id word_no_wi [symmetric]) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
266 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
267 |
lemma bl_word_xor: "to_bl (v XOR w) = app2 op ~= (to_bl v) (to_bl w)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
268 |
unfolding to_bl_def word_log_defs bl_xor_bin |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
269 |
by (simp add: number_of_is_id word_no_wi [symmetric]) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
270 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
271 |
lemma bl_word_or: "to_bl (v OR w) = app2 op | (to_bl v) (to_bl w)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
272 |
unfolding to_bl_def word_log_defs |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
273 |
by (simp add: bl_or_bin number_of_is_id word_no_wi [symmetric]) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
274 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
275 |
lemma bl_word_and: "to_bl (v AND w) = app2 op & (to_bl v) (to_bl w)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
276 |
unfolding to_bl_def word_log_defs |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
277 |
by (simp add: bl_and_bin number_of_is_id word_no_wi [symmetric]) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
278 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
279 |
lemma word_lsb_last: "lsb (w::'a::len word) = last (to_bl w)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
280 |
apply (unfold word_lsb_def uint_bl bin_to_bl_def) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
281 |
apply (rule_tac bin="uint w" in bin_exhaust) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
282 |
apply (cases "size w") |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
283 |
apply auto |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
284 |
apply (auto simp add: bin_to_bl_aux_alt) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
285 |
done |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
286 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
287 |
lemma word_msb_alt: "msb (w::'a::len word) = hd (to_bl w)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
288 |
apply (unfold word_msb_nth uint_bl) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
289 |
apply (subst hd_conv_nth) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
290 |
apply (rule length_greater_0_conv [THEN iffD1]) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
291 |
apply simp |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
292 |
apply (simp add : nth_bin_to_bl word_size) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
293 |
done |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
294 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
295 |
lemma bin_nth_uint': |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
296 |
"bin_nth (uint w) n = (rev (bin_to_bl (size w) (uint w)) ! n & n < size w)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
297 |
apply (unfold word_size) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
298 |
apply (safe elim!: bin_nth_uint_imp) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
299 |
apply (frule bin_nth_uint_imp) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
300 |
apply (fast dest!: bin_nth_bl)+ |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
301 |
done |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
302 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
303 |
lemmas bin_nth_uint = bin_nth_uint' [unfolded word_size] |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
304 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
305 |
lemma test_bit_bl: "w !! n = (rev (to_bl w) ! n & n < size w)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
306 |
unfolding to_bl_def word_test_bit_def word_size |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
307 |
by (rule bin_nth_uint) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
308 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
309 |
lemma to_bl_nth: "n < size w ==> to_bl w ! n = w !! (size w - Suc n)" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
310 |
apply (unfold test_bit_bl) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
311 |
apply clarsimp |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
312 |
apply (rule trans) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
313 |
apply (rule nth_rev_alt) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
314 |
apply (auto simp add: word_size) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
315 |
done |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
316 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
317 |
lemma of_bl_rep_False: "of_bl (replicate n False @ bs) = of_bl bs" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
318 |
unfolding of_bl_def bl_to_bin_rep_F by auto |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
319 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
320 |
lemma td_ext_nth': |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
321 |
"n = size (w::'a::len0 word) ==> ofn = set_bits ==> [w, ofn g] = l ==> |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
322 |
td_ext test_bit ofn {f. ALL i. f i --> i < n} (%h i. h i & i < n)"
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
323 |
apply (unfold word_size td_ext_def') |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
324 |
apply safe |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
325 |
apply (rule_tac [3] ext) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
326 |
apply (rule_tac [4] ext) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
327 |
apply (unfold word_size of_nth_def test_bit_bl) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
328 |
apply safe |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
329 |
defer |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
330 |
apply (clarsimp simp: word_bl.Abs_inverse)+ |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
331 |
apply (rule word_bl.Rep_inverse') |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
332 |
apply (rule sym [THEN trans]) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
333 |
apply (rule bl_of_nth_nth) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
334 |
apply simp |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
335 |
apply (rule bl_of_nth_inj) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
336 |
apply (clarsimp simp add : test_bit_bl word_size) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
337 |
done |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
338 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
339 |
lemmas td_ext_nth = td_ext_nth' [OF refl refl refl, unfolded word_size] |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
340 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
341 |
interpretation test_bit: |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
342 |
td_ext ["op !! :: 'a::len0 word => nat => bool" |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
343 |
set_bits |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
344 |
"{f. \<forall>i. f i \<longrightarrow> i < len_of TYPE('a::len0)}"
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
345 |
"(\<lambda>h i. h i \<and> i < len_of TYPE('a::len0))"]
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
346 |
by (rule td_ext_nth) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
347 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
348 |
declare test_bit.Rep' [simp del] |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
349 |
declare test_bit.Rep' [rule del] |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
350 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
351 |
lemmas td_nth = test_bit.td_thm |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
352 |
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
353 |
lemma to_bl_n1: |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
354 |
"to_bl (-1::'a::len0 word) = replicate (len_of TYPE ('a)) True"
|
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
355 |
apply (rule word_bl.Abs_inverse') |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
356 |
apply simp |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
357 |
apply (rule word_eqI) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
358 |
apply (clarsimp simp add: word_size test_bit_no) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
359 |
apply (auto simp add: word_bl.Abs_inverse test_bit_bl word_size) |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
360 |
done |
|
d9d2aa843a3b
move bool list operations from WordBitwise to WordBoolList
huffman
parents:
24397
diff
changeset
|
361 |
|
|
24397
eaf37b780683
move bool list stuff from WordDefinition and WordArith to new WordBoolList theory
huffman
parents:
diff
changeset
|
362 |
end |