Prev Next

@(@\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_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)} \in \B{R}^n @)@ and it returns the corresponding vector @(@ y^{(0)} \in \B{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)} , \cdots , 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_2.omh