To goal of this lecture note is,
The accompanying file, contains several versions of the addition and multiplication functions:
(The tail-recursive versions of the multiplication function you will actually need to implement.)
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 03). 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_v1.
Prove that O is left-neutral for add_v2.
Prove that O is right-neutral for add_v1.
Prove that O is right-neutral for add_v2.
Prove that add_v1 is associative.
Prove that add_v2 is associative.
Prove that add_v1 is commutative.
Prove that add_v2 is commutative.
Using add_v1, implement a recursive version of the multiplication function, mul_v11, unit-test it, and state its fold-unfold lemmas.
See the accompanying file.
Using add_v2, implement a recursive version of the multiplication function, mul_v12, unit-test it, and state its fold-unfold lemmas.
See the accompanying file.
Using add_v1, implement a tail-recursive version of the multiplication function, mul_v21, 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.)
Using add_v2, implement a tail-recursive version of the multiplication function, mul_v22, unit-test it, and state its fold-unfold lemmas.
Prove that mul_v11, mul_v12, mul_v21, and mul_v22 are equivalent.
Prove that 0 is left-absorbing with respect to mul_v11, mul_v12, mul_v21, and mul_v22.
Prove that 1 is left-neutral with respect to mul_v11, mul_v12, mul_v21, and mul_v22.
Prove that 0 is right-absorbing with respect to mul_v11, mul_v12, mul_v21, and mul_v22.
Prove that 1 is right-neutral with respect to mul_v11, mul_v12, mul_v21, and mul_v22.
Prove that each of mul_v11, mul_v12, mul_v21, and mul_v22 is right-distributive over its own version of the addition function (i.e., mul_v11 is right-distributive over add_v1, mul_v12 is right-distributive over add_v2, etc.).
Prove that each of mul_v11, mul_v12, mul_v21, and mul_v22 is associative.
Prove that each of mul_v11, mul_v12, mul_v21, and mul_v22 is commutative.
Prove that each of mul_v11, mul_v12, mul_v21, and mul_v22 is left-distributive over its own version of the addition function (i.e., mul_v11 is left-distributive over add_v1, mul_v12 is left-distributive over add_v2, etc.).
Created [09 Feb 2024]