1. Let B be a (mathematical) function mapping natural numbers to integers. Devise a pseudo-tail recursive definition for the function Max having the property that, for n >= 0,
For example, Max.4 = B.0 max B.1 max B.2 max B.3.
From that definition, derive a (fully) tail recursive definition for the function Max' having the property that, for any n >= 0,
Using either the tail recursive definition of Max' or the pseudo-tail recursive definition of Max, derive a program that computes Max. In your program, use N as the input variable (constant) and y as the output variable. Thus, its postcondition should be y = Max.N (which is equivalent to y = Max'.N.0). Of course, your program may refer to B (e.g., as though it were an array). That is, for example, if k is an integer variable with value at least zero, the expression B.k (or B(k) if you prefer) yields the intended value.
2. Using the notation [v] as shorthand for v ⊕ empty, here is a pseudo-tail recursive definition of the list reversal function:
rev.x = { empty if x = empty
{ rev.(tail.x) | [head.x] otherwise
Note that, in this definition, the recursive application of the
function is within the left operand of the main operator (|),
not the right operand.
From this derive a tail recursive definition of rev' such that rev'.x.empty = rev.x. Then show the corresponding program, whose input variable (constant) is X and whose postcondition is rev.X = y.