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