 
Summary: CMPS 282: Software Engineering, Spring 201011 Instructor: Paul Attie
Problem set 4 Due: Wednesday April 6
Department of Computer Science American University of Beirut
All variables used are integer type, unless declared otherwise. In all your answers, provide full
anotations similar to the examples that I have presented in class. In particular, include the loop
invariant for any loop.
1. (30 points) Show that the program below is conditionally correct with respect to its pre
condition a 0 and postcondition b = rev(a), where:
· rev is a function that takes a single string argument and returns the reversed string
(e.g., rev("abc") = "cba").
· a denotes the length of string a.
· "" denotes the empty string.
· + denotes concatentation of two strings, or of a character and a string.
· a[i] denotes the i'th character of string a, with indexing starting at 0 (so that indices
range from 0 to a  1).
For the program below to make sense, interpret the assignment b := a[i] + b as creating a
new string whose value is a[i] + b, and then updating b with this value (as in Java). You
can then apply the assignment axiom.
procedure reverse(value string a; valueresult string b):
{a 0}
