exp_eps: Operation Sequence and Zero Order Forward Sweep
Keywords: exp_eps: operation sequence zero order forward sweep example mathematical form variable parameter index code return value comparisons verification exercises

| Prev | Next |  |  |  |  |  |  |

exp_eps: Operation Sequence and Zero Order Forward Sweep
Mathematical Form
Suppose that we use the algorithm exp_eps.hpp to compute `exp_eps(x, epsilon)` with `x` is equal to .5 and `epsilon` is equal to .2. For this case, the mathematical form for the operation sequence corresponding to the `exp_eps` is f ( x , ε ) = 1 + x + x 2 / 2 Note that, for these particular values of `x` and `epsilon` , this is the same as the mathematical form for exp_2 .
Operation Sequence
We consider the operation sequence corresponding to the algorithm exp_eps.hpp with the argument `x` is equal to .5 and `epsilon` is equal to .2.
Variable
We refer to values that depend on the input variables `x` and `epsilon` as variables.
Parameter
We refer to values that do not depend on the input variables `x` or `epsilon` as parameters. Operations where the result is a parameter are not included in the zero order sweep below.
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.
Sweep

Index | `` | Code | `` | Operation | `` | Zero Order
1 | `` | `abs_x = x;` |  | v 1 = x |  | v 1 ( 0 ) = 0.5
2 | `` | `temp = term * abs_x;` |  | v 2 = 1 * v 1 |  | v 2 ( 0 ) = 0.5
3 | `` | `term = temp / Type(k);` |  | v 3 = v 2 / 1 |  | v 3 ( 0 ) = 0.5
4 | `` | `sum = sum + term;` |  | v 4 = 1 + v 3 |  | v 4 ( 0 ) = 1.5
5 | `` | `temp = term * abs_x;` |  | v 5 = v 3 * v 1 |  | v 5 ( 0 ) = 0.25
6 | `` | `term = temp / Type(k);` |  | v 6 = v 5 / 2 |  | v 6 ( 0 ) = 0.125
7 | `` | `sum = sum + term;` |  | v 7 = v 4 + v 6 |  | v 7 ( 0 ) = 1.625

Return Value
The return value for this case is 1.625 = v 7 ( 0 ) = f ( x ( 0 ) , ε ( 0 ) )
Comparisons
If `x` were negative, or if `epsilon` were a much smaller or much larger value, the results of the following comparisons could be different: `

         if( Type(0) > x )
         while(term > epsilon)

` This in turn would result in a different operation sequence. Thus the operation sequence above only corresponds to exp_eps.hpp for values of `x` and `epsilon` within a certain range. Note that there is a neighborhood of x = 0.5 for which the comparisons would have the same result and hence the operation sequence would be the same.
Verification
The file exp_eps_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 ) = .1 , 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 7 ( 0 ) .
2. Create a modified version of exp_eps_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_eps_for0.cpp in the previous exercise.

Input File: introduction/exp_apx/exp_eps.omh