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

| Prev | Next |  |  |  |  |  |  |

exp_2: Second Order Forward Mode
Second Order Expansion
We define x ( t ) near t = 0 by the second order expansion x ( t ) = x ( 0 ) + x ( 1 ) * t + x ( 2 ) * t 2 / 2 It follows that for k = 0 , 1 , 2 , x ( k ) = d k d t k x ( 0 )
Purpose
In general, a second order forward sweep is given the first order expansion for all of the variables in an operation sequence, and the second order derivatives for the independent variables. It uses these to compute the second order derivative, and thereby obtain the second order expansion, for all the 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 second derivative function is ∂ 2 ∂ x 2 f ( x ) = 1
Operation Sequence
We consider the case where exp_2.hpp is executed with x = .5 . The corresponding operation sequence, zero order forward sweep values, and first order forward sweep values are inputs and are used by a second 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.
Zero
The Zero column contains the zero order sweep results for the corresponding variable in the operation sequence (see zero order sweep ).
Operation
The Operation column contains the first order sweep operation for this variable.
First
The First column contains the first order sweep results for the corresponding variable in the operation sequence (see first order sweep ).
Derivative
The Derivative column contains the mathematical function corresponding to the second derivative with respect to t , at t = 0 , for each variable in the sequence.
Second
The Second column contains the second order derivatives for the corresponding variable in the operation sequence; i.e., the second order expansion for the `i`-th variable is given by v i ( t ) = v i ( 0 ) + v i ( 1 ) * t + v i ( 2 ) * t 2 / 2 We use x ( 0 ) = 1 , and x ( 2 ) = 0 so that second order differentiation with respect to t , at t = 0 , is the same as the second partial differentiation with respect to x at x = x ( 0 ) .
Sweep

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

Return Value
The second derivative of the return value for this case is 1 = v 5 ( 2 ) = [∂ 2 ∂ t 2 v 5 ] t = 0 = [∂ 2 ∂ t 2 f ( x ( 0 ) + x ( 1 ) * t ) ] t = 0 = x ( 1 ) * ∂ 2 ∂ x 2 f ( x ( 0 ) ) * x ( 1 ) = ∂ 2 ∂ x 2 f ( x ( 0 ) ) (We have used the fact that x ( 1 ) = 1 and x ( 2 ) = 0 .)
Verification
The file exp_2_for2.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_for2.cpp uses the values that are calculated by the routine defined by exp_2_for1.cpp ?
2. Suppose that x = .1 , what are the results of a zero, first, and second order forward sweep for the operation sequence above; i.e., what are the corresponding values for v i ( k ) for i = 1 , … , 5 and k = 0 , 1 , 2 .
3. Create a modified version of exp_2_for2.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_for2.cpp .

Input File: introduction/exp_apx/exp_2.omh