symbolic differentiation
I got excited last week by the numeric differentiator challenge. When I originally read that section of SICP so many years ago, I was elated. Do you know how hard that would be to do in Java?
Now for something that's even harder to do in Java: symbolic differentiation.
Here's the relevant link into SICP, for reference.
The challenge this week is to use four differentiation formulas to make a symbolic differentiator. It has been a while since I've done any calculus, so I had to look these up:
dc/dx = 0
(for a constant c, or variable c different from x)dx/dx = 1
d(u+v)/dx = du/dx + dv/dx
(addition rule)d(uv)/dx = u(dv/dx) + v(du/dx)
(product rule)
This won't differentiate every formula, but it will differentiate sums and products of variables and numbers. You should make a function that takes an expression and a variable to differentiate by, like so:
(deriv '(+ x 5) 'x) ;=> (+ 1 0)
Don't worry about simplifying the final expression. Just make sure it's right.