src/HOL/SMT_Examples/SMT_Word_Examples.thy
author haftmann
Sat Jul 05 11:01:53 2014 +0200 (2014-07-05)
changeset 57514 bdc2c6b40bf2
parent 56109 1ba56358eba4
child 58061 3d060f43accb
permissions -rw-r--r--
prefer ac_simps collections over separate name bindings for add and mult
     1 (*  Title:      HOL/SMT_Examples/SMT_Word_Examples.thy
     2     Author:     Sascha Boehme, TU Muenchen
     3 *)
     4 
     5 header {* Word examples for for SMT binding *}
     6 
     7 theory SMT_Word_Examples
     8 imports "~~/src/HOL/Word/Word"
     9 begin
    10 
    11 declare [[smt2_oracle = true]]
    12 declare [[z3_new_extensions = true]]
    13 declare [[smt2_certificates = "SMT_Word_Examples.certs2"]]
    14 declare [[smt2_read_only_certificates = true]]
    15 
    16 text {*
    17 Currently, there is no proof reconstruction for words.
    18 All lemmas are proved using the oracle mechanism.
    19 *}
    20 
    21 
    22 section {* Bitvector numbers *}
    23 
    24 lemma "(27 :: 4 word) = -5" by smt2
    25 lemma "(27 :: 4 word) = 11" by smt2
    26 lemma "23 < (27::8 word)" by smt2
    27 lemma "27 + 11 = (6::5 word)" by smt2
    28 lemma "7 * 3 = (21::8 word)" by smt2
    29 lemma "11 - 27 = (-16::8 word)" by smt2
    30 lemma "- -11 = (11::5 word)" by smt2
    31 lemma "-40 + 1 = (-39::7 word)" by smt2
    32 lemma "a + 2 * b + c - b = (b + c) + (a :: 32 word)" by smt2
    33 lemma "x = (5 :: 4 word) \<Longrightarrow> 4 * x = 4" by smt2
    34 
    35 
    36 section {* Bit-level logic *}
    37 
    38 lemma "0b110 AND 0b101 = (0b100 :: 32 word)" by smt2
    39 lemma "0b110 OR 0b011 = (0b111 :: 8 word)" by smt2
    40 lemma "0xF0 XOR 0xFF = (0x0F :: 8 word)" by smt2
    41 lemma "NOT (0xF0 :: 16 word) = 0xFF0F" by smt2
    42 lemma "word_cat (27::4 word) (27::8 word) = (2843::12 word)" by smt2
    43 lemma "word_cat (0b0011::4 word) (0b1111::6word) = (0b0011001111 :: 10 word)" by smt2
    44 lemma "slice 1 (0b10110 :: 4 word) = (0b11 :: 2 word)" by smt2
    45 lemma "ucast (0b1010 :: 4 word) = (0b1010 :: 10 word)" by smt2
    46 lemma "scast (0b1010 :: 4 word) = (0b111010 :: 6 word)" by smt2
    47 lemma "0b10011 << 2 = (0b1001100::8 word)" by smt2
    48 lemma "0b11001 >> 2 = (0b110::8 word)" by smt2
    49 lemma "0b10011 >>> 2 = (0b100::8 word)" by smt2
    50 lemma "word_rotr 2 0b0110 = (0b1001::4 word)" by smt2
    51 lemma "word_rotl 1 0b1110 = (0b1101::4 word)" by smt2
    52 lemma "(x AND 0xff00) OR (x AND 0x00ff) = (x::16 word)" by smt2
    53 lemma "w < 256 \<Longrightarrow> (w :: 16 word) AND 0x00FF = w" by smt2
    54 
    55 
    56 section {* Combined integer-bitvector properties *}
    57 
    58 lemma
    59   assumes "bv2int 0 = 0"
    60       and "bv2int 1 = 1"
    61       and "bv2int 2 = 2"
    62       and "bv2int 3 = 3"
    63       and "\<forall>x::2 word. bv2int x > 0"
    64   shows "\<forall>i::int. i < 0 \<longrightarrow> (\<forall>x::2 word. bv2int x > i)"
    65   using assms by smt2
    66 
    67 lemma "P (0 \<le> (a :: 4 word)) = P True" by smt2
    68 
    69 end