exp_2: Operation Sequence and Zero Order Forward Mode
Keywords: exp_2: operation sequence zero order forward mode example mathematical form expansion index code sweep return value verification exercises

| Prev | Next |  |  |  |  |  |  |

exp_2: Operation Sequence and Zero Order Forward Mode
Mathematical Form
The operation sequence (see below) corresponding to the algorithm exp_2.hpp is the same for all values of `x` . The mathematical form for the corresponding function is f ( x ) = 1 + x + x 2 / 2 An algorithmic differentiation package does not operate on the mathematical function f ( x ) but rather on the particular algorithm used to compute the function (in this case exp_2.hpp ).
Zero Order Expansion
In general, a zero order forward sweep is given a vector x ( 0 ) ∈ R n and it returns the corresponding vector y ( 0 ) ∈ R m given by y ( 0 ) = f ( x ( 0 ) ) The superscript ( 0 ) denotes zero order derivative; i.e., it is equal to the value of the corresponding variable. For the example we are considering here, both n and m are equal to one.
Operation Sequence
An atomic `Type` operation is an operation that has a `Type` result and is not made up of other more basic operations. A sequence of atomic `Type` operations is called a `Type` operation sequence. Given an C++ algorithm and its inputs, there is a corresponding `Type` operation sequence for each type. If `Type` is clear from the context, we drop it and just refer to the operation sequence. `
` We consider the case where exp_2.hpp is executed with x ( 0 ) = .5 . The table below contains the corresponding operation sequence and the results of a zero order sweep.
Index
The Index column contains the index in the operation sequence of the corresponding atomic operation and variable. A Forward sweep starts with the first operation and ends with the last.
Code
The Code column contains the C++ source code corresponding to the corresponding atomic operation in the sequence.
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 derivative for the corresponding variable in the operation sequence. Forward mode refers to the fact that these coefficients are computed in the same order as the original algorithm; i.e, in order of increasing index in the operation sequence.
Sweep

Index | `` | Code | `` | Operation | `` | Zero Order
1 | `` | `Type v1 = x;` |  | v 1 = x |  | v 1 ( 0 ) = 0.5
2 | `` | `Type v2 = Type(1) + v1;` |  | v 2 = 1 + v 1 |  | v 2 ( 0 ) = 1.5
3 | `` | `Type v3 = v1 * v1;` |  | v 3 = v 1 * v 1 |  | v 3 ( 0 ) = 0.25
4 | `` | `Type v4 = v3 / Type(2);` |  | v 4 = v 3 / 2 |  | v 4 ( 0 ) = 0.125
5 | `` | `Type v5 = v2 + v4;` |  | v 5 = v 2 + v 4 |  | v 5 ( 0 ) = 1.625

Return Value
The return value for this case is 1.625 = v 5 ( 0 ) = f ( x ( 0 ) )
Verification
The file exp_2_for0.cpp contains a routine that verifies the values computed above. It returns true for success and false for failure.
Exercises

1. Suppose that x ( 0 ) = .2 , what is the result of a zero 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 )
2. Create a modified version of exp_2_for0.cpp that verifies the values you obtained for the previous exercise.
3. Create and run a main program that reports the result of calling the modified version of exp_2_for0.cpp in the previous exercise.

Input File: introduction/exp_apx/exp_2.omh