CS 334
Programming Languages
Spring 2000

Assignment 8
Due Friday, 4/28/2000


  1. Use the formal rules for axiomatic semantics given in the lecture notes to prove the correctness of the following program:
    {Precondition: n > 0}
       i <- n
       fact <- 1
       while i > 0 do
       {assert:  ...}
          fact <- fact * i
          i <- i - 1
       end while
    {Postcondition:	fact = 1*2*...*n}
    Hint: You need to figure out the loop invariant before you can complete the proof. Your proof should take the same form as the one in the lecture notes - hand-waving is NOT acceptable. Be sure to prove the entire algorithm is correct with respect to the precondition and postcondition. The lecture notes example only includes showing the loop invariant is correct. You must prove the entire program correct with respect to the precondition and postcondition!

    Note: If you prefer to use the weakest precondition rules in the text, be my guest, but I suspect you will find it easier to use those given in class instead.

  2. Do problem 14 on page 493 of the text using the "small-step" operational semantics given in the text. See the solution to problem 12 in the back of the book for a good hint as to how this is done.

  3. Do problem 22 on page 542 of the text.