Lesson 2 of 15

The Derivative Operator

The Derivative Operator

In standard calculus, the derivative is written ddxf(x)\frac{d}{dx}f(x) — an expression that involves a specific variable name. This is ambiguous in complex situations. Is xx a free variable? Which xx?

Sussman and Wisdom replace expression derivatives with functional derivatives. The operator DD takes a function and returns a new function — its derivative:

(Df)(x)=limh0f(x+h)f(xh)2h(Df)(x) = \lim_{h \to 0} \frac{f(x+h) - f(x-h)}{2h}

This is unambiguous: DD is a higher-order function (a function that takes and returns functions).

Examples

D(xx2)=(x2x)D(x \mapsto x^2) = (x \mapsto 2x) D(xsinx)=(xcosx)D(x \mapsto \sin x) = (x \mapsto \cos x) D(D(xx3))=(x6x)D(D(x \mapsto x^3)) = (x \mapsto 6x)

Numerical Implementation

We approximate DD using the central difference formula:

Df(x)f(x+h)f(xh)2hDf(x) \approx \frac{f(x+h) - f(x-h)}{2h}

With h=107h = 10^{-7}, this is accurate to about 14 significant figures for smooth functions.

Your Task

Implement D(f) that returns the numerical derivative of f as a new function.

Python runtime loading...
Loading...
Click "Run" to execute your code.