SICP Exercise 2.56
Question
Show how to extend the basic differentiator to handle more kinds of expressions. For instance, implement the differentiation rule
\[\frac{\partial (u^n)}{\partial x}=nu^{n-1}\frac{\partial u}{\partial x}\]
by adding a new clause to the deriv
program and defining appropriate
procedures exponentiation?
, base
, exponent
, and
make-exponentiation
. (You may use the symbol **
to denote exponentiation.)
Build in the rules that anything raised to the power \(0\) is \(1\) and anything
raised to the power \(1\) is the thing itself.
Answer
We are once again going to make use of our wishful thinking technique here and
first simply implement the new version of deriv
with no regard for the actual
helper function implementations (the newly added part is highlighted):
|
|
Then, we can continue by first implementing the exponentiation?
, base
and
exponent
helper functions. These are completely analogue to the helpers for
make-sum
and make-product
.
|
|
Finally, we are defining make-exponentiation
with the simplification rules as
specified in the question.
|
|
So, let’s test it with \(x^3\) and see what happens.
(deriv '(** x 3) 'x)
We receive the expected result, since \(\frac{\partial x^3}{\partial x}=3x^2\).
(* 3 (** x 2))