The present exercise arose from a live-coding section in class, where a previous generation of students proposed a collection of tests to populate the unit-test function for the power function, based on its specification (see Exercise 11):
Given an integer x,
- base case (i = 0): exponentiating x with 0 yields 1
- induction step (i = succ i’): given a number i’ such that exponentiating x with i’ yields ih (which is the induction hypothesis), exponentiating x with succ i' should yield x * ih
(The intuition behind this inductive specification is that x^n = x * (x * (...(x * 1)...)), where x is iteratively multiplied n times, starting with 1, as per Exercise 01.l in the lecture note about strings.)
The lecturer then fleshed the resulting .ml file with informative error messages, should one of the tests fail.
This .ml file contains a bug, and your task is to locate and fix this bug.
To this end, load this file a few times in OCaml, as in:
# #use "week-05_power.ml";;
...
#
until the bug becomes apparent (i.e., when an assertion fails to hold).
Then figure it out and fix it.
Hint: redefine the silent flag at the beginning of the file to enable the displaying of error messages.
Added Exercise 12 [12 Feb 2023]
Streamlined the unit-test function in the accompanying .ml file for Exercise 21 [11 Feb 2023]
Created [10 Jan 2023]