<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='pmathml.xsl'?>
<html xmlns='http://www.w3.org/1999/xhtml'>

<head><title>cppad-20100316: A Package for Differentiation of C++ Algorithms</title></head>
<body>

<hr/>
,






<center><b><big><big>cppad-20100316: A Package for Differentiation of C++ Algorithms</big></big></b></center>
<table><tr><td align='left'  valign='top'>
</td><td align='left'  valign='top'>
One web page per Section <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>

	All as one web page
</td></tr><tr><td align='left'  valign='top'>

</td><td align='left'  valign='top'>

	(fast to load) <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>

	(slow to load)
</td></tr><tr><td align='left'  valign='top'>

Math displayed using Latex <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>

<a href="cppad.htm" target="_top"><span style='white-space: nowrap'>cppad.htm</span></a>

<code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>

<a href="_printable.htm" target="_top"><span style='white-space: nowrap'>_printable.htm</span></a>

</td></tr><tr><td align='left'  valign='top'>

Math displayed using MathML <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>

<a href="cppad.xml" target="_top"><span style='white-space: nowrap'>cppad.xml</span></a>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>

<a href="_printable.xml" target="_top"><span style='white-space: nowrap'>_printable.xml</span></a>

</td></tr>
</table>
<br/>
<b><big><a name="a" id="a">a: Syntax</a></big></b>

<code><font color="blue"><br/>
# include &lt;cppad/cppad.hpp&gt;</font></code>

<br/>
<br/>
<b><big><a name="b" id="b">b: Introduction</a></big></b>

