Smatchcube's website 🌍

Exercise 2.58


We only need to change the representation thanks to the power of abstraction.


As the deriv procedure is checking if it’s a sum before if it’s a product we can make only relatively small changes in order to respect priority of computation and to drop useless parentheses. Indeed, if the deriv procedure is computing the derivative of a product in an expression, it means that the expression is not a sum (because it’s checking first if it’s a sum), so it takes automatically care of priority. It’s a bit tricky but it works perfectly. I’m pretty sure the order of the predicates in the deriv procedure was carefully thought from the beginning by the wise authors to take this idea into account.

Note that I’m not changing the constructor make-sum and make-product to drop useless parentheses for the output because it can really be complicated.