

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


This assignment considers program verification, which is the process of prov- ing properties about the executions of programs. We will do some written exercises using Hoare Logic, a logic about program executions, and also make use of the Simplify automatic theorem prover. For this assignment, you will get experience using the (aka rccjava), a typechecker that checks for race conditions in Java programs.
Please do the following exercises from your handout material:
For a primer, try the practice exercises at http://www.cis.ksu.edu/~huth/ lics/tutor/chap4/questions.html.
Now for the fun part. We will write our own little program verifier. Given a program Π, you will prove that executing a program in a state that satisfies precondition Πpre will result in a state that satsifies postcondition Πpost. This will occur in two steps:
We will define programs as having the following grammar:
E ::= n | x | (+ E E) | (− E E) | (∗ E E) B ::= TRUE | FALSE | (NOT B) | (AND B B) | (OR B B) | (EQ E E) | (< E E) C ::= (SET! x E) | (SEQ C C) | (IF B C C) | (WHILE P B C)
All program forms are s-expressions, as in Lisp or Scheme. This will simplify the process of feeding assertions to Simplify for proof, which expects s-expressions in the form above, and will also simplify the process of writing a parser for your language. All WHILE expressions are annotated with an assertion P , which serves as the loop invariant. Our assertion language P essentially extends boolean expressions with implication and universal quantification:
P ::= (FORALL (V ) P ) | (IMPLIES P P ) | TRUE | FALSE | (NOT P ) | (AND P P ) | (OR P P ) | (EQ E E) | (< E E) V ::= x | V x
Your prover will read in programs which start with a precondition, then have a command, and conclude with a postcondition. As an example, the factorial program on page 249 of the handout would be written as follows:
(TRUE) ; precondition (SEQ (SET! y 1) (SEQ (SET! z 0) (SEQ (WHILE (EQ Y (FACT Z)) ; loop invariant (NOT (EQ Z X)) ; loop guard (SEQ (SET! Z (+ Z 1)) ; loop body (SET! Y (* Y Z))))))) (EQ Y (FACT X)) ; postcondition
The text following ; are comments. Note that the loop invariant and postcondi- tion here is not actually expressible in our assertion language P , since we don’t have a predicate FACT. We’ll have to relegate ourselves to simpler assertions. Your program will read in a program Π like the above, generate a verification condition V C(Π) for it, and then feed the compound assertion to simplify that suggests the precondition implies the verification condition. Simplify should return either valid, or invalid. You can ignore the error context. Your program should print out the assertion you gave to simplify, and whether Simplify thought it was valid or not. To test your solution, try out your answers to the exercises above, and see what verifications get generated and whether Simplify can prove them correct. Submit for me your working prover, and its output for these exercises.