<br/>
We refer to the
step by step conversion from an algorithm that computes function values
to an algorithm that computes derivative values
as <i>Algorithmic Differentiation</i>
(often referred to as <i>Automatic Differentiation</i>.) 
Given a C++ algorithm that computes function values,
CppAD generates an algorithm that computes its derivative values.
A brief introduction to Algorithmic Differentiation can be found in
<a href="http://en.wikipedia.org/wiki/Automatic_differentiation" target="_top"><span style='white-space: nowrap'>wikipedia</span></a>
 (http://en.wikipedia.org/wiki/Automatic_differentiation) .
The web site 
<a href="http://www.autodiff.org" target="_top"><span style='white-space: nowrap'>autodiff.org</span></a>
 (http://www.autodiff.org) 
is dedicated to research about, and promoting the use of, AD.

<ol type="1"><li>
<a href="http://www.coin-or.org/CppAD/" target="_top"><span style='white-space: nowrap'>CppAD</span></a>
 (http://www.coin-or.org/CppAD/) 
uses operator overloading to compute derivatives of algorithms defined in C++.
It is distributed by the 
<a href="http://www.coin-or.org/foundation.html" target="_top"><span style='white-space: nowrap'>COIN-OR&#xA0;Foundation</span></a>
 (http://www.coin-or.org/foundation.html) 
with the Common Public License 
<a href="http://www.opensource.org/licenses/cpl1.0.php" target="_top"><span style='white-space: nowrap'>CPL</span></a>
 (http://www.opensource.org/licenses/cpl1.0.php) 
or the GNU General Public License
<a href="http://www.opensource.org/licenses/gpl-license.php" target="_top"><span style='white-space: nowrap'>GPL</span></a>
 (http://www.opensource.org/licenses/gpl-license.php) .
Installation procedures are provided for both
<a href="#2.1">2.1: <span style='white-space: nowrap'>Unix</span></a>
 and <a href="#2.2">2.2: <span style='white-space: nowrap'>MS&#xA0;Windows</span></a>

operating systems.
Extensive user and developer documentation is included.

</li><li>

An AD of <i>Base</i>
<a href="#9.4.g.b">9.4.g.b: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>

is stored as an 
<a href="#5">5: <span style='white-space: nowrap'>AD&#xA0;function&#xA0;object</span></a>
 
which can evaluate function values and derivatives.
Arbitrary order 
<a href="#5.6.1">5.6.1: <span style='white-space: nowrap'>forward</span></a>
 and <a href="#5.6.2">5.6.2: <span style='white-space: nowrap'>reverse</span></a>

mode derivative calculations
can be preformed on the operation sequence.
Logical comparisons can be included in an operation sequence
using AD <a href="#4.4.4">4.4.4: <span style='white-space: nowrap'>conditional&#xA0;expressions</span></a>
.
Evaluation of user defined unary 
<a href="#4.4.5">4.4.5: <span style='white-space: nowrap'>discrete&#xA0;functions</span></a>
 can also be included
in the sequence of operations; i.e.,
functions that depend on the
<a href="#9.4.j.c">9.4.j.c: <span style='white-space: nowrap'>independent&#xA0;variables</span></a>

but which have identically zero derivatives
(e.g., a step function).

</li><li>

Derivatives of functions that are defined in terms of other derivatives
can be computed using multiple levels of AD;
see <a href="#7.1.9.1">7.1.9.1: <span style='white-space: nowrap'>mul_level.cpp</span></a>
 for a simple example
and <a href="#7.1.11">7.1.11: <span style='white-space: nowrap'>ode_taylor.cpp</span></a>
 for a more realistic example.
To this end, CppAD can also be used with other AD types; for example see
<a href="#7.1.12">7.1.12: <span style='white-space: nowrap'>ode_taylor_adolc.cpp</span></a>
.

</li><li>

A set of programs for doing <a href="#9.2">9.2: <span style='white-space: nowrap'>speed</span></a>
 comparisons between
<a href="http://www.math.tu-dresden.de/~adol-c/" target="_top"><span style='white-space: nowrap'>Adolc</span></a>
 (http://www.math.tu-dresden.de/~adol-c/) ,
CppAD,
<a href="http://www.imm.dtu.dk/fadbad.html/" target="_top"><span style='white-space: nowrap'>Fadbad</span></a>
 (http://www.imm.dtu.dk/fadbad.html/) ,
and
<a href="http://trilinos.sandia.gov/packages/sacado/" target="_top"><span style='white-space: nowrap'>Sacado</span></a>
 (http://trilinos.sandia.gov/packages/sacado/) 
are included.


</li><li>

Includes a C++ <a href="#6">6: <span style='white-space: nowrap'>library</span></a>
 that is useful
for general operator overloaded numerical method.
Allows for replacement of the
<a href="#7.4">7.4: <span style='white-space: nowrap'>test_vector</span></a>
 
template vector class which is used for extensive testing; 
for example, you can do your testing with the
<a href="http://www.boost.org/libs/numeric/ublas/doc/index.htm" target="_top"><span style='white-space: nowrap'>uBlas</span></a>
 (http://www.boost.org/libs/numeric/ublas/doc/index.htm)  
template vector class.

</li><li>

See <a href="#9.8">9.8: <span style='white-space: nowrap'>whats_new</span></a>
 for a list of recent extensions and bug fixes.

</li></ol>


You can find out about other algorithmic differentiation tools
and about algorithmic differentiation in general at the following web sites:
<a href="http://en.wikipedia.org/wiki/Automatic_differentiation" target="_top"><span style='white-space: nowrap'>wikipedia</span></a>
 (http://en.wikipedia.org/wiki/Automatic_differentiation) ,
<a href="http://www.autodiff.org" target="_top"><span style='white-space: nowrap'>autodiff.org</span></a>
 (http://www.autodiff.org) .

<br/>
<br/>
<b><big><a name="c" id="c">c: Example</a></big></b>
<br/>
The file
<a href="#3.1">3.1: <span style='white-space: nowrap'>get_started.cpp</span></a>

contains an example and test of using CppAD to compute
the derivative of a polynomial.
There are many other 
<a href="#7">7: <span style='white-space: nowrap'>examples</span></a>
.

<br/>
<br/>
<b><big><a name="d" id="d">d: Include File</a></big></b>


<br/>
The following include directive
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;#&#xA0;include&#xA0;&lt;cppad/cppad.hpp&gt;<br/>
</span></font></code>includes the CppAD package for the rest of the current compilation unit.

<br/>
<br/>
<b><big><a name="e" id="e">e: Preprocessor Symbols</a></big></b>



<br/>
All the preprocessor symbols used by CppAD begin with eight
<code><font color="blue">CppAD</font></code> or <code><font color="blue">CPPAD_</font></code>; 
see <a href="#8">8: <span style='white-space: nowrap'>configure</span></a>
 for the few exceptions to this rule.

<br/>
<br/>
<b><big><a name="f" id="f">f: Namespace</a></big></b>


<br/>
All of the functions and objects defined by CppAD are in the
<code><font color="blue">CppAD</font></code> namespace; for example, you can access the <a href="#4">4: <span style='white-space: nowrap'>AD</span></a>
 types as 
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;size_t&#xA0;n&#xA0;=&#xA0;2;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CppAD::vector&lt;&#xA0;CppAD::AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>n</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>You can abbreviate access to one object or function a <code><font color="blue">using</font></code> 
command of the form
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;using&#xA0;CppAD::AD<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CppAD::vector&lt;&#xA0;AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>n</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>You can abbreviate access to all CppAD objects and functions 
with a command of the form
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;using&#xA0;namespace&#xA0;CppAD<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;vector&lt;&#xA0;AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>n</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>If you include other namespaces in a similar manner,
this can cause naming conflicts.


<br/>
<br/>
<b><big><a name="g" id="g">g: Contents</a></big></b>
<br/>
<table>
<tr><td><a href="#1" target="_top">_contents:&#xA0;1</a></td><td>Table&#xA0;of&#xA0;Contents</td></tr><tr><td><a href="#2" target="_top">Install:&#xA0;2</a></td><td>CppAD&#xA0;Download,&#xA0;Test,&#xA0;and&#xA0;Installation&#xA0;Instructions</td></tr><tr><td><a href="#3" target="_top">Introduction:&#xA0;3</a></td><td>An&#xA0;Introduction&#xA0;by&#xA0;Example&#xA0;to&#xA0;Algorithmic&#xA0;Differentiation</td></tr><tr><td><a href="#4" target="_top">AD:&#xA0;4</a></td><td>AD&#xA0;Objects</td></tr><tr><td><a href="#5" target="_top">ADFun:&#xA0;5</a></td><td>ADFun&#xA0;Objects</td></tr><tr><td><a href="#6" target="_top">library:&#xA0;6</a></td><td>The&#xA0;CppAD&#xA0;General&#xA0;Purpose&#xA0;Library</td></tr><tr><td><a href="#7" target="_top">Example:&#xA0;7</a></td><td>Examples</td></tr><tr><td><a href="#8" target="_top">configure:&#xA0;8</a></td><td>Preprocessor&#xA0;Definitions&#xA0;Used&#xA0;by&#xA0;CppAD</td></tr><tr><td><a href="#9" target="_top">Appendix:&#xA0;9</a></td><td>Appendix</td></tr><tr><td><a href="#10" target="_top">_reference:&#xA0;10</a></td><td>Alphabetic&#xA0;Listing&#xA0;of&#xA0;Cross&#xA0;Reference&#xA0;Tags</td></tr><tr><td><a href="#11" target="_top">_index:&#xA0;11</a></td><td>Keyword&#xA0;Index</td></tr><tr><td><a href="#12" target="_top">_external:&#xA0;12</a></td><td>External&#xA0;Internet&#xA0;References</td></tr></table>
<hr/>Input File: doc.omh

<hr/>
<center><b><big><big>
1: Table of Contents</big></big></b></center>

<pre>
cppad-20100316: A Package for Differentiation of C++ Algorithms: <a href="#">: CppAD</a>
    Table of Contents: <a href="#1">1: _contents</a>
    CppAD Download, Test, and Installation Instructions: <a href="#2">2: Install</a>
        Unix Download, Test and Installation: <a href="#2.1">2.1: InstallUnix</a>
            Using Subversion To Download Source Code: <a href="#2.1.1">2.1.1: subversion</a>
        Windows Download and Test: <a href="#2.2">2.2: InstallWindows</a>
    An Introduction by Example to Algorithmic Differentiation: <a href="#3">3: Introduction</a>
        A Simple Program Using CppAD to Compute Derivatives: <a href="#3.1">3.1: get_started.cpp</a>
        Second Order Exponential Approximation: <a href="#3.2">3.2: exp_2</a>
            exp_2: Implementation: <a href="#3.2.1">3.2.1: exp_2.hpp</a>
            exp_2: Test: <a href="#3.2.2">3.2.2: exp_2.cpp</a>
            exp_2: Operation Sequence and Zero Order Forward Mode: <a href="#3.2.3">3.2.3: exp_2_for0</a>
                exp_2: Verify Zero Order Forward Sweep: <a href="#3.2.3.1">3.2.3.1: exp_2_for0.cpp</a>
            exp_2: First Order Forward Mode: <a href="#3.2.4">3.2.4: exp_2_for1</a>
                exp_2: Verify First Order Forward Sweep: <a href="#3.2.4.1">3.2.4.1: exp_2_for1.cpp</a>
            exp_2: First Order Reverse Mode: <a href="#3.2.5">3.2.5: exp_2_rev1</a>
                exp_2: Verify First Order Reverse Sweep: <a href="#3.2.5.1">3.2.5.1: exp_2_rev1.cpp</a>
            exp_2: Second Order Forward Mode: <a href="#3.2.6">3.2.6: exp_2_for2</a>
                exp_2: Verify Second Order Forward Sweep: <a href="#3.2.6.1">3.2.6.1: exp_2_for2.cpp</a>
            exp_2: Second Order Reverse Mode: <a href="#3.2.7">3.2.7: exp_2_rev2</a>
                exp_2: Verify Second Order Reverse Sweep: <a href="#3.2.7.1">3.2.7.1: exp_2_rev2.cpp</a>
            exp_2: CppAD Forward and Reverse Sweeps: <a href="#3.2.8">3.2.8: exp_2_cppad</a>
        An Epsilon Accurate Exponential Approximation: <a href="#3.3">3.3: exp_eps</a>
            exp_eps: Implementation: <a href="#3.3.1">3.3.1: exp_eps.hpp</a>
            exp_eps: Test of exp_eps: <a href="#3.3.2">3.3.2: exp_eps.cpp</a>
            exp_eps: Operation Sequence and Zero Order Forward Sweep: <a href="#3.3.3">3.3.3: exp_eps_for0</a>
                exp_eps: Verify Zero Order Forward Sweep: <a href="#3.3.3.1">3.3.3.1: exp_eps_for0.cpp</a>
            exp_eps: First Order Forward Sweep: <a href="#3.3.4">3.3.4: exp_eps_for1</a>
                exp_eps: Verify First Order Forward Sweep: <a href="#3.3.4.1">3.3.4.1: exp_eps_for1.cpp</a>
            exp_eps: First Order Reverse Sweep: <a href="#3.3.5">3.3.5: exp_eps_rev1</a>
                exp_eps: Verify First Order Reverse Sweep: <a href="#3.3.5.1">3.3.5.1: exp_eps_rev1.cpp</a>
            exp_eps: Second Order Forward Mode: <a href="#3.3.6">3.3.6: exp_eps_for2</a>
                exp_eps: Verify Second Order Forward Sweep: <a href="#3.3.6.1">3.3.6.1: exp_eps_for2.cpp</a>
            exp_eps: Second Order Reverse Sweep: <a href="#3.3.7">3.3.7: exp_eps_rev2</a>
                exp_eps: Verify Second Order Reverse Sweep: <a href="#3.3.7.1">3.3.7.1: exp_eps_rev2.cpp</a>
            exp_eps: CppAD Forward and Reverse Sweeps: <a href="#3.3.8">3.3.8: exp_eps_cppad</a>
        Run the exp_2 and exp_eps Tests: <a href="#3.4">3.4: exp_apx_main.cpp</a>
    AD Objects: <a href="#4">4: AD</a>
        AD Default Constructor: <a href="#4.1">4.1: Default</a>
            Default AD Constructor: Example and Test: <a href="#4.1.1">4.1.1: Default.cpp</a>
        AD Copy Constructor and Assignment Operator: <a href="#4.2">4.2: ad_copy</a>
            AD Copy Constructor: Example and Test: <a href="#4.2.1">4.2.1: CopyAD.cpp</a>
            AD Constructor From Base Type: Example and Test: <a href="#4.2.2">4.2.2: CopyBase.cpp</a>
            AD Assignment Operator: Example and Test: <a href="#4.2.3">4.2.3: Eq.cpp</a>
        Conversion and Printing of AD Objects: <a href="#4.3">4.3: Convert</a>
            Convert From an AD Type to its Base Type: <a href="#4.3.1">4.3.1: Value</a>
                Convert From AD to its Base Type: Example and Test: <a href="#4.3.1.1">4.3.1.1: Value.cpp</a>
            Convert From AD to Integer: <a href="#4.3.2">4.3.2: Integer</a>
                Convert From AD to Integer: Example and Test: <a href="#4.3.2.1">4.3.2.1: Integer.cpp</a>
            AD Output Stream Operator: <a href="#4.3.3">4.3.3: Output</a>
                AD Output Operator: Example and Test: <a href="#4.3.3.1">4.3.3.1: Output.cpp</a>
            Printing AD Values During Forward Mode: <a href="#4.3.4">4.3.4: PrintFor</a>
                Printing During Forward Mode: Example and Test: <a href="#4.3.4.1">4.3.4.1: PrintFor.cpp</a>
            Convert an AD Variable to a Parameter: <a href="#4.3.5">4.3.5: Var2Par</a>
                Convert an AD Variable to a Parameter: Example and Test: <a href="#4.3.5.1">4.3.5.1: Var2Par.cpp</a>
        AD Valued Operations and Functions: <a href="#4.4">4.4: ADValued</a>
            AD Arithmetic Operators and Computed Assignments: <a href="#4.4.1">4.4.1: Arithmetic</a>
                AD Unary Plus Operator: <a href="#4.4.1.1">4.4.1.1: UnaryPlus</a>
                    AD Unary Plus Operator: Example and Test: <a href="#4.4.1.1.1">4.4.1.1.1: UnaryPlus.cpp</a>
                AD Unary Minus Operator: <a href="#4.4.1.2">4.4.1.2: UnaryMinus</a>
                    AD Unary Minus Operator: Example and Test: <a href="#4.4.1.2.1">4.4.1.2.1: UnaryMinus.cpp</a>
                AD Binary Arithmetic Operators: <a href="#4.4.1.3">4.4.1.3: ad_binary</a>
                    AD Binary Addition: Example and Test: <a href="#4.4.1.3.1">4.4.1.3.1: Add.cpp</a>
                    AD Binary Subtraction: Example and Test: <a href="#4.4.1.3.2">4.4.1.3.2: Sub.cpp</a>
                    AD Binary Multiplication: Example and Test: <a href="#4.4.1.3.3">4.4.1.3.3: Mul.cpp</a>
                    AD Binary Division: Example and Test: <a href="#4.4.1.3.4">4.4.1.3.4: Div.cpp</a>
                AD Computed Assignment Operators: <a href="#4.4.1.4">4.4.1.4: compute_assign</a>
                    AD Computed Assignment Addition: Example and Test: <a href="#4.4.1.4.1">4.4.1.4.1: AddEq.cpp</a>
                    AD Computed Assignment Subtraction: Example and Test: <a href="#4.4.1.4.2">4.4.1.4.2: SubEq.cpp</a>
                    AD Computed Assignment Multiplication: Example and Test: <a href="#4.4.1.4.3">4.4.1.4.3: MulEq.cpp</a>
                    AD Computed Assignment Division: Example and Test: <a href="#4.4.1.4.4">4.4.1.4.4: DivEq.cpp</a>
            AD Standard Math Unary Functions: <a href="#4.4.2">4.4.2: std_math_ad</a>
                The AD acos Function: Example and Test: <a href="#4.4.2.1">4.4.2.1: Acos.cpp</a>
                The AD asin Function: Example and Test: <a href="#4.4.2.2">4.4.2.2: Asin.cpp</a>
                The AD atan Function: Example and Test: <a href="#4.4.2.3">4.4.2.3: Atan.cpp</a>
                The AD cos Function: Example and Test: <a href="#4.4.2.4">4.4.2.4: Cos.cpp</a>
                The AD cosh Function: Example and Test: <a href="#4.4.2.5">4.4.2.5: Cosh.cpp</a>
                The AD exp Function: Example and Test: <a href="#4.4.2.6">4.4.2.6: Exp.cpp</a>
                The AD log Function: Example and Test: <a href="#4.4.2.7">4.4.2.7: Log.cpp</a>
                The AD log10 Function: Example and Test: <a href="#4.4.2.8">4.4.2.8: Log10.cpp</a>
                The AD sin Function: Example and Test: <a href="#4.4.2.9">4.4.2.9: Sin.cpp</a>
                The AD sinh Function: Example and Test: <a href="#4.4.2.10">4.4.2.10: Sinh.cpp</a>
                The AD sqrt Function: Example and Test: <a href="#4.4.2.11">4.4.2.11: Sqrt.cpp</a>
                The AD tan Function: Example and Test: <a href="#4.4.2.12">4.4.2.12: Tan.cpp</a>
                The AD tanh Function: Example and Test: <a href="#4.4.2.13">4.4.2.13: Tanh.cpp</a>
            Other AD Math Functions: <a href="#4.4.3">4.4.3: MathOther</a>
                AD Absolute Value Function: <a href="#4.4.3.1">4.4.3.1: abs</a>
                    AD Absolute Value Function: Example and Test: <a href="#4.4.3.1.1">4.4.3.1.1: Abs.cpp</a>
                AD Two Argument Inverse Tangent Function: <a href="#4.4.3.2">4.4.3.2: atan2</a>
                    The AD atan2 Function: Example and Test: <a href="#4.4.3.2.1">4.4.3.2.1: Atan2.cpp</a>
                The AD Error Function: <a href="#4.4.3.3">4.4.3.3: erf</a>
                    The AD erf Function: Example and Test: <a href="#4.4.3.3.1">4.4.3.3.1: Erf.cpp</a>
                The AD Power Function: <a href="#4.4.3.4">4.4.3.4: pow</a>
                    The AD Power Function: Example and Test: <a href="#4.4.3.4.1">4.4.3.4.1: Pow.cpp</a>
                    The Pow Integer Exponent: Example and Test: <a href="#4.4.3.4.2">4.4.3.4.2: pow_int.cpp</a>
            AD Conditional Expressions: <a href="#4.4.4">4.4.4: CondExp</a>
                Conditional Expressions: Example and Test: <a href="#4.4.4.1">4.4.4.1: CondExp.cpp</a>
            Discrete AD Functions: <a href="#4.4.5">4.4.5: Discrete</a>
                Taping Array Index Operation: Example and Test: <a href="#4.4.5.1">4.4.5.1: TapeIndex.cpp</a>
                Interpolation With Out Retaping: Example and Test: <a href="#4.4.5.2">4.4.5.2: interp_onetape.cpp</a>
                Interpolation With Retaping: Example and Test: <a href="#4.4.5.3">4.4.5.3: interp_retape.cpp</a>
        Bool Valued Operations and Functions with AD Arguments: <a href="#4.5">4.5: BoolValued</a>
            AD Binary Comparison Operators: <a href="#4.5.1">4.5.1: Compare</a>
                AD Binary Comparison Operators: Example and Test: <a href="#4.5.1.1">4.5.1.1: Compare.cpp</a>
            Compare AD and Base Objects for Nearly Equal: <a href="#4.5.2">4.5.2: NearEqualExt</a>
                Compare AD with Base Objects: Example and Test: <a href="#4.5.2.1">4.5.2.1: NearEqualExt.cpp</a>
            AD Boolean Functions: <a href="#4.5.3">4.5.3: BoolFun</a>
                AD Boolean Functions: Example and Test: <a href="#4.5.3.1">4.5.3.1: BoolFun.cpp</a>
            Is an AD Object a Parameter or Variable: <a href="#4.5.4">4.5.4: ParVar</a>
                AD Parameter and Variable Functions: Example and Test: <a href="#4.5.4.1">4.5.4.1: ParVar.cpp</a>
            Check if Equal and Correspond to Same Operation Sequence: <a href="#4.5.5">4.5.5: EqualOpSeq</a>
                EqualOpSeq: Example and Test: <a href="#4.5.5.1">4.5.5.1: EqualOpSeq.cpp</a>
        AD Vectors that Record Index Operations: <a href="#4.6">4.6: VecAD</a>
            AD Vectors that Record Index Operations: Example and Test: <a href="#4.6.1">4.6.1: vec_ad.cpp</a>
        AD&lt;Base&gt; Requirements for Base Type: <a href="#4.7">4.7: base_require</a>
            Enable use of AD&lt;Base&gt; where Base is std::complex&lt;double&gt;: <a href="#4.7.1">4.7.1: base_complex.hpp</a>
                Complex Polynomial: Example and Test: <a href="#4.7.1.1">4.7.1.1: ComplexPoly.cpp</a>
                Not Complex Differentiable: Example and Test: <a href="#4.7.1.2">4.7.1.2: not_complex_ad.cpp</a>
            Enable use of AD&lt;Base&gt; where Base is Adolc's adouble Type: <a href="#4.7.2">4.7.2: base_adolc.hpp</a>
                Using Adolc with Multiple Levels of Taping: Example and Test: <a href="#4.7.2.1">4.7.2.1: mul_level_adolc.cpp</a>
    ADFun Objects: <a href="#5">5: ADFun</a>
        Declare Independent Variables and Start Recording: <a href="#5.1">5.1: Independent</a>
            Independent and ADFun Constructor: Example and Test: <a href="#5.1.1">5.1.1: Independent.cpp</a>
        Construct an ADFun Object and Stop Recording: <a href="#5.2">5.2: FunConstruct</a>
            ADFun Assignment: Example and Test: <a href="#5.2.1">5.2.1: fun_assign.cpp</a>
        Stop Recording and Store Operation Sequence: <a href="#5.3">5.3: Dependent</a>
        Abort Recording of an Operation Sequence: <a href="#5.4">5.4: abort_recording</a>
            Abort Current Recording: Example and Test: <a href="#5.4.1">5.4.1: abort_recording.cpp</a>
        ADFun Sequence Properties: <a href="#5.5">5.5: seq_property</a>
            ADFun Sequence Properties: Example and Test: <a href="#5.5.1">5.5.1: seq_property.cpp</a>
        Evaluate ADFun Functions, Derivatives, and Sparsity Patterns: <a href="#5.6">5.6: FunEval</a>
            Forward Mode: <a href="#5.6.1">5.6.1: Forward</a>
                Zero Order Forward Mode: Function Values: <a href="#5.6.1.1">5.6.1.1: ForwardZero</a>
                First Order Forward Mode: Derivative Values: <a href="#5.6.1.2">5.6.1.2: ForwardOne</a>
                Any Order Forward Mode: <a href="#5.6.1.3">5.6.1.3: ForwardAny</a>
                Number Taylor Coefficients, Per Variable, Currently Stored: <a href="#5.6.1.4">5.6.1.4: size_taylor</a>
                Comparison Changes During Zero Order Forward Mode: <a href="#5.6.1.5">5.6.1.5: CompareChange</a>
                    CompareChange and Re-Tape: Example and Test: <a href="#5.6.1.5.1">5.6.1.5.1: CompareChange.cpp</a>
                Controlling Taylor Coefficients Memory Allocation: <a href="#5.6.1.6">5.6.1.6: capacity_taylor</a>
                Forward Mode: Example and Test: <a href="#5.6.1.7">5.6.1.7: Forward.cpp</a>
            Reverse Mode: <a href="#5.6.2">5.6.2: Reverse</a>
                First Order Reverse Mode: <a href="#5.6.2.1">5.6.2.1: reverse_one</a>
                    First Order Reverse Mode: Example and Test: <a href="#5.6.2.1.1">5.6.2.1.1: reverse_one.cpp</a>
                Second Order Reverse Mode: <a href="#5.6.2.2">5.6.2.2: reverse_two</a>
                    Second Order Reverse ModeExample and Test: <a href="#5.6.2.2.1">5.6.2.2.1: reverse_two.cpp</a>
                    Hessian Times Direction: Example and Test: <a href="#5.6.2.2.2">5.6.2.2.2: HesTimesDir.cpp</a>
                Any Order Reverse Mode: <a href="#5.6.2.3">5.6.2.3: reverse_any</a>
                    Third Order Reverse Mode: Example and Test: <a href="#5.6.2.3.1">5.6.2.3.1: reverse_three.cpp</a>
                    Reverse Mode General Case: Example and Test: <a href="#5.6.2.3.2">5.6.2.3.2: reverse_any.cpp</a>
                    Checkpoint and Function Composition: Example and Test: <a href="#5.6.2.3.3">5.6.2.3.3: checkpoint.cpp</a>
            Calculating Sparsity Patterns: <a href="#5.6.3">5.6.3: Sparse</a>
                Jacobian Sparsity Pattern: Forward Mode: <a href="#5.6.3.1">5.6.3.1: ForSparseJac</a>
                    Forward Mode Jacobian Sparsity: Example and Test: <a href="#5.6.3.1.1">5.6.3.1.1: ForSparseJac.cpp</a>
                Jacobian Sparsity Pattern: Reverse Mode: <a href="#5.6.3.2">5.6.3.2: RevSparseJac</a>
                    Reverse Mode Jacobian Sparsity: Example and Test: <a href="#5.6.3.2.1">5.6.3.2.1: RevSparseJac.cpp</a>
                Hessian Sparsity Pattern: Reverse Mode: <a href="#5.6.3.3">5.6.3.3: RevSparseHes</a>
                    Reverse Mode Hessian Sparsity: Example and Test: <a href="#5.6.3.3.1">5.6.3.3.1: RevSparseHes.cpp</a>
        First and Second Derivatives: Easy Drivers: <a href="#5.7">5.7: Drivers</a>
            Jacobian: Driver Routine: <a href="#5.7.1">5.7.1: Jacobian</a>
                Jacobian: Example and Test: <a href="#5.7.1.1">5.7.1.1: Jacobian.cpp</a>
            First Order Partial Derivative: Driver Routine: <a href="#5.7.2">5.7.2: ForOne</a>
                First Order Partial Driver: Example and Test: <a href="#5.7.2.1">5.7.2.1: ForOne.cpp</a>
            First Order Derivative: Driver Routine: <a href="#5.7.3">5.7.3: RevOne</a>
                First Order Derivative Driver: Example and Test: <a href="#5.7.3.1">5.7.3.1: RevOne.cpp</a>
            Hessian: Easy Driver: <a href="#5.7.4">5.7.4: Hessian</a>
                Hessian: Example and Test: <a href="#5.7.4.1">5.7.4.1: Hessian.cpp</a>
                Hessian of Lagrangian and ADFun Default Constructor: Example and Test: <a href="#5.7.4.2">5.7.4.2: HesLagrangian.cpp</a>
            Forward Mode Second Partial Derivative Driver: <a href="#5.7.5">5.7.5: ForTwo</a>
                Subset of Second Order Partials: Example and Test: <a href="#5.7.5.1">5.7.5.1: ForTwo.cpp</a>
            Reverse Mode Second Partial Derivative Driver: <a href="#5.7.6">5.7.6: RevTwo</a>
                Second Partials Reverse Driver: Example and Test: <a href="#5.7.6.1">5.7.6.1: RevTwo.cpp</a>
            Sparse Jacobian: Easy Driver: <a href="#5.7.7">5.7.7: sparse_jacobian</a>
                Sparse Jacobian: Example and Test: <a href="#5.7.7.1">5.7.7.1: sparse_jacobian.cpp</a>
            Sparse Hessian: Easy Driver: <a href="#5.7.8">5.7.8: sparse_hessian</a>
                Sparse Hessian: Example and Test: <a href="#5.7.8.1">5.7.8.1: sparse_hessian.cpp</a>
        Check an ADFun Sequence of Operations: <a href="#5.8">5.8: FunCheck</a>
            ADFun Check and Re-Tape: Example and Test: <a href="#5.8.1">5.8.1: FunCheck.cpp</a>
        OpenMP Maximum Thread Number: <a href="#5.9">5.9: omp_max_thread</a>
            Compile and Run the OpenMP Test: <a href="#5.9.1">5.9.1: openmp_run.sh</a>
                A Simple Parallel Loop: <a href="#5.9.1.1">5.9.1.1: example_a11c.cpp</a>
                Multi-Threaded Newton's Method Main Program: <a href="#5.9.1.2">5.9.1.2: multi_newton.cpp</a>
                    Multi-Threaded Newton's Method Routine: <a href="#5.9.1.2.1">5.9.1.2.1: multi_newton</a>
                    OpenMP Multi-Threading Newton's Method Source Code: <a href="#5.9.1.2.2">5.9.1.2.2: multi_newton.hpp</a>
                Sum of 1/i Main Program: <a href="#5.9.1.3">5.9.1.3: sum_i_inv.cpp</a>
        Optimize the Tape Corresponding to an ADFun object: <a href="#5.10">5.10: optimize</a>
            ADFun Operation Sequence Optimization: Example and Test: <a href="#5.10.1">5.10.1: optimize.cpp</a>
        ADFun Object Deprecated Member Functions: <a href="#5.11">5.11: FunDeprecated</a>
    The CppAD General Purpose Library: <a href="#6">6: library</a>
        Replacing the CppAD Error Handler: <a href="#6.1">6.1: ErrorHandler</a>
            Replacing The CppAD Error Handler: Example and Test: <a href="#6.1.1">6.1.1: ErrorHandler.cpp</a>
            CppAD Assertions During Execution: <a href="#6.1.2">6.1.2: cppad_assert</a>
        Determine if Two Values Are Nearly Equal: <a href="#6.2">6.2: NearEqual</a>
            NearEqual Function: Example and Test: <a href="#6.2.1">6.2.1: Near_Equal.cpp</a>
        Run One Speed Test and Return Results: <a href="#6.3">6.3: speed_test</a>
            Returns Elapsed Number of Seconds: <a href="#6.3.1">6.3.1: elapsed_seconds</a>
                Elapsed Seconds: Example and Test: <a href="#6.3.1.1">6.3.1.1: elapsed_seconds.cpp</a>
            speed_test: Example and test: <a href="#6.3.2">6.3.2: speed_test.cpp</a>
        Run One Speed Test and Print Results: <a href="#6.4">6.4: SpeedTest</a>
            Example Use of SpeedTest: <a href="#6.4.1">6.4.1: speed_program.cpp</a>
        Definition of a Numeric Type: <a href="#6.5">6.5: NumericType</a>
            The NumericType: Example and Test: <a href="#6.5.1">6.5.1: NumericType.cpp</a>
        Check NumericType Class Concept: <a href="#6.6">6.6: CheckNumericType</a>
            The CheckNumericType Function: Example and Test: <a href="#6.6.1">6.6.1: CheckNumericType.cpp</a>
        Definition of a Simple Vector: <a href="#6.7">6.7: SimpleVector</a>
            Simple Vector Template Class: Example and Test: <a href="#6.7.1">6.7.1: SimpleVector.cpp</a>
        Check Simple Vector Concept: <a href="#6.8">6.8: CheckSimpleVector</a>
            The CheckSimpleVector Function: Example and Test: <a href="#6.8.1">6.8.1: CheckSimpleVector.cpp</a>
        Obtain Nan and Determine if a Value is Nan: <a href="#6.9">6.9: nan</a>
            nan: Example and Test: <a href="#6.9.1">6.9.1: nan.cpp</a>
        The Integer Power Function: <a href="#6.10">6.10: pow_int</a>
        Evaluate a Polynomial or its Derivative: <a href="#6.11">6.11: Poly</a>
            Polynomial Evaluation: Example and Test: <a href="#6.11.1">6.11.1: Poly.cpp</a>
            Source: Poly: <a href="#6.11.2">6.11.2: poly.hpp</a>
        Compute Determinants and Solve Equations by LU Factorization: <a href="#6.12">6.12: LuDetAndSolve</a>
            Compute Determinant and Solve Linear Equations: <a href="#6.12.1">6.12.1: LuSolve</a>
                LuSolve With Complex Arguments: Example and Test: <a href="#6.12.1.1">6.12.1.1: LuSolve.cpp</a>
                Source: LuSolve: <a href="#6.12.1.2">6.12.1.2: lu_solve.hpp</a>
            LU Factorization of A Square Matrix: <a href="#6.12.2">6.12.2: LuFactor</a>
                LuFactor: Example and Test: <a href="#6.12.2.1">6.12.2.1: LuFactor.cpp</a>
                Source: LuFactor: <a href="#6.12.2.2">6.12.2.2: lu_factor.hpp</a>
            Invert an LU Factored Equation: <a href="#6.12.3">6.12.3: LuInvert</a>
                LuInvert: Example and Test: <a href="#6.12.3.1">6.12.3.1: LuInvert.cpp</a>
                Source: LuInvert: <a href="#6.12.3.2">6.12.3.2: lu_invert.hpp</a>
        One DimensionalRomberg Integration: <a href="#6.13">6.13: RombergOne</a>
            One Dimensional Romberg Integration: Example and Test: <a href="#6.13.1">6.13.1: RombergOne.cpp</a>
        Multi-dimensional Romberg Integration: <a href="#6.14">6.14: RombergMul</a>
            One Dimensional Romberg Integration: Example and Test: <a href="#6.14.1">6.14.1: RombergMul.cpp</a>
        An Embedded 4th and 5th Order Runge-Kutta ODE Solver: <a href="#6.15">6.15: Runge45</a>
            Runge45: Example and Test: <a href="#6.15.1">6.15.1: runge_45_1.cpp</a>
            Runge45: Example and Test: <a href="#6.15.2">6.15.2: runge_45_2.cpp</a>
        A 3rd and 4th Order Rosenbrock ODE Solver: <a href="#6.16">6.16: Rosen34</a>
            Rosen34: Example and Test: <a href="#6.16.1">6.16.1: Rosen34.cpp</a>
        An Error Controller for ODE Solvers: <a href="#6.17">6.17: OdeErrControl</a>
            OdeErrControl: Example and Test: <a href="#6.17.1">6.17.1: OdeErrControl.cpp</a>
            OdeErrControl: Example and Test Using Maxabs Argument: <a href="#6.17.2">6.17.2: OdeErrMaxabs.cpp</a>
        An Arbitrary Order Gear Method: <a href="#6.18">6.18: OdeGear</a>
            OdeGear: Example and Test: <a href="#6.18.1">6.18.1: OdeGear.cpp</a>
        An Error Controller for Gear's Ode Solvers: <a href="#6.19">6.19: OdeGearControl</a>
            OdeGearControl: Example and Test: <a href="#6.19.1">6.19.1: OdeGearControl.cpp</a>
        Computing Jacobian and Hessian of Bender's Reduced Objective: <a href="#6.20">6.20: BenderQuad</a>
            BenderQuad: Example and Test: <a href="#6.20.1">6.20.1: BenderQuad.cpp</a>
        Jacobian and Hessian of Optimal Values: <a href="#6.21">6.21: opt_val_hes</a>
            opt_val_hes: Example and Test: <a href="#6.21.1">6.21.1: opt_val_hes.cpp</a>
        LU Factorization of A Square Matrix and Stability Calculation: <a href="#6.22">6.22: LuRatio</a>
            LuRatio: Example and Test: <a href="#6.22.1">6.22.1: LuRatio.cpp</a>
        Float and Double Standard Math Unary Functions: <a href="#6.23">6.23: std_math_unary</a>
        The CppAD::vector Template Class: <a href="#6.24">6.24: CppAD_vector</a>
            CppAD::vector Template Class: Example and Test: <a href="#6.24.1">6.24.1: CppAD_vector.cpp</a>
            CppAD::vectorBool Class: Example and Test: <a href="#6.24.2">6.24.2: vectorBool.cpp</a>
        Routines That Track Use of New and Delete: <a href="#6.25">6.25: TrackNewDel</a>
            Tracking Use of New and Delete: Example and Test: <a href="#6.25.1">6.25.1: TrackNewDel.cpp</a>
    Examples: <a href="#7">7: Example</a>
        General Examples: <a href="#7.1">7.1: General</a>
            Creating Your Own Interface to an ADFun Object: <a href="#7.1.1">7.1.1: ad_fun.cpp</a>
            Example and Test Linking CppAD to Languages Other than C++: <a href="#7.1.2">7.1.2: ad_in_c.cpp</a>
            Gradient of Determinant Using Expansion by Minors: Example and Test: <a href="#7.1.3">7.1.3: HesMinorDet.cpp</a>
            Gradient of Determinant Using LU Factorization: Example and Test: <a href="#7.1.4">7.1.4: HesLuDet.cpp</a>
            Nonlinear Programming Using the CppAD Interface to Ipopt: <a href="#7.1.5">7.1.5: cppad_ipopt_nlp</a>
                Linking the CppAD Interface to Ipopt in Visual Studio 9.0: <a href="#7.1.5.1">7.1.5.1: cppad_ipopt_windows</a>
                Nonlinear Programming Using CppAD and Ipopt: Example and Test: <a href="#7.1.5.2">7.1.5.2: ipopt_get_started.cpp</a>
                Example Simultaneous Solution of Forward and Inverse Problem: <a href="#7.1.5.3">7.1.5.3: cppad_ipopt_ode</a>
                    An ODE Inverse Problem Example: <a href="#7.1.5.3.1">7.1.5.3.1: ipopt_ode_problem</a>
                        ODE Inverse Problem Definitions: Source Code: <a href="#7.1.5.3.1.1">7.1.5.3.1.1: ipopt_ode_problem.hpp</a>
                    ODE Fitting Using Simple Representation: <a href="#7.1.5.3.2">7.1.5.3.2: ipopt_ode_simple</a>
                        ODE Fitting Using Simple Representation: <a href="#7.1.5.3.2.1">7.1.5.3.2.1: ipopt_ode_simple.hpp</a>
                    ODE Fitting Using Fast Representation: <a href="#7.1.5.3.3">7.1.5.3.3: ipopt_ode_fast</a>
                        ODE Fitting Using Fast Representation: <a href="#7.1.5.3.3.1">7.1.5.3.3.1: ipopt_ode_fast.hpp</a>
                    Driver for Running the Ipopt ODE Example: <a href="#7.1.5.3.4">7.1.5.3.4: ipopt_ode_run.hpp</a>
                    Correctness Check for Both Simple and Fast Representations: <a href="#7.1.5.3.5">7.1.5.3.5: ipopt_ode_check.cpp</a>
                Speed Test for Both Simple and Fast Representations: <a href="#7.1.5.4">7.1.5.4: ipopt_ode_speed.cpp</a>
            Interfacing to C: Example and Test: <a href="#7.1.6">7.1.6: Interface2C.cpp</a>
            Gradient of Determinant Using Expansion by Minors: Example and Test: <a href="#7.1.7">7.1.7: JacMinorDet.cpp</a>
            Gradient of Determinant Using Lu Factorization: Example and Test: <a href="#7.1.8">7.1.8: JacLuDet.cpp</a>
            Using Multiple Levels of AD: <a href="#7.1.9">7.1.9: mul_level</a>
                Multiple Tapes: Example and Test: <a href="#7.1.9.1">7.1.9.1: mul_level.cpp</a>
            A Stiff Ode: Example and Test: <a href="#7.1.10">7.1.10: OdeStiff.cpp</a>
            Taylor's Ode Solver: An Example and Test: <a href="#7.1.11">7.1.11: ode_taylor.cpp</a>
            Using Adolc with Taylor's Ode Solver: An Example and Test: <a href="#7.1.12">7.1.12: ode_taylor_adolc.cpp</a>
            Example Differentiating a Stack Machine Interpreter: <a href="#7.1.13">7.1.13: StackMachine.cpp</a>
        Utility Routines used by CppAD Examples: <a href="#7.2">7.2: ExampleUtility</a>
            Program That Runs the CppAD Examples: <a href="#7.2.1">7.2.1: Example.cpp</a>
            Program That Runs the Speed Examples: <a href="#7.2.2">7.2.2: speed_example.cpp</a>
            Lu Factor and Solve with Recorded Pivoting: <a href="#7.2.3">7.2.3: LuVecAD</a>
                Lu Factor and Solve With Recorded Pivoting: Example and Test: <a href="#7.2.3.1">7.2.3.1: LuVecADOk.cpp</a>
        List of All the CppAD Examples: <a href="#7.3">7.3: ListAllExamples</a>
        Choosing The Vector Testing Template Class: <a href="#7.4">7.4: test_vector</a>
    Preprocessor Definitions Used by CppAD: <a href="#8">8: configure</a>
    Appendix: <a href="#9">9: Appendix</a>
        Frequently Asked Questions and Answers: <a href="#9.1">9.1: Faq</a>
        Speed Test Routines: <a href="#9.2">9.2: speed</a>
            Speed Testing Main Program: <a href="#9.2.1">9.2.1: speed_main</a>
                Speed Testing Gradient of Determinant Using Lu Factorization: <a href="#9.2.1.1">9.2.1.1: link_det_lu</a>
                Speed Testing Gradient of Determinant by Minor Expansion: <a href="#9.2.1.2">9.2.1.2: link_det_minor</a>
                Speed Testing the Jacobian of Ode Solution: <a href="#9.2.1.3">9.2.1.3: link_ode</a>
                Speed Testing Second Derivative of a Polynomial: <a href="#9.2.1.4">9.2.1.4: link_poly</a>
                Speed Testing Sparse Hessian: <a href="#9.2.1.5">9.2.1.5: link_sparse_hessian</a>
                Speed Testing Sparse Jacobian: <a href="#9.2.1.6">9.2.1.6: link_sparse_jacobian</a>
                Microsoft Version of Elapsed Number of Seconds: <a href="#9.2.1.7">9.2.1.7: microsoft_timer</a>
            Speed Testing Utilities: <a href="#9.2.2">9.2.2: speed_utility</a>
                Simulate a [0,1] Uniform Random Variate: <a href="#9.2.2.1">9.2.2.1: uniform_01</a>
                    Source: uniform_01: <a href="#9.2.2.1.1">9.2.2.1.1: uniform_01.hpp</a>
                Determinant of a Minor: <a href="#9.2.2.2">9.2.2.2: det_of_minor</a>
                    Determinant of a Minor: Example and Test: <a href="#9.2.2.2.1">9.2.2.2.1: det_of_minor.cpp</a>
                    Source: det_of_minor: <a href="#9.2.2.2.2">9.2.2.2.2: det_of_minor.hpp</a>
                Determinant Using Expansion by Minors: <a href="#9.2.2.3">9.2.2.3: det_by_minor</a>
                    Determinant Using Expansion by Minors: Example and Test: <a href="#9.2.2.3.1">9.2.2.3.1: det_by_minor.cpp</a>
                    Source: det_by_minor: <a href="#9.2.2.3.2">9.2.2.3.2: det_by_minor.hpp</a>
                Determinant Using Expansion by Lu Factorization: <a href="#9.2.2.4">9.2.2.4: det_by_lu</a>
                    Determinant Using Lu Factorization: Example and Test: <a href="#9.2.2.4.1">9.2.2.4.1: det_by_lu.cpp</a>
                    Source: det_by_lu: <a href="#9.2.2.4.2">9.2.2.4.2: det_by_lu.hpp</a>
                Check Determinant of 3 by 3 matrix: <a href="#9.2.2.5">9.2.2.5: det_33</a>
                    Source: det_33: <a href="#9.2.2.5.1">9.2.2.5.1: det_33.hpp</a>
                Check Gradient of Determinant of 3 by 3 matrix: <a href="#9.2.2.6">9.2.2.6: det_grad_33</a>
                    Source: det_grad_33: <a href="#9.2.2.6.1">9.2.2.6.1: det_grad_33.hpp</a>
                Evaluate a Function Defined in Terms of an ODE: <a href="#9.2.2.7">9.2.2.7: ode_evaluate</a>
                    ode_evaluate: Example and test: <a href="#9.2.2.7.1">9.2.2.7.1: ode_evaluate.cpp</a>
                    Source: ode_evaluate: <a href="#9.2.2.7.2">9.2.2.7.2: ode_evaluate.hpp</a>
                Evaluate a Function That Has a Sparse Hessian: <a href="#9.2.2.8">9.2.2.8: sparse_evaluate</a>
                    sparse_evaluate: Example and test: <a href="#9.2.2.8.1">9.2.2.8.1: sparse_evaluate.cpp</a>
                    Source: sparse_evaluate: <a href="#9.2.2.8.2">9.2.2.8.2: sparse_evaluate.hpp</a>
            Speed Test Functions in Double: <a href="#9.2.3">9.2.3: speed_double</a>
                Double Speed: Determinant by Minor Expansion: <a href="#9.2.3.1">9.2.3.1: double_det_minor.cpp</a>
                Double Speed: Determinant Using Lu Factorization: <a href="#9.2.3.2">9.2.3.2: double_det_lu.cpp</a>
                Double Speed: Ode Solution: <a href="#9.2.3.3">9.2.3.3: double_ode.cpp</a>
                Double Speed: Evaluate a Polynomial: <a href="#9.2.3.4">9.2.3.4: double_poly.cpp</a>
                Double Speed: Sparse Hessian: <a href="#9.2.3.5">9.2.3.5: double_sparse_hessian.cpp</a>
                Double Speed: Sparse Jacobian: <a href="#9.2.3.6">9.2.3.6: double_sparse_jacobian.cpp</a>
            Speed Test Derivatives Using Adolc: <a href="#9.2.4">9.2.4: speed_adolc</a>
                Adolc Speed: Gradient of Determinant by Minor Expansion: <a href="#9.2.4.1">9.2.4.1: adolc_det_minor.cpp</a>
                Adolc Speed: Gradient of Determinant Using Lu Factorization: <a href="#9.2.4.2">9.2.4.2: adolc_det_lu.cpp</a>
                Adolc Speed: Ode: <a href="#9.2.4.3">9.2.4.3: adolc_ode.cpp</a>
                Adolc Speed: Second Derivative of a Polynomial: <a href="#9.2.4.4">9.2.4.4: adolc_poly.cpp</a>
                Adolc Speed: Sparse Hessian: <a href="#9.2.4.5">9.2.4.5: adolc_sparse_hessian.cpp</a>
                adolc Speed: sparse_jacobian: <a href="#9.2.4.6">9.2.4.6: adolc_sparse_jacobian.cpp</a>
            Speed Test Derivatives Using CppAD: <a href="#9.2.5">9.2.5: speed_cppad</a>
                CppAD Speed: Gradient of Determinant by Minor Expansion: <a href="#9.2.5.1">9.2.5.1: cppad_det_minor.cpp</a>
                CppAD Speed: Gradient of Determinant Using Lu Factorization: <a href="#9.2.5.2">9.2.5.2: cppad_det_lu.cpp</a>
                CppAD Speed: Gradient of Ode Solution: <a href="#9.2.5.3">9.2.5.3: cppad_ode.cpp</a>
                CppAD Speed: Second Derivative of a Polynomial: <a href="#9.2.5.4">9.2.5.4: cppad_poly.cpp</a>
                CppAD Speed: Sparse Hessian: <a href="#9.2.5.5">9.2.5.5: cppad_sparse_hessian.cpp</a>
                CppAD Speed: Sparse Jacobian: <a href="#9.2.5.6">9.2.5.6: cppad_sparse_jacobian.cpp</a>
            Speed Test Derivatives Using Fadbad: <a href="#9.2.6">9.2.6: speed_fadbad</a>
                Fadbad Speed: Gradient of Determinant by Minor Expansion: <a href="#9.2.6.1">9.2.6.1: fadbad_det_minor.cpp</a>
                Fadbad Speed: Gradient of Determinant Using Lu Factorization: <a href="#9.2.6.2">9.2.6.2: fadbad_det_lu.cpp</a>
                Fadbad Speed: Ode: <a href="#9.2.6.3">9.2.6.3: fadbad_ode.cpp</a>
                Fadbad Speed: Second Derivative of a Polynomial: <a href="#9.2.6.4">9.2.6.4: fadbad_poly.cpp</a>
                Fadbad Speed: Sparse Hessian: <a href="#9.2.6.5">9.2.6.5: fadbad_sparse_hessian.cpp</a>
                fadbad Speed: sparse_jacobian: <a href="#9.2.6.6">9.2.6.6: fadbad_sparse_jacobian.cpp</a>
            Speed Test Derivatives Using Sacado: <a href="#9.2.7">9.2.7: speed_sacado</a>
                Sacado Speed: Gradient of Determinant by Minor Expansion: <a href="#9.2.7.1">9.2.7.1: sacado_det_minor.cpp</a>
                Sacado Speed: Gradient of Determinant Using Lu Factorization: <a href="#9.2.7.2">9.2.7.2: sacado_det_lu.cpp</a>
                Sacado Speed: Gradient of Ode Solution: <a href="#9.2.7.3">9.2.7.3: sacado_ode.cpp</a>
                Sacado Speed: Second Derivative of a Polynomial: <a href="#9.2.7.4">9.2.7.4: sacado_poly.cpp</a>
                Sacado Speed: Sparse Hessian: <a href="#9.2.7.5">9.2.7.5: sacado_sparse_hessian.cpp</a>
                sacado Speed: sparse_jacobian: <a href="#9.2.7.6">9.2.7.6: sacado_sparse_jacobian.cpp</a>
        The Theory of Derivative Calculations: <a href="#9.3">9.3: Theory</a>
            The Theory of Forward Mode: <a href="#9.3.1">9.3.1: ForwardTheory</a>
                Exponential Function Forward Taylor Polynomial Theory: <a href="#9.3.1.1">9.3.1.1: ExpForward</a>
                Logarithm Function Forward Taylor Polynomial Theory: <a href="#9.3.1.2">9.3.1.2: LogForward</a>
                Square Root Function Forward Taylor Polynomial Theory: <a href="#9.3.1.3">9.3.1.3: SqrtForward</a>
                Trigonometric and Hyperbolic Sine and Cosine Forward Theory: <a href="#9.3.1.4">9.3.1.4: SinCosForward</a>
                Arctangent Function Forward Taylor Polynomial Theory: <a href="#9.3.1.5">9.3.1.5: AtanForward</a>
                Arcsine Function Forward Taylor Polynomial Theory: <a href="#9.3.1.6">9.3.1.6: AsinForward</a>
                Arccosine Function Forward Taylor Polynomial Theory: <a href="#9.3.1.7">9.3.1.7: AcosForward</a>
            The Theory of Reverse Mode: <a href="#9.3.2">9.3.2: ReverseTheory</a>
                Exponential Function Reverse Mode Theory: <a href="#9.3.2.1">9.3.2.1: ExpReverse</a>
                Logarithm Function Reverse Mode Theory: <a href="#9.3.2.2">9.3.2.2: LogReverse</a>
                Square Root Function Reverse Mode Theory: <a href="#9.3.2.3">9.3.2.3: SqrtReverse</a>
                Trigonometric and Hyperbolic Sine and Cosine Reverse Theory: <a href="#9.3.2.4">9.3.2.4: SinCosReverse</a>
                Arctangent Function Reverse Mode Theory: <a href="#9.3.2.5">9.3.2.5: AtanReverse</a>
                Arcsine Function Reverse Mode Theory: <a href="#9.3.2.6">9.3.2.6: AsinReverse</a>
                Arccosine Function Reverse Mode Theory: <a href="#9.3.2.7">9.3.2.7: AcosReverse</a>
            An Important Reverse Mode Identity: <a href="#9.3.3">9.3.3: reverse_identity</a>
        Glossary: <a href="#9.4">9.4: glossary</a>
        Bibliography: <a href="#9.5">9.5: Bib</a>
        Know Bugs and Problems Using CppAD: <a href="#9.6">9.6: Bugs</a>
        The CppAD Wish List: <a href="#9.7">9.7: WishList</a>
        Changes and Additions to CppAD: <a href="#9.8">9.8: whats_new</a>
            Changes and Additions to CppAD During 2010: <a href="#9.8.1">9.8.1: whats_new_10</a>
            Changes and Additions to CppAD During 2009: <a href="#9.8.2">9.8.2: whats_new_09</a>
            Changes and Additions to CppAD During 2008: <a href="#9.8.3">9.8.3: whats_new_08</a>
            Changes and Additions to CppAD During 2007: <a href="#9.8.4">9.8.4: whats_new_07</a>
            Changes and Additions to CppAD During 2006: <a href="#9.8.5">9.8.5: whats_new_06</a>
            Changes and Additions to CppAD During 2005: <a href="#9.8.6">9.8.6: whats_new_05</a>
            Changes and Additions to CppAD During 2004: <a href="#9.8.7">9.8.7: whats_new_04</a>
            Changes and Additions to CppAD During 2003: <a href="#9.8.8">9.8.8: whats_new_03</a>
        Deprecated Include Files: <a href="#9.9">9.9: include_deprecated</a>
        Your License for the CppAD Software: <a href="#9.10">9.10: License</a>
    Alphabetic Listing of Cross Reference Tags: <a href="#10">10: _reference</a>
    Keyword Index: <a href="#11">11: _index</a>
    External Internet References: <a href="#12">12: _external</a>
</pre>
<hr/>
<center><b><big><big><a name="2" id="2">2: CppAD Download, Test, and Installation Instructions</a>
</big></big></b></center>
<br/>
<b><big><a name="2.a" id="2.a">2.a: Contents</a></big></b>
<br/>
<div><a href="#2.1" target="_top">2.1:&#xA0;Unix&#xA0;Download,&#xA0;Test&#xA0;and&#xA0;Installation</a><br/>
<a href="#2.2" target="_top">2.2:&#xA0;Windows&#xA0;Download&#xA0;and&#xA0;Test</a><br/>
</div>
<hr/>Input File: omh/install.omh

<hr/>
<center><b><big><big><a name="2.1" id="2.1">2.1: Unix Download, Test and Installation</a>
</big></big></b></center>
<br/>
<b><big><a name="2.1.a" id="2.1.a">2.1.a: Fedora</a></big></b>


<br/>
CppAD is available through yum on the Fedora operating system starting
Fedora version 7. You can download and install CppAD with the instruction
<code><font color="blue">
	yum install cppad-devel
</font></code>
(In Fedora, <code><font color="blue">devel</font></code> is used for program development tools.)
You can download and install the corresponding version of the
documentation using the command
<code><font color="blue">
	yum install cppad-doc
</font></code> 

<br/>
<br/>
<b><big><a name="2.1.b" id="2.1.b">2.1.b: RPM</a></big></b>


<br/>
If you want to use the Fedora <code><font color="blue">cppad.spec</font></code> file
to build an RPM for some other operating system,
it can be found at
<code><span style='white-space: nowrap'><br/>
</span></code><a href="https://projects.coin-or.org/CppAD/browser/trunk/cppad.spec" target="_top"><span style='white-space: nowrap'>https://projects.coin-or.org/CppAD/browser/trunk/cppad.spec</span></a>



<br/>
<br/>
<b><big><a name="2.1.c" id="2.1.c">2.1.c: Download</a></big></b>





<br/>
<br/>
<b><a name="2.1.c.a" id="2.1.c.a">2.1.c.a: Subversion</a></b>
<br/>
If you are familiar with subversion, you may want to follow
the more complicated CppAD download instructions;
see the following <a href="#2.1.1">2.1.1: <span style='white-space: nowrap'>subversion&#xA0;instructions</span></a>
.

<br/>
<br/>
<b><a name="2.1.c.b" id="2.1.c.b">2.1.c.b: Web Link</a></b>
<br/>
If you are not using the subversion download instructions,
make sure you are reading the web version of this documentation by
following the link 
<a href="http://www.coin-or.org/CppAD/Doc/installunix.htm" target="_top"><span style='white-space: nowrap'>web&#xA0;version</span></a>
 (http://www.coin-or.org/CppAD/Doc/installunix.htm) .
Then proceed with the instruction that appear below this point.

<br/>
<br/>
<b><a name="2.1.c.c" id="2.1.c.c">2.1.c.c: Unix Tar Files</a></b>


<br/>
The download files below were first archived with <code><font color="blue">tar</font></code>
and then compressed with <code><font color="blue">gzip</font></code>:
The ascii files for these downloads are in 
Unix format; i.e., each line ends with just a line feed.

<table><tr><td align='left'  valign='top'>

CPL License <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <a href="cppad-20100316.cpl.tgz" target="_top"><span style='white-space: nowrap'>cppad-20100316.cpl.tgz</span></a>
 
</td></tr><tr><td align='left'  valign='top'>

GPL License <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <a href="cppad-20100316.gpl.tgz" target="_top"><span style='white-space: nowrap'>cppad-20100316.gpl.tgz</span></a>

</td></tr>
</table>
<br/>
<b><a name="2.1.c.d" id="2.1.c.d">2.1.c.d: Tar File Extraction</a></b>
<br/>
Use the unix command

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;tar&#xA0;-xvzf&#xA0;cppad-20100316.</span></font><i><font color="black"><span style='white-space: nowrap'>license</span></font></i><font color="blue"><span style='white-space: nowrap'>.tgz<br/>
</span></font></code>
(where 
<code><i><font color="black"><span style='white-space: nowrap'>license</span></font></i></code>
 is <code><font color="blue">cpl</font></code> or <code><font color="blue">gpl</font></code>)
to decompress and extract the unix format version
into the distribution directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cppad-20100316<br/>
</span></font></code>
To see if this has been done correctly, check for the following file:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cppad-20100316/cppad/cppad.hpp<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.d" id="2.1.d">2.1.d: Configure</a></big></b>

<br/>
Enter the 
<code><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i></code>

(the directory created by the extraction) and execute the command:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;./configure&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;--prefix=</span></font><i><font color="black"><span style='white-space: nowrap'>PrefixDir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;--with-Documentation&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;--with-stdvector&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;POSTFIX_DIR=</span></font><i><font color="black"><span style='white-space: nowrap'>PostfixDir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;ADOLC_DIR=</span></font><i><font color="black"><span style='white-space: nowrap'>AdolcDir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;FADBAD_DIR=</span></font><i><font color="black"><span style='white-space: nowrap'>FadbadDir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;SADADO_DIR=</span></font><i><font color="black"><span style='white-space: nowrap'>SacadoDir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;BOOST_DIR=</span></font><i><font color="black"><span style='white-space: nowrap'>BoostDir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;IPOPT_DIR=</span></font><i><font color="black"><span style='white-space: nowrap'>IpoptDir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CXX_FLAGS=</span></font><i><font color="black"><span style='white-space: nowrap'>CompilerFlags</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;<br/>
</span></font></code>
where only the <code><font color="blue">configure</font></code> command need appear.
The entries one each of the other lines are optional
and the text in italic is replaced values that you choose.

<br/>
<br/>
<b><big><a name="2.1.e" id="2.1.e">2.1.e: make test</a></big></b>
<br/>
You can run all of the CppAD correctness tests by executing the 
command <code><font color="blue">make test</font></code> in the 
<code><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i></code>
.
A description of the tests, and instructions for running individual tests,
are described below.

<br/>
<br/>
<b><big><a name="2.1.f" id="2.1.f">2.1.f: Introduction</a></big></b>


<br/>
<br/>
<b><a name="2.1.f.a" id="2.1.f.a">2.1.f.a: Getting Started</a></b>


<br/>
You can run the CppAD getting started example / test 
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/introduction/get_started<br/>
</span></font></code>
<br/>
<b><a name="2.1.f.b" id="2.1.f.b">2.1.f.b: exp_apx</a></b>




<br/>
You can run the examples / tests for the <code><font color="blue">exp_apx</font></code> function 
(used in the <a href="#3">3: <span style='white-space: nowrap'>Introduction</span></a>
)
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/introduction/exp_apx<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.g" id="2.1.g">2.1.g: CppAD Examples</a></big></b>


<br/>
You can run a large number of the examples / tests showing how to use CppAD
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/example<br/>
</span></font></code>
See <a href="#7.3">7.3: <span style='white-space: nowrap'>ListAllExamples</span></a>
 for a list of all the CppAD examples.

<br/>
<br/>
<b><big><a name="2.1.h" id="2.1.h">2.1.h: More Testing</a></big></b>


<br/>
You can run a large number of tests (that are not intended to be examples)
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/test_more<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.i" id="2.1.i">2.1.i: Speed Testing</a></big></b>


<br/>
<br/>
<b><a name="2.1.i.a" id="2.1.i.a">2.1.i.a: CppAD Derivative Speed Tests</a></b>


<br/>
A set of CppAD derivative value <a href="#9.2.5">9.2.5: <span style='white-space: nowrap'>speed</span></a>
 tests 
are included with this distribution. 
You can test that the results computed during these tests are correct
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/speed/cppad<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run the CppAD derivative speed tests 
by executing the command <code><font color="blue">./cppad</font></code> (see <a href="#9.2.1">9.2.1: <span style='white-space: nowrap'>speed_main</span></a>
).

<br/>
<br/>
<b><a name="2.1.i.b" id="2.1.i.b">2.1.i.b: Function Speed Tests</a></b>


<br/>
A set of functions value <a href="#9.2.3">9.2.3: <span style='white-space: nowrap'>speed</span></a>
 tests 
are included (to compare with derivative values speeds).
You can test that the results computed during these tests are correct
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/speed/double<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run the function value speed tests 
by executing the command <code><font color="blue">./double</font></code> (see <a href="#9.2.1">9.2.1: <span style='white-space: nowrap'>speed_main</span></a>
).

<br/>
<br/>
<b><a name="2.1.i.c" id="2.1.i.c">2.1.i.c: Examples For Speed Tests</a></b>



<br/>
The speed tests use some utilities that have their own set of 
examples / tests.
You can test that the results computed by this utilities are correct
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/speed/example<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.j" id="2.1.j">2.1.j: Profiling CppAD</a></big></b>



<br/>
The CppAD derivative speed tests mentioned above can be profiled.
You can test that the results computed during this profiling are correct
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/speed/profile<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run the profile tests 
by executing the command <code><font color="blue">./profile</font></code> (see <a href="#9.2.1">9.2.1: <span style='white-space: nowrap'>speed_main</span></a>
).
You can then obtain the profiling results with

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;gprof&#xA0;-b&#xA0;speed/profile/profile<br/>
</span></font></code>
If you are using a windows operating system with Cygwin or MinGW, 
you may have to replace <code><font color="blue">profile</font></code> by <code><font color="blue">profile.exe</font></code>
in the <code><font color="blue">gprof</font></code> command above; i.e.,
<code><font color='blue'><pre style='display:inline'> 
	gprof -b speed/profile/profile.exe
</pre></font></code>

In C++, template parameters and argument types become part of a 
routines's name.
This can make the <code><font color="blue">gprof</font></code> output hard to read 
(the routine names can be very long).
You can remove the template parameters and argument types from the 
routine names by executing the following command
<code><font color='blue'><pre style='display:inline'> 
	gprof -b speed/profile/profile | sed -f speed/profile/gprof.sed
</pre></font></code>

If you are using a windows operating system with Cygwin or MinGW, 
you would need to use
<code><font color='blue'><pre style='display:inline'> 
	gprof -b speed/profile/profile.exe | sed -f speed/profile/gprof.sed
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.1.k" id="2.1.k">2.1.k: PrintFor</a></big></b>


<br/>
You can test the <a href="#4.3.4">4.3.4: <span style='white-space: nowrap'>PrintFor</span></a>
 command
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/print_for<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.l" id="2.1.l">2.1.l: PrefixDir</a></big></b>



<br/>
The default value for prefix directory is <code><font color="blue">$HOME</font></code>
i.e., by default the CppAD include files 
will <a href="#2.1.v">2.1.v: <span style='white-space: nowrap'>install</span></a>
 below <code><font color="blue">$HOME</font></code>.
If you want to install elsewhere, you will have to use this option.
As an example of using the 
<code><font color="blue"><span style='white-space: nowrap'>--prefix=</span></font><i><font color="black"><span style='white-space: nowrap'>PrefixDir</span></font></i></code>
 option,
if you specify
<code><font color='blue'><pre style='display:inline'> 
	./configure --prefix=/usr/local
</pre></font></code>
 
the CppAD include files will be installed in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;/usr/local/include/cppad<br/>
</span></font></code>
If <a href="#2.1.m">2.1.m: <span style='white-space: nowrap'>--with-Documentation</span></a>

is specified, the CppAD documentation files will be installed in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;/usr/local/share/doc/cppad-20100316<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.m" id="2.1.m">2.1.m: --with-Documentation</a></big></b>


<br/>
If the command line argument <code><font color="blue">--with-Documentation</font></code> is specified,
the CppAD documentation HTML and XML files are copied to the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>PrefixDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/share/doc/</span></font><i><font color="black"><span style='white-space: nowrap'>PostfixDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad-20100316<br/>
</span></font></code>
(see <a href="#2.1.o">2.1.o: <span style='white-space: nowrap'>PostfixDir</span></a>
).
The top of the CppAD HTML documentation tree 
(with mathematics displayed as LaTex command) will be located at

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>PrefixDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/share/doc/</span></font><i><font color="black"><span style='white-space: nowrap'>PostfixDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad-20100316/cppad.htm<br/>
</span></font></code>
and the top of the XML documentation tree
(with mathematics displayed as MathML) will be located at

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>PrefixDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/share/doc/</span></font><i><font color="black"><span style='white-space: nowrap'>PostfixDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad-20100316/cppad.xml<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.n" id="2.1.n">2.1.n: --with-stdvector</a></big></b>

<br/>
The 
<small><a href="#7.4">7.4: <span style='white-space: nowrap'>CPPAD_TEST_VECTOR</span></a>
 </small>
template class is used for extensive examples and testing of CppAD.
If the command line argument <code><font color="blue">--with-stdvector</font></code> is specified,
the default definition this template class is replaced by
<code><font color='blue'><pre style='display:inline'> 
	std::vector
</pre></font></code>

(In this case 
<code><i><font color="black"><span style='white-space: nowrap'>BoostDir</span></font></i></code>
 must not also be specified.)

<br/>
<br/>
<b><big><a name="2.1.o" id="2.1.o">2.1.o: PostfixDir</a></big></b>



<br/>
By default, the postfix directory is empty; i.e., there
is no postfix directory.
As an example of using the 
<code><font color="blue"><span style='white-space: nowrap'>POSTFIX_DIR=</span></font><i><font color="black"><span style='white-space: nowrap'>PostfixDir</span></font></i></code>
 option,
if you specify
<code><font color='blue'><pre style='display:inline'> 
	./configure --prefix=/usr/local POSTFIX_DIR=coin
</pre></font></code>
 
the CppAD include files will be 
<a href="#2.1.v">2.1.v: <span style='white-space: nowrap'>installed</span></a>
 in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;/usr/local/include/coin/cppad<br/>
</span></font></code>
If <a href="#2.1.m">2.1.m: <span style='white-space: nowrap'>--with-Documentation</span></a>

is specified, the CppAD documentation files will be installed in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;/usr/local/share/doc/coin/cppad-20100316<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.p" id="2.1.p">2.1.p: AdolcDir</a></big></b>

<br/>
If you have 
<a href="http://www.math.tu-dresden.de/~adol-c/" target="_top"><span style='white-space: nowrap'>Adolc&#xA0;1.10.2</span></a>
 (http://www.math.tu-dresden.de/~adol-c/) 
installed on your system, you can 
specify a value for 
<code><i><font color="black"><span style='white-space: nowrap'>AdolcDir</span></font></i></code>
 in the 
<a href="#2.1.d">2.1.d: <span style='white-space: nowrap'>configure</span></a>
 command line.
The value of 
<code><i><font color="black"><span style='white-space: nowrap'>AdolcDir</span></font></i></code>
 must be such that

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>AdolcDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/include/adolc/adouble.h<br/>
</span></font></code>
is a valid way to reference <code><font color="blue">adouble.h</font></code>.
In this case, you can run the Adolc speed correctness tests by 
executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/speed/adolc<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run the Adolc speed tests 
by executing the command <code><font color="blue">./adolc</font></code> (see <a href="#9.2.1">9.2.1: <span style='white-space: nowrap'>speed_main</span></a>
).

<br/>
<br/>
<b><a name="2.1.p.a" id="2.1.p.a">2.1.p.a: Linux</a></b>
<br/>
If you are using Linux, 
you will have to add to following lines to the file
<code><font color="blue">.bash_profile</font></code> in your home directory:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;LD_LIBRARY_PATH=</span></font><i><font color="black"><span style='white-space: nowrap'>AdolcDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/lib:${LD_LIBRARY_PATH}<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;export&#xA0;LD_LIBRARY_PATH<br/>
</span></font></code>
in order for Adolc to run properly.

<br/>
<br/>
<b><a name="2.1.p.b" id="2.1.p.b">2.1.p.b: Cygwin</a></b>
<br/>
If you are using Cygwin, 
you will have to add to following lines to the file
<code><font color="blue">.bash_profile</font></code> in your home directory:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;PATH=</span></font><i><font color="black"><span style='white-space: nowrap'>AdolcDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/bin:${PATH}<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;export&#xA0;PATH<br/>
</span></font></code>
in order for Adolc to run properly.
If 
<code><i><font color="black"><span style='white-space: nowrap'>AdolcDir</span></font></i></code>
 begins with a disk specification,
you must use the Cygwin format for the disk specification.
For example, 
if <code><font color="blue">d:/adolc_base</font></code> is the proper directory,
<code><font color="blue">/cygdrive/d/adolc_base</font></code> should be used for 
<code><i><font color="black"><span style='white-space: nowrap'>AdolcDir</span></font></i></code>
.

<br/>
<br/>
<b><big><a name="2.1.q" id="2.1.q">2.1.q: FadbadDir</a></big></b>

<br/>
If you have
<a href="http://www.fadbad.com/" target="_top"><span style='white-space: nowrap'>Fadbad&#xA0;2.1</span></a>
 (http://www.fadbad.com/) 
installed on your system, you can 
specify a value for 
<code><i><font color="black"><span style='white-space: nowrap'>FadbadDir</span></font></i></code>
.
It must be such that

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>FadbadDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/FADBAD++/badiff.h<br/>
</span></font></code>
is a valid reference to <code><font color="blue">badiff.h</font></code>.

In this case, you can run the Fadbad speed correctness tests by 
executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/speed/fadbad<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run the Fadbad speed tests 
by executing the command <code><font color="blue">./fadbad</font></code> (see <a href="#9.2.1">9.2.1: <span style='white-space: nowrap'>speed_main</span></a>
).


<br/>
<br/>
<b><big><a name="2.1.r" id="2.1.r">2.1.r: SacadoDir</a></big></b>

<br/>
If you have
<a href="http://trilinos.sandia.gov/packages/sacado/" target="_top"><span style='white-space: nowrap'>Sacado</span></a>
 (http://trilinos.sandia.gov/packages/sacado/) 
installed on your system, you can 
specify a value for 
<code><i><font color="black"><span style='white-space: nowrap'>SacadoDir</span></font></i></code>
.
It must be such that

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>SacadoDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/include/Sacado.hpp<br/>
</span></font></code>
is a valid reference to <code><font color="blue">Sacado.hpp</font></code>.

In this case, you can run the Sacado speed correctness tests by 
executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/speed/sacado<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run the Sacado speed tests 
by executing the command <code><font color="blue">./sacado</font></code> (see <a href="#9.2.1">9.2.1: <span style='white-space: nowrap'>speed_main</span></a>
).


<br/>
<br/>
<b><big><a name="2.1.s" id="2.1.s">2.1.s: BoostDir</a></big></b>

<br/>
The
<small><a href="#7.4">7.4: <span style='white-space: nowrap'>CPPAD_TEST_VECTOR</span></a>
 </small>
template class is used for extensive examples and testing of CppAD.
The default definition for <code><font color="blue">CPPAD_TEST_VECTOR</font></code> is
<a href="#6.24">6.24: <span style='white-space: nowrap'>CppAD::vector</span></a>
.
If the command line argument

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;BOOST_DIR=</span></font><i><font color="black"><span style='white-space: nowrap'>BoostDir</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
is present, it must be such that

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>BoostDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/boost/numeric/ublas/vector.hpp<br/>
</span></font></code>
is a valid reference to the file <code><font color="blue">vector.hpp</font></code>.
In this case, the default definition of <code><font color="blue">CPPAD_TEST_VECTOR</font></code> 
is replaced by
<code><font color='blue'><pre style='display:inline'> 
	boost::numeric::ublas::vector
</pre></font></code>

(see <a href="http://www.boost.org" target="_top"><span style='white-space: nowrap'>boost</span></a>
 (http://www.boost.org) ).
If 
<code><i><font color="black"><span style='white-space: nowrap'>BoostDir</span></font></i></code>
 is present, the argument <code><font color="blue">--with-stdvector</font></code>
must not be present.

<br/>
<br/>
<b><big><a name="2.1.t" id="2.1.t">2.1.t: IpoptDir</a></big></b>

<br/>
If you have
<a href="http://www.coin-or.org/projects/Ipopt.xml" target="_top"><span style='white-space: nowrap'>Ipopt</span></a>
 (http://www.coin-or.org/projects/Ipopt.xml) 
installed on your system, you can 
specify a value for 
<code><i><font color="black"><span style='white-space: nowrap'>IpoptDir</span></font></i></code>
.
It must be such that

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>IpoptDir</span></font></i><font color="blue"><span style='white-space: nowrap'>/include/coin/IpIpoptApplication.hpp<br/>
</span></font></code>
is a valid reference to <code><font color="blue">IpIpoptApplication.hpp</font></code>.
In this case, the CppAD interface to Ipopt
<a href="#7.1.5.t">7.1.5.t: <span style='white-space: nowrap'>examples</span></a>
 can be built and tested
by executing the command <code><font color="blue">make test</font></code> in the directory

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad_ipopt/example<br/>
</span></font></code>
You can do more testing of this interface by executing <code><font color="blue">make test</font></code>
in the directories

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad_ipopt/test<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad_ipopt/speed<br/>
</span></font></code>
Once this has been done, you can execute the program

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>distribution_directory</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad_ipopt/speed/speed<br/>
</span></font></code>
see <a href="#7.1.5.4">7.1.5.4: <span style='white-space: nowrap'>ipopt_ode_speed.cpp</span></a>
.

<br/>
<br/>
<b><big><a name="2.1.u" id="2.1.u">2.1.u: CompilerFlags</a></big></b>


<br/>
If the command line argument 
<code><i><font color="black"><span style='white-space: nowrap'>CompilerFlags</span></font></i></code>
 is present,
it specifies compiler flags.
For example,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CXX_FLAGS=&quot;-Wall&#xA0;-ansi&quot;<br/>
</span></font></code>
would specify that warning flags <code><font color="blue">-Wall</font></code>
and <code><font color="blue">-ansi</font></code> should be included
in all the C++ compile commands.
The error and warning flags chosen must be valid options
for the C++ compiler.
The default value for 
<code><i><font color="black"><span style='white-space: nowrap'>CompilerFlags</span></font></i></code>
 is the
empty string.


<br/>
<br/>
<b><big><a name="2.1.v" id="2.1.v">2.1.v: make install</a></big></b>
<br/>
Once you are satisfied that the tests are giving correct results,
you can install CppAD into easy to use directories by executing the command
<code><font color='blue'><pre style='display:inline'> 
	make install
</pre></font></code>

This will install CppAD in the location specified by 
<a href="#2.1.l">2.1.l: <span style='white-space: nowrap'>PrefixDir</span></a>
.
You must have permission to write in the 
<code><i><font color="black"><span style='white-space: nowrap'>PrefixDir</span></font></i></code>

directory to execute this command. 
You may optionally specify a destination directory for the install; i.e.,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;install&#xA0;DESTDIR=</span></font><i><font color="black"><span style='white-space: nowrap'>DestinationDirectory</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>

<hr/>Input File: omh/install_unix.omh

<hr/>
<center><b><big><big><a name="2.1.1" id="2.1.1">2.1.1: Using Subversion To Download Source Code</a>
</big></big></b></center>
<br/>
<b><big><a name="2.1.1.a" id="2.1.1.a">2.1.1.a: File Format</a></big></b>
<br/>
The files corresponding to this download
procedure are in Unix format; i.e., 
each line ends with just a line feed.

<br/>
<br/>
<b><big><a name="2.1.1.b" id="2.1.1.b">2.1.1.b: Subversion</a></big></b>
<br/>
You must have
<a href="http://subversion.tigris.org/" target="_top"><span style='white-space: nowrap'>subversion</span></a>
 (http://subversion.tigris.org/) 
installed to use this download procedure.
In Unix, you can check if subversion 
is already installed in your path by entering the command
<code><font color='blue'><pre style='display:inline'> 
	which svn
</pre></font></code>



<br/>
<br/>
<b><big><a name="2.1.1.c" id="2.1.1.c">2.1.1.c: OMhelp</a></big></b>
<br/>
The documentation for CppAD is built from the source code files using
<a href="http://www.seanet.com/~bradbell/omhelp/" target="_top"><span style='white-space: nowrap'>OMhelp</span></a>
 (http://www.seanet.com/~bradbell/omhelp/) .
In Unix, you can check if OMhelp 
is already installed in your path by entering the command
<code><font color='blue'><pre style='display:inline'> 
	which omhelp
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.1.1.d" id="2.1.1.d">2.1.1.d: Current Version</a></big></b>
<br/>
The following command will download the 
current version of the CppAD source code:
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;svn&#xA0;co&#xA0;https://projects.coin-or.org/svn/CppAD/</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>where <i>dir</i> is replaced by <code><font color="blue">trunk</font></code>.
To see if this has been done correctly, check for the following file:
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>/cppad/cppad.hpp<br/>
</span></font></code>Since you downloaded the current version,
you should set the version of CppAD to the current date.
Using an editor of you choice, open the file
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>/configure<br/>
</span></font></code>(if you plan to use the 
<a href="#2.2">2.2: <span style='white-space: nowrap'>Windows&#xA0;install</span></a>
 instructions,
edit <code><font color="blue"><span style='white-space: nowrap'>dir</span></font></code><i><span style='white-space: nowrap'>/cppad/config.h</span></i> instead of <code><font color="blue"><span style='white-space: nowrap'>dir</span></font></code><i><span style='white-space: nowrap'>/configure</span></i>).
Search this file for text of the form <i>yyyymmdd</i>
where <i>yyyy</i> are four decimal digits representing a year,
<i>mm</i> is two decimal digits representing a month,
and <i>dd</i> is two decimal digits representing a day.
Replace each occurrence of this text with the decimal digits
for the current year, month, and day
(i.e., the eight decimal digits representing the current date).

<br/>
<br/>
<b><big><a name="2.1.1.e" id="2.1.1.e">2.1.1.e: Stable Version</a></big></b>
<br/>
Subversion downloads are available for the following stable versions
of CppAD:
<table><tr><td align='left'  valign='top'>

<i>dir</i>        </td><td align='left'  valign='top'>
 <i>yyyymmdd</i>  </td></tr><tr><td align='left'  valign='top'>

<code><font color="blue">1.0</font></code> <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">20060913</font></code>    </td></tr><tr><td align='left'  valign='top'>

<code><font color="blue">2.0</font></code> <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">20071016</font></code>    </td></tr><tr><td align='left'  valign='top'>

<code><font color="blue">2.1</font></code> <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">20071124</font></code>    </td></tr><tr><td align='left'  valign='top'>

<code><font color="blue">2.2</font></code> <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">20071210</font></code>
</td></tr>
</table>
The following command will download a 
stable version of the CppAD source code:
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;svn&#xA0;co&#xA0;https://projects.coin-or.org/svn/CppAD/stable/</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>To see if this has been done correctly, check for the following file:
if <i>dir</i> is <code><font color="blue">1.0</font></code> check for
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;1.0/CppAD/CppAD.h<br/>
</span></font></code>otherwise check for
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>/cppad/cppad.hpp<br/>
</span></font></code>Since you downloaded a stable version,
the version of CppAD <code><font color="blue">configure</font></code>,
and all the other relevant files, is correct.

<br/>
<br/>
<b><big><a name="2.1.1.f" id="2.1.1.f">2.1.1.f: Build the Documentation</a></big></b>
<br/>
Now build the documentation for this version using the commands
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;mkdir&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>/doc<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>/doc<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;omhelp&#xA0;../doc.omh&#xA0;-noframe&#xA0;-debug&#xA0;-l&#xA0;http://www.coin-or.org/CppAD/<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;omhelp&#xA0;../doc.omh&#xA0;-noframe&#xA0;-debug&#xA0;-l&#xA0;http://www.coin-or.org/CppAD/&#xA0;-xml<br/>
</span></font></code><br/>
<b><big><a name="2.1.1.g" id="2.1.1.g">2.1.1.g: Continue with Installation</a></big></b>
<br/>
Once the steps above are completed,
you can proceed with the install instructions in 
the documentation you just built.
Start by opening the one of the two files
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>/doc/index.xml<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>dir</span></i><code><font color="blue"><span style='white-space: nowrap'>/doc/index.htm<br/>
</span></font></code>in a web browser and proceeding to the 
<a href="#2.1">2.1: <span style='white-space: nowrap'>Unix</span></a>
 or <a href="#2.2">2.2: <span style='white-space: nowrap'>Windows</span></a>

install instructions.


<hr/>Input File: omh/subversion.omh

<hr/>







<center><b><big><big><a name="2.2" id="2.2">2.2: Windows Download and Test</a>
</big></big></b></center>
<br/>
<b><big><a name="2.2.a" id="2.2.a">2.2.a: Cygwin</a></big></b>
<br/>
If you are using Cygwin, or MinGW with MSYS, follow the 
<a href="#2.1">2.1: <span style='white-space: nowrap'>unix&#xA0;install</span></a>
 instructions.

<br/>
<br/>
<b><big><a name="2.2.b" id="2.2.b">2.2.b: Download</a></big></b>






<br/>
<br/>
<b><a name="2.2.b.a" id="2.2.b.a">2.2.b.a: Subversion</a></b>
<br/>
If you are familiar with subversion, you may want to follow
the more complicated <a href="#2.1.1">2.1.1: <span style='white-space: nowrap'>subversion</span></a>
 download instructions 
instead of the ones below.

<br/>
<br/>
<b><a name="2.2.b.b" id="2.2.b.b">2.2.b.b: Web Link</a></b>
<br/>
If you are not using the subversion download instructions,
sure you are reading the web based version of this documentation by
following the link
<a href="http://www.coin-or.org/CppAD/Doc/installwindows.htm" target="_top"><span style='white-space: nowrap'>web&#xA0;version</span></a>
 (http://www.coin-or.org/CppAD/Doc/installwindows.htm) .
Then proceed with the instruction that appear below this point.

<br/>
<br/>
<b><a name="2.2.b.c" id="2.2.b.c">2.2.b.c: Unix Tar Files</a></b>
<br/>
The download files below were first archived with <code><font color="blue">tar</font></code>
and then compressed with <code><font color="blue">gzip</font></code>.
The ascii files are in Unix format; i.e., each line ends with a 
line feed (instead of a carriage return and line feed as is standard for
windows formatted files).
Visual Studio can handel this formatting just fine, but you may 
want to convert the format to the windows standard if you are using 
and editor that has trouble viewing the files in Unix format.
and then a line feed. 

<table><tr><td align='left'  valign='top'>

CPL License <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <a href="cppad-20100316.cpl.tgz" target="_top"><span style='white-space: nowrap'>cppad-20100316.cpl.tgz</span></a>
 
</td></tr><tr><td align='left'  valign='top'>

GPL License <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <a href="cppad-20100316.gpl.tgz" target="_top"><span style='white-space: nowrap'>cppad-20100316.gpl.tgz</span></a>

</td></tr>
</table>
The following steps will decompress and extract the files using
<a href="http://www.winzip.com/index.htm" target="_top"><span style='white-space: nowrap'>Winzip</span></a>
 (http://www.winzip.com/index.htm)  version 7.0
(other version of Winzip and other decompression programs will be similar).
<ol type="1"><li>
Download your choice between these two licenses listed above and 
store the result in a file on disk.
</li><li>

Open the file using Winzip (using <code><font color="blue">All archives</font></code>) as the file type
in the Open browser.
</li><li>

Winzip will ask if it should decompress the file into a temporary folder
and open it. Respond by selecting the <code><font color="blue">Yes</font></code> button.
</li><li>

Now select the <code><font color="blue">Extract</font></code> button from the main menu.
</li><li>

Place the name of the directory were you want the distribution in the
<code><font color="blue">Extract to</font></code> field and then select the <code><font color="blue">Extract</font></code> button
in the pop-up dialog.
Winzip will create a subdirectory called <code><font color="blue">cppad-20100316</font></code>
where the files are placed.
</li></ol>


<br/>
<br/>
<b><big><a name="2.2.c" id="2.2.c">2.2.c: Getting Started</a></big></b>

<br/>
The following steps will build the <a href="#3.1">3.1: <span style='white-space: nowrap'>get_started.cpp</span></a>
 example.
Using Microsoft Visual C++, open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20100316\introduction\get_started\get_started.sln
</pre></font></code>

in Visual Studio and then select <code><font color="blue">Build | Build get_started.exe</font></code>.
Then in a Dos box, and in the cppad-20100316 directory,
execute the following command
<code><font color='blue'><pre style='display:inline'> 
	introduction\get_started\Debug\get_started
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.2.d" id="2.2.d">2.2.d: Introduction</a></big></b>

<br/>
The following steps will build the routines that verify the calculations
in the exp_apx calculations in the <a href="#3">3: <span style='white-space: nowrap'>Introduction</span></a>
 section.
Using Microsoft Visual C++, open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20100316\introduction\exp_apx\exp_apx.sln
</pre></font></code>
 in Visual Studio.
Then select <code><font color="blue">Build | Build exp_apx.exe</font></code>.
Then in a Dos box, and in the cppad-20100316 directory,
execute the following command
<code><font color='blue'><pre style='display:inline'> 
	introduction\exp_apx\Debug\exp_apx
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.2.e" id="2.2.e">2.2.e: Examples and Testing</a></big></b>


<br/>
The following steps will build an extensive set of examples
and correctness tests.
Using Microsoft Visual C++, open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20100316\example\example.sln
</pre></font></code>
 in Visual Studio.
Then select <code><font color="blue">Build | Build Example.exe</font></code>.
Then in a Dos box, and in the cppad-20100316 directory,
execute the following command
<code><font color='blue'><pre style='display:inline'> 
	example\Debug\example
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.2.f" id="2.2.f">2.2.f: More Correctness Testing</a></big></b>

<br/>
Using Microsoft Visual C++,
open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20100316\test_more\test_more.sln
</pre></font></code>

in Visual Studio and then select <code><font color="blue">Build | Build test_more.exe</font></code>.
Then in a Dos box, and in the cppad-20100316 directory,
execute the following command
<code><font color='blue'><pre style='display:inline'> 
	test_more\Debug\test_more
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.2.g" id="2.2.g">2.2.g: Printing During Forward Mode</a></big></b>


<br/>
Using Microsoft Visual C++, open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20100316\print_for\print_for.sln
</pre></font></code>
 in Visual Studio.
Then select <code><font color="blue">Build | Build print_for.exe</font></code>.
Then in a Dos box, and in the cppad-20100316 directory,
execute the following command
<code><font color='blue'><pre style='display:inline'> 
	print_for\Debug\print_for
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.2.h" id="2.2.h">2.2.h: CppAD Speed Test</a></big></b>



<br/>
Using Microsoft Visual C++,
open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20100316\speed\cppad\cppad.sln
</pre></font></code>
 in Visual Studio.
Then select <code><font color="blue">Build | Build cppad.exe</font></code>.
Then in a Dos box, and in the cppad-20100316 directory,
execute the following commands
<code><font color='blue'><pre style='display:inline'> 
	speed\cppad\Debug\cppad correct 123
	speed\cppad\Debug\cppad speed 123
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.2.i" id="2.2.i">2.2.i: Double Speed Test</a></big></b>



<br/>
Using Microsoft Visual C++,
open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20100316\speed\double\double.sln
</pre></font></code>
 in Visual Studio.
Then select <code><font color="blue">Build | Build double.exe</font></code>.
Then in a Dos box, and in the cppad-20100316 directory,
execute the following commands
<code><font color='blue'><pre style='display:inline'> 
	speed\double\Debug\double correct 123
	speed\double\Debug\double speed 123
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.2.j" id="2.2.j">2.2.j: Speed Utility Example</a></big></b>



<br/>
Using Microsoft Visual C++,
open the workspace 
<code><font color="blue">
	cppad-20100316\speed\example\example.sln
</font></code> in Visual Studio.
Then select <code><font color="blue">Build | Build example.exe</font></code>.
Then in a Dos box, and in the cppad-20100316 directory,
execute the following command
<code><font color='blue'><pre style='display:inline'> 
	speed\example\Debug\example
</pre></font></code>



<hr/>Input File: omh/install_windows.omh

<hr/>









<center><b><big><big><a name="3" id="3">3: An Introduction by Example to Algorithmic Differentiation</a>
</big></big></b></center>
<br/>
<b><big><a name="3.a" id="3.a">3.a: Preface</a></big></b>


<br/>
<br/>
<b><a name="3.a.a" id="3.a.a">3.a.a: Algorithmic Differentiation</a></b>
<br/>
Algorithmic Differentiation 
(often referred to as Automatic Differentiation or just AD)
uses the software representation 
of a function to obtain an efficient method for calculating its derivatives.
These derivatives can be of arbitrary order and are analytic in nature 
(do not have any truncation error).

<br/>
<br/>
<b><a name="3.a.b" id="3.a.b">3.a.b: Forward Mode</a></b>
<br/>
A forward mode sweep computes 
the partial derivative of all the dependent variables with respect
to one independent variable (or independent variable direction). 

<br/>
<br/>
<b><a name="3.a.c" id="3.a.c">3.a.c: Reverse Mode</a></b>
<br/>
A reverse mode sweep computes 
the derivative of one dependent variable
(or one dependent variable direction) 
with respect to all the independent variables.

<br/>
<br/>
<b><a name="3.a.d" id="3.a.d">3.a.d: Operation Count</a></b>
<br/>
The number of floating point operations for either a 
forward or reverse mode sweep
is a small multiple of the number required to evaluate the original function. 
Thus, using reverse mode,
you can evaluate the derivative of a scalar valued function 
with respect to thousands of variables in a small multiple of the
work to evaluate the original function.

<br/>
<br/>
<b><a name="3.a.e" id="3.a.e">3.a.e: Efficiency</a></b>
<br/>
AD automatically takes advantage of the
speed of your algorithmic representation of a function.
For example,
if you calculate a determinant using LU factorization,
AD will use the LU representation for
the derivative of the determinant
(which is faster than using the definition of the determinant).

<br/>
<br/>
<b><big><a name="3.b" id="3.b">3.b: Purpose</a></big></b>
<br/>
This is an introduction by example
to Algorithmic Differentiation.
Its purpose is to aid in understand what AD calculates,
how the calculations are preformed,
and the amount of computation and memory required 
for a forward or reverse sweep.

<br/>
<br/>
<b><big><a name="3.c" id="3.c">3.c: Outline</a></big></b>

<ol type="A"><li>
Demonstrate the use of CppAD to calculate derivatives of a 
polynomial: <a href="#3.1">3.1: <span style='white-space: nowrap'>get_started.cpp</span></a>
.

</li><li>

Present two algorithms that approximate the exponential function.
The first algorithm <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 is simpler and does not 
include any logical variables or loops.
The second algorithm <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>
 includes
logical operations and a <code><font color="blue">while</font></code> loop.
For each of these algorithms, do the following:

<ol type="1"><li>
Define the mathematical function corresponding to the algorithm
(<a href="#3.2">3.2: <span style='white-space: nowrap'>exp_2</span></a>
 and <a href="#3.3">3.3: <span style='white-space: nowrap'>exp_eps</span></a>
).
</li><li>

Write out the floating point operation sequence,
and corresponding values,
that correspond to executing the algorithm for a specific input
(<a href="#3.2.3">3.2.3: <span style='white-space: nowrap'>exp_2_for0</span></a>
 and <a href="#3.3.3">3.3.3: <span style='white-space: nowrap'>exp_eps_for0</span></a>
).
</li><li>

Compute a forward sweep derivative of the operation sequence
(<a href="#3.2.4">3.2.4: <span style='white-space: nowrap'>exp_2_for1</span></a>
 and <a href="#3.3.4">3.3.4: <span style='white-space: nowrap'>exp_eps_for1</span></a>
).
</li><li>

Compute a reverse sweep derivative of the operation sequence
(<a href="#3.2.5">3.2.5: <span style='white-space: nowrap'>exp_2_rev1</span></a>
 and <a href="#3.3.5">3.3.5: <span style='white-space: nowrap'>exp_eps_rev1</span></a>
).
</li><li>

Use CppAD to compute both a forward and reverse sweep 
of the operation sequence
(<a href="#3.2.8">3.2.8: <span style='white-space: nowrap'>exp_2_cppad</span></a>
 and <a href="#3.3.8">3.3.8: <span style='white-space: nowrap'>exp_eps_cppad</span></a>
).
</li></ol>


</li><li>

The program <a href="#3.4">3.4: <span style='white-space: nowrap'>exp_apx_main.cpp</span></a>
 runs all of the test
routines that validate the calculations in the <a href="#3.2">3.2: <span style='white-space: nowrap'>exp_2</span></a>

and <a href="#3.3">3.3: <span style='white-space: nowrap'>exp_eps</span></a>
 presentation.
</li></ol>


<br/>
<br/>
<b><big><a name="3.d" id="3.d">3.d: Reference</a></big></b>
<br/>
An in-depth review of AD theory and methods can be found in 
the book
<i>
Evaluating Derivatives:
Principles and Techniques of Algorithmic Differentiation
</i>,
Andreas Griewank,
SIAM Frontiers in Applied Mathematics, 
2000.

<br/>
<br/>
<b><big><a name="3.e" id="3.e">3.e: Contents</a></big></b>
<br/>
<table>
<tr><td><a href="#3.1" target="_top">get_started.cpp:&#xA0;3.1</a></td><td>A&#xA0;Simple&#xA0;Program&#xA0;Using&#xA0;CppAD&#xA0;to&#xA0;Compute&#xA0;Derivatives</td></tr><tr><td><a href="#3.2" target="_top">exp_2:&#xA0;3.2</a></td><td>Second&#xA0;Order&#xA0;Exponential&#xA0;Approximation</td></tr><tr><td><a href="#3.3" target="_top">exp_eps:&#xA0;3.3</a></td><td>An&#xA0;Epsilon&#xA0;Accurate&#xA0;Exponential&#xA0;Approximation</td></tr><tr><td><a href="#3.4" target="_top">exp_apx_main.cpp:&#xA0;3.4</a></td><td>Run&#xA0;the&#xA0;exp_2&#xA0;and&#xA0;exp_eps&#xA0;Tests</td></tr></table>
<hr/>Input File: omh/introduction.omh

<hr/>
<center><b><big><big><a name="3.1" id="3.1">3.1: A Simple Program Using CppAD to Compute Derivatives</a>
</big></big></b></center>
<br/>
<b><big><a name="3.1.a" id="3.1.a">3.1.a: Purpose</a></big></b>
<br/>
Demonstrate the use of CppAD by computing the derivative 
of a simple example function.

<br/>
<br/>
<b><big><a name="3.1.b" id="3.1.b">3.1.b: Function</a></big></b>
<br/>
The example function 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">:</mo>
<mrow><mstyle mathvariant='bold'><mi mathvariant='bold'>R</mi>
</mstyle></mrow>
<mo stretchy="false">&#x02192;</mo>
<mrow><mstyle mathvariant='bold'><mi mathvariant='bold'>R</mi>
</mstyle></mrow>
</mrow></math>

 is defined by 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>a</mi>
<mn>0</mn>
</msub>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>a</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>1</mn>
</msup>
<mo stretchy="false">+</mo>
<mo stretchy="false">&#x022EF;</mo>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>a</mi>
<mrow><mi mathvariant='italic'>k</mi>
<mn>-1</mn>
</mrow>
</msub>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mi mathvariant='italic'>k</mi>
<mn>-1</mn>
</mrow>
</msup>
</mrow></math>

where <i>a</i> is a fixed vector of length <i>k</i>.

<br/>
<br/>
<b><big><a name="3.1.c" id="3.1.c">3.1.c: Derivative</a></big></b>
<br/>
The derivative of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
</mrow></math>

 is given by

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">'</mo>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>a</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">+</mo>
<mn>2</mn>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>a</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<mo stretchy="false">&#x022EF;</mo>
<mo stretchy="false">+</mo>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>k</mi>
<mn>-1</mn>
<mo stretchy="false">)</mo>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>a</mi>
<mrow><mi mathvariant='italic'>k</mi>
<mn>-1</mn>
</mrow>
</msub>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mi mathvariant='italic'>k</mi>
<mn>-2</mn>
</mrow>
</msup>
</mrow></math>

<br/>
<b><big><a name="3.1.d" id="3.1.d">3.1.d: Value</a></big></b>
<br/>
For the particular case in this example,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
</mrow></math>

 is equal to 5, 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>a</mi>
<mo stretchy="false">=</mo>
<mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow></math>

, and 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>3</mn>
</mrow></math>

.
If follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">'</mo>
<mo stretchy="false">(</mo>
<mn>3</mn>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mn>2</mn>
<mo stretchy="false">*</mo>
<mn>3</mn>
<mo stretchy="false">+</mo>
<mn>3</mn>
<mo stretchy="false">*</mo>
<msup><mn>3</mn>
<mn>2</mn>
</msup>
<mo stretchy="false">+</mo>
<mn>4</mn>
<mo stretchy="false">*</mo>
<msup><mn>3</mn>
<mn>3</mn>
</msup>
<mo stretchy="false">=</mo>
<mn>142</mn>
</mrow></math>

<br/>
<b><big><a name="3.1.e" id="3.1.e">3.1.e: Poly</a></big></b>
<br/>
The routine <code><font color="blue">Poly</font></code> is defined below for this particular application.
A general purpose polynomial evaluation routine is documented and
distributed with CppAD (see <a href="#6.11">6.11: <span style='white-space: nowrap'>Poly</span></a>
).

<br/>
<br/>
<b><big><a name="3.1.f" id="3.1.f">3.1.f: Exercises</a></big></b>
<br/>
Modify the program below to accomplish the following tasks
using CppAD:
<ol type="1"><li>
Compute and print the derivative of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>3</mn>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>4</mn>
</msup>
</mrow></math>


at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>2</mn>
</mrow></math>

. 
</li><li>

Compute and print the derivative of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

.
</li><li>

Compute and print the derivative of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mi>exp</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">-</mo>
<mn>1</mn>
<mo stretchy="false">-</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">-</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

.
</li></ol>



<br/>
<br/>
<b><big><a name="3.1.g" id="3.1.g">3.1.g: Program</a></big></b>

<code><font color='blue'><pre style='display:inline'> 
#include &lt;iostream&gt;      // standard input/output 
#include &lt;vector&gt;        // standard vector
#include &lt;cppad/cppad.hpp&gt; // the CppAD package http://www.coin-or.org/CppAD/

namespace { 
      // define y(x) = Poly(a, x) in the empty namespace
      template &lt;class Type&gt;
      Type Poly(const std::vector&lt;double&gt; &amp;a, const Type &amp;x)
      {     size_t k  = a.size();
            Type y   = 0.;  // initialize summation
            Type x_i = 1.;  // initialize x^i
            size_t i;
            for(i = 0; i &lt; k; i++)
            {     y   += a[i] * x_i;  // y   = y + a_i * x^i
                  x_i *= x;           // x_i = x_i * x
            }
            return y;
      }
}
// main program
int main(void)
{     using CppAD::AD;           // use AD as abbreviation for CppAD::AD
      using std::vector;         // use vector as abbreviation for std::vector
      size_t i;                  // a temporary index

      // vector of polynomial coefficients
      size_t k = 5;              // number of polynomial coefficients
      vector&lt;double&gt; a(k);       // vector of polynomial coefficients
      for(i = 0; i &lt; k; i++)
            a[i] = 1.;           // value of polynomial coefficients

      // domain space vector
      size_t n = 1;              // number of domain space variables
      vector&lt; <a href="#4">AD</a>&lt;double&gt; &gt; X(n); // vector of domain space variables
      X[0] = 3.;                 // value corresponding to operation sequence

      // declare independent variables and start recording operation sequence
      CppAD::<a href="#5.1">Independent</a>(X);

      // range space vector
      size_t m = 1;              // number of ranges space variables
      vector&lt; <a href="#4">AD</a>&lt;double&gt; &gt; Y(m); // vector of ranges space variables
      Y[0] = Poly(a, X[0]);      // value during recording of operations

      // store operation sequence in f: X -&gt; Y and stop recording
      CppAD::<a href="#5.2">ADFun</a>&lt;double&gt; f(X, Y);

      // compute derivative using operation sequence stored in f
      vector&lt;double&gt; jac(m * n); // Jacobian of f (m by n matrix)
      vector&lt;double&gt; x(n);       // domain space vector
      x[0] = 3.;                 // argument value for derivative
      jac  = f.<a href="#5.7.1">Jacobian</a>(x);      // Jacobian for operation sequence

      // print the results
      std::cout &lt;&lt; &quot;f'(3) computed by CppAD = &quot; &lt;&lt; jac[0] &lt;&lt; std::endl;

      // check if the derivative is correct
      int error_code;
      if( jac[0] == 142. )
            error_code = 0;      // return code for correct case
      else  error_code = 1;      // return code for incorrect case

      return error_code;
}
</pre></font></code>

<br/>
<br/>
<b><big><a name="3.1.h" id="3.1.h">3.1.h: Output</a></big></b>
<br/>
Executing the program above will generate the following output:
<code><font color='blue'><pre style='display:inline'> 
	f'(3) computed by CppAD = 142
</pre></font></code>


<hr/>Input File: introduction/get_started/get_started.cpp

<hr/>



<center><b><big><big><a name="3.2" id="3.2">3.2: Second Order Exponential Approximation</a>
</big></big></b></center>
<br/>
<b><big><a name="3.2.a" id="3.2.a">3.2.a: Syntax</a></big></b>

<br/>
<code><font color="blue"><span style='white-space: nowrap'>#&#xA0;include&#xA0;&quot;exp_2.hpp&quot;</span></font></code>
<code><span style='white-space: nowrap'><br/>
</span></code><code><font color="blue"></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;exp_2(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>


<br/>
<br/>
<b><big><a name="3.2.b" id="3.2.b">3.2.b: Purpose</a></big></b>
<br/>
This is a simple example algorithm that is used to demonstrate 
Algorithmic Differentiation
(see <a href="#3.3">3.3: <span style='white-space: nowrap'>exp_eps</span></a>
 for a more complex example).

<br/>
<br/>
<b><big><a name="3.2.c" id="3.2.c">3.2.c: Mathematical Form</a></big></b>
<br/>
The exponential function can be defined by

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi>exp</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>1</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>1</mn>
<mo stretchy="false">!</mo>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
<mo stretchy="false">!</mo>
<mo stretchy="false">+</mo>
<mo stretchy="false">&#x022EF;</mo>
</mrow></math>

The second order approximation for the exponential function is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>exp</mi>
<mo stretchy="false">_</mo>
<mn>2</mn>
</mstyle></mrow>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

<br/>
<b><big><a name="3.2.d" id="3.2.d">3.2.d: include</a></big></b>
<br/>
The include command in the syntax is relative to 
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cppad-</span></font></code><i><span style='white-space: nowrap'>yy</span></i><code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>mm</span></i><code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>dd</span></i><code><font color="blue"><span style='white-space: nowrap'>/introduction/exp_apx<br/>
</span></font></code>where <code><font color="blue"><span style='white-space: nowrap'>cppad-</span></font></code><i><span style='white-space: nowrap'>yy</span></i><code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>mm</span></i><code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>dd</span></i> is the distribution directory
created during the beginning steps of the
<a href="#2">2: <span style='white-space: nowrap'>installation</span></a>
 of CppAD.

<br/>
<br/>
<b><big><a name="3.2.e" id="3.2.e">3.2.e: x</a></big></b>
<br/>
The argument <i>x</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font></code><i><span style='white-space: nowrap'>Type</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>(see <i>Type</i> below).
It specifies the point at which to evaluate the 
approximation for the second order exponential approximation.

<br/>
<br/>
<b><big><a name="3.2.f" id="3.2.f">3.2.f: y</a></big></b>
<br/>
The result <i>y</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>Type</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>It is the value of the exponential function 
approximation defined above.

<br/>
<br/>
<b><big><a name="3.2.g" id="3.2.g">3.2.g: Type</a></big></b>
<br/>
If <i>u</i> and <i>v</i> are <i>Type</i> objects and <i>i</i>
is an <code><font color="blue">int</font></code>: 

<table><tr><td align='left'  valign='top'>

<b>Operation</b>  </td><td align='left'  valign='top'>
 <b>Result Type</b> </td><td align='left'  valign='top'>
 <b>Description</b>
</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>Type</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>i</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code> 
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 object with value equal to <i>i</i> 
</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i> 
	</td><td align='left'  valign='top'>
 new <i>u</i> (and result) is value of <i>v</i>
</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;*&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 result is value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>u</mi>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>v</mi>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;/&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 result is value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>u</mi>
<mo stretchy="false">/</mo>
<mi mathvariant='italic'>v</mi>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;+&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 result is value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>u</mi>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>v</mi>
</mrow></math>


</td></tr>
</table>
<br/>
<b><big><a name="3.2.h" id="3.2.h">3.2.h: Contents</a></big></b>
<br/>
<table>
<tr><td><a href="#3.2.1" target="_top">exp_2.hpp:&#xA0;3.2.1</a></td><td>exp_2:&#xA0;Implementation</td></tr><tr><td><a href="#3.2.2" target="_top">exp_2.cpp:&#xA0;3.2.2</a></td><td>exp_2:&#xA0;Test</td></tr><tr><td><a href="#3.2.3" target="_top">exp_2_for0:&#xA0;3.2.3</a></td><td>exp_2:&#xA0;Operation&#xA0;Sequence&#xA0;and&#xA0;Zero&#xA0;Order&#xA0;Forward&#xA0;Mode</td></tr><tr><td><a href="#3.2.4" target="_top">exp_2_for1:&#xA0;3.2.4</a></td><td>exp_2:&#xA0;First&#xA0;Order&#xA0;Forward&#xA0;Mode</td></tr><tr><td><a href="#3.2.5" target="_top">exp_2_rev1:&#xA0;3.2.5</a></td><td>exp_2:&#xA0;First&#xA0;Order&#xA0;Reverse&#xA0;Mode</td></tr><tr><td><a href="#3.2.6" target="_top">exp_2_for2:&#xA0;3.2.6</a></td><td>exp_2:&#xA0;Second&#xA0;Order&#xA0;Forward&#xA0;Mode</td></tr><tr><td><a href="#3.2.7" target="_top">exp_2_rev2:&#xA0;3.2.7</a></td><td>exp_2:&#xA0;Second&#xA0;Order&#xA0;Reverse&#xA0;Mode</td></tr><tr><td><a href="#3.2.8" target="_top">exp_2_cppad:&#xA0;3.2.8</a></td><td>exp_2:&#xA0;CppAD&#xA0;Forward&#xA0;and&#xA0;Reverse&#xA0;Sweeps</td></tr></table><br/>
<b><big><a name="3.2.i" id="3.2.i">3.2.i: Implementation</a></big></b>
<br/>
The file <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>

contains a C++ implementation of this function.

<br/>
<br/>
<b><big><a name="3.2.j" id="3.2.j">3.2.j: Test</a></big></b>
<br/>
The file <a href="#3.2.2">3.2.2: <span style='white-space: nowrap'>exp_2.cpp</span></a>
 
contains a test of this implementation.
It returns true for success and false for failure.


<br/>
<br/>
<b><big><a name="3.2.k" id="3.2.k">3.2.k: Exercises</a></big></b>

<ol type="1"><li>
Suppose that we make the call 
<code><font color='blue'><pre style='display:inline'> 
	double x = .1;
	double y = exp_2(x);
</pre></font></code>

What is the value assigned to 
<code><font color="blue">v1</font></code>, <code><font color="blue">v2</font></code>, ... ,<code><font color="blue">v5</font></code> in <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 ?
</li><li>

Extend the routine <code><font color="blue">exp_2.hpp</font></code> to
a routine <code><font color="blue">exp_3.hpp</font></code> that computes

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
<mo stretchy="false">!</mo>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>3</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>3</mn>
<mo stretchy="false">!</mo>
</mrow></math>

Do this in a way that only assigns one value to each variable
(as <code><font color="blue">exp_2</font></code> does).
</li><li>

Suppose that we make the call
<code><font color='blue'><pre style='display:inline'> 
	double x = .5;
	double y = exp_3(x);
</pre></font></code>

using <code><font color="blue">exp_3</font></code> created in the previous problem.
What is the value assigned to the new variables in <code><font color="blue">exp_3</font></code>
(variables that are in <code><font color="blue">exp_3</font></code> and not in <code><font color="blue">exp_2</font></code>) ?
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_2.hpp

<hr/>



<center><b><big><big><a name="3.2.1" id="3.2.1">3.2.1: exp_2: Implementation</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
template &lt;class Type&gt;
Type exp_2(const Type &amp;x) 
{       Type v1  = x;                // v1 = x
        Type v2  = Type(1) + v1;     // v2 = 1 + x
        Type v3  = v1 * v1;          // v3 = x^2
        Type v4  = v3 / Type(2);     // v4 = x^2 / 2 
        Type v5  = v2 + v4;          // v5 = 1 + x + x^2 / 2
        return v5;                   // exp_2(x) = 1 + x + x^2 / 2
}</pre>
</font></code>


<hr/>Input File: introduction/exp_apx/exp_2.omh

<hr/>



<center><b><big><big><a name="3.2.2" id="3.2.2">3.2.2: exp_2: Test</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
# include &lt;cmath&gt;           // define fabs function
# include &quot;exp_2.hpp&quot;       // definition of exp_2 algorithm
bool exp_2(void)
{	double x     = .5;
	double check = 1 + x + x * x / 2.; 
	bool   ok    = std::fabs( exp_2(x) - check ) &lt;= 1e-10; 
	return ok;
}</pre>
</font></code>


<hr/>Input File: introduction/exp_apx/exp_2.omh

<hr/>



<center><b><big><big><a name="3.2.3" id="3.2.3">3.2.3: exp_2: Operation Sequence and Zero Order Forward Mode</a>
</big></big></b></center>
<br/>
<b><big><a name="3.2.3.a" id="3.2.3.a">3.2.3.a: Mathematical Form</a></big></b>
<br/>
The operation sequence (see below) corresponding to
the algorithm <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 is the same for all values of <i>x</i>.
The mathematical form for the corresponding function is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

An algorithmic differentiation package
does not operate on the mathematical function 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
</mrow></math>


but rather on the particular algorithm used to compute the function 
(in this case <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
).

<br/>
<br/>
<b><big><a name="3.2.3.b" id="3.2.3.b">3.2.3.b: Zero Order Expansion</a></big></b>



<br/>
In general, a zero order forward sweep is given a vector

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">&#x02208;</mo>
<msup><mrow><mstyle mathvariant='bold'><mi mathvariant='bold'>R</mi>
</mstyle></mrow>
<mi mathvariant='italic'>n</mi>
</msup>
</mrow></math>

 and it returns the corresponding vector

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>y</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">&#x02208;</mo>
<msup><mrow><mstyle mathvariant='bold'><mi mathvariant='bold'>R</mi>
</mstyle></mrow>
<mi mathvariant='italic'>m</mi>
</msup>
</mrow></math>

 given by

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msup><mi mathvariant='italic'>y</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mrow></math>

The superscript 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow></math>

 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 xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>n</mi>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>m</mi>
</mrow></math>

 are equal to one.


<br/>
<br/>
<b><big><a name="3.2.3.c" id="3.2.3.c">3.2.3.c: Operation Sequence</a></big></b>
<br/>
An atomic <i>Type</i> operation is an operation
that has a <i>Type</i> result and is not made up of 
other more basic operations.
A sequence of atomic <i>Type</i> operations is called a
<i>Type</i> operation sequence.
Given an C++ algorithm and its inputs,
there is a corresponding <i>Type</i> operation sequence for each type. 
If <i>Type</i> is clear from the context, 
we drop it and just refer to the operation sequence.
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>We consider the case where <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 is executed with

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

.
The table below contains the corresponding operation sequence
and the results of a zero order sweep.

<br/>
<br/>
<b><a name="3.2.3.c.a" id="3.2.3.c.a">3.2.3.c.a: Index</a></b>
<br/>
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.

<br/>
<br/>
<b><a name="3.2.3.c.b" id="3.2.3.c.b">3.2.3.c.b: Code</a></b>
<br/>
The Code column contains the C++ source code corresponding 
to the corresponding atomic operation in the sequence. 

<br/>
<br/>
<b><a name="3.2.3.c.c" id="3.2.3.c.c">3.2.3.c.c: Operation</a></b>
<br/>
The Operation column contains the 
mathematical function corresponding to each atomic operation in the sequence.

<br/>
<br/>
<b><a name="3.2.3.c.d" id="3.2.3.c.d">3.2.3.c.d: Zero Order</a></b>
<br/>
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.

<br/>
<br/>
<b><a name="3.2.3.c.e" id="3.2.3.c.e">3.2.3.c.e: Sweep</a></b>

<center>
<table><tr><td align='left'  valign='top'>

<b>Index</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Code</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Operation</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Zero Order</b>
</td></tr><tr><td align='left'  valign='top'>

1
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">Type v1  = x;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<mi mathvariant='italic'>x</mi>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

2
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">Type v2  = Type(1) + v1;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

3
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">Type v3  = v1 * v1;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

4
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">Type v4  = v3 / Type(2);</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.125</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

5
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue"> Type v5  = v2 + v4;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1.625</mn>
</mrow></math>


</td></tr>
</table>
</center><b><big><a name="3.2.3.d" id="3.2.3.d">3.2.3.d: Return Value</a></big></b>
<br/>
The return value for this case is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mn>1.625</mn>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mrow></math>

<br/>
<b><big><a name="3.2.3.e" id="3.2.3.e">3.2.3.e: Verification</a></big></b>
<br/>
The file <a href="#3.2.3.1">3.2.3.1: <span style='white-space: nowrap'>exp_2_for0.cpp</span></a>
 contains a routine 
that verifies the values computed above.
It returns true for success and false for failure.

<br/>
<br/>
<b><big><a name="3.2.3.f" id="3.2.3.f">3.2.3.f: Exercises</a></big></b>

<ol type="1"><li>
Suppose that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>.2</mn>
</mrow></math>

,
what is the result of a zero order forward sweep for 
the operation sequence above; 
i.e., what are the corresponding values for

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x022EF;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

</li><li>
Create a modified version of 
<a href="#3.2.3.1">3.2.3.1: <span style='white-space: nowrap'>exp_2_for0.cpp</span></a>
 that verifies the values you obtained
for the previous exercise.
</li><li>

Create and run a main program that reports the result of calling 
the modified version 
of <a href="#3.2.3.1">3.2.3.1: <span style='white-space: nowrap'>exp_2_for0.cpp</span></a>
 in the previous exercise.
</li></ol>




<hr/>Input File: introduction/exp_apx/exp_2.omh

<hr/>



<center><b><big><big><a name="3.2.3.1" id="3.2.3.1">3.2.3.1: exp_2: Verify Zero Order Forward Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cmath&gt;            // for fabs function
bool exp_2_for0(double *v0)  // double v0[6]
{	bool  ok = true;
	double x = .5;

	v0[1] = x;                                  // v1 = x
	ok  &amp;= std::fabs( v0[1] - 0.5) &lt; 1e-10;

	v0[2] = 1. + v0[1];                         // v2 = 1 + v1
	ok  &amp;= std::fabs( v0[2] - 1.5) &lt; 1e-10;

	v0[3] = v0[1] * v0[1];                      // v3 = v1 * v1
	ok  &amp;= std::fabs( v0[3] - 0.25) &lt; 1e-10;

	v0[4] = v0[3] / 2.;                         // v4 = v3 / 2
	ok  &amp;= std::fabs( v0[4] - 0.125) &lt; 1e-10;

	v0[5] = v0[2] + v0[4];                      // v5  = v2 + v4
	ok  &amp;= std::fabs( v0[5] - 1.625) &lt; 1e-10;

	return ok;
}
bool exp_2_for0(void)
{	double v0[6];
	return exp_2_for0(v0);
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_2_for0.cpp

<hr/>



<center><b><big><big><a name="3.2.4" id="3.2.4">3.2.4: exp_2: First Order Forward Mode</a>
</big></big></b></center>
<br/>
<b><big><a name="3.2.4.a" id="3.2.4.a">3.2.4.a: First Order Expansion</a></big></b>



<br/>
We define 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow></math>

 near 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

 by the first order expansion

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
</mrow></math>

it follows that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

 is the zero,
and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

 the first,
order derivative of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow></math>


at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

.

<br/>
<br/>
<b><big><a name="3.2.4.b" id="3.2.4.b">3.2.4.b: Purpose</a></big></b>
<br/>
In general, a first order forward sweep is given the
<a href="#3.2.3.b">3.2.3.b: <span style='white-space: nowrap'>zero&#xA0;order&#xA0;derivative</span></a>

for all of the variables in an operation sequence,
and the first order derivatives for the independent variables.
It uses these to compute the first order derivatives,
and thereby obtain the first order expansion,
for all the other variables in the operation sequence.

<br/>
<br/>
<b><big><a name="3.2.4.c" id="3.2.4.c">3.2.4.c: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 to compute 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

The corresponding derivative function is 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</msub>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
</mrow></math>

An algorithmic differentiation package
does not operate on the mathematical form of the function,
or its derivative,
but rather on the 
<a href="#3.2.3.c">3.2.3.c: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>

for the for the algorithm that is used to evaluate the function.

<br/>
<br/>
<b><big><a name="3.2.4.d" id="3.2.4.d">3.2.4.d: Operation Sequence</a></big></b>
<br/>
We consider the case where <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 is executed with

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

.
The corresponding operation sequence and 
zero order forward mode values
(see <a href="#3.2.3.c.e">3.2.3.c.e: <span style='white-space: nowrap'>zero&#xA0;order&#xA0;sweep</span></a>
)
are inputs and are used by a first order forward sweep.

<br/>
<br/>
<b><a name="3.2.4.d.a" id="3.2.4.d.a">3.2.4.d.a: Index</a></b>
<br/>
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.

<br/>
<br/>
<b><a name="3.2.4.d.b" id="3.2.4.d.b">3.2.4.d.b: Operation</a></b>
<br/>
The Operation column contains the 
mathematical function corresponding to each atomic operation in the sequence.

<br/>
<br/>
<b><a name="3.2.4.d.c" id="3.2.4.d.c">3.2.4.d.c: Zero Order</a></b>
<br/>
The Zero Order column contains the zero order derivatives
for the corresponding variable in the operation sequence
(see <a href="#3.2.3.c.e">3.2.3.c.e: <span style='white-space: nowrap'>zero&#xA0;order&#xA0;sweep</span></a>
).

<br/>
<br/>
<b><a name="3.2.4.d.d" id="3.2.4.d.d">3.2.4.d.d: Derivative</a></b>
<br/>
The Derivative column contains the
mathematical function corresponding to the derivative
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
</mrow></math>

,
at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

, for each variable in the sequence.

<br/>
<br/>
<b><a name="3.2.4.d.e" id="3.2.4.d.e">3.2.4.d.e: First Order</a></b>
<br/>
The First Order column contains the first order derivatives
for the corresponding variable in the operation sequence; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>j</mi>
</msub>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>j</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>j</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mi mathvariant='italic'>t</mi>
</mrow></math>

We use 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

 so that differentiation
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
</mrow></math>

,
at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

, is the same partial differentiation 
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

 at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

.



<br/>
<br/>
<b><a name="3.2.4.d.f" id="3.2.4.d.f">3.2.4.d.f: Sweep</a></b>


<center>
<table><tr><td align='left'  valign='top'>

<b>Index</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Operation</b> 
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Zero Order</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Derivative</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>First Order</b>
</td></tr><tr><td align='left'  valign='top'>

1
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<mi mathvariant='italic'>x</mi>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

2
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

3
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.25
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>2</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

4
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.125
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

5	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;</span></code>  </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.625
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mrow></math>


</td></tr>
</table>
</center><b><big><a name="3.2.4.e" id="3.2.4.e">3.2.4.e: Return Value</a></big></b>
<br/>
The derivative of the return value for this case is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mn>1.5</mn>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msub><mrow><mo stretchy="true">[</mo><mrow><mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>t</mi>
</mrow>
</mfrac>
</mrow><mo stretchy="true">]</mo></mrow>
<mrow><mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
</msub>
<mo stretchy="false">=</mo>
<msub><mrow><mo stretchy="true">[</mo><mrow><mfrac><mrow><mo stretchy="false">&#x02202;</mo>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>t</mi>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow><mo stretchy="true">]</mo></mrow>
<mrow><mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msup><mi mathvariant='italic'>f</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>f</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mtd></mtr></mtable>
</mrow></math>

(We have used the fact that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

.)


<br/>
<br/>
<b><big><a name="3.2.4.f" id="3.2.4.f">3.2.4.f: Verification</a></big></b>
<br/>
The file <a href="#3.2.4.1">3.2.4.1: <span style='white-space: nowrap'>exp_2_for1.cpp</span></a>
 contains a routine 
which verifies the values computed above.
It returns true for success and false for failure.

<br/>
<br/>
<b><big><a name="3.2.4.g" id="3.2.4.g">3.2.4.g: Exercises</a></big></b>

<ol type="1"><li>
Which statement in the routine defined by <a href="#3.2.4.1">3.2.4.1: <span style='white-space: nowrap'>exp_2_for1.cpp</span></a>
 uses 
the values that are calculated by the routine 
defined by <a href="#3.2.3.1">3.2.3.1: <span style='white-space: nowrap'>exp_2_for0.cpp</span></a>
 ?
</li><li>

Suppose that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

,
what are the results of a zero and first order forward sweep for 
the operation sequence above; 
i.e., what are the corresponding values for

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x022EF;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x022EF;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 ?
</li><li>

Create a modified version of <a href="#3.2.4.1">3.2.4.1: <span style='white-space: nowrap'>exp_2_for1.cpp</span></a>
 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
<a href="#3.2.4.1">3.2.4.1: <span style='white-space: nowrap'>exp_2_for1.cpp</span></a>
.
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_2.omh

<hr/>



<center><b><big><big><a name="3.2.4.1" id="3.2.4.1">3.2.4.1: exp_2: Verify First Order Forward Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cmath&gt;                   // prototype for fabs
extern bool exp_2_for0(double *v0); // computes zero order forward sweep
bool exp_2_for1(double *v1)         // double v1[6]
{	bool ok = true;
	double v0[6];

	// set the value of v0[j] for j = 1 , ... , 5
	ok &amp;= exp_2_for0(v0);

	v1[1] = 1.;                                     // v1 = x
	ok    &amp;= std::fabs( v1[1] - 1. ) &lt;= 1e-10;

	v1[2] = v1[1];                                  // v2 = 1 + v1
	ok    &amp;= std::fabs( v1[2] - 1. ) &lt;= 1e-10;

	v1[3] = v1[1] * v0[1] + v0[1] * v1[1];          // v3 = v1 * v1
	ok    &amp;= std::fabs( v1[3] - 1. ) &lt;= 1e-10;

	v1[4] = v1[3] / 2.;                             // v4 = v3 / 2
	ok    &amp;= std::fabs( v1[4] - 0.5) &lt;= 1e-10;

	v1[5] = v1[2] + v1[4];                          // v5 = v2 + v4
	ok    &amp;= std::fabs( v1[5] - 1.5) &lt;= 1e-10;

	return ok;
}
bool exp_2_for1(void)
{	double v1[6];
	return exp_2_for1(v1);
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_2_for1.cpp

<hr/>



<center><b><big><big><a name="3.2.5" id="3.2.5">3.2.5: exp_2: First Order Reverse Mode</a>
</big></big></b></center>
<br/>
<b><big><a name="3.2.5.a" id="3.2.5.a">3.2.5.a: Purpose</a></big></b>
<br/>
First order reverse mode uses the 
<a href="#3.2.3.c">3.2.3.c: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>
,
and zero order forward sweep values,
to compute the first order derivative
of one dependent variable with respect to all the independent variables. 
The computations are done in reverse 
of the order of the computations in the original algorithm.

<br/>
<br/>
<b><big><a name="3.2.5.b" id="3.2.5.b">3.2.5.b: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 to compute 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

The corresponding derivative function is 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</msub>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
</mrow></math>

<br/>
<b><big><a name="3.2.5.c" id="3.2.5.c">3.2.5.c: f_5</a></big></b>
<br/>
For our example, we chose to compute the derivative
of the value returned by <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>

which is equal to the symbol 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow></math>

 in the
<a href="#3.2.3.c">3.2.3.c: <span style='white-space: nowrap'>exp_2&#xA0;operation&#xA0;sequence</span></a>
.
We begin with the function 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>

 where 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow></math>

 
is both an argument and the value of the function; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.2.5.d" id="3.2.5.d">3.2.5.d: Index 5: f_4</a></big></b>
<br/>
Reverse mode starts with the last operation in the sequence.
For the case in question, this is the operation with index 5,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow></math>

 is eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.2.5.e" id="3.2.5.e">3.2.5.e: Index 4: f_3</a></big></b>
<br/>
The next operation has index 4, 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow></math>

 is eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.2.5.f" id="3.2.5.f">3.2.5.f: Index 3: f_2</a></big></b>
<br/>
The next operation has index 3,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow></math>

 is eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

Note that the value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

 is equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>


which is .5 for this evaluation.
It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.2.5.g" id="3.2.5.g">3.2.5.g: Index 2: f_1</a></big></b>
<br/>
The next operation has index 2,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow></math>

 is eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mtd></mtr></mtable>
</mrow></math>

Note that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

 is equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
so the derivative of this is the derivative of
the function defined by <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

.


<br/>
<br/>
<b><big><a name="3.2.5.h" id="3.2.5.h">3.2.5.h: Verification</a></big></b>
<br/>
The file <a href="#3.2.5.1">3.2.5.1: <span style='white-space: nowrap'>exp_2_rev1.cpp</span></a>
 contains a routine 
which verifies the values computed above.
It returns true for success and false for failure.
It only tests the partial derivatives of

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 that might not be equal to the corresponding
partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow>
</msub>
</mrow></math>

; i.e., the
other partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 must be equal to the corresponding
partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow>
</msub>
</mrow></math>

.

<br/>
<br/>
<b><big><a name="3.2.5.i" id="3.2.5.i">3.2.5.i: Exercises</a></big></b>

<ol type="1"><li>
Which statement in the routine defined by <a href="#3.2.5.1">3.2.5.1: <span style='white-space: nowrap'>exp_2_rev1.cpp</span></a>
 uses 
the values that are calculated by the routine 
defined by <a href="#3.2.3.1">3.2.3.1: <span style='white-space: nowrap'>exp_2_for0.cpp</span></a>
 ?
</li><li>

Consider the case where 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>


and we first preform a zero order forward sweep
for the operation sequence used above.
What are the results of a 
first order reverse sweep; i.e.,
what are the corresponding derivatives of

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow></math>

.
</li><li>

Create a modified version of 
<a href="#3.2.5.1">3.2.5.1: <span style='white-space: nowrap'>exp_2_rev1.cpp</span></a>
 
that verifies the values you obtained for the previous exercise.
Also create and run a main program that reports the result
of calling the modified version of
<a href="#3.2.5.1">3.2.5.1: <span style='white-space: nowrap'>exp_2_rev1.cpp</span></a>
.
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_2.omh

<hr/>



<center><b><big><big><a name="3.2.5.1" id="3.2.5.1">3.2.5.1: exp_2: Verify First Order Reverse Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cstddef&gt;                 // define size_t
# include &lt;cmath&gt;                   // prototype for fabs
extern bool exp_2_for0(double *v0); // computes zero order forward sweep
bool exp_2_rev1(void)
{	bool ok = true;

	// set the value of v0[j] for j = 1 , ... , 5
	double v0[6];
	ok &amp;= exp_2_for0(v0);

	// initial all partial derivatives as zero
	double f_v[6];
	size_t j;
	for(j = 0; j &lt; 6; j++)
		f_v[j] = 0.;

	// set partial derivative for f5
	f_v[5] = 1.;
	ok &amp;= std::fabs( f_v[5] - 1. ) &lt;= 1e-10; // f5_v5

	// f4 = f5( v1 , v2 , v3 , v4 , v2 + v4 )
	f_v[2] += f_v[5] * 1.;
	f_v[4] += f_v[5] * 1.;
	ok &amp;= std::fabs( f_v[2] - 1. ) &lt;= 1e-10; // f4_v2
	ok &amp;= std::fabs( f_v[4] - 1. ) &lt;= 1e-10; // f4_v4

	// f3 = f4( v1 , v2 , v3 , v3 / 2 )
	f_v[3] += f_v[4] / 2.;
	ok &amp;= std::fabs( f_v[3] - 0.5) &lt;= 1e-10; // f3_v3

	// f2 = f3( v1 , v2 , v1 * v1 )
	f_v[1] += f_v[3] * 2. * v0[1];
	ok &amp;= std::fabs( f_v[1] - 0.5) &lt;= 1e-10; // f2_v1

	// f1 = f2( v1 , 1 + v1 )
	f_v[1] += f_v[2] * 1.;
	ok &amp;= std::fabs( f_v[1] - 1.5) &lt;= 1e-10; // f1_v1

	return ok;
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_2_rev1.cpp

<hr/>



<center><b><big><big><a name="3.2.6" id="3.2.6">3.2.6: exp_2: Second Order Forward Mode</a>
</big></big></b></center>
<br/>
<b><big><a name="3.2.6.a" id="3.2.6.a">3.2.6.a: Second Order Expansion</a></big></b>



<br/>
We define 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow></math>

 near 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

 by the second order expansion

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>t</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

It follows that for 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mn>2</mn>
</mrow></math>

,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mfrac><mrow><msup><mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>d</mi>
</mstyle></mrow>
<mrow><mi mathvariant='italic'>k</mi>
</mrow>
</msup>
</mrow>
<mrow><mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>d</mi>
</mstyle></mrow>
<mspace width='.18em'/>
<msup><mrow><mi mathvariant='italic'>t</mi>
</mrow>
<mrow><mi mathvariant='italic'>k</mi>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow></math>

<br/>
<b><big><a name="3.2.6.b" id="3.2.6.b">3.2.6.b: Purpose</a></big></b>
<br/>
In general, a second order forward sweep is given the
<a href="#3.2.4.a">3.2.4.a: <span style='white-space: nowrap'>first&#xA0;order&#xA0;expansion</span></a>

for all of the variables in an operation sequence,
and the second order derivatives for the independent variables.
It uses these to compute the second order derivative,
and thereby obtain the second order expansion,
for all the variables in the operation sequence.

<br/>
<br/>
<b><big><a name="3.2.6.c" id="3.2.6.c">3.2.6.c: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 to compute 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

The corresponding second derivative function is 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

<br/>
<b><big><a name="3.2.6.d" id="3.2.6.d">3.2.6.d: Operation Sequence</a></big></b>
<br/>
We consider the case where <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 is executed with

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

.
The corresponding operation sequence,
zero order forward sweep values,
and first order forward sweep values
are inputs and are used by a second order forward sweep.

<br/>
<br/>
<b><a name="3.2.6.d.a" id="3.2.6.d.a">3.2.6.d.a: Index</a></b>
<br/>
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.

<br/>
<br/>
<b><a name="3.2.6.d.b" id="3.2.6.d.b">3.2.6.d.b: Zero</a></b>
<br/>
The Zero column contains the zero order sweep results
for the corresponding variable in the operation sequence
(see <a href="#3.2.3.c.e">3.2.3.c.e: <span style='white-space: nowrap'>zero&#xA0;order&#xA0;sweep</span></a>
).

<br/>
<br/>
<b><a name="3.2.6.d.c" id="3.2.6.d.c">3.2.6.d.c: Operation</a></b>
<br/>
The Operation column contains the 
first order sweep operation for this variable.

<br/>
<br/>
<b><a name="3.2.6.d.d" id="3.2.6.d.d">3.2.6.d.d: First</a></b>
<br/>
The First column contains the first order sweep results
for the corresponding variable in the operation sequence
(see <a href="#3.2.4.d.f">3.2.4.d.f: <span style='white-space: nowrap'>first&#xA0;order&#xA0;sweep</span></a>
).

<br/>
<br/>
<b><a name="3.2.6.d.e" id="3.2.6.d.e">3.2.6.d.e: Derivative</a></b>
<br/>
The Derivative column contains the
mathematical function corresponding to the second derivative
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
</mrow></math>

,
at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

, for each variable in the sequence.

<br/>
<br/>
<b><a name="3.2.6.d.f" id="3.2.6.d.f">3.2.6.d.f: Second</a></b>
<br/>
The Second column contains the second order derivatives
for the corresponding variable in the operation sequence; i.e.,
the second order expansion for the <i>i</i>-th variable is given by

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
</msub>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>t</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

We use 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

, and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>


so that second order differentiation
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
</mrow></math>

, at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

, 
is the same as the second partial differentiation 
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

 at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

.


<br/>
<br/>
<b><a name="3.2.6.d.g" id="3.2.6.d.g">3.2.6.d.g: Sweep</a></b>


<center>
<table><tr><td align='left'  valign='top'>

<b>Index</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Zero</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Operation</b> 
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>First</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Derivative</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Second</b>
</td></tr><tr><td align='left'  valign='top'>

1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

2
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.5
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

3
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.25
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>2</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>2</mn>
<mo stretchy="false">*</mo>
<mo stretchy="false">(</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">)</mo>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>2</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

4
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.125
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 .5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.625
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;</span></code>  </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr>
</table>
</center><b><big><a name="3.2.6.e" id="3.2.6.e">3.2.6.e: Return Value</a></big></b>
<br/>
The second derivative of the return value for this case is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mn>1</mn>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msub><mrow><mo stretchy="true">[</mo><mrow><mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>t</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow><mo stretchy="true">]</mo></mrow>
<mrow><mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
</msub>
<mo stretchy="false">=</mo>
<msub><mrow><mo stretchy="true">[</mo><mrow><mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>t</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow><mo stretchy="true">]</mo></mrow>
<mrow><mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mtd></mtr></mtable>
</mrow></math>

(We have used the fact that

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

.)


<br/>
<br/>
<b><big><a name="3.2.6.f" id="3.2.6.f">3.2.6.f: Verification</a></big></b>
<br/>
The file <a href="#3.2.6.1">3.2.6.1: <span style='white-space: nowrap'>exp_2_for2.cpp</span></a>
 contains a routine 
which verifies the values computed above.
It returns true for success and false for failure.

<br/>
<br/>
<b><big><a name="3.2.6.g" id="3.2.6.g">3.2.6.g: Exercises</a></big></b>

<ol type="1"><li>
Which statement in the routine defined by <a href="#3.2.6.1">3.2.6.1: <span style='white-space: nowrap'>exp_2_for2.cpp</span></a>
 uses 
the values that are calculated by the routine 
defined by <a href="#3.2.4.1">3.2.4.1: <span style='white-space: nowrap'>exp_2_for1.cpp</span></a>
 ?
</li><li>

Suppose that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

,
what are the results of a zero, first, and second order forward sweep for 
the operation sequence above; 
i.e., what are the corresponding values for

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
<mrow><mo stretchy="false">(</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 for 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>i</mi>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<mn>5</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mn>2</mn>
</mrow></math>

.
</li><li>

Create a modified version of <a href="#3.2.6.1">3.2.6.1: <span style='white-space: nowrap'>exp_2_for2.cpp</span></a>
 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
<a href="#3.2.6.1">3.2.6.1: <span style='white-space: nowrap'>exp_2_for2.cpp</span></a>
.
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_2.omh

<hr/>



<center><b><big><big><a name="3.2.6.1" id="3.2.6.1">3.2.6.1: exp_2: Verify Second Order Forward Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cmath&gt;                   // prototype for fabs
extern bool exp_2_for0(double *v0); // computes zero order forward sweep
extern bool exp_2_for1(double *v1); // computes first order forward sweep
bool exp_2_for2(void)
{	bool ok = true;
	double v0[6], v1[6], v2[6];

	// set the value of v0[j], v1[j], for j = 1 , ... , 5
	ok &amp;= exp_2_for0(v0);
	ok &amp;= exp_2_for1(v1);

	v2[1] = 0.;                                     // v1 = x
	ok    &amp;= std::fabs( v2[1] - 0. ) &lt;= 1e-10;

	v2[2] = v2[1];                                  // v2 = 1 + v1
	ok    &amp;= std::fabs( v2[2] - 0. ) &lt;= 1e-10;

	v2[3] = 2.*(v0[1]*v2[1] + v1[1]*v1[1]);         // v3 = v1 * v1
	ok    &amp;= std::fabs( v2[3] - 2. ) &lt;= 1e-10;

	v2[4] = v2[3] / 2.;                             // v4 = v3 / 2
	ok    &amp;= std::fabs( v2[4] - 1. ) &lt;= 1e-10;

	v2[5] = v2[2] + v2[4];                          // v5 = v2 + v4
	ok    &amp;= std::fabs( v2[5] - 1. ) &lt;= 1e-10;

	return ok;
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_2_for2.cpp

<hr/>



<center><b><big><big><a name="3.2.7" id="3.2.7">3.2.7: exp_2: Second Order Reverse Mode</a>
</big></big></b></center>
<br/>
<b><big><a name="3.2.7.a" id="3.2.7.a">3.2.7.a: Purpose</a></big></b>
<br/>
In general, a second order reverse sweep is given the
<a href="#3.2.4.a">3.2.4.a: <span style='white-space: nowrap'>first&#xA0;order&#xA0;expansion</span></a>

for all of the variables in an operation sequence.
Given a choice of a particular variable, 
it computes the derivative, 
of that variables first order expansion coefficient, 
with respect to all of the independent variables.

<br/>
<br/>
<b><big><a name="3.2.7.b" id="3.2.7.b">3.2.7.b: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 to compute 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

The corresponding second derivative is 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

<br/>
<b><big><a name="3.2.7.c" id="3.2.7.c">3.2.7.c: f_5</a></big></b>
<br/>
For our example, we chose to compute the derivative of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


with respect to all the independent variable.
For the case computed for the
<a href="#3.2.4.d.f">3.2.4.d.f: <span style='white-space: nowrap'>first&#xA0;order&#xA0;sweep</span></a>
,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 is the derivative 
of the value returned by <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
.
This the value computed will be the second derivative of 
the value returned by  <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
.
We begin with the function 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>

 where 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 
is both an argument and the value of the function; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.2.7.d" id="3.2.7.d">3.2.7.d: Index 5: f_4</a></big></b>
<br/>
Second order reverse mode starts with the last operation in the sequence.
For the case in question, this is the operation with index 5.
The zero and first order sweep representations of this operation are

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 are eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.2.7.e" id="3.2.7.e">3.2.7.e: Index 4: f_3</a></big></b>
<br/>
The next operation has index 4, 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 
are eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.2.7.f" id="3.2.7.f">3.2.7.f: Index 3: f_2</a></big></b>
<br/>
The next operation has index 3,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>2</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 are
eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">(</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">)</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">(</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">)</mo>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

Note that, from the 
<a href="#3.2.4.d.f">3.2.4.d.f: <span style='white-space: nowrap'>first&#xA0;order&#xA0;forward&#xA0;sweep</span></a>
,
the value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 is equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mn>.5</mn>
</mrow></math>


and  
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 is equal 1. 
It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.2.7.g" id="3.2.7.g">3.2.7.g: Index 2: f_1</a></big></b>
<br/>
The next operation has index 2,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">(</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and  
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


are eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">(</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">)</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">(</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">)</mo>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mtd></mtr></mtable>
</mrow></math>

Note that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

 is equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
so the second derivative of 
the function defined by <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>


is given by

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</mrow>
</mfrac>
<mo stretchy="false">=</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">=</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

There is a theorem about Algorithmic Differentiation that explains why
the other partial of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow></math>

 is equal to the
first derivative of 
the function defined by <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

.



<br/>
<br/>
<b><big><a name="3.2.7.h" id="3.2.7.h">3.2.7.h: Verification</a></big></b>
<br/>
The file <a href="#3.2.7.1">3.2.7.1: <span style='white-space: nowrap'>exp_2_rev2.cpp</span></a>
 contains a routine 
which verifies the values computed above.
It returns true for success and false for failure.
It only tests the partial derivatives of

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 that might not be equal to the corresponding
partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow>
</msub>
</mrow></math>

; i.e., the
other partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 must be equal to the corresponding
partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow>
</msub>
</mrow></math>

.

<br/>
<br/>
<b><big><a name="3.2.7.i" id="3.2.7.i">3.2.7.i: Exercises</a></big></b>

<ol type="1"><li>
Which statement in the routine defined by <a href="#3.2.7.1">3.2.7.1: <span style='white-space: nowrap'>exp_2_rev2.cpp</span></a>
 uses 
the values that are calculated by the routine 
defined by <a href="#3.2.3.1">3.2.3.1: <span style='white-space: nowrap'>exp_2_for0.cpp</span></a>
 ?
Which statements use values that are calculate by the routine
defined in <a href="#3.2.4.1">3.2.4.1: <span style='white-space: nowrap'>exp_2_for1.cpp</span></a>
 ?
</li><li>

Consider the case where 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>


and we first preform a zero order forward sweep,
then a first order sweep,
for the operation sequence used above.
What are the results of a 
second order reverse sweep; i.e.,
what are the corresponding derivatives of

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow></math>

.
</li><li>

Create a modified version of 
<a href="#3.2.7.1">3.2.7.1: <span style='white-space: nowrap'>exp_2_rev2.cpp</span></a>
 
that verifies the values you obtained for the previous exercise.
Also create and run a main program that reports the result
of calling the modified version of
<a href="#3.2.7.1">3.2.7.1: <span style='white-space: nowrap'>exp_2_rev2.cpp</span></a>
.
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_2.omh

<hr/>



<center><b><big><big><a name="3.2.7.1" id="3.2.7.1">3.2.7.1: exp_2: Verify Second Order Reverse Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cstddef&gt;                 // define size_t
# include &lt;cmath&gt;                   // prototype for fabs
extern bool exp_2_for0(double *v0); // computes zero order forward sweep
extern bool exp_2_for1(double *v1); // computes first order forward sweep
bool exp_2_rev2(void)
{	bool ok = true;

	// set the value of v0[j], v1[j] for j = 1 , ... , 5
	double v0[6], v1[6];
	ok &amp;= exp_2_for0(v0);
	ok &amp;= exp_2_for1(v1);

	// initial all partial derivatives as zero
	double f_v0[6], f_v1[6];
	size_t j;
	for(j = 0; j &lt; 6; j++)
	{	f_v0[j] = 0.;
		f_v1[j] = 0.;
	}

	// set partial derivative for f_5
	f_v1[5] = 1.;
	ok &amp;= std::fabs( f_v1[5] - 1. ) &lt;= 1e-10; // partial f_5 w.r.t v_5^1

	// f_4 = f_5( v_1^0 , ... , v_4^1 , v_2^0 + v_4^0 , v_2^1 + v_4^1 )
	f_v0[2] += f_v0[5] * 1.;
	f_v0[4] += f_v0[5] * 1.;
	f_v1[2] += f_v1[5] * 1.;
	f_v1[4] += f_v1[5] * 1.;
	ok &amp;= std::fabs( f_v0[2] - 0. ) &lt;= 1e-10; // partial f_4 w.r.t. v_2^0
	ok &amp;= std::fabs( f_v0[4] - 0. ) &lt;= 1e-10; // partial f_4 w.r.t. v_4^0
	ok &amp;= std::fabs( f_v1[2] - 1. ) &lt;= 1e-10; // partial f_4 w.r.t. v_2^1
	ok &amp;= std::fabs( f_v1[4] - 1. ) &lt;= 1e-10; // partial f_4 w.r.t. v_4^1

	// f_3 = f_4( v_1^0 , ... , v_3^1, v_3^0 / 2 , v_3^1 / 2 )
	f_v0[3] += f_v0[4] / 2.;
	f_v1[3] += f_v1[4] / 2.;
	ok &amp;= std::fabs( f_v0[3] - 0.  ) &lt;= 1e-10; // partial f_3 w.r.t. v_3^0
	ok &amp;= std::fabs( f_v1[3] - 0.5 ) &lt;= 1e-10; // partial f_3 w.r.t. v_3^1

	// f_2 = f_3(  v_1^0 , ... , v_2^1, v_1^0 * v_1^0 , 2 * v_1^0 * v_1^1 )
	f_v0[1] += f_v0[3] * 2. * v0[1];
	f_v0[1] += f_v1[3] * 2. * v1[1];
	f_v1[1] += f_v1[3] * 2. * v0[1];
	ok &amp;= std::fabs( f_v0[1] - 1.  ) &lt;= 1e-10; // partial f_2 w.r.t. v_1^0
	ok &amp;= std::fabs( f_v1[1] - 0.5 ) &lt;= 1e-10; // partial f_2 w.r.t. v_1^1

	// f_1 = f_2( v_1^0 , v_1^1 , 1 + v_1^0 , v_1^1 )
	f_v0[1] += f_v0[2] * 1.;
	f_v1[1] += f_v1[2] * 1.;
	ok &amp;= std::fabs( f_v0[1] - 1. ) &lt;= 1e-10; // partial f_1 w.r.t. v_1^0
	ok &amp;= std::fabs( f_v1[1] - 1.5) &lt;= 1e-10; // partial f_1 w.r.t. v_1^1

	return ok;
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_2_rev2.cpp

<hr/>



<center><b><big><big><a name="3.2.8" id="3.2.8">3.2.8: exp_2: CppAD Forward and Reverse Sweeps</a>
</big></big></b></center>
.

<br/>
<br/>
<b><big><a name="3.2.8.a" id="3.2.8.a">3.2.8.a: Purpose</a></big></b>
<br/>
Use CppAD forward and reverse modes to compute the
partial derivative with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

,
of the function 
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;exp_2(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>as defined by the <a href="#3.2.1">3.2.1: <span style='white-space: nowrap'>exp_2.hpp</span></a>
 include file.

<br/>
<br/>
<b><big><a name="3.2.8.b" id="3.2.8.b">3.2.8.b: Exercises</a></big></b>

<ol type="1"><li>
Create and test a modified version of the routine below that computes
the same order derivatives with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

 
of the function 
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;exp_2(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code></li><li>
Create a routine called
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;exp_3(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>that evaluates the function

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>3</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>6</mn>
</mrow></math>

Test a modified version of the routine below that computes
the derivative of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
</mrow></math>


at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

.
</li></ol>

<code><font color='blue'><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;  // http://www.coin-or.org/CppAD/ 
# include &quot;exp_2.hpp&quot;        // second order exponential approximation
bool exp_2_cppad(void)
{	bool ok = true;
	using CppAD::AD;
	using CppAD::vector;    // can use any simple vector template class
	using CppAD::NearEqual; // checks if values are nearly equal

	// domain space vector
	size_t n = 1; // dimension of the domain space
	vector&lt; <a href="#4">AD</a>&lt;double&gt; &gt; X(n);
	X[0] = .5;    // value of x for this operation sequence

	// declare independent variables and start recording operation sequence
	CppAD::<a href="#5.1">Independent</a>(X);

	// evaluate our exponential approximation
	<a href="#4">AD</a>&lt;double&gt; x   = X[0];
	<a href="#4">AD</a>&lt;double&gt; apx = exp_2(x);  

	// range space vector
	size_t m = 1;  // dimension of the range space
	vector&lt; <a href="#4">AD</a>&lt;double&gt; &gt; Y(m);
	Y[0] = apx;    // variable that represents only range space component

	// Create f: X -&gt; Y corresponding to this operation sequence
	// and stop recording. This also executes a zero order forward 
	// sweep using values in X for x.
	CppAD::<a href="#5.2">ADFun</a>&lt;double&gt; f(X, Y);

	// first order forward sweep that computes
	// partial of exp_2(x) with respect to x
	vector&lt;double&gt; dx(n);  // differential in domain space
	vector&lt;double&gt; dy(m);  // differential in range space
	dx[0] = 1.;            // direction for partial derivative
	dy    = f.<a href="#5.6.1">Forward</a>(1, dx);
	double check = 1.5;
	ok   &amp;= <a href="#6.2">NearEqual</a>(dy[0], check, 1e-10, 1e-10);

	// first order reverse sweep that computes the derivative
	vector&lt;double&gt;  w(m);   // weights for components of the range
	vector&lt;double&gt; dw(n);   // derivative of the weighted function
	w[0] = 1.;              // there is only one weight
	dw   = f.<a href="#5.6.2">Reverse</a>(1, w); // derivative of w[0] * exp_2(x)
	check = 1.5;            // partial of exp_2(x) with respect to x
	ok   &amp;= <a href="#6.2">NearEqual</a>(dw[0], check, 1e-10, 1e-10);

	// second order forward sweep that computes
	// second partial of exp_2(x) with respect to x
	vector&lt;double&gt; x2(n);     // second order Taylor coefficients 
	vector&lt;double&gt; y2(m);  
	x2[0] = 0.;               // evaluate second partial .w.r.t. x
	y2    = f.<a href="#5.6.1">Forward</a>(2, x2);
	check = 0.5 * 1.;         // Taylor coef is 1/2 second derivative 
	ok   &amp;= <a href="#6.2">NearEqual</a>(y2[0], check, 1e-10, 1e-10);

	// second order reverse sweep that computes
	// derivative of partial of exp_2(x) w.r.t. x
	dw.resize(2 * n);         // space for first and second derivatives
	dw    = f.<a href="#5.6.2">Reverse</a>(2, w);
	check = 1.;               // result should be second derivative
	ok   &amp;= <a href="#6.2">NearEqual</a>(dw[0*2+1], check, 1e-10, 1e-10);

	return ok;
}

</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_2_cppad.cpp

<hr/>



<center><b><big><big><a name="3.3" id="3.3">3.3: An Epsilon Accurate Exponential Approximation</a>
</big></big></b></center>
<br/>
<b><big><a name="3.3.a" id="3.3.a">3.3.a: Syntax</a></big></b>

<br/>
<code><font color="blue"><span style='white-space: nowrap'>#&#xA0;include&#xA0;&quot;exp_eps.hpp&quot;</span></font></code>
<code><span style='white-space: nowrap'><br/>
</span></code><code><font color="blue"></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>


<br/>
<br/>
<b><big><a name="3.3.b" id="3.3.b">3.3.b: Purpose</a></big></b>
<br/>
This is a an example algorithm that is used to demonstrate 
how Algorithmic Differentiation works with loops and  
boolean decision variables
(see <a href="#3.2">3.2: <span style='white-space: nowrap'>exp_2</span></a>
 for a simpler example). 

<br/>
<br/>
<b><big><a name="3.3.c" id="3.3.c">3.3.c: Mathematical Function</a></big></b>
<br/>
The exponential function can be defined by

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi>exp</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>1</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>1</mn>
<mo stretchy="false">!</mo>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
<mo stretchy="false">!</mo>
<mo stretchy="false">+</mo>
<mo stretchy="false">&#x022EF;</mo>
</mrow></math>

We define 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mrow></math>

 as the smallest
non-negative integer such that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">&#x02265;</mo>
<msup><mi mathvariant='italic'>x</mi>
<mi mathvariant='italic'>k</mi>
</msup>
<mo stretchy="false">/</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">!</mo>
</mrow></math>

; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mi>min</mi>
<mo stretchy="false">{</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">&#x02208;</mo>
<msub><mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>Z</mi>
</mstyle></mrow>
<mo stretchy="false">+</mo>
</msub>
<mspace width='.3em'/>
<mo stretchy="false">|</mo>
<mspace width='.3em'/>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">&#x02265;</mo>
<msup><mi mathvariant='italic'>x</mi>
<mi mathvariant='italic'>k</mi>
</msup>
<mo stretchy="false">/</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">!</mo>
<mo stretchy="false">}</mo>
</mrow></math>

The mathematical form for our approximation of the exponential function is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>exp</mi>
<mo stretchy="false">_</mo>
<mi mathvariant='normal'>eps</mi>
</mstyle></mrow>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mrow><mo stretchy="true">{</mo><mrow><mtable rowalign="center" ><mtr><mtd columnalign="left" >
<mfrac><mrow><mn>1</mn>
</mrow>
<mrow><mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>exp</mi>
<mo stretchy="false">_</mo>
<mi mathvariant='normal'>eps</mi>
</mstyle></mrow>
<mo stretchy="false">(</mo>
<mo stretchy="false">-</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>if</mi>
</mstyle></mrow>
<mspace width='.3em'/>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">&lt;</mo>
<mn>0</mn>
</mtd></mtr><mtr><mtd columnalign="left" >
<mn>1</mn>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>1</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>1</mn>
<mo stretchy="false">!</mo>
<mo stretchy="false">+</mo>
<mo stretchy="false">&#x022EF;</mo>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mi mathvariant='italic'>k</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">/</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">!</mo>
</mtd><mtd columnalign="left" >
<mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>otherwise</mi>
</mstyle></mrow>
</mtd></mtr></mtable>
</mrow><mo stretchy="true"> </mo></mrow>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.d" id="3.3.d">3.3.d: include</a></big></b>
<br/>
The include command in the syntax is relative to 
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cppad-</span></font></code><i><span style='white-space: nowrap'>yy</span></i><code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>mm</span></i><code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>dd</span></i><code><font color="blue"><span style='white-space: nowrap'>/introduction/exp_apx<br/>
</span></font></code>where <code><font color="blue"><span style='white-space: nowrap'>cppad-</span></font></code><i><span style='white-space: nowrap'>yy</span></i><code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>mm</span></i><code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>dd</span></i> is the distribution directory
created during the beginning steps of the
<a href="#2">2: <span style='white-space: nowrap'>installation</span></a>
 of CppAD.


<br/>
<br/>
<b><big><a name="3.3.e" id="3.3.e">3.3.e: x</a></big></b>
<br/>
The argument <i>x</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font></code><i><span style='white-space: nowrap'>Type</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>(see <i>Type</i> below).
It specifies the point at which to evaluate the 
approximation for the exponential function.

<br/>
<br/>
<b><big><a name="3.3.f" id="3.3.f">3.3.f: epsilon</a></big></b>
<br/>
The argument <i>epsilon</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font></code><i><span style='white-space: nowrap'>Type</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>It specifies the accuracy with which
to approximate the exponential function value; i.e.,
it is the value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
</mrow></math>

 in the 
exponential function approximation defined above.

<br/>
<br/>
<b><big><a name="3.3.g" id="3.3.g">3.3.g: y</a></big></b>
<br/>
The result <i>y</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>Type</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>It is the value of the exponential function 
approximation defined above.

<br/>
<br/>
<b><big><a name="3.3.h" id="3.3.h">3.3.h: Type</a></big></b>
<br/>
If <i>u</i> and <i>v</i> are <i>Type</i> objects and <i>i</i>
is an <code><font color="blue">int</font></code>: 

<table><tr><td align='left'  valign='top'>

<b>Operation</b>  </td><td align='left'  valign='top'>
 <b>Result Type</b> </td><td align='left'  valign='top'>
 <b>Description</b>
</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>Type</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>i</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code> 
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 object with value equal to <i>i</i> 
</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <code><font color="blue">bool</font></code>
	</td><td align='left'  valign='top'>
 true,
	if <i>u</i> greater than <i>v</i>, an false otherwise
</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i> 
	</td><td align='left'  valign='top'>
 new <i>u</i> (and result) is value of <i>v</i>
</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;*&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 result is value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>u</mi>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>v</mi>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;/&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 result is value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>u</mi>
<mo stretchy="false">/</mo>
<mi mathvariant='italic'>v</mi>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;+&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 result is value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>u</mi>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>v</mi>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

<code><font color="blue"><span style='white-space: nowrap'>-</span></font></code><i><span style='white-space: nowrap'>u</span></i>
	</td><td align='left'  valign='top'>
 <i>Type</i>
	</td><td align='left'  valign='top'>
 result is value of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mo stretchy="false">-</mo>
<mi mathvariant='italic'>u</mi>
</mrow></math>


</td></tr>
</table>
<br/>
<b><big><a name="3.3.i" id="3.3.i">3.3.i: Implementation</a></big></b>
<br/>
The file <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

contains a C++ implementation of this function.

<br/>
<br/>
<b><big><a name="3.3.j" id="3.3.j">3.3.j: Test</a></big></b>
<br/>
The file <a href="#3.3.2">3.3.2: <span style='white-space: nowrap'>exp_eps.cpp</span></a>
 
contains a test of this implementation.
It returns true for success and false for failure.

<br/>
<br/>
<b><big><a name="3.3.k" id="3.3.k">3.3.k: Exercises</a></big></b>

<ol type="1"><li>
Using the definition of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mrow></math>

 above,
what is the value of 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">(</mo>
<mn>.5</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow></math>

, 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">(</mo>
<mn>.5</mn>
<mo stretchy="false">,</mo>
<mn>.1</mn>
<mo stretchy="false">)</mo>
</mrow></math>

, and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">(</mo>
<mn>.5</mn>
<mo stretchy="false">,</mo>
<mn>.01</mn>
<mo stretchy="false">)</mo>
</mrow></math>

 ?
</li><li>

Suppose that we make the following call to <code><font color="blue">exp_eps</font></code>:
<code><font color='blue'><pre style='display:inline'> 
	double x       = 1.;
	double epsilon = .01;
	double y = exp_eps(x, epsilon);
</pre></font></code>

What is the value assigned to 
<code><font color="blue">k</font></code>, <code><font color="blue">temp</font></code>, <code><font color="blue">term</font></code>, and <code><font color="blue">sum</font></code>
the first time through the <code><font color="blue">while</font></code> loop in <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>
 ?
</li><li>

Continuing the previous exercise, 
what is the value assigned to 
<code><font color="blue">k</font></code>, <code><font color="blue">temp</font></code>, <code><font color="blue">term</font></code>, and <code><font color="blue">sum</font></code>
the second time through the <code><font color="blue">while</font></code> loop in <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>
 ?
</li></ol>




<hr/>Input File: introduction/exp_apx/exp_eps.hpp

<hr/>



<center><b><big><big><a name="3.3.1" id="3.3.1">3.3.1: exp_eps: Implementation</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
template &lt;class Type&gt;
Type exp_eps(const Type &amp;x, const Type &amp;epsilon)
{	// abs_x = |x|
	Type abs_x = x;
	if( Type(0) &gt; x )
		abs_x = - x;
	// initialize
	int  k    = 0;          // initial order 
	Type term = 1.;         // term = |x|^k / k !
	Type sum  = term;       // initial sum
	while(term &gt; epsilon)
	{	k         = k + 1;          // order for next term
		Type temp = term * abs_x;   // term = |x|^k / (k-1)!
		term      = temp / Type(k); // term = |x|^k / k !
		sum       = sum + term;     // sum  = 1 + ... + |x|^k / k !
	}
	// In the case where x is negative, use exp(x) = 1 / exp(-|x|)
	if( Type(0) &gt; x ) 
		sum = Type(1) / sum;
	return sum;
}</pre>
</font></code>


<hr/>Input File: introduction/exp_apx/exp_eps.omh

<hr/>



<center><b><big><big><a name="3.3.2" id="3.3.2">3.3.2: exp_eps: Test of exp_eps</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 
# include &lt;cmath&gt;             // for fabs function
# include &quot;exp_eps.hpp&quot;       // definition of exp_eps algorithm
bool exp_eps(void)
{	double x       = .5;
	double epsilon = .2;
	double check   = 1 + .5 + .125; // include 1 term less than epsilon
	bool   ok      = std::fabs( exp_eps(x, epsilon) - check ) &lt;= 1e-10; 
	return ok;
}</pre>
</font></code>


<hr/>Input File: introduction/exp_apx/exp_eps.omh

<hr/>



<center><b><big><big><a name="3.3.3" id="3.3.3">3.3.3: exp_eps: Operation Sequence and Zero Order Forward Sweep</a>
</big></big></b></center>
<br/>
<b><big><a name="3.3.3.a" id="3.3.3.a">3.3.3.a: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

to compute <code><font color="blue"><span style='white-space: nowrap'>exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
with <i>x</i> is equal to .5
and <i>epsilon</i> is equal to .2. 
For this case, 
the mathematical form for the operation sequence 
corresponding to the <code><font color="blue">exp_eps</font></code> is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

Note that, for these particular values of <i>x</i> and <i>epsilon</i>,
this is the same as the mathematical form for
<a href="#3.2.3.a">3.2.3.a: <span style='white-space: nowrap'>exp_2</span></a>
.


<br/>
<br/>
<b><big><a name="3.3.3.b" id="3.3.3.b">3.3.3.b: Operation Sequence</a></big></b>
<br/>
We consider the 
<a href="#9.4.g.b">9.4.g.b: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>

corresponding to the algorithm <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

with the argument <i>x</i> is equal to .5
and <i>epsilon</i> is equal to .2. 

<br/>
<br/>
<b><a name="3.3.3.b.a" id="3.3.3.b.a">3.3.3.b.a: Variable</a></b>
<br/>
We refer to values that depend on the input variables
<i>x</i> and <i>epsilon</i> as variables.

<br/>
<br/>
<b><a name="3.3.3.b.b" id="3.3.3.b.b">3.3.3.b.b: Parameter</a></b>
<br/>
We refer to values that do not depend on the input variables
<i>x</i> or <i>epsilon</i> as parameters.
Operations where the result is a parameter are not included
in the zero order sweep below.


<br/>
<br/>
<b><a name="3.3.3.b.c" id="3.3.3.b.c">3.3.3.b.c: Index</a></b>
<br/>
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.

<br/>
<br/>
<b><a name="3.3.3.b.d" id="3.3.3.b.d">3.3.3.b.d: Code</a></b>
<br/>
The Code column contains the C++ source code corresponding 
to the corresponding atomic operation in the sequence. 

<br/>
<br/>
<b><a name="3.3.3.b.e" id="3.3.3.b.e">3.3.3.b.e: Operation</a></b>
<br/>
The Operation column contains the 
mathematical function corresponding to each atomic operation in the sequence.

<br/>
<br/>
<b><a name="3.3.3.b.f" id="3.3.3.b.f">3.3.3.b.f: Zero Order</a></b>
<br/>
The Zero Order column contains the 
<a href="#3.2.3.b">3.2.3.b: <span style='white-space: nowrap'>zero&#xA0;order&#xA0;derivative</span></a>

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.


<br/>
<br/>
<b><a name="3.3.3.b.g" id="3.3.3.b.g">3.3.3.b.g: Sweep</a></b>

<center>
<table><tr><td align='left'  valign='top'>

<b>Index</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Code</b> 
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Operation</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Zero Order</b>
</td></tr><tr><td align='left'  valign='top'>

1
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">abs_x = x;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<mi mathvariant='italic'>x</mi>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

2
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">temp  = term * abs_x;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

3
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">term = temp / Type(k);</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>1</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

4
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">sum  = sum + term;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

5
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
  <code><font color="blue">temp  = term * abs_x;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

6
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">term = temp / Type(k);</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.125</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

7
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <code><font color="blue">sum  = sum + term;</font></code>
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1.625</mn>
</mrow></math>


</td></tr>
</table>
</center><b><big><a name="3.3.3.c" id="3.3.3.c">3.3.3.c: Return Value</a></big></b>
<br/>
The return value for this case is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mn>1.625</mn>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">,</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mrow></math>

<br/>
<b><big><a name="3.3.3.d" id="3.3.3.d">3.3.3.d: Comparisons</a></big></b>
<br/>
If <i>x</i> were negative,
or if <i>epsilon</i> were a much smaller or much larger value,
the results of the following comparisons could be different:
<code><font color='blue'><pre style='display:inline'> 
	if( Type(0) &gt; x ) 
	while(term &gt; epsilon)
</pre></font></code>

This in turn would result in a different operation sequence.
Thus the operation sequence above only corresponds to 
<a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

for values of <i>x</i> and <i>epsilon</i> within a certain range.
Note that there is a neighborhood
of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>

 for which the comparisons would have the 
same result and hence the operation sequence would be the same.



<br/>
<br/>
<b><big><a name="3.3.3.e" id="3.3.3.e">3.3.3.e: Verification</a></big></b>
<br/>
The file <a href="#3.3.3.1">3.3.3.1: <span style='white-space: nowrap'>exp_eps_for0.cpp</span></a>
 contains a routine 
that verifies the values computed above.
It returns true for success and false for failure.

<br/>
<br/>
<b><big><a name="3.3.3.f" id="3.3.3.f">3.3.3.f: Exercises</a></big></b>

<ol type="1"><li>
Suppose that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

,
what is the result of a zero order forward sweep for 
the operation sequence above; 
i.e., what are the corresponding values for

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

.
</li><li>

Create a modified version of 
<a href="#3.3.3.1">3.3.3.1: <span style='white-space: nowrap'>exp_eps_for0.cpp</span></a>
 that verifies the values you obtained
for the previous exercise.
</li><li>

Create and run a main program that reports the result of calling 
the modified version 
of <a href="#3.3.3.1">3.3.3.1: <span style='white-space: nowrap'>exp_eps_for0.cpp</span></a>
 in the previous exercise.
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_eps.omh

<hr/>




<center><b><big><big><a name="3.3.3.1" id="3.3.3.1">3.3.3.1: exp_eps: Verify Zero Order Forward Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cmath&gt;                // for fabs function
bool exp_eps_for0(double *v0)    // double v0[8]
{	bool  ok = true;
	double x = .5;

	v0[1] = x;                                  // abs_x = x;
	ok  &amp;= std::fabs( v0[1] - 0.5) &lt; 1e-10;

	v0[2] = 1. * v0[1];                         // temp = term * abs_x;
	ok  &amp;= std::fabs( v0[2] - 0.5) &lt; 1e-10;

	v0[3] = v0[2] / 1.;                         // term = temp / Type(k);
	ok  &amp;= std::fabs( v0[3] - 0.5) &lt; 1e-10;

	v0[4] = 1. + v0[3];                         // sum = sum + term;
	ok  &amp;= std::fabs( v0[4] - 1.5) &lt; 1e-10;

	v0[5] = v0[3] * v0[1];                      // temp = term * abs_x;
	ok  &amp;= std::fabs( v0[5] - 0.25) &lt; 1e-10;

	v0[6] = v0[5] / 2.;                         // term = temp / Type(k);
	ok  &amp;= std::fabs( v0[6] - 0.125) &lt; 1e-10;

	v0[7] = v0[4] + v0[6];                      // sum = sum + term;
	ok  &amp;= std::fabs( v0[7] - 1.625) &lt; 1e-10;

	return ok;
}
bool exp_eps_for0(void)
{	double v0[8];
	return exp_eps_for0(v0);
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_eps_for0.cpp

<hr/>



<center><b><big><big><a name="3.3.4" id="3.3.4">3.3.4: exp_eps: First Order Forward Sweep</a>
</big></big></b></center>
<br/>
<b><big><a name="3.3.4.a" id="3.3.4.a">3.3.4.a: First Order Expansion</a></big></b>



<br/>
We define 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

 near 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

 
by the first order expansions

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
</mtd></mtr><mtr><mtd columnalign="right" >
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
</mtd></mtr></mtable>
</mrow></math>

It follows that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

 (
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

) is the zero,
and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

  (
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

) the first,
order derivative of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow></math>


at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

 (
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow></math>

)
at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

.

<br/>
<br/>
<b><big><a name="3.3.4.b" id="3.3.4.b">3.3.4.b: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

to compute <code><font color="blue"><span style='white-space: nowrap'>exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
with <i>x</i> is equal to .5
and <i>epsilon</i> is equal to .2. 
For this case, the mathematical function for the operation sequence
corresponding to <code><font color="blue">exp_eps</font></code> is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

The corresponding partial derivative with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
and the value of the derivative, are

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</msub>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mrow></math>

<br/>
<b><big><a name="3.3.4.c" id="3.3.4.c">3.3.4.c: Operation Sequence</a></big></b>


<br/>
<br/>
<b><a name="3.3.4.c.a" id="3.3.4.c.a">3.3.4.c.a: Index</a></b>
<br/>
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.

<br/>
<br/>
<b><a name="3.3.4.c.b" id="3.3.4.c.b">3.3.4.c.b: Operation</a></b>
<br/>
The Operation column contains the 
mathematical function corresponding to each atomic operation in the sequence.

<br/>
<br/>
<b><a name="3.3.4.c.c" id="3.3.4.c.c">3.3.4.c.c: Zero Order</a></b>
<br/>
The Zero Order column contains the zero order derivatives
for the corresponding variable in the operation sequence
(see <a href="#3.2.4.d.f">3.2.4.d.f: <span style='white-space: nowrap'>zero&#xA0;order&#xA0;sweep</span></a>
).

<br/>
<br/>
<b><a name="3.3.4.c.d" id="3.3.4.c.d">3.3.4.c.d: Derivative</a></b>
<br/>
The Derivative column contains the
mathematical function corresponding to the derivative
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
</mrow></math>

,
at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

, for each variable in the sequence.

<br/>
<br/>
<b><a name="3.3.4.c.e" id="3.3.4.c.e">3.3.4.c.e: First Order</a></b>
<br/>
The First Order column contains the first order derivatives
for the corresponding variable in the operation sequence; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>j</mi>
</msub>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>j</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>j</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mi mathvariant='italic'>t</mi>
</mrow></math>

We use 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

,
so that differentiation with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
</mrow></math>

,
at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

, 
is the same partial differentiation with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

 
at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

.


<br/>
<br/>
<b><a name="3.3.4.c.f" id="3.3.4.c.f">3.3.4.c.f: Sweep</a></b>


<center>
<table><tr><td align='left'  valign='top'>

<b>Index</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Operation</b> 
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Zero Order</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Derivative</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>First Order</b>
</td></tr><tr><td align='left'  valign='top'>

1
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<mi mathvariant='italic'>x</mi>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
  
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

2
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

3
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>1</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>1</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

4
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

5
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.25
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

6
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.125
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>


</td></tr><tr><td align='left'  valign='top'>

7
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.625
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mrow></math>


</td></tr>
</table>
</center><b><big><a name="3.3.4.d" id="3.3.4.d">3.3.4.d: Return Value</a></big></b>
<br/>
The derivative of the return value for this case is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mn>1.5</mn>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msub><mrow><mo stretchy="true">[</mo><mrow><mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>t</mi>
</mrow>
</mfrac>
</mrow><mo stretchy="true">]</mo></mrow>
<mrow><mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
</msub>
<mo stretchy="false">=</mo>
<msub><mrow><mo stretchy="true">[</mo><mrow><mfrac><mrow><mo stretchy="false">&#x02202;</mo>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>t</mi>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">,</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mrow><mo stretchy="true">]</mo></mrow>
<mrow><mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</msub>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">,</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</msub>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">,</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mtd></mtr></mtable>
</mrow></math>

(We have used the fact that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

.)



<br/>
<br/>
<b><big><a name="3.3.4.e" id="3.3.4.e">3.3.4.e: Verification</a></big></b>
<br/>
The file <a href="#3.3.4.1">3.3.4.1: <span style='white-space: nowrap'>exp_eps_for1.cpp</span></a>
 contains a routine 
that verifies the values computed above.
It returns true for success and false for failure.

<br/>
<br/>
<b><big><a name="3.3.4.f" id="3.3.4.f">3.3.4.f: Exercises</a></big></b>

<ol type="1"><li>
Suppose that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

,
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 xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x022EF;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x022EF;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 ?
</li><li>

Create a modified version of <a href="#3.3.4.1">3.3.4.1: <span style='white-space: nowrap'>exp_eps_for1.cpp</span></a>
 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
<a href="#3.3.4.1">3.3.4.1: <span style='white-space: nowrap'>exp_eps_for1.cpp</span></a>
.
</li><li>

Suppose that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x02208;</mi>
<mo stretchy="false">=</mo>
<mn>.2</mn>
</mrow></math>

,
what is the operation sequence corresponding to 
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code></li></ol>

<hr/>Input File: introduction/exp_apx/exp_eps.omh

<hr/>



<center><b><big><big><a name="3.3.4.1" id="3.3.4.1">3.3.4.1: exp_eps: Verify First Order Forward Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cmath&gt;                     // for fabs function
extern bool exp_eps_for0(double *v0); // computes zero order forward sweep
bool exp_eps_for1(double *v1)         // double v[8]
{	bool ok = true;
	double v0[8];

	// set the value of v0[j] for j = 1 , ... , 7
	ok &amp;= exp_eps_for0(v0);

	v1[1] = 1.;                                      // v1 = x
	ok    &amp;= std::fabs( v1[1] - 1. ) &lt;= 1e-10;

	v1[2] = 1. * v1[1];                              // v2 = 1 * v1
	ok    &amp;= std::fabs( v1[2] - 1. ) &lt;= 1e-10;

	v1[3] = v1[2] / 1.;                              // v3 = v2 / 1
	ok    &amp;= std::fabs( v1[3] - 1. ) &lt;= 1e-10;

	v1[4] = v1[3];                                   // v4 = 1 + v3
	ok    &amp;= std::fabs( v1[4] - 1. ) &lt;= 1e-10;

	v1[5] = v1[3] * v0[1] + v0[3] * v1[1];           // v5 = v3 * v1
	ok    &amp;= std::fabs( v1[5] - 1. ) &lt;= 1e-10;

	v1[6] = v1[5] / 2.;                              // v6 = v5 / 2
	ok    &amp;= std::fabs( v1[6] - 0.5 ) &lt;= 1e-10;

	v1[7] = v1[4] + v1[6];                           // v7 = v4 + v6
	ok    &amp;= std::fabs( v1[7] - 1.5 ) &lt;= 1e-10;

	return ok;
}
bool exp_eps_for1(void)
{	double v1[8];
	return exp_eps_for1(v1);
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_eps_for1.cpp

<hr/>
<center><b><big><big><a name="3.3.5" id="3.3.5">3.3.5: exp_eps: First Order Reverse Sweep</a>
</big></big></b></center>
<br/>
<b><big><a name="3.3.5.a" id="3.3.5.a">3.3.5.a: Purpose</a></big></b>
<br/>
First order reverse mode uses the 
<a href="#3.3.3.b">3.3.3.b: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>
,
and zero order forward sweep values,
to compute the first order derivative
of one dependent variable with respect to all the independent variables. 
The computations are done in reverse 
of the order of the computations in the original algorithm.

<br/>
<br/>
<b><big><a name="3.3.5.b" id="3.3.5.b">3.3.5.b: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

to compute <code><font color="blue"><span style='white-space: nowrap'>exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
with <i>x</i> is equal to .5
and <i>epsilon</i> is equal to .2. 
For this case, the mathematical function for the operation sequence
corresponding to <code><font color="blue">exp_eps</font></code> is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

The corresponding partial derivatives,
and the value of the derivatives, are

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</msub>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
</msub>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>0</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.5.c" id="3.3.5.c">3.3.5.c: epsilon</a></big></b>
<br/>
Since 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
</mrow></math>

 is an independent variable,
it could included as an argument to all of the

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 functions below.
The result would be that all the partials with respect to 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
</mrow></math>

 would be zero and hence we drop it to simplify
the presentation.

<br/>
<br/>
<b><big><a name="3.3.5.d" id="3.3.5.d">3.3.5.d: f_7</a></big></b>
<br/>
In reverse mode we choose one dependent variable and
compute its derivative with respect to all the independent variables.
For our example, we chose the value returned by <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

which is 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow></math>

.
We begin with the function 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow></math>

 where 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow></math>

 
is both an argument and the value of the function; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.3.5.e" id="3.3.5.e">3.3.5.e: Index 7: f_6</a></big></b>
<br/>
The last operation has index 7, 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow></math>

 is eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.3.5.f" id="3.3.5.f">3.3.5.f: Index 6: f_5</a></big></b>
<br/>
The previous operation has index 6, 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow></math>

 is eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.3.5.g" id="3.3.5.g">3.3.5.g: Index 5: f_4</a></big></b>
<br/>
The previous operation has index 5,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow></math>

 is eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

Given the information from the forward sweep, we have

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>

.
It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.5.h" id="3.3.5.h">3.3.5.h: Index 4: f_3</a></big></b>
<br/>
The previous operation has index 4,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow></math>

 is eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1.25</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.5.i" id="3.3.5.i">3.3.5.i: Index 3: f_2</a></big></b>
<br/>
The previous operation has index 3,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">/</mo>
<mn>1</mn>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow></math>

 is eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1.25</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.5.j" id="3.3.5.j">3.3.5.j: Index 2: f_1</a></big></b>
<br/>
The previous operation has index 1,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">*</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">)</mo>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow></math>

 is eliminated using this operation; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">[</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">,</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">(</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mtd></mtr></mtable>
</mrow></math>

Note that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

 is equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
so the derivative of <code><font color="blue"><span style='white-space: nowrap'>exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code> 
at <i>x</i> equal to .5 and <i>epsilon</i> equal .2 is
1.5 in the <i>x</i> direction and zero in the <i>epsilon</i> direction.
We also note that 
<a href="#3.3.4">3.3.4: <span style='white-space: nowrap'>forward</span></a>
 forward mode gave the 
same result for the partial in the <i>x</i> direction.




<br/>
<br/>
<b><big><a name="3.3.5.k" id="3.3.5.k">3.3.5.k: Verification</a></big></b>
<br/>
The file <a href="#3.3.5.1">3.3.5.1: <span style='white-space: nowrap'>exp_eps_rev1.cpp</span></a>
 contains a routine 
that verifies the values computed above.
It returns true for success and false for failure.
It only tests the partial derivatives of

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 that might not be equal to the corresponding
partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow>
</msub>
</mrow></math>

; i.e., the
other partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 must be equal to the corresponding
partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow>
</msub>
</mrow></math>

.

<br/>
<br/>
<b><big><a name="3.3.5.l" id="3.3.5.l">3.3.5.l: Exercises</a></big></b>

<ol type="1"><li>
Consider the case where 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>


and we first preform a zero order forward mode sweep
for the operation sequence used above (in reverse order).
What are the results of a 
first order reverse mode sweep; i.e.,
what are the corresponding values for 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>k</mi>
</msub>
</mrow>
</mfrac>
</mrow></math>

 for all 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>j</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>k</mi>
</mrow></math>

 such that

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>k</mi>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">&#x02260;</mo>
<mn>0</mn>
</mrow></math>

.
</li><li>

Create a modified version of 
<a href="#3.3.5.1">3.3.5.1: <span style='white-space: nowrap'>exp_eps_rev1.cpp</span></a>
 
that verifies the values you obtained for the previous exercise.
Also create and run a main program that reports the result
of calling the modified version of
<a href="#3.3.5.1">3.3.5.1: <span style='white-space: nowrap'>exp_eps_rev1.cpp</span></a>
.
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_eps.omh

<hr/>



<center><b><big><big><a name="3.3.5.1" id="3.3.5.1">3.3.5.1: exp_eps: Verify First Order Reverse Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cstddef&gt;                     // define size_t
# include &lt;cmath&gt;                       // for fabs function
extern bool exp_eps_for0(double *v0);   // computes zero order forward sweep
bool exp_eps_rev1(void)
{	bool ok = true;

	// set the value of v0[j] for j = 1 , ... , 7
	double v0[8];
	ok &amp;= exp_eps_for0(v0);

	// initial all partial derivatives as zero
	double f_v[8];
	size_t j;
	for(j = 0; j &lt; 8; j++)
		f_v[j] = 0.;

	// set partial derivative for f7
	f_v[7] = 1.;
	ok    &amp;= std::fabs( f_v[7] - 1. ) &lt;= 1e-10;     // f7_v7

	// f6( v1 , v2 , v3 , v4 , v5 , v6 )
	f_v[4] += f_v[7] * 1.;
	f_v[6] += f_v[7] * 1.;
	ok     &amp;= std::fabs( f_v[4] - 1.  ) &lt;= 1e-10;   // f6_v4
	ok     &amp;= std::fabs( f_v[6] - 1.  ) &lt;= 1e-10;   // f6_v6

	// f5( v1 , v2 , v3 , v4 , v5 )
	f_v[5] += f_v[6] / 2.;
	ok     &amp;= std::fabs( f_v[5] - 0.5 ) &lt;= 1e-10;   // f5_v5

	// f4( v1 , v2 , v3 , v4 )
	f_v[1] += f_v[5] * v0[3];
	f_v[3] += f_v[5] * v0[1];
	ok     &amp;= std::fabs( f_v[1] - 0.25) &lt;= 1e-10;   // f4_v1
	ok     &amp;= std::fabs( f_v[3] - 0.25) &lt;= 1e-10;   // f4_v3

	// f3( v1 , v2 , v3 )
	f_v[3] += f_v[4] * 1.;
	ok     &amp;= std::fabs( f_v[3] - 1.25) &lt;= 1e-10;   // f3_v3

	// f2( v1 , v2 )
	f_v[2] += f_v[3] / 1.;
	ok     &amp;= std::fabs( f_v[2] - 1.25) &lt;= 1e-10;   // f2_v2

	// f1( v1 )
	f_v[1] += f_v[2] * 1.;
	ok     &amp;= std::fabs( f_v[1] - 1.5 ) &lt;= 1e-10;   // f1_v2

	return ok;
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_eps_rev1.cpp

<hr/>



<center><b><big><big><a name="3.3.6" id="3.3.6">3.3.6: exp_eps: Second Order Forward Mode</a>
</big></big></b></center>
<br/>
<b><big><a name="3.3.6.a" id="3.3.6.a">3.3.6.a: Second Order Expansion</a></big></b>



<br/>
We define 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">]</mo>
</mrow></math>

 near 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

 
by the second order expansions

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>t</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>t</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mtd></mtr></mtable>
</mrow></math>

It follows that for 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mn>2</mn>
</mrow></math>

,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><msup><mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>d</mi>
</mstyle></mrow>
<mrow><mi mathvariant='italic'>k</mi>
</mrow>
</msup>
</mrow>
<mrow><mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>d</mi>
</mstyle></mrow>
<mspace width='.18em'/>
<msup><mrow><mi mathvariant='italic'>t</mi>
</mrow>
<mrow><mi mathvariant='italic'>k</mi>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mtd></mtr><mtr><mtd columnalign="right" >
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><msup><mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>d</mi>
</mstyle></mrow>
<mrow><mi mathvariant='italic'>k</mi>
</mrow>
</msup>
</mrow>
<mrow><mrow><mstyle mathvariant='normal'><mi mathvariant='normal'>d</mi>
</mstyle></mrow>
<mspace width='.18em'/>
<msup><mrow><mi mathvariant='italic'>t</mi>
</mrow>
<mrow><mi mathvariant='italic'>k</mi>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.6.b" id="3.3.6.b">3.3.6.b: Purpose</a></big></b>
<br/>
In general, a second order forward sweep is given the
<a href="#3.2.4.a">3.2.4.a: <span style='white-space: nowrap'>first&#xA0;order&#xA0;expansion</span></a>

for all of the variables in an operation sequence,
and the second order derivatives for the independent variables.
It uses these to compute the second order derivative,
and thereby obtain the second order expansion,
for all the variables in the operation sequence.

<br/>
<br/>
<b><big><a name="3.3.6.c" id="3.3.6.c">3.3.6.c: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

to compute <code><font color="blue"><span style='white-space: nowrap'>exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
with <i>x</i> is equal to .5
and <i>epsilon</i> is equal to .2. 
For this case, the mathematical function for the operation sequence
corresponding to <code><font color="blue">exp_eps</font></code> is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

The corresponding second partial derivative with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
and the value of the derivative, are

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1.</mn>
</mrow></math>

<br/>
<b><big><a name="3.3.6.d" id="3.3.6.d">3.3.6.d: Operation Sequence</a></big></b>


<br/>
<br/>
<b><a name="3.3.6.d.a" id="3.3.6.d.a">3.3.6.d.a: Index</a></b>
<br/>
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.

<br/>
<br/>
<b><a name="3.3.6.d.b" id="3.3.6.d.b">3.3.6.d.b: Zero</a></b>
<br/>
The Zero column contains the zero order sweep results
for the corresponding variable in the operation sequence
(see <a href="#3.2.3.c.e">3.2.3.c.e: <span style='white-space: nowrap'>zero&#xA0;order&#xA0;sweep</span></a>
).

<br/>
<br/>
<b><a name="3.3.6.d.c" id="3.3.6.d.c">3.3.6.d.c: Operation</a></b>
<br/>
The Operation column contains the 
first order sweep operation for this variable.

<br/>
<br/>
<b><a name="3.3.6.d.d" id="3.3.6.d.d">3.3.6.d.d: First</a></b>
<br/>
The First column contains the first order sweep results
for the corresponding variable in the operation sequence
(see <a href="#3.2.4.d.f">3.2.4.d.f: <span style='white-space: nowrap'>first&#xA0;order&#xA0;sweep</span></a>
).

<br/>
<br/>
<b><a name="3.3.6.d.e" id="3.3.6.d.e">3.3.6.d.e: Derivative</a></b>
<br/>
The Derivative column contains the
mathematical function corresponding to the second derivative
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
</mrow></math>

,
at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

, for each variable in the sequence.

<br/>
<br/>
<b><a name="3.3.6.d.f" id="3.3.6.d.f">3.3.6.d.f: Second</a></b>
<br/>
The Second column contains the second order derivatives
for the corresponding variable in the operation sequence; i.e.,
the second order expansion for the <i>i</i>-th variable is given by

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
</msub>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>t</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

We use 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

, 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

,
use 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

, and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>


so that second order differentiation
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
</mrow></math>

, at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

, 
is the same as the second partial differentiation 
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

 at 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>

.


<br/>
<br/>
<b><a name="3.3.6.d.g" id="3.3.6.d.g">3.3.6.d.g: Sweep</a></b>


<center>
<table><tr><td align='left'  valign='top'>

<b>Index</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Zero</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Operation</b> 
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>First</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Derivative</b>
	</td><td align='left'  valign='top'>
 <code><span style='white-space: nowrap'>&#xA0;&#xA0;</span></code> </td><td align='left'  valign='top'>
 <b>Second</b>
</td></tr><tr><td align='left'  valign='top'>

1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0
</td></tr><tr><td align='left'  valign='top'>

2
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0
</td></tr><tr><td align='left'  valign='top'>

3
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>1</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>1</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0
</td></tr><tr><td align='left'  valign='top'>

4
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0
</td></tr><tr><td align='left'  valign='top'>

5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.25
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<mn>2</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 2
</td></tr><tr><td align='left'  valign='top'>

6
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.125
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 0.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
</td></tr><tr><td align='left'  valign='top'>

7
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.625
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 
	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1.5
	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>

	
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>


	</td><td align='left'  valign='top'>
 </td><td align='left'  valign='top'>
 1
</td></tr>
</table>
</center><b><big><a name="3.3.6.e" id="3.3.6.e">3.3.6.e: Return Value</a></big></b>
<br/>
The second derivative of the return value for this case is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mn>1</mn>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msub><mrow><mo stretchy="true">[</mo><mrow><mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>t</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow><mo stretchy="true">]</mo></mrow>
<mrow><mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
</msub>
<mo stretchy="false">=</mo>
<msub><mrow><mo stretchy="true">[</mo><mrow><mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>t</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mi mathvariant='italic'>t</mi>
<mo stretchy="false">,</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mrow><mo stretchy="true">]</mo></mrow>
<mrow><mi mathvariant='italic'>t</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow>
</msub>
</mtd></mtr><mtr><mtd columnalign="right" >
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">*</mo>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">,</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
<mo stretchy="false">*</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">,</mo>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mtd></mtr></mtable>
</mrow></math>

(We have used the fact that

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

, 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='italic'>x</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

, and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msup><mi mathvariant='normal'>&#x003B5;</mi>
<mrow><mo stretchy="false">(</mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
</mrow>
</msup>
<mo stretchy="false">=</mo>
<mn>0</mn>
</mrow></math>

.)


<br/>
<br/>
<b><big><a name="3.3.6.f" id="3.3.6.f">3.3.6.f: Verification</a></big></b>
<br/>
The file <a href="#3.3.6.1">3.3.6.1: <span style='white-space: nowrap'>exp_eps_for2.cpp</span></a>
 contains a routine 
which verifies the values computed above.
It returns true for success and false for failure.

<br/>
<br/>
<b><big><a name="3.3.6.g" id="3.3.6.g">3.3.6.g: Exercises</a></big></b>

<ol type="1"><li>
Which statement in the routine defined by <a href="#3.3.6.1">3.3.6.1: <span style='white-space: nowrap'>exp_eps_for2.cpp</span></a>
 uses 
the values that are calculated by the routine 
defined by <a href="#3.3.4.1">3.3.4.1: <span style='white-space: nowrap'>exp_eps_for1.cpp</span></a>
 ?
</li><li>

Suppose that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

,
what are the results of a zero, first, and second order forward sweep for 
the operation sequence above; 
i.e., what are the corresponding values for

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>i</mi>
<mrow><mo stretchy="false">(</mo>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 for 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>i</mi>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<mn>7</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>k</mi>
<mo stretchy="false">=</mo>
<mn>0</mn>
<mo stretchy="false">,</mo>
<mn>1</mn>
<mo stretchy="false">,</mo>
<mn>2</mn>
</mrow></math>

.
</li><li>

Create a modified version of <a href="#3.3.6.1">3.3.6.1: <span style='white-space: nowrap'>exp_eps_for2.cpp</span></a>
 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
<a href="#3.3.6.1">3.3.6.1: <span style='white-space: nowrap'>exp_eps_for2.cpp</span></a>
.
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_eps.omh

<hr/>



<center><b><big><big><a name="3.3.6.1" id="3.3.6.1">3.3.6.1: exp_eps: Verify Second Order Forward Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cmath&gt;                     // for fabs function
extern bool exp_eps_for0(double *v0); // computes zero order forward sweep
extern bool exp_eps_for1(double *v1); // computes first order forward sweep
bool exp_eps_for2(void)
{	bool ok = true;
	double v0[8], v1[8], v2[8];

	// set the value of v0[j], v1[j] for j = 1 , ... , 7
	ok &amp;= exp_eps_for0(v0);
	ok &amp;= exp_eps_for1(v1);

	v2[1] = 0.;                                      // v1 = x
	ok    &amp;= std::fabs( v2[1] - 0. ) &lt;= 1e-10;

	v2[2] = 1. * v2[1];                              // v2 = 1 * v1
	ok    &amp;= std::fabs( v2[2] - 0. ) &lt;= 1e-10;

	v2[3] = v2[2] / 1.;                              // v3 = v2 / 1
	ok    &amp;= std::fabs( v2[3] - 0. ) &lt;= 1e-10;

	v2[4] = v2[3];                                   // v4 = 1 + v3
	ok    &amp;= std::fabs( v2[4] - 0. ) &lt;= 1e-10;

	v2[5] = v2[3] * v0[1] + 2. * v1[3] * v1[1]       // v5 = v3 * v1
	      + v0[3] * v2[1];           
	ok    &amp;= std::fabs( v2[5] - 2. ) &lt;= 1e-10;

	v2[6] = v2[5] / 2.;                              // v6 = v5 / 2
	ok    &amp;= std::fabs( v2[6] - 1. ) &lt;= 1e-10;

	v2[7] = v2[4] + v2[6];                           // v7 = v4 + v6
	ok    &amp;= std::fabs( v2[7] - 1. ) &lt;= 1e-10;

	return ok;
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_eps_for2.cpp

<hr/>



<center><b><big><big><a name="3.3.7" id="3.3.7">3.3.7: exp_eps: Second Order Reverse Sweep</a>
</big></big></b></center>
<br/>
<b><big><a name="3.3.7.a" id="3.3.7.a">3.3.7.a: Purpose</a></big></b>
<br/>
In general, a second order reverse sweep is given the
<a href="#3.3.4.a">3.3.4.a: <span style='white-space: nowrap'>first&#xA0;order&#xA0;expansion</span></a>

for all of the variables in an operation sequence.
Given a choice of a particular variable, 
it computes the derivative, 
of that variables first order expansion coefficient, 
with respect to all of the independent variables.

<br/>
<br/>
<b><big><a name="3.3.7.b" id="3.3.7.b">3.3.7.b: Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

to compute <code><font color="blue"><span style='white-space: nowrap'>exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
with <i>x</i> is equal to .5
and <i>epsilon</i> is equal to .2. 
For this case, the mathematical function for the operation sequence
corresponding to <code><font color="blue">exp_eps</font></code> is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">+</mo>
<msup><mi mathvariant='italic'>x</mi>
<mn>2</mn>
</msup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mrow></math>

The corresponding derivative of the
partial derivative with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

 is

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
</msub>
<msub><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</msub>
<mi mathvariant='italic'>f</mi>
<mo stretchy="false">(</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">)</mo>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>0</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.7.c" id="3.3.7.c">3.3.7.c: epsilon</a></big></b>
<br/>
Since 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
</mrow></math>

 is an independent variable,
it could included as an argument to all of the

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 functions below.
The result would be that all the partials with respect to 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
</mrow></math>

 would be zero and hence we drop it to simplify
the presentation.

<br/>
<br/>
<b><big><a name="3.3.7.d" id="3.3.7.d">3.3.7.d: f_7</a></big></b>
<br/>
In reverse mode we choose one dependent variable and
compute its derivative with respect to all the independent variables.
For our example, we chose the value returned by <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>

which is 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow></math>

.
We begin with the function 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow></math>

 where 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>7</mn>
</msub>
</mrow></math>

 
is both an argument and the value of the function; i.e.,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.3.7.e" id="3.3.7.e">3.3.7.e: Index 7: f_6</a></big></b>
<br/>
The last operation has index 7,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 are eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>7</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.3.7.f" id="3.3.7.f">3.3.7.f: Index 6: f_5</a></big></b>
<br/>
The previous operation has index 6, 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>2</mn>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 are eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mn>5</mn>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>6</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>6</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.3.7.g" id="3.3.7.g">3.3.7.g: Index 5: f_4</a></big></b>
<br/>
The previous operation has index 5,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 are eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

Given the information from the forward sweep, we have

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>

,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mrow></math>

,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

,
and the fact that the partial of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>

 with respect to

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 is zero, we have

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>5</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

All the other partial derivatives of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>5</mn>
</msub>
</mrow></math>

 are zero.

<br/>
<br/>
<b><big><a name="3.3.7.h" id="3.3.7.h">3.3.7.h: Index 4: f_3</a></big></b>
<br/>
The previous operation has index 4,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 are eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>4</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>4</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1.25</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.7.i" id="3.3.7.i">3.3.7.i: Index 3: f_2</a></big></b>
<br/>
The previous operation has index 3,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">/</mo>
<mn>1</mn>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 are eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<mo stretchy="false">&#x02026;</mo>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.25</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>0.5</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>3</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>3</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1.25</mn>
</mtd></mtr></mtable>
</mrow></math>

<br/>
<b><big><a name="3.3.7.j" id="3.3.7.j">3.3.7.j: Index 2: f_1</a></big></b>
<br/>
The previous operation has index 1,

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr><mtr><mtd columnalign="right" >
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mn>1</mn>
<mo stretchy="false">*</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mtd></mtr></mtable>
</mrow></math>

We define the function 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow></math>


as equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow></math>


except that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow></math>

 are eliminated using 
this operation; i.e.

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
<mo stretchy="false">=</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
<mrow><mo stretchy="true">[</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
<mo stretchy="false">,</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mrow><mo stretchy="true">(</mo><mrow><msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow><mo stretchy="true">)</mo></mrow>
</mrow><mo stretchy="true">]</mo></mrow>
</mrow></math>

It follows that 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mtable rowalign="center" ><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1</mn>
</mtd></mtr><mtr><mtd columnalign="right" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="center" >
<mo stretchy="false">=</mo>
</mtd><mtd columnalign="left" >
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">+</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>2</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">*</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>2</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
</mtd><mtd columnalign="left" >
<mo stretchy="false">=</mo>
<mn>1.5</mn>
</mtd></mtr></mtable>
</mrow></math>

Note that 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>v</mi>
<mn>1</mn>
</msub>
</mrow></math>

 is equal to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
so the second partial derivative of 
<code><font color="blue"><span style='white-space: nowrap'>exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code> 
at <i>x</i> equal to .5 and <i>epsilon</i> equal .2 is 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mfrac><mrow><msup><mo stretchy="false">&#x02202;</mo>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msup><mrow><mi mathvariant='italic'>x</mi>
</mrow>
<mrow><mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
<mo stretchy="false">=</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>7</mn>
<mrow><mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<mi mathvariant='italic'>x</mi>
</mrow>
</mfrac>
<mo stretchy="false">=</mo>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msubsup><mi mathvariant='italic'>v</mi>
<mn>1</mn>
<mrow><mo stretchy="false">(</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
</mrow>
</msubsup>
</mrow>
</mfrac>
<mo stretchy="false">=</mo>
<mn>1</mn>
</mrow></math>

There is a theorem about algorithmic differentiation that explains why
the other partial of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mn>1</mn>
</msub>
</mrow></math>

 is equal to the first partial of
<code><font color="blue"><span style='white-space: nowrap'>exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code> 
with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

.




<br/>
<br/>
<b><big><a name="3.3.7.k" id="3.3.7.k">3.3.7.k: Verification</a></big></b>
<br/>
The file <a href="#3.3.7.1">3.3.7.1: <span style='white-space: nowrap'>exp_eps_rev2.cpp</span></a>
 contains a routine 
that verifies the values computed above.
It returns true for success and false for failure.
It only tests the partial derivatives of

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 that might not be equal to the corresponding
partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow>
</msub>
</mrow></math>

; i.e., the
other partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow></math>

 must be equal to the corresponding
partials of 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<msub><mi mathvariant='italic'>f</mi>
<mrow><mi mathvariant='italic'>j</mi>
<mo stretchy="false">+</mo>
<mn>1</mn>
</mrow>
</msub>
</mrow></math>

.

<br/>
<br/>
<b><big><a name="3.3.7.l" id="3.3.7.l">3.3.7.l: Exercises</a></big></b>

<ol type="1"><li>
Consider the case where 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>


and we first preform a zero order forward mode sweep
for the operation sequence used above (in reverse order).
What are the results of a 
first order reverse mode sweep; i.e.,
what are the corresponding values for 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>k</mi>
</msub>
</mrow>
</mfrac>
</mrow></math>

 for all 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>j</mi>
<mo stretchy="false">,</mo>
<mi mathvariant='italic'>k</mi>
</mrow></math>

 such that

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mfrac><mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>f</mi>
<mi mathvariant='italic'>j</mi>
</msub>
</mrow>
<mrow><mo stretchy="false">&#x02202;</mo>
<msub><mi mathvariant='italic'>v</mi>
<mi mathvariant='italic'>k</mi>
</msub>
</mrow>
</mfrac>
<mo stretchy="false">&#x02260;</mo>
<mn>0</mn>
</mrow></math>

.
</li><li>

Create a modified version of 
<a href="#3.3.7.1">3.3.7.1: <span style='white-space: nowrap'>exp_eps_rev2.cpp</span></a>
 
that verifies the values you obtained for the previous exercise.
Also create and run a main program that reports the result
of calling the modified version of
<a href="#3.3.7.1">3.3.7.1: <span style='white-space: nowrap'>exp_eps_rev2.cpp</span></a>
.
</li></ol>



<hr/>Input File: introduction/exp_apx/exp_eps.omh

<hr/>



<center><b><big><big><a name="3.3.7.1" id="3.3.7.1">3.3.7.1: exp_eps: Verify Second Order Reverse Sweep</a>
</big></big></b></center>
<code><font color='blue'><pre style='display:inline'> # include &lt;cstddef&gt;                     // define size_t
# include &lt;cmath&gt;                       // for fabs function
extern bool exp_eps_for0(double *v0);   // computes zero order forward sweep
extern bool exp_eps_for1(double *v1);   // computes first order forward sweep
bool exp_eps_rev2(void)
{	bool ok = true;

	// set the value of v0[j], v1[j] for j = 1 , ... , 7
	double v0[8], v1[8];
	ok &amp;= exp_eps_for0(v0);
	ok &amp;= exp_eps_for1(v1);

	// initial all partial derivatives as zero
	double f_v0[8], f_v1[8];
	size_t j;
	for(j = 0; j &lt; 8; j++)
	{	f_v0[j] = 0.;
		f_v1[j] = 0.;
	}

	// set partial derivative for f_7
	f_v1[7] = 1.;
	ok &amp;= std::fabs( f_v1[7] - 1.  ) &lt;= 1e-10; // partial f_7 w.r.t. v_7^1

	// f_6 = f_7( v_1^0 , ... , v_6^1 , v_4^0 + v_6^0, v_4^1 , v_6^1 )
	f_v0[4] += f_v0[7];
	f_v0[6] += f_v0[7];
	f_v1[4] += f_v1[7];
	f_v1[6] += f_v1[7];
	ok &amp;= std::fabs( f_v0[4] - 0.  ) &lt;= 1e-10; // partial f_6 w.r.t. v_4^0
	ok &amp;= std::fabs( f_v0[6] - 0.  ) &lt;= 1e-10; // partial f_6 w.r.t. v_6^0
	ok &amp;= std::fabs( f_v1[4] - 1.  ) &lt;= 1e-10; // partial f_6 w.r.t. v_4^1
	ok &amp;= std::fabs( f_v1[6] - 1.  ) &lt;= 1e-10; // partial f_6 w.r.t. v_6^1

	// f_5 = f_6( v_1^0 , ... , v_5^1 , v_5^0 / 2 , v_5^1 / 2 )
	f_v0[5] += f_v0[6] / 2.;
	f_v1[5] += f_v1[6] / 2.;
	ok &amp;= std::fabs( f_v0[5] - 0.  ) &lt;= 1e-10; // partial f_5 w.r.t. v_5^0
	ok &amp;= std::fabs( f_v1[5] - 0.5 ) &lt;= 1e-10; // partial f_5 w.r.t. v_5^1

	// f_4 = f_5( v_1^0 , ... , v_4^1 , v_3^0 * v_1^0 , 
	//            v_3^1 * v_1^0 + v_3^0 * v_1^1 )
	f_v0[1] += f_v0[5] * v0[3] + f_v1[5] * v1[3];
	f_v0[3] += f_v0[5] * v0[1] + f_v1[5] * v1[1];
	f_v1[1] += f_v1[5] * v0[3];
	f_v1[3] += f_v1[5] * v0[1];
	ok &amp;= std::fabs( f_v0[1] - 0.5  ) &lt;= 1e-10; // partial f_4 w.r.t. v_1^0
	ok &amp;= std::fabs( f_v0[3] - 0.5  ) &lt;= 1e-10; // partial f_4 w.r.t. v_3^0
	ok &amp;= std::fabs( f_v1[1] - 0.25 ) &lt;= 1e-10; // partial f_4 w.r.t. v_1^1
	ok &amp;= std::fabs( f_v1[3] - 0.25 ) &lt;= 1e-10; // partial f_4 w.r.t. v_3^1

	// f_3 = f_4(  v_1^0 , ... , v_3^1 , 1 + v_3^0 , v_3^1 )
	f_v0[3] += f_v0[4];
	f_v1[3] += f_v1[4];
	ok &amp;= std::fabs( f_v0[3] - 0.5 ) &lt;= 1e-10;  // partial f_3 w.r.t. v_3^0
	ok &amp;= std::fabs( f_v1[3] - 1.25) &lt;= 1e-10;  // partial f_3 w.r.t. v_3^1

	// f_2 = f_3( v_1^0 , ... , v_2^1 , v_2^0 , v_2^1 )
	f_v0[2] += f_v0[3];
	f_v1[2] += f_v1[3];
	ok &amp;= std::fabs( f_v0[2] - 0.5 ) &lt;= 1e-10;  // partial f_2 w.r.t. v_2^0
	ok &amp;= std::fabs( f_v1[2] - 1.25) &lt;= 1e-10;  // partial f_2 w.r.t. v_2^1

	// f_1 = f_2 ( v_1^0 , v_2^0 , v_1^0 , v_2^0 )
	f_v0[1] += f_v0[2];
	f_v1[1] += f_v1[2];
	ok &amp;= std::fabs( f_v0[1] - 1.  ) &lt;= 1e-10;  // partial f_1 w.r.t. v_1^0
	ok &amp;= std::fabs( f_v1[1] - 1.5 ) &lt;= 1e-10;  // partial f_1 w.r.t. v_1^1

	return ok;
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_eps_rev2.cpp

<hr/>



<center><b><big><big><a name="3.3.8" id="3.3.8">3.3.8: exp_eps: CppAD Forward and Reverse Sweeps</a>
</big></big></b></center>
.

<br/>
<br/>
<b><big><a name="3.3.8.a" id="3.3.8.a">3.3.8.a: Purpose</a></big></b>
<br/>
Use CppAD forward and reverse modes to compute the
partial derivative with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">=</mo>
<mn>.2</mn>
</mrow></math>

,
of the function 
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>as defined by the <a href="#3.3.1">3.3.1: <span style='white-space: nowrap'>exp_eps.hpp</span></a>
 include file.

<br/>
<br/>
<b><big><a name="3.3.8.b" id="3.3.8.b">3.3.8.b: Exercises</a></big></b>

<ol type="1"><li>
Create and test a modified version of the routine below that computes
the same order derivatives with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">=</mo>
<mn>.2</mn>
</mrow></math>

,
of the function 
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;exp_eps(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code></li><li>
Create and test a modified version of the routine below that computes
partial derivative with respect to 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
</mrow></math>

,
at the point 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.1</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">=</mo>
<mn>.2</mn>
</mrow></math>

,
of the function corresponding to the operation sequence 
for 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">=</mo>
<mn>.5</mn>
</mrow></math>

 and 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='normal'>&#x003B5;</mi>
<mo stretchy="false">=</mo>
<mn>.2</mn>
</mrow></math>

.
Hint: you could define a vector u with two components and use
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'>.Forward(0,&#xA0;</span></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>to run zero order forward mode at a point different
form the point where the operation sequence corresponding to
<i>f</i> was recorded.
</li></ol>

<code><font color='blue'><pre style='display:inline'> 
# include &lt;cppad/cppad.hpp&gt;  // http://www.coin-or.org/CppAD/ 
# include &quot;exp_eps.hpp&quot;      // our example exponential function approximation
bool exp_eps_cppad(void)
{	bool ok = true;
	using CppAD::AD;
	using CppAD::vector;    // can use any simple vector template class
	using CppAD::NearEqual; // checks if values are nearly equal

	// domain space vector
	size_t n = 2; // dimension of the domain space
	vector&lt; <a href="#4">AD</a>&lt;double&gt; &gt; U(n);
	U[0] = .5;    // value of x for this operation sequence
	U[1] = .2;    // value of e for this operation sequence

	// declare independent variables and start recording operation sequence
	CppAD::<a href="#5.1">Independent</a>(U);

	// evaluate our exponential approximation
	<a href="#4">AD</a>&lt;double&gt; x       = U[0];
	<a href="#4">AD</a>&lt;double&gt; epsilon = U[1];
	<a href="#4">AD</a>&lt;double&gt; apx = exp_eps(x, epsilon);  

	// range space vector
	size_t m = 1;  // dimension of the range space
	vector&lt; <a href="#4">AD</a>&lt;double&gt; &gt; Y(m);
	Y[0] = apx;    // variable that represents only range space component

	// Create f: U -&gt; Y corresponding to this operation sequence
	// and stop recording. This also executes a zero order forward 
	// mode sweep using values in U for x and e.
	CppAD::<a href="#5.2">ADFun</a>&lt;double&gt; f(U, Y);

	// first order forward mode sweep that computes partial w.r.t x
	vector&lt;double&gt; du(n);      // differential in domain space
	vector&lt;double&gt; dy(m);      // differential in range space
	du[0] = 1.;                // x direction in domain space
	du[1] = 0.;
	dy    = f.<a href="#5.6.1">Forward</a>(1, du);  // partial w.r.t. x
	double check = 1.5;
	ok   &amp;= <a href="#6.2">NearEqual</a>(dy[0], check, 1e-10, 1e-10);

	// first order reverse mode sweep that computes the derivative
	vector&lt;double&gt;  w(m);     // weights for components of the range
	vector&lt;double&gt; dw(n);     // derivative of the weighted function
	w[0] = 1.;                // there is only one weight 
	dw   = f.<a href="#5.6.2">Reverse</a>(1, w);   // derivative of w[0] * exp_eps(x, epsilon)
	check = 1.5;              // partial w.r.t. x
	ok   &amp;= <a href="#6.2">NearEqual</a>(dw[0], check, 1e-10, 1e-10);
	check = 0.;               // partial w.r.t. epsilon
	ok   &amp;= <a href="#6.2">NearEqual</a>(dw[1], check, 1e-10, 1e-10);

	// second order forward sweep that computes
	// second partial of exp_eps(x, epsilon) w.r.t. x
	vector&lt;double&gt; x2(n);     // second order Taylor coefficients
	vector&lt;double&gt; y2(m);
	x2[0] = 0.;               // evaluate partial w.r.t x
	x2[1] = 0.;
	y2    = f.<a href="#5.6.1">Forward</a>(2, x2);
	check = 0.5 * 1.;         // Taylor coef is 1/2 second derivative
	ok   &amp;= <a href="#6.2">NearEqual</a>(y2[0], check, 1e-10, 1e-10);

	// second order reverse sweep that computes
	// derivative of partial of exp_eps(x, epsilon) w.r.t. x
	dw.resize(2 * n);         // space for first and second derivative
	dw    = f.<a href="#5.6.2">Reverse</a>(2, w);
	check = 1.;               // result should be second derivative
	ok   &amp;= <a href="#6.2">NearEqual</a>(dw[0*2+1], check, 1e-10, 1e-10);

	return ok;
}
</pre></font></code>


<hr/>Input File: introduction/exp_apx/exp_eps_cppad.cpp

<hr/>



<center><b><big><big><a name="3.4" id="3.4">3.4: Run the exp_2 and exp_eps Tests</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

// system include files used for I/O
# include &lt;iostream&gt;

// external complied tests
extern bool exp_2(void);
extern bool exp_2_cppad(void);
extern bool exp_2_for1(void);
extern bool exp_2_for2(void);
extern bool exp_2_rev1(void);
extern bool exp_2_rev2(void);
extern bool exp_2_for0(void);
extern bool exp_eps(void);
extern bool exp_eps_cppad(void);
extern bool exp_eps_for1(void);
extern bool exp_eps_for2(void);
extern bool exp_eps_for0(void);
extern bool exp_eps_rev1(void);
extern bool exp_eps_rev2(void);

namespace {
	static size_t Run_ok_count    = 0;
	static size_t Run_error_count = 0;
	bool Run(bool TestOk(void), std::string name)
	{	bool ok               = true;
		std::streamsize width =  20;         
		std::cout.width( width );
		std::cout.setf( std::ios_base::left );
		std::cout &lt;&lt; name.c_str();
		//
		ok &amp;= name.size() &lt; size_t(width);
		ok &amp;= TestOk();
		if( ok )
		{	std::cout &lt;&lt; &quot;OK&quot; &lt;&lt; std::endl;
			Run_ok_count++;
		}
		else
		{	std::cout &lt;&lt; &quot;Error&quot; &lt;&lt; std::endl;
			Run_error_count++;
		}
		return ok;
	}
}

// main program that runs all the tests
int main(void)
{	bool ok = true;
	using namespace std;

	// This comment is used by OneTest 

	// external compiled tests
	ok &amp;= Run( exp_2,           &quot;exp_2&quot;          );
	ok &amp;= Run( exp_2_cppad,     &quot;exp_2_cppad&quot;    );
	ok &amp;= Run( exp_2_for0,      &quot;exp_2_for0&quot;     );
	ok &amp;= Run( exp_2_for1,      &quot;exp_2_for1&quot;     );
	ok &amp;= Run( exp_2_for2,      &quot;exp_2_for2&quot;     );
	ok &amp;= Run( exp_2_rev1,      &quot;exp_2_rev1&quot;     );
	ok &amp;= Run( exp_2_rev2,      &quot;exp_2_rev2&quot;     );
	ok &amp;= Run( exp_eps,         &quot;exp_eps&quot;        );
	ok &amp;= Run( exp_eps_cppad,   &quot;exp_eps_cppad&quot;  );
	ok &amp;= Run( exp_eps_for0,    &quot;exp_eps_for0&quot;   );
	ok &amp;= Run( exp_eps_for1,    &quot;exp_eps_for1&quot;   );
	ok &amp;= Run( exp_eps_for2,    &quot;exp_eps_for2&quot;   );
	ok &amp;= Run( exp_eps_rev1,    &quot;exp_eps_rev1&quot;   );
	ok &amp;= Run( exp_eps_rev2,    &quot;exp_eps_rev2&quot;   );
	if( ok )
		cout &lt;&lt; &quot;All &quot; &lt;&lt; int(Run_ok_count) &lt;&lt; &quot; tests passed.&quot; &lt;&lt; endl;
	else	cout &lt;&lt; int(Run_error_count) &lt;&lt; &quot; tests failed.&quot; &lt;&lt; endl;

	return static_cast&lt;int&gt;( ! ok );
}</pre>
</font></code>


<hr/>Input File: introduction/exp_apx/main.cpp

<hr/>



<center><b><big><big><a name="4" id="4">4: AD Objects</a>
</big></big></b></center>
<br/>
<b><big><a name="4.a" id="4.a">4.a: Purpose</a></big></b>
<br/>
The sections listed below describe the operations 
that are available to <a href="#9.4.b">9.4.b: <span style='white-space: nowrap'>AD&#xA0;of&#xA0;Base</span></a>
 objects.
These objects are used to <a href="#9.4.j">9.4.j: <span style='white-space: nowrap'>tape</span></a>

an AD of <i>Base</i>
<a href="#9.4.g.b">9.4.g.b: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>
.
This operation sequence can
be transferred to an <a href="#5">5: <span style='white-space: nowrap'>ADFun</span></a>
 object where it
can be used to evaluate the corresponding 
function and derivative values.

<br/>
<br/>
<b><big><a name="4.b" id="4.b">4.b: Base Type Requirements</a></big></b>

<br/>
The <i>Base</i> requirements are provided by the CppAD package 
for the following base types:
<code><font color="blue">float</font></code>, 
<code><font color="blue">double</font></code>,
<code><font color="blue">std::complex&lt;float&gt;</font></code>, 
<code><font color="blue">std::complex&lt;double&gt;</font></code>.
Otherwise, see <a href="#4.7">4.7: <span style='white-space: nowrap'>base_require</span></a>
.


<br/>
<br/>
<b><big><a name="4.c" id="4.c">4.c: Contents</a></big></b>
<br/>
<table>
<tr><td><a href="#4.1" target="_top">Default:&#xA0;4.1</a></td><td>AD&#xA0;Default&#xA0;Constructor</td></tr><tr><td><a href="#4.2" target="_top">ad_copy:&#xA0;4.2</a></td><td>AD&#xA0;Copy&#xA0;Constructor&#xA0;and&#xA0;Assignment&#xA0;Operator</td></tr><tr><td><a href="#4.3" target="_top">Convert:&#xA0;4.3</a></td><td>Conversion&#xA0;and&#xA0;Printing&#xA0;of&#xA0;AD&#xA0;Objects</td></tr><tr><td><a href="#4.4" target="_top">ADValued:&#xA0;4.4</a></td><td>AD&#xA0;Valued&#xA0;Operations&#xA0;and&#xA0;Functions</td></tr><tr><td><a href="#4.5" target="_top">BoolValued:&#xA0;4.5</a></td><td>Bool&#xA0;Valued&#xA0;Operations&#xA0;and&#xA0;Functions&#xA0;with&#xA0;AD&#xA0;Arguments</td></tr><tr><td><a href="#4.6" target="_top">VecAD:&#xA0;4.6</a></td><td>AD&#xA0;Vectors&#xA0;that&#xA0;Record&#xA0;Index&#xA0;Operations</td></tr><tr><td><a href="#4.7" target="_top">base_require:&#xA0;4.7</a></td><td>AD&lt;Base&gt;&#xA0;Requirements&#xA0;for&#xA0;Base&#xA0;Type</td></tr></table>
<hr/>Input File: cppad/local/user_ad.hpp

<hr/>
<center><b><big><big><a name="4.1" id="4.1">4.1: AD Default Constructor</a>
</big></big></b></center>
<br/>
<b><big><a name="4.1.a" id="4.1.a">4.1.a: Syntax</a></big></b>

<br/>
<code><font color="blue"><span style='white-space: nowrap'>AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>;</span></font></code>


<br/>
<br/>
<b><big><a name="4.1.b" id="4.1.b">4.1.b: Purpose</a></big></b>
<br/>
Constructs an AD object with an unspecified value.
Directly after this construction,
the object is a <a href="#9.4.h">9.4.h: <span style='white-space: nowrap'>parameter</span></a>
.


<br/>
<br/>
<b><big><a name="4.1.c" id="4.1.c">4.1.c: Example</a></big></b>

<br/>
The file
<a href="#4.1.1">4.1.1: <span style='white-space: nowrap'>Default.cpp</span></a>

contains an example and test of this operation.
It returns true if it succeeds and false otherwise.


<hr/>Input File: cppad/local/default.hpp

<hr/>



<center><b><big><big><a name="4.1.1" id="4.1.1">4.1.1: Default AD Constructor: Example and Test</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

bool Default(void)
{	bool ok = true;
	using CppAD::AD;

	// default AD constructor
	<a href="#4">AD</a>&lt;double&gt; x, y;

	// check that they are parameters
	ok &amp;= Parameter(x);
	ok &amp;= Parameter(y);

	// assign them values
	x = 3.; 
	y = 4.;

	// just check a simple operation
	ok &amp;= (x + y == 7.);

	return ok;
}
</pre>
</font></code>


<hr/>Input File: example/default.cpp

<hr/>














<center><b><big><big><a name="4.2" id="4.2">4.2: AD Copy Constructor and Assignment Operator</a>
</big></big></b></center>
<br/>
<b><big><a name="4.2.a" id="4.2.a">4.2.a: Syntax</a></big></b>


<br/>
<br/>
<b><a name="4.2.a.a" id="4.2.a.a">4.2.a.a: Constructor</a></b>

<br/>
<code><font color="blue"><span style='white-space: nowrap'>AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code><code><font color="blue"><span style='white-space: nowrap'>AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i>

<br/>
<br/>
<b><a name="4.2.a.b" id="4.2.a.b">4.2.a.b: Assignment</a></b>

<br/>
<code><font color="blue"></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i>

<br/>
<br/>
<b><big><a name="4.2.b" id="4.2.b">4.2.b: Purpose</a></big></b>
<br/>
The constructor creates a new <code><font color="blue"><span style='white-space: nowrap'>AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code> object <i>y</i> 
and the assignment operator uses an existing <i>y</i>.
In either case, 
<i>y</i> has the same value as <i>x</i>,
and the same dependence on the 
<a href="#9.4.j.c">9.4.j.c: <span style='white-space: nowrap'>independent&#xA0;variables</span></a>

(<i>y</i> is a 
<a href="#9.4.l">9.4.l: <span style='white-space: nowrap'>variable</span></a>
 if and only if <i>x</i> is a variable).

<br/>
<br/>
<b><big><a name="4.2.c" id="4.2.c">4.2.c: x</a></big></b>
<br/>
The argument <i>x</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font></code><i><span style='white-space: nowrap'>Type</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>where <i>Type</i> is
<code><font color="blue"><span style='white-space: nowrap'>VecAD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;::reference</span></font></code>,
<code><font color="blue"><span style='white-space: nowrap'>AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>,
<i>Base</i>, or
<code><font color="blue">double</font></code>.

<br/>
<br/>
<b><big><a name="4.2.d" id="4.2.d">4.2.d: y</a></big></b>
<br/>
The target <i>y</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code><br/>
<b><big><a name="4.2.e" id="4.2.e">4.2.e: Example</a></big></b>

<br/>
The following files contain examples and tests of these operations.
Each test returns true if it succeeds and false otherwise.
<table><tr><td align='left'  valign='top'>

<a href="#4.2.1">4.2.1: CopyAD.cpp</a></td><td>
AD Copy Constructor: Example and Test</td></tr>
<tr><td>

<a href="#4.2.2">4.2.2: CopyBase.cpp</a></td><td>
AD Constructor From Base Type: Example and Test</td></tr>
<tr><td>

<a href="#4.2.3">4.2.3: Eq.cpp</a></td><td>
AD Assignment Operator: Example and Test</td></tr>
<tr><td>

</td></tr>
</table>

<hr/>Input File: cppad/local/ad_copy.hpp

<hr/>
<center><b><big><big><a name="4.2.1" id="4.2.1">4.2.1: AD Copy Constructor: Example and Test</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

bool CopyAD(void)
{	bool ok = true;   // initialize test result flag
	using CppAD::AD;  // so can use AD in place of CppAD::AD

	// domain space vector
	size_t n = 1;
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; x(n);
	x[0]     = 2.;

	// declare independent variables and start tape recording
	CppAD::<a href="#5.1">Independent</a>(x);

	// create an <a href="#4">AD</a>&lt;double&gt; that does not depend on x
	<a href="#4">AD</a>&lt;double&gt; b = 3.;   

	// use copy constructor 
	<a href="#4">AD</a>&lt;double&gt; u(x[0]);    
	<a href="#4">AD</a>&lt;double&gt; v = b;

	// check which are parameters
	ok &amp;= Variable(u);
	ok &amp;= Parameter(v);

	// range space vector
	size_t m = 2;
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; y(m);
	y[0]  = u;
	y[1]  = v;

	// create f: x -&gt; y and vectors used for derivative calculations
	CppAD::<a href="#5.2">ADFun</a>&lt;double&gt; f(x, y);
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt;double&gt; dx(n);
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt;double&gt; dy(m);
 
 	// check parameters flags
 	ok &amp;= ! f.Parameter(0);
 	ok &amp;=   f.Parameter(1);

	// check function values
	ok &amp;= ( y[0] == 2. );
	ok &amp;= ( y[1] == 3. );

	// forward computation of partials w.r.t. x[0]
	dx[0] = 1.;
	dy    = f.<a href="#5.6.1">Forward</a>(1, dx);
	ok   &amp;= ( dy[0] == 1. );   // du / dx
	ok   &amp;= ( dy[1] == 0. );   // dv / dx

	return ok;
}
</pre>
</font></code>


<hr/>Input File: example/copy_ad.cpp

<hr/>



<center><b><big><big><a name="4.2.2" id="4.2.2">4.2.2: AD Constructor From Base Type: Example and Test</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

bool CopyBase(void)
{	bool ok = true;    // initialize test result flag
	using CppAD::AD;   // so can use AD in place of CppAD::AD

	// construct directly from Base where Base is double 
	<a href="#4">AD</a>&lt;double&gt; x(1.); 

	// construct from a type that converts to Base where Base is double
	<a href="#4">AD</a>&lt;double&gt; y = 2;

	// construct from a type that converts to Base where Base = <a href="#4">AD</a>&lt;double&gt;
	<a href="#4">AD</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; z(3); 

	// check that resulting objects are parameters
	ok &amp;= Parameter(x);
	ok &amp;= Parameter(y);
	ok &amp;= Parameter(z);

	// check values of objects (compare <a href="#4">AD</a>&lt;double&gt; with double)
	ok &amp;= ( x == 1.);
	ok &amp;= ( y == 2.);
	ok &amp;= ( Value(z) == 3.);

	// user constructor through the static_cast template function
	x   = static_cast &lt; <a href="#4">AD</a>&lt;double&gt; &gt;( 4 );
	z  = static_cast &lt; <a href="#4">AD</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; &gt;( 5 );

	ok &amp;= ( x == 4. );
	ok &amp;= ( Value(z) == 5. );

	return ok;
}
</pre>
</font></code>


<hr/>Input File: example/copy_base.cpp

<hr/>



<center><b><big><big><a name="4.2.3" id="4.2.3">4.2.3: AD Assignment Operator: Example and Test</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

bool Eq(void)
{	bool ok = true;
	using CppAD::AD;

	// domain space vector
	size_t n = 3;
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; x(n);
	x[0]     = 2;      // <a href="#4">AD</a>&lt;double&gt; = int
	x[1]     = 3.;     // <a href="#4">AD</a>&lt;double&gt; = double
	x[2]     = x[1];   // <a href="#4">AD</a>&lt;double&gt; = <a href="#4">AD</a>&lt;double&gt;

	// declare independent variables and start tape recording
	CppAD::<a href="#5.1">Independent</a>(x);
	
	// range space vector 
	size_t m = 3;
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; y(m);

	// assign an <a href="#4">AD</a>&lt;Base&gt; object equal to an independent variable
	// (choose the first independent variable to check a special case)
	// use the value returned by the assignment (for another assignment)
	y[0] = y[1] = x[0];  

	// assign an <a href="#4">AD</a>&lt;Base&gt; object equal to an expression 
	y[1] = x[1] + 1.;
	y[2] = x[2] + 2.;

	// check that all the resulting components of y depend on x
	ok &amp;= Variable(y[0]);  // y[0] = x[0]
	ok &amp;= Variable(y[1]);  // y[1] = x[1] + 1
	ok &amp;= Variable(y[2]);  // y[2] = x[2] + 2

	// construct f : x -&gt; y and stop the tape recording
	CppAD::<a href="#5.2">ADFun</a>&lt;double&gt; f(x, y);

	// check variable values
	ok &amp;= ( y[0] == 2.);
	ok &amp;= ( y[1] == 4.);
	ok &amp;= ( y[2] == 5.);

	// compute partials w.r.t x[1]
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt;double&gt; dx(n);
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt;double&gt; dy(m);
	dx[0] = 0.;
	dx[1] = 1.;
	dx[2] = 0.;
	dy   = f.<a href="#5.6.1">Forward</a>(1, dx);
	ok  &amp;= (dy[0] == 0.);  // dy[0] / dx[1]
	ok  &amp;= (dy[1] == 1.);  // dy[1] / dx[1]
	ok  &amp;= (dy[2] == 0.);  // dy[2] / dx[1]

	// compute the derivative y[2]
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt;double&gt;  w(m);
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt;double&gt; dw(n);
	w[0] = 0.;
	w[1] = 0.;
	w[2] = 1.;
	dw   = f.<a href="#5.6.2">Reverse</a>(1, w);
	ok  &amp;= (dw[0] == 0.);  // dy[2] / dx[0]
	ok  &amp;= (dw[1] == 0.);  // dy[2] / dx[1]
	ok  &amp;= (dw[2] == 1.);  // dy[2] / dx[2]

	// assign a VecAD&lt;Base&gt;::reference
	CppAD::VecAD&lt;double&gt; v(1);
	<a href="#4">AD</a>&lt;double&gt; zero(0);
	v[zero] = 5.;
	ok     &amp;= (v[0] == 5.);

	return ok;
}
</pre>
</font></code>


<hr/>Input File: example/eq.cpp

<hr/>






<center><b><big><big><a name="4.3" id="4.3">4.3: Conversion and Printing of AD Objects</a>
</big></big></b></center>
<table><tr><td align='left'  valign='top'>
<a href="#4.3.1">4.3.1: Value</a></td><td>
Convert From an AD Type to its Base Type</td></tr>
<tr><td>
<a href="#4.3.2">4.3.2: Integer</a></td><td>
Convert From AD to Integer</td></tr>
<tr><td>
<a href="#4.3.3">4.3.3: Output</a></td><td>
AD Output Stream Operator</td></tr>
<tr><td>
<a href="#4.3.4">4.3.4: PrintFor</a></td><td>
Printing AD Values During Forward Mode</td></tr>
<tr><td>
<a href="#4.3.5">4.3.5: Var2Par</a></td><td>
Convert an AD Variable to a Parameter</td></tr>
<tr><td>
</td></tr>
</table>

<hr/>Input File: cppad/local/convert.hpp

<hr/>
<center><b><big><big><a name="4.3.1" id="4.3.1">4.3.1: Convert From an AD Type to its Base Type</a>
</big></big></b></center>
<br/>
<b><big><a name="4.3.1.a" id="4.3.1.a">4.3.1.a: Syntax</a></big></b>

<br/>
<code><font color="blue"></font></code><i><span style='white-space: nowrap'>b</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;Value(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>


<br/>
<br/>
<b><big><a name="4.3.1.b" id="4.3.1.b">4.3.1.b: Purpose</a></big></b>
<br/>
Converts from an AD type to the corresponding
<a href="#9.4.e">9.4.e: <span style='white-space: nowrap'>base&#xA0;type</span></a>
.

<br/>
<br/>
<b><big><a name="4.3.1.c" id="4.3.1.c">4.3.1.c: x</a></big></b>
<br/>
The argument <i>x</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code><br/>
<b><big><a name="4.3.1.d" id="4.3.1.d">4.3.1.d: b</a></big></b>
<br/>
The return value <i>b</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font></code><i><span style='white-space: nowrap'>b</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code><br/>
<b><big><a name="4.3.1.e" id="4.3.1.e">4.3.1.e: Operation Sequence</a></big></b>
<br/>
The result of this operation is not an 
<a href="#9.4.b">9.4.b: <span style='white-space: nowrap'>AD&#xA0;of&#xA0;Base</span></a>
 object.
Thus it will not be recorded as part of an
AD of <i>Base</i>
<a href="#9.4.g.b">9.4.g.b: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>
.

<br/>
<br/>
<b><big><a name="4.3.1.f" id="4.3.1.f">4.3.1.f: Restriction</a></big></b>
<br/>
If the argument <i>x</i> is a 
<a href="#9.4.l">9.4.l: <span style='white-space: nowrap'>variable</span></a>
 its dependency information 
would not be included in the <code><font color="blue">Value</font></code> result (see above).
For this reason,
the argument <i>x</i> must be a <a href="#9.4.h">9.4.h: <span style='white-space: nowrap'>parameter</span></a>
; i.e.,
it cannot depend on the current
<a href="#9.4.j.c">9.4.j.c: <span style='white-space: nowrap'>independent&#xA0;variables</span></a>
.

<br/>
<br/>
<b><big><a name="4.3.1.g" id="4.3.1.g">4.3.1.g: Example</a></big></b>

<br/>
The file
<a href="#4.3.1.1">4.3.1.1: <span style='white-space: nowrap'>Value.cpp</span></a>

contains an example and test of this operation.


<hr/>Input File: cppad/local/value.hpp

<hr/>



<center><b><big><big><a name="4.3.1.1" id="4.3.1.1">4.3.1.1: Convert From AD to its Base Type: Example and Test</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

bool Value(void)
{	bool ok = true;
	using CppAD::AD;
	using CppAD::Value;

	// domain space vector
	size_t n = 2;
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; x(n);
	x[0] = 3.;
	x[1] = 4.;

	// check value before recording
	ok &amp;= (Value(x[0]) == 3.);
	ok &amp;= (Value(x[1]) == 4.);

	// declare independent variables and start tape recording
	CppAD::<a href="#5.1">Independent</a>(x);

	// range space vector 
	size_t m = 1;
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; y(m);
	y[0] = - x[1];

	// cannot call Value(x[j]) or Value(y[0]) here (currently variables)
	<a href="#4">AD</a>&lt;double&gt; p = 5.;        // p is a parameter (does not depend on x)
	ok &amp;= (Value(p) == 5.);

	// create f: x -&gt; y and stop tape recording
	CppAD::<a href="#5.2">ADFun</a>&lt;double&gt; f(x, y);

	// can call Value(x[j]) or Value(y[0]) here (currently parameters)
	ok &amp;= (Value(x[0]) ==  3.);
	ok &amp;= (Value(x[1]) ==  4.);
	ok &amp;= (Value(y[0]) == -4.);

	return ok;
}</pre>
</font></code>


<hr/>Input File: example/value.cpp

<hr/>








<center><b><big><big><a name="4.3.2" id="4.3.2">4.3.2: Convert From AD to Integer</a>
</big></big></b></center>
<br/>
<b><big><a name="4.3.2.a" id="4.3.2.a">4.3.2.a: Syntax</a></big></b>

<br/>
<code><font color="blue"></font></code><i><span style='white-space: nowrap'>i</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;Integer(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>


<br/>
<br/>
<b><big><a name="4.3.2.b" id="4.3.2.b">4.3.2.b: Purpose</a></big></b>
<br/>
Converts from an AD type to the corresponding integer value.

<br/>
<br/>
<b><big><a name="4.3.2.c" id="4.3.2.c">4.3.2.c: i</a></big></b>
<br/>
The result <i>i</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;int&#xA0;</span></font></code><i><span style='white-space: nowrap'>i</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code><br/>
<b><big><a name="4.3.2.d" id="4.3.2.d">4.3.2.d: x</a></big></b>


<br/>
<br/>
<b><a name="4.3.2.d.a" id="4.3.2.d.a">4.3.2.d.a: Real Types</a></b>
<br/>
If the argument <i>x</i> has either of the following prototypes:
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;float&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;double&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>the fractional part is dropped to form the integer value.
For example, if <i>x</i> is 1.5, <i>i</i> is 1.
In general, if 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">&#x02265;</mo>
<mn>0</mn>
</mrow></math>

, <i>i</i> is the 
greatest integer less than or equal <i>x</i>.
If 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">&#x02264;</mo>
<mn>0</mn>
</mrow></math>

, <i>i</i> is the 
smallest integer greater than or equal <i>x</i>.

<br/>
<br/>
<b><a name="4.3.2.d.b" id="4.3.2.d.b">4.3.2.d.b: Complex Types</a></b>
<br/>
If the argument <i>x</i> has either of the following prototypes:
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;std::complex&lt;float&gt;&#xA0;&#xA0;</span></font></code><i></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;std::complex&lt;double&gt;&#xA0;</span></font></code><i></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>The result <i>i</i> is given by
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>i</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;Integer(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>.real())<br/>
</span></font></code><br/>
<b><a name="4.3.2.d.c" id="4.3.2.d.c">4.3.2.d.c: AD Types</a></b>
<br/>
If the argument <i>x</i> has either of the following prototypes:
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;VecAD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;::reference&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code><i>Base</i> must support the <code><font color="blue">Integer</font></code> function and
the conversion has the same meaning as for <i>Base</i>.

<br/>
<br/>
<b><big><a name="4.3.2.e" id="4.3.2.e">4.3.2.e: Operation Sequence</a></big></b>
<br/>
The result of this operation is not an
<a href="#9.4.b">9.4.b: <span style='white-space: nowrap'>AD&#xA0;of&#xA0;Base</span></a>
 object.
Thus it will not be recorded as part of an
AD of <i>Base</i>
<a href="#9.4.g.b">9.4.g.b: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>
.

<br/>
<br/>
<b><big><a name="4.3.2.f" id="4.3.2.f">4.3.2.f: Example</a></big></b>

<br/>
The file
<a href="#4.3.2.1">4.3.2.1: <span style='white-space: nowrap'>Integer.cpp</span></a>

contains an example and test of this operation.


<hr/>Input File: cppad/local/integer.hpp

<hr/>



<center><b><big><big><a name="4.3.2.1" id="4.3.2.1">4.3.2.1: Convert From AD to Integer: Example and Test</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

bool Integer(void)
{	bool ok = true;
	using CppAD::AD;
	using CppAD::Integer;

	// domain space vector
	size_t n = 2;
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; x(n);
	x[0] = 3.5;
	x[1] = 4.5;

	// check integer before recording
	ok &amp;= (Integer(x[0]) == 3);
	ok &amp;= (Integer(x[1]) == 4);

	// start recording

	// declare independent variables and start tape recording
	CppAD::<a href="#5.1">Independent</a>(x);

	// check integer during recording
	ok &amp;= (Integer(x[0]) == 3);
	ok &amp;= (Integer(x[1]) == 4);

	// check integer for VecAD element
	CppAD::VecAD&lt;double&gt; v(1);
	<a href="#4">AD</a>&lt;double&gt; zero(0);
	v[zero] = 2;
	ok &amp;= (Integer(v[zero]) == 2);

	// range space vector 
	size_t m = 1;
	<a href="#7.4">CPPAD_TEST_VECTOR</a>&lt; <a href="#4">AD</a>&lt;double&gt; &gt; y(m);
	y[0] = - x[1];

	// create f: x -&gt; y and stop recording
	CppAD::<a href="#5.2">ADFun</a>&lt;double&gt; f(x, y);

	// check integer after recording
	ok &amp;= (Integer(x[0]) ==  3.);
	ok &amp;= (Integer(x[1]) ==  4.);
	ok &amp;= (Integer(y[0]) == -4.);

	return ok;
}</pre>
</font></code>


<hr/>Input File: example/integer.cpp

<hr/>









<center><b><big><big><a name="4.3.3" id="4.3.3">4.3.3: AD Output Stream Operator</a>
</big></big></b></center>
<br/>
<b><big><a name="4.3.3.a" id="4.3.3.a">4.3.3.a: Syntax</a></big></b>

<br/>
<code><font color="blue"></font></code><i><span style='white-space: nowrap'>os</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&lt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i>


<br/>
<br/>
<b><big><a name="4.3.3.b" id="4.3.3.b">4.3.3.b: Purpose</a></big></b>
<br/>
Writes the <i>Base</i> value_, corresponding to <i>x</i>,
to the output stream <i>os</i>.

<br/>
<br/>
<b><big><a name="4.3.3.c" id="4.3.3.c">4.3.3.c: os</a></big></b>
<br/>
The operand <i>os</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;std::ostream&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>os</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code><br/>
<b><big><a name="4.3.3.d" id="4.3.3.d">4.3.3.d: x</a></big></b>
<br/>
The operand <i>x</i> has one of the following prototypes
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;VecAD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;::reference&#xA0;&amp;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code><br/>
<b><big><a name="4.3.3.e" id="4.3.3.e">4.3.3.e: Result</a></big></b>
<br/>
The result of this operation can be used as a reference to <i>os</i>.
For example, if the operand <i>y</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>then the syntax
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>os</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&lt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&lt;&#xA0;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>will output the value corresponding to <i>x</i>
followed by the value corresponding to <i>y</i>. 

<br/>
<br/>
<b><big><a name="4.3.3.f" id="4.3.3.f">4.3.3.f: Operation Sequence</a></big></b>
<br/>
The result of this operation is not an
<a href="#9.4.b">9.4.b: <span style='white-space: nowrap'>AD&#xA0;of&#xA0;Base</span></a>
 object.
Thus it will not be recorded as part of an
AD of <i>Base</i>
<a href="#9.4.g.b">9.4.g.b: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>
.

<br/>
<br/>
<b><big><a name="4.3.3.g" id="4.3.3.g">4.3.3.g: Example</a></big></b>

<br/>
The file
<a href="#4.3.3.1">4.3.3.1: <span style='white-space: nowrap'>Output.cpp</span></a>

contains an example and test of this operation.
It returns true if it succeeds and false otherwise.


<hr/>Input File: cppad/local/output.hpp

<hr/>



<center><b><big><big><a name="4.3.3.1" id="4.3.3.1">4.3.3.1: AD Output Operator: Example and Test</a>
</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

# include &lt;sstream&gt;  // std::ostringstream
# include &lt;string&gt;   // std::string
# include &lt;iomanip&gt;  // std::setprecision, setw, setfill, right

namespace {
	template &lt;class S&gt;
	void set_ostream(S &amp;os)
	{	os 
		&lt;&lt; std::setprecision(4) // 4 digits of precision
		&lt;&lt; std::setw(6)         // 6 characters per field
		&lt;&lt; std::setfill(' ')    // fill with spaces
		&lt;&lt; std::right;          // adjust value to the right
	}
}

bool Output(void)
{	bool ok = true;

	// This output stream is an ostringstream for testing purposes.
	// You can use &lt;&lt; with other types of streams; i.e., std::cout.
	std::ostringstream stream;

	// ouput an <a href="#4">AD</a>&lt;double&gt; object
	CppAD::<a href="#4">AD</a>&lt;double&gt;  pi = 4. * atan(1.); // 3.1415926536
	set_ostream(stream);
	stream &lt;&lt; pi;

	// ouput a VecAD&lt;double&gt;::reference object
	CppAD::VecAD&lt;double&gt; v(1);
	CppAD::<a href="#4">AD</a>&lt;double&gt; zero(0);
	v[zero]   = exp(1.);                  // 2.7182818285
	set_ostream(stream); 
	stream &lt;&lt; v[zero];

	// convert output from stream to string
	std::string str = stream.str();

	// check the output
	ok      &amp;= (str == &quot; 3.142 2.718&quot;);

	return ok;
}</pre>
</font></code>


<hr/>Input File: example/output.cpp

<hr/>










<center><b><big><big><a name="4.3.4" id="4.3.4">4.3.4: Printing AD Values During Forward Mode</a>
</big></big></b></center>
<br/>
<b><big><a name="4.3.4.a" id="4.3.4.a">4.3.4.a: Syntax</a></big></b>

<br/>
<code><font color="blue"><span style='white-space: nowrap'>PrintFor(</span></font></code><i><span style='white-space: nowrap'>text</span></i><code><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
<code><span style='white-space: nowrap'><br/>
</span></code><code><font color="blue"></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'>.Forward(0,&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>


<br/>
<br/>
<b><big><a name="4.3.4.b" id="4.3.4.b">4.3.4.b: Purpose</a></big></b>
<br/>
The current value of an <code><font color="blue"><span style='white-space: nowrap'>AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code> 
object <i>y</i> is the result of an AD of <i>Base</i> operation.
This operation may be part of the 
<a href="#9.4.g.b">9.4.g.b: <span style='white-space: nowrap'>operation&#xA0;sequence</span></a>

that is transferred to an <a href="#5">5: <span style='white-space: nowrap'>ADFun</span></a>
 object <i>f</i>.
The <code><font color="blue">ADFun</font></code> object can be evaluated at different values for the
<a href="#9.4.j.c">9.4.j.c: <span style='white-space: nowrap'>independent&#xA0;variables</span></a>
.
This may result in a corresponding value for <i>y</i> 
that is different from when the operation sequence was recorded.
The routine <code><font color="blue">PrintFor</font></code> requests a printing,
when <code><font color="blue"></font></code><i><span style='white-space: nowrap'>f</span></i><code><font color="blue"><span style='white-space: nowrap'>.Forward(0,&#xA0;</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code> is executed,
of the value for <i>y</i> that corresponds to the 
independent variable values specified by <i>x</i>.

<br/>
<br/>
<b><big><a name="4.3.4.c" id="4.3.4.c">4.3.4.c: text</a></big></b>
<br/>
The argument <i>text</i> has prototype
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;char&#xA0;*</span></font></code><i><span style='white-space: nowrap'>text</span></i><code><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>The corresponding text is written to <code><font color="blue">std::cout</font></code> before the 
value of <i>y</i>. 

<br/>
<br/>
<b><big><a name="4.3.4.d" id="4.3.4.d">4.3.4.d: y</a></big></b>
<br/>
The argument <i>y</i> has one of the following prototypes
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;AD&lt;</span></font></code><i><span style='white-space: nowrap'>Base</span></i><code><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#x