82523
|
1 |
(* Author: Florian Haftmann, TU Muenchen *)
|
|
2 |
|
|
3 |
section \<open>Tests for simplifying word operations on ground terms\<close>
|
|
4 |
|
|
5 |
theory Word_Computations
|
|
6 |
imports
|
|
7 |
"HOL.Bit_Operations"
|
|
8 |
"HOL-Library.Word"
|
|
9 |
begin
|
|
10 |
|
|
11 |
unbundle bit_operations_syntax
|
|
12 |
|
|
13 |
named_theorems eval
|
|
14 |
|
|
15 |
declare mask_numeral [eval]
|
|
16 |
|
|
17 |
type_synonym word16 = \<open>16 word\<close>
|
|
18 |
type_synonym word32 = \<open>32 word\<close>
|
|
19 |
|
|
20 |
definition computations_arith where
|
|
21 |
[eval]: \<open>computations_arith = (
|
|
22 |
[473514 + - 763, - 5324 - 7892 :: word16],
|
|
23 |
[3131 * - 42, - 2342 div 1213, 2152 mod - 235 :: word16],
|
|
24 |
[12323 \<le> (- 12132 :: word16), - 123 < (321312 :: word16), 12323 \<le>s (- 12132 :: word16), - 123 <s (321312 :: word16)]
|
|
25 |
)\<close>
|
|
26 |
|
|
27 |
definition results_arith where
|
|
28 |
[eval]: \<open>results_arith = (
|
|
29 |
[472751, - 13216 :: word16],
|
|
30 |
[- 131502, 52, 2152 :: word16],
|
|
31 |
[True, False, False, False]
|
|
32 |
)\<close>
|
|
33 |
|
|
34 |
lemma \<open>computations_arith = results_arith\<close>
|
|
35 |
by (simp add: eval)
|
|
36 |
|
|
37 |
definition computations_bit where
|
|
38 |
[eval]: \<open>computations_bit = (
|
|
39 |
[bit (473514 :: word16) 5, bit (- 805167 :: word16) 7],
|
|
40 |
[NOT 473513, NOT (- 805167) :: word16],
|
|
41 |
[473514 AND 767063, - 805167 AND 767063, 473514 AND - 314527, - 805167 AND - 314527 :: word16],
|
|
42 |
[473514 OR 767063, - 805167 OR 767063, 473514 OR - 314527, - 805167 OR - 314527 :: word16],
|
|
43 |
[473514 XOR 767063, - 805167 XOR 767063, 473514 XOR - 314527, - 805167 XOR - 314527 :: word16],
|
|
44 |
mask 11 :: word16,
|
|
45 |
[set_bit 15 473514, set_bit 11 (- 805167) :: word16],
|
|
46 |
[unset_bit 13 473514, unset_bit 12 (- 805167) :: word16],
|
|
47 |
[flip_bit 15 473514, flip_bit 12 (- 805167) :: word16],
|
|
48 |
[push_bit 12 473514, push_bit 12 (- 805167) :: word16],
|
|
49 |
[drop_bit 12 65344, drop_bit 12 (- 17405) :: word16],
|
|
50 |
[signed_drop_bit 12 (- 17405) :: word16],
|
|
51 |
[take_bit 12 473514, take_bit 12 (- 805167) :: word16],
|
|
52 |
[signed_take_bit 12 473514, signed_take_bit 12 (- 805167) :: word16]
|
|
53 |
)\<close>
|
|
54 |
|
|
55 |
definition results_bit where
|
|
56 |
[eval]: \<open>results_bit = (
|
|
57 |
[True, True],
|
|
58 |
[- 473514, 805166 :: word16],
|
|
59 |
[208898, 242769, 209184, - 839103 :: word16],
|
|
60 |
[1031679, - 280873, - 50197, - 280591 :: word16],
|
|
61 |
[822781, - 523642, - 259381, 558512 :: word16],
|
|
62 |
2047 :: word16,
|
|
63 |
[506282, - 803119 :: word16],
|
|
64 |
[465322, - 809263 :: word16],
|
|
65 |
[506282, - 809263 :: word16],
|
|
66 |
[1939513344, - 3297964032 :: word16],
|
|
67 |
[15, 11 :: word16],
|
|
68 |
[- 5 :: word16],
|
|
69 |
[2474, 1745 :: word16],
|
|
70 |
[- 1622, - 2351 :: word16]
|
|
71 |
)\<close>
|
|
72 |
|
|
73 |
lemma \<open>computations_bit = results_bit\<close>
|
|
74 |
by (simp add: eval)
|
|
75 |
|
|
76 |
end
|