In automatic differentiation, especially the forward mode, when computing the function value f, the derivative is calculated simultaneously. For example, if we want to compute the derivative of y(x)=ln(x2+sinx), we can calculate it using the following formula, which we will call w˙=dxdw.
In this case, by using operations on dual numbers, it is possible to simultaneously and naturally compute the function value and the derivative. Let us express the dual number a+bϵ as an ordered pair (a,b).
For f,g:R→R,
(f∘g)(a+bϵ):=f(g(a))+f′(g(a))g′(a)bϵ=(f(g(a)),bf′(g(a))g′(a))
Differentiation
Consider a variable to be differentiated x, represented as a dual number (x,1), and a constant α, represented as (α,0). Then, the addition of dual numbers itself represents the first component as the function value and the second component as the derivative. For example, consider a function (constant addition) x↦x+α. The function value from x=x0 is x0+α, and its derivative is dxd(x+α)x=x0=1. Expressed in dual numbers, it is as follows:
(x,1)+(α,0)=(x+α,1)
The first component is the function value x+α, and the second component is the derivative 1. Of course, this also holds for x+x.
dxd(x+x)=2x,(x,1)+(x,1)=(2x,2)
Now, consider the function x↦αx (multiplication). From x=x0, the function value is αx0, and the derivative is dxd(αx)x=x0=α. In dual numbers, it is expressed as follows:
(x,1)(α,0)=(αx,x⋅0+1⋅α)=(αx,α)
Similarly, the first component is the function value, and the second component is the derivative. This also holds for exponentiation x↦x2.
(x,1)(x,1)=(x2,2x)
The derivative is preserved when substituted into the differentiable function f and the composite function f∘g.
Now, let’s revisit the example y(x)=ln(x2+sinx) mentioned earlier. If we substitute the dual number (x,1) instead of the real number x, the calculation is as follows: