Exercise 5

This exercise should take less time than the previous weeks.

As before, put any observations you may have, in a report.txt, and hand that in as part of a .zip or tarball containing all relevant Why3 files.

Please, work in pairs!

Submit this exercise in Brightspace; the deadline for submission is Tuesday 5 March 2019, 18:00.

Task: Turing's proof applied to C code

This is a continuation of Task B of exercise 4. Up till now, we have ignored integer overflow (as Turing did), and assumed a computer that supports integers of arbitrary size.

Turing's computer had 80 bits integers; today 64 bits are more natural. So, modify your verified version (or if you failed, use the provided solution) so that it works on 64-bit integers.

Instructions
  1. Use mach.int.UInt64 and modify the signature of fac so it operates on uint64.

  2. The preconditions of some operations will now not hold. Feel free to make minor changes to the code (which do not alter its meaning) to fix this.

  3. Figure out what a maximum n is for which fac still computes factorial correctly, and verify using Why3 that fac indeed computes correctly for inputs up to that maximum value.

  4. Use Why3 to extract C code from your .mlw file. Note: you will need to replace the absurd statement with a simpler return statement that returns your favourite 64-bit integer.

    Does the final C code look reasonable to you?