=========================================================================== CSC 236 Tutorial Exercises for Week 9 Fall 2007 =========================================================================== This is the example in section 2.4 of the textbook, rephrased to use the same notation I use in lecture. Prove the correctness of the following algorithm. Recall that the "right shift" operator >> removes some number of bits from the right end of its first operand (e.g., 11010 >> 1 = 1101). Similarly, the "left shift" operator << adds 0s to the right end of its first operand (e.g., 1101 << 1 = 11010). mult(m, n): # Pre: m in N, n in Z x = m y = n z = 0 # Loop Inv: z = m * n - x * y while x != 0: if x % 2 == 1: z += y x >>= 1 # right shift, equivalent to x /= 2 y <<= 1 # left shift, equivalent to y *= 2 return z # Post: returns m * n