Prev Next Index-> contents reference index search external Up-> CppAD Introduction exp_eps exp_eps_for0 CppAD-> Install Introduction AD ADFun preprocessor multi_thread utility ipopt_solve Example speed Appendix Introduction-> exp_2 exp_eps exp_apx.cpp exp_eps-> exp_eps.hpp exp_eps.cpp exp_eps_for0 exp_eps_for1 exp_eps_rev1 exp_eps_for2 exp_eps_rev2 exp_eps_cppad exp_eps_for0-> exp_eps_for0.cpp Headings-> Mathematical Form Operation Sequence ---..Variable ---..Parameter ---..Index ---..Code ---..Operation ---..Zero Order ---..Sweep Return Value Comparisons Verification Exercises

$\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }$
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 , \varepsilon ) = 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)} , \varepsilon^{(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)} , \ldots , 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_eps.omh