author | wenzelm |
Sun, 05 Jul 2020 11:06:09 +0200 | |
changeset 71999 | 720b72513ae5 |
parent 66453 | cc19f7ca2ed6 |
child 72508 | c89d8e8bd8c7 |
permissions | -rw-r--r-- |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
1 |
(* Title: HOL/SMT_Examples/SMT_Word_Examples.thy |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
2 |
Author: Sascha Boehme, TU Muenchen |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
3 |
*) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
4 |
|
63167 | 5 |
section \<open>Word examples for for SMT binding\<close> |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
6 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
7 |
theory SMT_Word_Examples |
66453
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents:
63167
diff
changeset
|
8 |
imports "HOL-Word.Word" |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
9 |
begin |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
10 |
|
58061 | 11 |
declare [[smt_oracle = true]] |
12 |
declare [[z3_extensions = true]] |
|
58367
8af1e68d7e1a
renamed SMT certificate files, following 'SMT2' -> 'SMT' renaming
blanchet
parents:
58061
diff
changeset
|
13 |
declare [[smt_certificates = "SMT_Word_Examples.certs"]] |
58061 | 14 |
declare [[smt_read_only_certificates = true]] |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
15 |
|
63167 | 16 |
text \<open> |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
17 |
Currently, there is no proof reconstruction for words. |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
18 |
All lemmas are proved using the oracle mechanism. |
63167 | 19 |
\<close> |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
20 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
21 |
|
63167 | 22 |
section \<open>Bitvector numbers\<close> |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
23 |
|
58061 | 24 |
lemma "(27 :: 4 word) = -5" by smt |
25 |
lemma "(27 :: 4 word) = 11" by smt |
|
26 |
lemma "23 < (27::8 word)" by smt |
|
27 |
lemma "27 + 11 = (6::5 word)" by smt |
|
28 |
lemma "7 * 3 = (21::8 word)" by smt |
|
29 |
lemma "11 - 27 = (-16::8 word)" by smt |
|
58410
6d46ad54a2ab
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents:
58367
diff
changeset
|
30 |
lemma "- (- 11) = (11::5 word)" by smt |
58061 | 31 |
lemma "-40 + 1 = (-39::7 word)" by smt |
32 |
lemma "a + 2 * b + c - b = (b + c) + (a :: 32 word)" by smt |
|
33 |
lemma "x = (5 :: 4 word) \<Longrightarrow> 4 * x = 4" by smt |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
34 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
35 |
|
63167 | 36 |
section \<open>Bit-level logic\<close> |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
37 |
|
58061 | 38 |
lemma "0b110 AND 0b101 = (0b100 :: 32 word)" by smt |
39 |
lemma "0b110 OR 0b011 = (0b111 :: 8 word)" by smt |
|
40 |
lemma "0xF0 XOR 0xFF = (0x0F :: 8 word)" by smt |
|
41 |
lemma "NOT (0xF0 :: 16 word) = 0xFF0F" by smt |
|
42 |
lemma "word_cat (27::4 word) (27::8 word) = (2843::12 word)" by smt |
|
43 |
lemma "word_cat (0b0011::4 word) (0b1111::6word) = (0b0011001111 :: 10 word)" by smt |
|
44 |
lemma "slice 1 (0b10110 :: 4 word) = (0b11 :: 2 word)" by smt |
|
45 |
lemma "ucast (0b1010 :: 4 word) = (0b1010 :: 10 word)" by smt |
|
46 |
lemma "scast (0b1010 :: 4 word) = (0b111010 :: 6 word)" by smt |
|
47 |
lemma "0b10011 << 2 = (0b1001100::8 word)" by smt |
|
48 |
lemma "0b11001 >> 2 = (0b110::8 word)" by smt |
|
49 |
lemma "0b10011 >>> 2 = (0b100::8 word)" by smt |
|
50 |
lemma "word_rotr 2 0b0110 = (0b1001::4 word)" by smt |
|
51 |
lemma "word_rotl 1 0b1110 = (0b1101::4 word)" by smt |
|
52 |
lemma "(x AND 0xff00) OR (x AND 0x00ff) = (x::16 word)" by smt |
|
53 |
lemma "w < 256 \<Longrightarrow> (w :: 16 word) AND 0x00FF = w" by smt |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
54 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
55 |
|
63167 | 56 |
section \<open>Combined integer-bitvector properties\<close> |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
57 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
58 |
lemma |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
59 |
assumes "bv2int 0 = 0" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
60 |
and "bv2int 1 = 1" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
61 |
and "bv2int 2 = 2" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
62 |
and "bv2int 3 = 3" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
63 |
and "\<forall>x::2 word. bv2int x > 0" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
64 |
shows "\<forall>i::int. i < 0 \<longrightarrow> (\<forall>x::2 word. bv2int x > i)" |
58061 | 65 |
using assms by smt |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
66 |
|
58061 | 67 |
lemma "P (0 \<le> (a :: 4 word)) = P True" by smt |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
68 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
diff
changeset
|
69 |
end |