lines 31-160 of file: introduction/exp_2.xrst

{xrst_begin exp_2_for0}

exp_2: Operation Sequence and Zero Order Forward Mode
#####################################################

Mathematical Form
*****************
The operation sequence (see below) corresponding to
the algorithm :ref:`exp_2.hpp-name` is the same for all values of *x* .
The mathematical form for the corresponding function is

.. math::

   f(x) = 1 + x + x^2 / 2

An algorithmic differentiation package
does not operate on the mathematical function :math:`f(x)`
but rather on the particular algorithm used to compute the function
(in this case :ref:`exp_2.hpp-name` ).

Zero Order Expansion
********************
In general, a zero order forward sweep is given a vector
:math:`x^{(0)} \in \B{R}^n` and it returns the corresponding vector
:math:`y^{(0)} \in \B{R}^m` given by

.. math::

   y^{(0)} = f( x^{(0)} )

The superscript :math:`(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 :math:`n` and :math:`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 :ref:`exp_2.hpp-name` is executed with
:math:`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
=====

.. csv-table::
   :widths: auto

   **Index**,,**Code**,,**Operation**,,**Zero Order**
   1,,``Type v1  = x;``,,:math:`v_1 = x`,,:math:`v_1^{(0)} = 0.5`
   2,,``Type v2  = Type(1) + v1;``,,:math:`v_2 = 1 + v_1`,,:math:`v_2^{(0)} = 1.5`
   3,,``Type v3  = v1 * v1;``,,:math:`v_3 = v_1 * v_1`,,:math:`v_3^{(0)} = 0.25`
   4,,``Type v4  = v3 / Type(2);``,,:math:`v_4 = v_3 / 2`,,:math:`v_4^{(0)} = 0.125`
   5,,``Type v5  = v2 + v4;``,,:math:`v_5 = v_2 + v_4`,,:math:`v_5^{(0)} = 1.625`

Return Value
************
The return value for this case is

.. math::

   1.625 =
   v_5^{(0)} =
   f( x^{(0)} )

{xrst_toc_hidden
   introduction/exp_2_for0.cpp
}

Verification
************
The file :ref:`exp_2_for0.cpp-name` contains a routine
that verifies the values computed above.

Exercises
*********

#. Suppose that :math:`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

   .. math::

      v_1^{(0)} , v_2^{(0)} , \cdots , v_5^{(0)}

#. Create a modified version of
   :ref:`exp_2_for0.cpp-name` that verifies the values you obtained
   for the previous exercise.
#. Create and run a main program that reports the result of calling
   the modified version
   of :ref:`exp_2_for0.cpp-name` in the previous exercise.

{xrst_end exp_2_for0}
