exp_2: First Order Forward Mode
Keywords: exp_2: first order forward mode expansion purpose mathematical form operation sequence index zero derivative sweep return value verification exercises

| Prev | Next |  |  |  |  |  |  |

exp_2: First Order Forward Mode
First Order Expansion
We define x ( t ) near t = 0 by the first order expansion x ( t ) = x ( 0 ) + x ( 1 ) * t it follows that x ( 0 ) is the zero, and x ( 1 ) the first, order derivative of x ( t ) at t = 0 .
Purpose
In general, a first order forward sweep is given the zero order derivative for all of the variables in an operation sequence, and the first order derivatives for the independent variables. It uses these to compute the first order derivatives, and thereby obtain the first order expansion, for all the other variables in the operation sequence.
Mathematical Form
Suppose that we use the algorithm exp_2.hpp to compute f ( x ) = 1 + x + x 2 / 2 The corresponding derivative function is ∂ x f ( x ) = 1 + x An algorithmic differentiation package does not operate on the mathematical form of the function, or its derivative, but rather on the operation sequence for the for the algorithm that is used to evaluate the function.
Operation Sequence
We consider the case where exp_2.hpp is executed with x = .5 . The corresponding operation sequence and zero order forward mode values (see zero order sweep ) are inputs and are used by a first order forward sweep.
Index
The Index column contains the index in the operation sequence of the corresponding atomic operation. A Forward sweep starts with the first operation and ends with the last.
Operation
The Operation column contains the mathematical function corresponding to each atomic operation in the sequence.
Zero Order
The Zero Order column contains the zero order derivatives for the corresponding variable in the operation sequence (see zero order sweep ).
Derivative
The Derivative column contains the mathematical function corresponding to the derivative with respect to t , at t = 0 , for each variable in the sequence.
First Order
The First Order column contains the first order derivatives for the corresponding variable in the operation sequence; i.e., v j ( t ) = v j ( 0 ) + v j ( 1 ) t We use x ( 1 ) = 1 so that differentiation with respect to t , at t = 0 , is the same as partial differentiation with respect to x at x = x ( 0 ) .
Sweep

Index | `` | Operation | `` | Zero Order | `` | Derivative | `` | First Order
1 | `` | v 1 = x |  | 0.5 |  | v 1 ( 1 ) = x ( 1 ) |  | v 1 ( 1 ) = 1
2 | `` | v 2 = 1 + v 1 |  | 1.5 |  | v 2 ( 1 ) = v 1 ( 1 ) |  | v 2 ( 1 ) = 1
3 | `` | v 3 = v 1 * v 1 |  | 0.25 |  | v 3 ( 1 ) = 2 * v 1 ( 0 ) * v 1 ( 1 ) |  | v 3 ( 1 ) = 1
4 | `` | v 4 = v 3 / 2 |  | 0.125 |  | v 4 ( 1 ) = v 3 ( 1 ) / 2 |  | v 4 ( 1 ) = 0.5
5 | `` | v 5 = v 2 + v 4 |  | 1.625 |  | v 5 ( 1 ) = v 2 ( 1 ) + v 4 ( 1 ) |  | v 5 ( 1 ) = 1.5

Return Value
The derivative of the return value for this case is 1.5 = v 5 ( 1 ) = [∂ v 5 ∂ t ] t = 0 = [∂ ∂ t f ( x ( 0 ) + x ( 1 ) t ) ] t = 0 = f ( 1 ) ( x ( 0 ) ) * x ( 1 ) = f ( 1 ) ( x ( 0 ) ) (We have used the fact that x ( 1 ) = 1 .)
Verification
The file exp_2_for1.cpp contains a routine which verifies the values computed above. It returns true for success and false for failure.
Exercises

1. Which statement in the routine defined by exp_2_for1.cpp uses the values that are calculated by the routine defined by exp_2_for0.cpp ?
2. Suppose that x = .1 , what are the results of a zero and first order forward sweep for the operation sequence above; i.e., what are the corresponding values for v 1 ( 0 ) , v 2 ( 0 ) , ⋯ , v 5 ( 0 ) and v 1 ( 1 ) , v 2 ( 1 ) , ⋯ , v 5 ( 1 ) ?
3. Create a modified version of exp_2_for1.cpp that verifies the derivative values from the previous exercise. Also create and run a main program that reports the result of calling the modified version of exp_2_for1.cpp .

Input File: introduction/exp_apx/exp_2.omh