To goal of this lecture note is,
Warning
This chapter is under revision.
The accompanying file, contains several versions of the addition and multiplication functions:
As usual for functional programming, unit tests must be provided (and they are in the accompanying file).
As usual for equational reasoning about structurally recursive functions, fold-unfold lemmas must be provided (and some are in the accompanying file).
The following exercises provide a safe, unthreatening playground (you have carried out similar proofs in your handin for Week 04). Some of these induction proofs are routine, and they should be treated as such. Several others require Eureka lemmas, and it is part of the value of these exercises to state these lemmas and to prove them. The skills you will acquire, namely
will prove valuable during the rest of this course (and beyond).
Prove that O is left-neutral for add.
Prove that O is left-neutral for add'.
Prove that O is right-neutral for add.
Prove that O is right-neutral for add'.
Prove that add is associative.
Prove that add' is associative.
Prove that add is commutative.
Prove that add' is commutative.
Using add, implement a recursive version of the multiplication function, mul, unit-test it, and state its fold-unfold lemmas.
See the accompanying file.
Using add', implement a recursive version of the multiplication function, mul', unit-test it, and state its fold-unfold lemmas.
See the accompanying file.
Using add, implement a tail-recursive version of the multiplication function, mul_alt, unit-test it, and state its fold-unfold lemmas.
(Hint: this function is not recursive, it merely calls an auxiliary function that is (tail) recursive (and that uses an accumulator). Only write fold-unfold lemmas for this auxiliary function.)
See the accompanying file.
Using add', implement a tail-recursive version of the multiplication function, mul'_alt, unit-test it, and state its fold-unfold lemmas.
See the accompanying file.
Prove that mul, mul', mul_alt, and mul'_alt are equivalent.
Prove that 0 is left-absorbing for mul, mul', mul_alt, and mul'_alt.
Prove that 1 is left-neutral for mul, mul', mul_alt, and mul'_alt.
Prove that 0 is right-absorbing for mul, mul', mul_alt, and mul'_alt.
Prove that 1 is right-neutral for mul, mul', mul_alt, and mul'_alt.
Prove that each of mul, mul', mul_alt, and mul'_alt is right-distributive over its own version of the addition function (i.e., mul is right-distributive over add, mul_alt is right-distributive over add, etc.).
Prove that each of mul, mul_alt, mul', and mul'_alt is associative.
Prove that each of mul, mul_alt, mul', and mul'_alt is commutative.
Prove that each of mul, mul_alt, mul', and mul'_alt is left-distributive over its own version of the addition function (i.e., mul is left-distributive over add, mul_alt is left-distributive over add, etc.).
Reformatted the unit-test functions uniformly in the resource file [16 Feb 2025]
Updated with more uniform function names [14 Feb 2025]
Created [13 Feb 2025]