What is the intuitive idea behind automatic differentiation?
If I have a program which computes $f(x, y)=x^2+yx$, which steps lead to the program which computes the derivative $df/dx$ of f?
double f(double x, double y)
{
double res = x*x;
double res2 = x*y;
double res3 = res + res2
return res3;
}
If I read the corresponding Wikipedia entry correctly I need nothing besides the chain rule, but I don't understand how this can be done in practice.
My understanding so far is that I use a table of the derivatives of all involved basic functions, such as:
- $dx/dx=1$
- $dy/dx=0$
- $d(x*y)/dx=y$
- $d(x+y)=dx/dx+0$
- $d(x^2)/dx=2x$
How do I get the final function from this?
I would expect something like this:
double f(double x, double y, double* dx)
{
*dx = 0;
double res = x*x;
? *dx = 2*x ?
double res2 = x*y;
? *dx = *dx ?
double res3 = res + res2
? *dx = ??? ?
return res3;
}
Edit: I have found this video "Beautiful Differentiation" of a talk at the International Conference on Functional Programming (ICFP) 2009, by Marcom Wallace which explains the topic quite well.