CSCI P415/515 | Tue Mar 29 14:27:08 EDT 2011 [SDJ] |
If you wish to do this assignment, consult with the instructor for help getting started.
Reverse(A, L, U) takes an array A with lower and upper bounds L and U, with L ≤ U.
Reverse(A: ARRAY[nat->T], L:nat, U:{i:nat | l <= i}): RECURSIVE ARRAY[nat->T] = ...
Reversed?(A, B: ARRAY[nat->T], L:nat, U:{i:nat | l <= i}): bool = FORALL (k: {i: nat | i <= U-L): A(L+k) = A(U-k)
Notes and Comments
is represented as an iterative function
while test do {body}
Loop(x, y, z): RECURSIVE state = IF NOT test THEN value ELSE Loop( {effect of body on x, y, z}) ENDIF MEASURE { some measure}
is similarly represented by nested function calls
while test1 do {
while test2 do { body }
}
InnerLoop(x, y, z): RECURSIVE state = IF NOT test2 THEN value2 ELSE InnerLoop( {effect of body on x, y, z}) ENDIF MEASURE { some measure} OuterLoop(x, y, z): RECURSIVE state = IF NOT test1 THEN value1 ELSE OuterLoop( InnerLoop(x, y, z)) ENDIF MEASURE { some measure}