More Axiomatic Program Verification

OVERVIEW



AXIOMS: Multi-assignment

We can modify the assignment axiom schema to allow for multiple, simultaneous assignments.

EXAMPLES

    { 12 > 0 and 15 > 0 } 
        x, y := 12, 15 
    { x > 0 and y > 0 }


    { b > a }  /* a swap */  
        a, b := b, a  
    { a > b }


    { m * 5 = 50 and t + 1 = 26 } 
         m, t := m * 5, t + 1 
    { m = 50 and t = 26 } 

Consider the difference:

    /* assignment sequence */
    { a = b = c = 10 }
        a := 12
        b := a+4
        c := b*2
    { a = 12 and b = 16 and c = 32 }
 

    /* multi-assignment */
    { a = b = c = 10 }
        a, b, c := 12, a+4, b*2
    { a = 12 and b = 14 and c = 20 }


Proof Example: Exponentiation

This is more complicated example containing while loop, if-then-else, and multi-assignment. Generating the loop invariant also requires a new trick.

VERIFYING PROGRAMS WITH ARRAYS

Alpha notation

      alpha(a,i,12)
is our notation for saying: This new mapping can be used as an array name is used...

Formal definition:

                        | i != k then x[k]
     alpha(x,i,f)[k] = -|
                        | i = k then f

ARRAY ASSIGNMENT AXIOMS

Examples of Array Assignment Axioms

   { Q: alpha(r,j,14)[j] < alpha(r,j,14)[k] }
       r[j] := 14
   { P: r[j] < r[k] }
Note: the substitution that has occurred is to replace "r" by "alpha(r,j,14)"
the subscript expressions like "[j]" etc. remain unchanged...

Successive assignments:

   { alpha(alpha(b,i,k),j,j+1)[m] = f(x) }
       b[i] := k
   { alpha(b,j,j+1)[m] = f(x) }    by A.A. axiom
and
   { alpha(b,j,j+1)[m] = f(x) }
       b[j] := j + 1
   { b[m] = f(x) }                 by A.A. axiom
so,
   { alpha(alpha(b,i,k),j,j+1)[m] = f(x) }
       b[i] := k
       b[j] := j + 1
   { b[m] = f(x) }                 by Composition


Proof Example: Using Arrays

This program does a left shift of elements in an array.


GENERATING NEW HOARE INFERENCE RULES