### Example: The Derivative

Ask a typical calculus student what a derivative is. The answer will often be of the form, It's like, x2 goes to 2x, or perhaps, The tangent line to a curve. Both of these answers make sense, given the way the idea of a derivative is taught. There is a graph of a function with a tangent line drawn. There are the rules for symbolic manipulation, carefully memorized and drilled into place.

At the same time that math departments are teaching calculus, computer science faculty are teaching students about functions. Those students are learning a different type of notation: an operation that takes arguments as inputs and returns values.

The calculus and the computer science will be taught in different rooms, and students will honor the distinction by storing what they learn in different mental compartments. Ask a computer science student to write a program for taking derivatives and he or she will insist this is a difficult task, perhaps involving trees and parsing of text.

There's a missed opportunity here, both for teaching computation and for teaching calculus. The computer science curriculum has an interest in how one represents things in the computer and how one constructs operations on those things. The calculus instructor would like students to learn about limits and the notion that differentiation is an operation and that a derivative is itself a function.

Suppose that calculus students were taught a very little bit about basic computation, for instance how to construct a function. Here are examples, in three different languages: R, Mathematica, and Matlab. Of course, you wouldn't want to teach three languages, but we're writing for instructors who might be familiar with one or the other

```f = function(x) { x^2 + 3*x + 2}   in R

f = Function[x, x^2 + 3*x + 2]     in Mathematica

f = @(x) x.^2 + 3.*x + 2             in Matlab
```

Teach one of these forms and exercise it so that students understand that there is a place to declare the name of the argument, a place to describe the computation in terms of that argument, a syntax that tells the language interpreter that you want to create a function, and a syntax for giving the function a name.

Now think about the idea of a derivative as local rise over run:

df/dx = limh -> 0 (f(x + h) - f(x))/h.

If students are to learn about modeling, they need at some point to learn about approximation: what it means, how to judge if it's good enough. Let's start by approximating the idea of a limit as meaning ``small.'' Of course this is wrong: limh -> 0 doesn't mean small. But if you are going to construct a path toward what it does mean, a good place to start is with small.

An important idea about a derivative is that it is an operation on a function. The notations df/dx or f', for all their virtues, don't make it clear that there's an operation here that is producing a function. The computer notation is better. Again, in all three languages:

```deriv = function(f) { function(x) { (f(x+.000001) - f(x))/.000001 } }

deriv = Function[f, Function[x, (f[x+.000001] - f[x])/.000001 ] ]

deriv = @(f) @(x) (f(x+.000001) - f(x))/.000001
```

Now you are in a position to do some experimenting. For conciseness, we'll use R. The process would be very similar in Mathematica or Matlab:

```> fprime = deriv(f)
> fprime(.2)
 3.400001
> plot( fprime, from=0, to=3 )
```

Want to demonstrate that the derivative of a sine function is a cosine?

```> what = deriv(sin)
> plot( what, from=0, to=10)
```

Second derivatives?

```> plot( deriv( deriv( sin ) ), from=0, to=10 )
```

Now you are in a position to see how the finite-difference approximation to the derivative is different from the derivative itself. You can talk about what happens as you vary h. Students can see why setting h to zero is not at all the same thing as taking the limit.

Pardon the metaphor, but a mosaic is not a one-way street. The computer scientist can have students program up derivatives of images to illustrate contrast enhancement in x-rays or auto-focus in photography.