lines 168-323 of file: introduction/exp_eps.xrst

{xrst_begin exp_eps_for1}
{xrst_spell
   expansions
}

exp_eps: First Order Forward Sweep
##################################

First Order Expansion
*********************
We define :math:`x(t)` and :math:`\varepsilon(t) ]` near :math:`t = 0`
by the first order expansions

.. math::
   :nowrap:

   \begin{eqnarray}
      x(t) & = & x^{(0)} + x^{(1)} * t
      \\
      \varepsilon(t) & = & \varepsilon^{(0)} + \varepsilon^{(1)} * t
   \end{eqnarray}

It follows that :math:`x^{(0)}` (:math:`\varepsilon^{(0)}`) is the zero,
and :math:`x^{(1)}`  (:math:`\varepsilon^{(1)}`) the first,
order derivative of :math:`x(t)`
at :math:`t = 0` (:math:`\varepsilon (t)`)
at :math:`t = 0`.

Mathematical Form
*****************
Suppose that we use the algorithm :ref:`exp_eps.hpp-name`
to compute ``exp_eps`` ( *x* , *epsilon* )
with *x* is equal to .5
and *epsilon* is equal to .2.
For this case, the mathematical function for the operation sequence
corresponding to ``exp_eps`` is

.. math::

   f ( x , \varepsilon ) =   1 + x + x^2 / 2

The corresponding partial derivative with respect to :math:`x`,
and the value of the derivative, are

.. math::

   \partial_x f ( x , \varepsilon ) =   1 + x  = 1.5

Operation Sequence
******************

Index
=====
The Index column contains the index in the operation sequence
of the corresponding atomic operation.
A Forward sweep starts with the first operation
and ends with the last.

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 derivatives
for the corresponding variable in the operation sequence
(see :ref:`zero order sweep<exp_2_for1@Operation Sequence@Sweep>` ).

Derivative
==========
The Derivative column contains the
mathematical function corresponding to the derivative
with respect to :math:`t`,
at :math:`t = 0`, for each variable in the sequence.

First Order
===========
The First Order column contains the first order derivatives
for the corresponding variable in the operation sequence; i.e.,

.. math::

   v_j (t) = v_j^{(0)} + v_j^{(1)} t

We use :math:`x^{(1)} = 1` and :math:`\varepsilon^{(1)} = 0`,
so that differentiation with respect to :math:`t`,
at :math:`t = 0`,
is the same partial differentiation with respect to :math:`x`
at :math:`x = x^{(0)}`.

Sweep
=====

.. csv-table::
   :widths: auto

   **Index**,,**Operation**,,**Zero Order**,,**Derivative**,,**First Order**
   1,,:math:`v_1 = x`,,0.5,,:math:`v_1^{(1)} = x^{(1)}`,,:math:`v_1^{(1)} = 1`
   2,,:math:`v_2 = 1 * v_1`,,0.5,,:math:`v_2^{(1)} = 1 * v_1^{(1)}`,,:math:`v_2^{(1)} = 1`
   3,,:math:`v_3 = v_2 / 1`,,0.5,,:math:`v_3^{(1)} = v_2^{(1)} / 1`,,:math:`v_3^{(1)} = 1`
   4,,:math:`v_4 = 1 + v_3`,,1.5,,:math:`v_4^{(1)} = v_3^{(1)}`,,:math:`v_4^{(1)} = 1`
   5,,:math:`v_5 = v_3 * v_1`,,0.25,,:math:`v_5^{(1)} = v_3^{(1)} * v_1^{(0)} + v_3^{(0)} * v_1^{(1)}`,,:math:`v_5^{(1)} = 1`
   6,,:math:`v_6 = v_5 / 2`,,0.125,,:math:`v_6^{(1)} = v_5^{(1)} / 2`,,:math:`v_6^{(1)} = 0.5`
   7,,:math:`v_7 = v_4 + v_6`,,1.625,,:math:`v_7^{(1)} = v_4^{(1)} + v_6^{(1)}`,,:math:`v_7^{(1)} = 1.5`

Return Value
************
The derivative of the return value for this case is

.. math::
   :nowrap:

   \begin{eqnarray}
   1.5
   & = &
   v_7^{(1)} =
   \left[ \D{v_7}{t} \right]_{t=0} =
   \left[ \D{}{t} f( x^{(0)} + x^{(1)} * t , \varepsilon^{(0)} ) \right]_{t=0}
   \\
   & = &
   \partial_x f ( x^{(0)} , \varepsilon^{(0)} ) * x^{(1)} =
   \partial_x f ( x^{(0)} , \varepsilon^{(0)} )
   \end{eqnarray}

(We have used the fact that
:math:`x^{(1)} = 1` and :math:`\varepsilon^{(1)} = 0`.)
{xrst_toc_hidden
   introduction/exp_eps_for1.cpp
}

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

Exercises
*********

#. Suppose that :math:`x = .1`,
   what are the results of a zero and first order forward mode sweep for
   the operation sequence above;
   i.e., what are the corresponding values for
   :math:`v_1^{(0)}, v_2^{(0)}, \cdots , v_7^{(0)}` and
   :math:`v_1^{(1)}, v_2^{(1)}, \cdots , v_7^{(1)}` ?
#. Create a modified version of :ref:`exp_eps_for1.cpp-name` that verifies
   the derivative values from the previous exercise.
   Also create and run a main program that reports the result
   of calling the modified version of
   :ref:`exp_eps_for1.cpp-name` .
#. Suppose that :math:`x = .1` and :math:`\epsilon = .2`,
   what is the operation sequence corresponding to

      ``exp_eps`` ( *x* , *epsilon* )

{xrst_end exp_eps_for1}
