src/HOL/Boogie/Examples/VCC_Max.thy
author boehmes
Mon, 04 Jun 2012 09:07:23 +0200
changeset 49084 e9b2782c4f99
parent 48023 446cfc760ccf
child 49922 5c4275c3b5b8
permissions -rw-r--r--
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
     1 (*  Title:      HOL/Boogie/Examples/VCC_Max.thy
     2     Author:     Sascha Boehme, TU Muenchen
     3 *)
     4 
     5 header {* Boogie example from VCC: get the greatest element of a list *}
     6 
     7 theory VCC_Max
     8 imports Boogie
     9 uses ("VCC_Max.b2i")
    10 begin
    11 
    12 text {*
    13 We prove correct the verification condition generated from the following
    14 C code:
    15 
    16 \begin{verbatim}
    17 #include "vcc.h"
    18 
    19 typedef unsigned char byte;
    20 typedef unsigned long ulong;
    21 
    22 static byte maximum(byte arr[], ulong len)
    23   requires(wrapped(as_array(arr, len)))
    24   requires (0 < len && len < (1UI64 << 40))
    25   ensures (forall(ulong i; i<len ==> arr[i] <= result))
    26   ensures (exists(ulong i; i<len && arr[i] == result))
    27 {
    28   byte max = arr[0];
    29   ulong p;
    30   spec(ulong witness = 0;)
    31 
    32   for (p = 1; p < len; p++)
    33     invariant(p <= len)
    34     invariant(forall(ulong i; i < p ==> arr[i] <= max))
    35     invariant(witness < len && arr[witness] == max)
    36   {
    37     if (arr[p] > max) 
    38     {
    39       max = arr[p];
    40       speconly(witness = p;)
    41     }
    42   }
    43   return max;
    44 }
    45 \end{verbatim}
    46 *}
    47 
    48 boogie_open (quiet) "VCC_Max.b2i"
    49 
    50 declare [[smt_certificates = "VCC_Max.certs"]]
    51 declare [[smt_read_only_certificates = true]]
    52 declare [[smt_oracle = false]]
    53 declare [[z3_with_extensions = true]]
    54 
    55 boogie_status
    56 
    57 boogie_vc maximum
    58   by boogie
    59 
    60 boogie_end
    61 
    62 end