1
Fall 2008 Programming Development Techniques 1
Topic 10 Example: Symbolic Differentiation
Section 2.3.2 October 2008
Fall 2008 Programming Development Techniques 2
Symbolic differentiation
- Polynomial a + bx + cx2 can be represented by the
list (+ a (+ (* b x) (* c (* x x))))
- Derivative with respect to x is b + 2cx, which can be
represented by (+ b (* 2 (* c x)))
- How can the derivative be computed?
Fall 2008 Programming Development Techniques 3
Basic calculus (2 arguments only)
dy/dx = 0 if y is a constant or a variable other than x dx/dx = 1 d(u+ v)/dx = du/dx + dv/dx (NOTE Recursive!) d(u* v)/dx = u * dv/dx + v * du/dx (NOTE Recursive!)
Fall 2008 Programming Development Techniques 4
Want to build a procedure to do differentiation
- Think of the first rules as base conditions, then other
rules can be used to decompose a problem into something easier.
- What do we need to do to tell which rule is
applicable?
– Differentiate between a constant, variable (and what it is), product, and sum – Extract parts of an expression
Fall 2008 Programming Development Techniques 5
Data abstraction to the rescue!
Some constructors, selectors and predicates: (variable? x) (same-variable? x y) (sum? x) (product? x) (make-sum x y) (make-product x y) (sum-arg1 x) (product-arg1 x) (sum-arg2 x) (product-arg2 x)
Fall 2008 Programming Development Techniques 6