SICP 2.3.2 Exercises
February 15, 2015 10:39
After the introduction of symbolic data, we jump right into one of several examples of how to use it. In this section, we create a symbolic differentiation processor. It seems like quite
When I first encountered this section, I have to admit I was quite impressed with how easy it is to create a powerful abstract system from a few simple rules. This was originally developed years ago when the book was first written. It would’ve blown me away then, and still somehow feels magical to me. Symbolic representation opens a lot of doors.
In the exercises file there are a few test functions that will run through some example derivatives to compute. The
basic-deriv-check and others like it merely show the result of the expression; it’s up to the user to actually check that it’s correct. The reason for this is apparent when considering one of the major limitations of the system, as mentioned in the text – it’s difficult to simplify results to a particular desired form. Since that isn’t really part of these exercises, it’s left as a matter for human inspection. Although even then it can be a bit tricky to determine that the answer is the desired one.
The final exercise really does involve a fair amount of work to get right. Since it can sometimes be a bit confusing to tell where exactly the problem is when testing the whole derivative process, there are several additional tests. The first test focus just on the selectors, which may or may not match with your approach. There is also a procedure called
calc-xpr (based on
deriv) that, instead of taking the derivative, merely calculates the expression given.
The tests I’ve provided assume you’re implementing the suggested extensions, but there isn’t any particular reason you’d have to. As much as I’d like to assist anyone trying to work their way through this text, I don’t want to hold anyone back from the experimentation that often leads to a greater understanding of the concepts. It’s something that I think the authors wished to encourage as well.