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

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

<hr/>
,






<center><b><big><big>cppad-20120203: 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.3">2.3: <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="#11.4.g.b">11.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="#11.4.j.c">11.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="#9.1.9.1">9.1.9.1: <span style='white-space: nowrap'>mul_level.cpp</span></a>
 for a simple example
and <a href="#9.1.11">9.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="#9.1.12">9.1.12: <span style='white-space: nowrap'>ode_taylor_adolc.cpp</span></a>
.

</li><li>

A set of programs for doing <a href="#11.2">11.2: <span style='white-space: nowrap'>speed</span></a>
 comparisons between
<a href="https://projects.coin-or.org/ADOL-C" target="_top"><span style='white-space: nowrap'>Adolc</span></a>
 (https://projects.coin-or.org/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="#7">7: <span style='white-space: nowrap'>library</span></a>
 that is useful
for general operator overloaded numerical method.
Allows for replacement of the
<a href="#9.4">9.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="#11.8">11.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="#9">9: <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 <a href="#10">10: <span style='white-space: nowrap'>preprocessor</span></a>
 symbols used by CppAD begin with eight
<code><font color="blue">CppAD</font></code> or <code><font color="blue">CPPAD_</font></code>.

<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">multi_thread:&#xA0;6</a></td><td>Using&#xA0;CppAD&#xA0;in&#xA0;a&#xA0;Multi-Threading&#xA0;Environment</td></tr><tr><td><a href="#7" target="_top">library:&#xA0;7</a></td><td>The&#xA0;CppAD&#xA0;General&#xA0;Purpose&#xA0;Library</td></tr><tr><td><a href="#8" target="_top">cppad_ipopt_nlp:&#xA0;8</a></td><td>Nonlinear&#xA0;Programming&#xA0;Using&#xA0;the&#xA0;CppAD&#xA0;Interface&#xA0;to&#xA0;Ipopt</td></tr><tr><td><a href="#9" target="_top">Example:&#xA0;9</a></td><td>Examples</td></tr><tr><td><a href="#10" target="_top">preprocessor:&#xA0;10</a></td><td>CppAD&#xA0;API&#xA0;Preprocessor&#xA0;Symbols</td></tr><tr><td><a href="#11" target="_top">Appendix:&#xA0;11</a></td><td>Appendix</td></tr><tr><td><a href="#12" target="_top">_reference:&#xA0;12</a></td><td>Alphabetic&#xA0;Listing&#xA0;of&#xA0;Cross&#xA0;Reference&#xA0;Tags</td></tr><tr><td><a href="#13" target="_top">_index:&#xA0;13</a></td><td>Keyword&#xA0;Index</td></tr><tr><td><a href="#14" target="_top">_external:&#xA0;14</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-20120203: 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>
        CppAD pkg-config Files: <a href="#2.2">2.2: pkgconfig</a>
        Windows Download and Test: <a href="#2.3">2.3: InstallWindows</a>
    An Introduction by Example to Algorithmic Differentiation: <a href="#3">3: Introduction</a>
        Getting Started 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>
        Correctness Tests For Exponential Approximation in Introduction: <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: print_for_cout.cpp</a>
                Print During Zero Order Forward Mode: Example and Test: <a href="#4.3.4.2">4.3.4.2: print_for_string.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>
                Sign Function: <a href="#4.4.3.2">4.4.3.2: sign</a>
                    Sign Function: Example and Test: <a href="#4.4.3.2.1">4.4.3.2.1: sign.cpp</a>
                AD Two Argument Inverse Tangent Function: <a href="#4.4.3.3">4.4.3.3: atan2</a>
                    The AD atan2 Function: Example and Test: <a href="#4.4.3.3.1">4.4.3.3.1: Atan2.cpp</a>
                Machine Epsilon For AD Types: <a href="#4.4.3.4">4.4.3.4: epsilon</a>
                    Machine Epsilon: Example and Test: <a href="#4.4.3.4.1">4.4.3.4.1: epsilon.cpp</a>
                The AD Error Function: <a href="#4.4.3.5">4.4.3.5: erf</a>
                    The AD erf Function: Example and Test: <a href="#4.4.3.5.1">4.4.3.5.1: Erf.cpp</a>
                The AD Power Function: <a href="#4.4.3.6">4.4.3.6: pow</a>
                    The AD Power Function: Example and Test: <a href="#4.4.3.6.1">4.4.3.6.1: Pow.cpp</a>
                    The Pow Integer Exponent: Example and Test: <a href="#4.4.3.6.2">4.4.3.6.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>
            User Defined Atomic AD Functions: <a href="#4.4.6">4.4.6: user_atomic</a>
                Tan and Tanh as User Atomic Operations: Example and Test: <a href="#4.4.6.1">4.4.6.1: user_tan.cpp</a>
                Matrix Multiply as a User Atomic Operation: Example and Test: <a href="#4.4.6.2">4.4.6.2: mat_mul.cpp</a>
                    Define Matrix Multiply as a User Atomic Operation: <a href="#4.4.6.2.1">4.4.6.2.1: mat_mul.hpp</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 Two Value are Identically Equal: <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>
            Base Type Requirements for Conditional Expressions: <a href="#4.7.1">4.7.1: base_cond_exp</a>
            Base Type Requirements for Identically Equal Comparisons: <a href="#4.7.2">4.7.2: base_identical</a>
            Base Type Requirements for Ordered Comparisons: <a href="#4.7.3">4.7.3: base_ordered</a>
            Base Type Requirements for Standard Math Functions: <a href="#4.7.4">4.7.4: base_std_math</a>
            Enable use of AD&lt;Base&gt; where Base is float: <a href="#4.7.5">4.7.5: base_float.hpp</a>
            Enable use of AD&lt;Base&gt; where Base is double: <a href="#4.7.6">4.7.6: base_double.hpp</a>
            Enable use of AD&lt;Base&gt; where Base is std::complex&lt;double&gt;: <a href="#4.7.7">4.7.7: base_complex.hpp</a>
                Complex Polynomial: Example and Test: <a href="#4.7.7.1">4.7.7.1: ComplexPoly.cpp</a>
                Not Complex Differentiable: Example and Test: <a href="#4.7.7.2">4.7.7.2: not_complex_ad.cpp</a>
            Enable use of AD&lt;Base&gt; where Base is Adolc's adouble Type: <a href="#4.7.8">4.7.8: base_adolc.hpp</a>
                Using Adolc with Multiple Levels of Taping: Example and Test: <a href="#4.7.8.1">4.7.8.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>
        Optimize an ADFun Object Tape: <a href="#5.9">5.9: optimize</a>
            ADFun Operation Sequence Optimization: Example and Test: <a href="#5.9.1">5.9.1: optimize.cpp</a>
    Using CppAD in a Multi-Threading Environment: <a href="#6">6: multi_thread</a>
        Enable AD Calculations During Parallel Mode: <a href="#6.1">6.1: parallel_ad</a>
        Specifications for A Team of AD Threads: <a href="#6.2">6.2: team_thread.hpp</a>
            OpenMP Implementation of a Team of AD Threads: <a href="#6.2.1">6.2.1: team_openmp.cpp</a>
            Boost Thread Implementation of a Team of AD Threads: <a href="#6.2.2">6.2.2: team_bthread.cpp</a>
            Pthread Implementation of a Team of AD Threads: <a href="#6.2.3">6.2.3: team_pthread.cpp</a>
        Run Multi-Threading Examples and Speed Tests: <a href="#6.3">6.3: thread_test.cpp</a>
            A Simple OpenMP Example and Test: <a href="#6.3.1">6.3.1: a11c_openmp.cpp</a>
            A Simple Boost Thread Example and Test: <a href="#6.3.2">6.3.2: a11c_bthread.cpp</a>
            A Simple Parallel Pthread Example and Test: <a href="#6.3.3">6.3.3: a11c_pthread.cpp</a>
        Simple Multi-Threading AD: Example and Test: <a href="#6.4">6.4: simple_ad.cpp</a>
            Two Argument Inverse Tangent Function: <a href="#6.4.1">6.4.1: arc_tan.cpp</a>
        Multi-Threaded Implementation of Summation of 1/i: <a href="#6.5">6.5: harmonic.cpp</a>
            Timing Test of Multi-Threaded Summation of 1/i: <a href="#6.5.1">6.5.1: harmonic_time.cpp</a>
            Multi-threading Sum of 1/i Utility Routines: <a href="#6.5.2">6.5.2: harmonic_work.cpp</a>
        A Multi-Threaded Newton's Method: <a href="#6.6">6.6: multi_newton.cpp</a>
            Timing Test of Multi-Threaded Newton Method: <a href="#6.6.1">6.6.1: multi_newton_time.cpp</a>
            Multi-threading Newton Method Utility Routines: <a href="#6.6.2">6.6.2: multi_newton_work.cpp</a>
    The CppAD General Purpose Library: <a href="#7">7: library</a>
        Replacing the CppAD Error Handler: <a href="#7.1">7.1: ErrorHandler</a>
            Replacing The CppAD Error Handler: Example and Test: <a href="#7.1.1">7.1.1: ErrorHandler.cpp</a>
            CppAD Assertions During Execution: <a href="#7.1.2">7.1.2: cppad_assert</a>
        Determine if Two Values Are Nearly Equal: <a href="#7.2">7.2: NearEqual</a>
            NearEqual Function: Example and Test: <a href="#7.2.1">7.2.1: Near_Equal.cpp</a>
        Run One Speed Test and Return Results: <a href="#7.3">7.3: speed_test</a>
            speed_test: Example and test: <a href="#7.3.1">7.3.1: speed_test.cpp</a>
        Run One Speed Test and Print Results: <a href="#7.4">7.4: SpeedTest</a>
            Example Use of SpeedTest: <a href="#7.4.1">7.4.1: speed_program.cpp</a>
        Determine Amount of Time to Execute a Test: <a href="#7.5">7.5: time_test</a>
            Returns Elapsed Number of Seconds: <a href="#7.5.1">7.5.1: elapsed_seconds</a>
                Elapsed Seconds: Example and Test: <a href="#7.5.1.1">7.5.1.1: elapsed_seconds.cpp</a>
            time_test: Example and test: <a href="#7.5.2">7.5.2: time_test.cpp</a>
        Definition of a Numeric Type: <a href="#7.6">7.6: NumericType</a>
            The NumericType: Example and Test: <a href="#7.6.1">7.6.1: NumericType.cpp</a>
        Check NumericType Class Concept: <a href="#7.7">7.7: CheckNumericType</a>
            The CheckNumericType Function: Example and Test: <a href="#7.7.1">7.7.1: CheckNumericType.cpp</a>
        Definition of a Simple Vector: <a href="#7.8">7.8: SimpleVector</a>
            Simple Vector Template Class: Example and Test: <a href="#7.8.1">7.8.1: SimpleVector.cpp</a>
        Check Simple Vector Concept: <a href="#7.9">7.9: CheckSimpleVector</a>
            The CheckSimpleVector Function: Example and Test: <a href="#7.9.1">7.9.1: CheckSimpleVector.cpp</a>
        Obtain Nan or Determine if a Value is Nan: <a href="#7.10">7.10: nan</a>
            nan: Example and Test: <a href="#7.10.1">7.10.1: nan.cpp</a>
        The Integer Power Function: <a href="#7.11">7.11: pow_int</a>
        Evaluate a Polynomial or its Derivative: <a href="#7.12">7.12: Poly</a>
            Polynomial Evaluation: Example and Test: <a href="#7.12.1">7.12.1: Poly.cpp</a>
            Source: Poly: <a href="#7.12.2">7.12.2: poly.hpp</a>
        Compute Determinants and Solve Equations by LU Factorization: <a href="#7.13">7.13: LuDetAndSolve</a>
            Compute Determinant and Solve Linear Equations: <a href="#7.13.1">7.13.1: LuSolve</a>
                LuSolve With Complex Arguments: Example and Test: <a href="#7.13.1.1">7.13.1.1: LuSolve.cpp</a>
                Source: LuSolve: <a href="#7.13.1.2">7.13.1.2: lu_solve.hpp</a>
            LU Factorization of A Square Matrix: <a href="#7.13.2">7.13.2: LuFactor</a>
                LuFactor: Example and Test: <a href="#7.13.2.1">7.13.2.1: LuFactor.cpp</a>
                Source: LuFactor: <a href="#7.13.2.2">7.13.2.2: lu_factor.hpp</a>
            Invert an LU Factored Equation: <a href="#7.13.3">7.13.3: LuInvert</a>
                LuInvert: Example and Test: <a href="#7.13.3.1">7.13.3.1: LuInvert.cpp</a>
                Source: LuInvert: <a href="#7.13.3.2">7.13.3.2: lu_invert.hpp</a>
        One DimensionalRomberg Integration: <a href="#7.14">7.14: RombergOne</a>
            One Dimensional Romberg Integration: Example and Test: <a href="#7.14.1">7.14.1: RombergOne.cpp</a>
        Multi-dimensional Romberg Integration: <a href="#7.15">7.15: RombergMul</a>
            One Dimensional Romberg Integration: Example and Test: <a href="#7.15.1">7.15.1: RombergMul.cpp</a>
        An Embedded 4th and 5th Order Runge-Kutta ODE Solver: <a href="#7.16">7.16: Runge45</a>
            Runge45: Example and Test: <a href="#7.16.1">7.16.1: runge_45_1.cpp</a>
            Runge45: Example and Test: <a href="#7.16.2">7.16.2: runge_45_2.cpp</a>
        A 3rd and 4th Order Rosenbrock ODE Solver: <a href="#7.17">7.17: Rosen34</a>
            Rosen34: Example and Test: <a href="#7.17.1">7.17.1: Rosen34.cpp</a>
        An Error Controller for ODE Solvers: <a href="#7.18">7.18: OdeErrControl</a>
            OdeErrControl: Example and Test: <a href="#7.18.1">7.18.1: OdeErrControl.cpp</a>
            OdeErrControl: Example and Test Using Maxabs Argument: <a href="#7.18.2">7.18.2: OdeErrMaxabs.cpp</a>
        An Arbitrary Order Gear Method: <a href="#7.19">7.19: OdeGear</a>
            OdeGear: Example and Test: <a href="#7.19.1">7.19.1: OdeGear.cpp</a>
        An Error Controller for Gear's Ode Solvers: <a href="#7.20">7.20: OdeGearControl</a>
            OdeGearControl: Example and Test: <a href="#7.20.1">7.20.1: OdeGearControl.cpp</a>
        Computing Jacobian and Hessian of Bender's Reduced Objective: <a href="#7.21">7.21: BenderQuad</a>
            BenderQuad: Example and Test: <a href="#7.21.1">7.21.1: BenderQuad.cpp</a>
        Jacobian and Hessian of Optimal Values: <a href="#7.22">7.22: opt_val_hes</a>
            opt_val_hes: Example and Test: <a href="#7.22.1">7.22.1: opt_val_hes.cpp</a>
        LU Factorization of A Square Matrix and Stability Calculation: <a href="#7.23">7.23: LuRatio</a>
            LuRatio: Example and Test: <a href="#7.23.1">7.23.1: LuRatio.cpp</a>
        The CppAD::vector Template Class: <a href="#7.24">7.24: CppAD_vector</a>
            CppAD::vector Template Class: Example and Test: <a href="#7.24.1">7.24.1: CppAD_vector.cpp</a>
            CppAD::vectorBool Class: Example and Test: <a href="#7.24.2">7.24.2: vectorBool.cpp</a>
        A Fast Multi-Threading Memory Allocator: <a href="#7.25">7.25: thread_alloc</a>
            Fast Multi-Threading Memory Allocator: Example and Test: <a href="#7.25.1">7.25.1: thread_alloc.cpp</a>
            Setup thread_alloc For Use in Multi-Threading Environment: <a href="#7.25.2">7.25.2: ta_parallel_setup</a>
            Get Number of Threads: <a href="#7.25.3">7.25.3: ta_num_threads</a>
            Is The Current Execution in Parallel Mode: <a href="#7.25.4">7.25.4: ta_in_parallel</a>
            Get the Current Thread Number: <a href="#7.25.5">7.25.5: ta_thread_num</a>
            Get At Least A Specified Amount of Memory: <a href="#7.25.6">7.25.6: ta_get_memory</a>
            Return Memory to thread_alloc: <a href="#7.25.7">7.25.7: ta_return_memory</a>
            Free Memory Currently Available for Quick Use by a Thread: <a href="#7.25.8">7.25.8: ta_free_available</a>
            Control When Thread Alloc Retains Memory For Future Use: <a href="#7.25.9">7.25.9: ta_hold_memory</a>
            Amount of Memory a Thread is Currently Using: <a href="#7.25.10">7.25.10: ta_inuse</a>
            Amount of Memory Available for Quick Use by a Thread: <a href="#7.25.11">7.25.11: ta_available</a>
            Allocate An Array and Call Default Constructor for its Elements: <a href="#7.25.12">7.25.12: ta_create_array</a>
            Deallocate An Array and Call Destructor for its Elements: <a href="#7.25.13">7.25.13: ta_delete_array</a>
        Memory Leak Detection: <a href="#7.26">7.26: memory_leak</a>
    Nonlinear Programming Using the CppAD Interface to Ipopt: <a href="#8">8: cppad_ipopt_nlp</a>
        Linking the CppAD Interface to Ipopt in Visual Studio 9.0: <a href="#8.1">8.1: cppad_ipopt_windows</a>
        Nonlinear Programming Using CppAD and Ipopt: Example and Test: <a href="#8.2">8.2: ipopt_get_started.cpp</a>
        Example Simultaneous Solution of Forward and Inverse Problem: <a href="#8.3">8.3: cppad_ipopt_ode</a>
            An ODE Inverse Problem Example: <a href="#8.3.1">8.3.1: ipopt_ode_problem</a>
                ODE Inverse Problem Definitions: Source Code: <a href="#8.3.1.1">8.3.1.1: ipopt_ode_problem.hpp</a>
            ODE Fitting Using Simple Representation: <a href="#8.3.2">8.3.2: ipopt_ode_simple</a>
                ODE Fitting Using Simple Representation: <a href="#8.3.2.1">8.3.2.1: ipopt_ode_simple.hpp</a>
            ODE Fitting Using Fast Representation: <a href="#8.3.3">8.3.3: ipopt_ode_fast</a>
                ODE Fitting Using Fast Representation: <a href="#8.3.3.1">8.3.3.1: ipopt_ode_fast.hpp</a>
            Driver for Running the Ipopt ODE Example: <a href="#8.3.4">8.3.4: ipopt_ode_run.hpp</a>
            Correctness Check for Both Simple and Fast Representations: <a href="#8.3.5">8.3.5: ipopt_ode_check.cpp</a>
        Speed Test for Both Simple and Fast Representations: <a href="#8.4">8.4: ipopt_ode_speed.cpp</a>
    Examples: <a href="#9">9: Example</a>
        General Examples: <a href="#9.1">9.1: General</a>
            Creating Your Own Interface to an ADFun Object: <a href="#9.1.1">9.1.1: ad_fun.cpp</a>
            Example and Test Linking CppAD to Languages Other than C++: <a href="#9.1.2">9.1.2: ad_in_c.cpp</a>
            Differentiate Conjugate Gradient Algorithm: Example and Test: <a href="#9.1.3">9.1.3: conj_grad.cpp</a>
            Gradient of Determinant Using Expansion by Minors: Example and Test: <a href="#9.1.4">9.1.4: HesMinorDet.cpp</a>
            Gradient of Determinant Using LU Factorization: Example and Test: <a href="#9.1.5">9.1.5: HesLuDet.cpp</a>
            Interfacing to C: Example and Test: <a href="#9.1.6">9.1.6: Interface2C.cpp</a>
            Gradient of Determinant Using Expansion by Minors: Example and Test: <a href="#9.1.7">9.1.7: JacMinorDet.cpp</a>
            Gradient of Determinant Using Lu Factorization: Example and Test: <a href="#9.1.8">9.1.8: JacLuDet.cpp</a>
            Using Multiple Levels of AD: <a href="#9.1.9">9.1.9: mul_level</a>
                Multiple Tapes: Example and Test: <a href="#9.1.9.1">9.1.9.1: mul_level.cpp</a>
                Computing a Jacobian With Constants that Change: <a href="#9.1.9.2">9.1.9.2: change_const.cpp</a>
            A Stiff Ode: Example and Test: <a href="#9.1.10">9.1.10: OdeStiff.cpp</a>
            Taylor's Ode Solver: An Example and Test: <a href="#9.1.11">9.1.11: ode_taylor.cpp</a>
            Using Adolc with Taylor's Ode Solver: An Example and Test: <a href="#9.1.12">9.1.12: ode_taylor_adolc.cpp</a>
            Example Differentiating a Stack Machine Interpreter: <a href="#9.1.13">9.1.13: StackMachine.cpp</a>
        Utility Routines used by CppAD Examples: <a href="#9.2">9.2: ExampleUtility</a>
            CppAD Examples and Tests: <a href="#9.2.1">9.2.1: example.cpp</a>
            Run the Speed Examples: <a href="#9.2.2">9.2.2: speed_example.cpp</a>
            Lu Factor and Solve with Recorded Pivoting: <a href="#9.2.3">9.2.3: LuVecAD</a>
                Lu Factor and Solve With Recorded Pivoting: Example and Test: <a href="#9.2.3.1">9.2.3.1: LuVecADOk.cpp</a>
        List of All the CppAD Examples: <a href="#9.3">9.3: ListAllExamples</a>
        Choosing The Vector Testing Template Class: <a href="#9.4">9.4: test_vector</a>
    CppAD API Preprocessor Symbols: <a href="#10">10: preprocessor</a>
    Appendix: <a href="#11">11: Appendix</a>
        Frequently Asked Questions and Answers: <a href="#11.1">11.1: Faq</a>
        Speed Test Routines: <a href="#11.2">11.2: speed</a>
            Speed Testing Main Program: <a href="#11.2.1">11.2.1: speed_main</a>
                Speed Testing Gradient of Determinant Using Lu Factorization: <a href="#11.2.1.1">11.2.1.1: link_det_lu</a>
                Speed Testing Gradient of Determinant by Minor Expansion: <a href="#11.2.1.2">11.2.1.2: link_det_minor</a>
                Speed Testing Derivative of Matrix Multiply: <a href="#11.2.1.3">11.2.1.3: link_mat_mul</a>
                Speed Testing the Jacobian of Ode Solution: <a href="#11.2.1.4">11.2.1.4: link_ode</a>
                Speed Testing Second Derivative of a Polynomial: <a href="#11.2.1.5">11.2.1.5: link_poly</a>
                Speed Testing Sparse Hessian: <a href="#11.2.1.6">11.2.1.6: link_sparse_hessian</a>
                Speed Testing Sparse Jacobian: <a href="#11.2.1.7">11.2.1.7: link_sparse_jacobian</a>
                Microsoft Version of Elapsed Number of Seconds: <a href="#11.2.1.8">11.2.1.8: microsoft_timer</a>
            Speed Testing Utilities: <a href="#11.2.2">11.2.2: speed_utility</a>
                Simulate a [0,1] Uniform Random Variate: <a href="#11.2.2.1">11.2.2.1: uniform_01</a>
                    Source: uniform_01: <a href="#11.2.2.1.1">11.2.2.1.1: uniform_01.hpp</a>
                Determinant of a Minor: <a href="#11.2.2.2">11.2.2.2: det_of_minor</a>
                    Determinant of a Minor: Example and Test: <a href="#11.2.2.2.1">11.2.2.2.1: det_of_minor.cpp</a>
                    Source: det_of_minor: <a href="#11.2.2.2.2">11.2.2.2.2: det_of_minor.hpp</a>
                Determinant Using Expansion by Minors: <a href="#11.2.2.3">11.2.2.3: det_by_minor</a>
                    Determinant Using Expansion by Minors: Example and Test: <a href="#11.2.2.3.1">11.2.2.3.1: det_by_minor.cpp</a>
                    Source: det_by_minor: <a href="#11.2.2.3.2">11.2.2.3.2: det_by_minor.hpp</a>
                Determinant Using Expansion by Lu Factorization: <a href="#11.2.2.4">11.2.2.4: det_by_lu</a>
                    Determinant Using Lu Factorization: Example and Test: <a href="#11.2.2.4.1">11.2.2.4.1: det_by_lu.cpp</a>
                    Source: det_by_lu: <a href="#11.2.2.4.2">11.2.2.4.2: det_by_lu.hpp</a>
                Check Determinant of 3 by 3 matrix: <a href="#11.2.2.5">11.2.2.5: det_33</a>
                    Source: det_33: <a href="#11.2.2.5.1">11.2.2.5.1: det_33.hpp</a>
                Check Gradient of Determinant of 3 by 3 matrix: <a href="#11.2.2.6">11.2.2.6: det_grad_33</a>
                    Source: det_grad_33: <a href="#11.2.2.6.1">11.2.2.6.1: det_grad_33.hpp</a>
                Sum Elements of a Matrix Times Itself: <a href="#11.2.2.7">11.2.2.7: mat_sum_sq</a>
                    Sum of the Elements of the Square of a Matrix: Example and Test: <a href="#11.2.2.7.1">11.2.2.7.1: mat_sum_sq.cpp</a>
                    Source: mat_sum_sq: <a href="#11.2.2.7.2">11.2.2.7.2: mat_sum_sq.hpp</a>
                Evaluate a Function Defined in Terms of an ODE: <a href="#11.2.2.8">11.2.2.8: ode_evaluate</a>
                    ode_evaluate: Example and test: <a href="#11.2.2.8.1">11.2.2.8.1: ode_evaluate.cpp</a>
                    Source: ode_evaluate: <a href="#11.2.2.8.2">11.2.2.8.2: ode_evaluate.hpp</a>
                Evaluate a Function That Has a Sparse Hessian: <a href="#11.2.2.9">11.2.2.9: sparse_evaluate</a>
                    sparse_evaluate: Example and test: <a href="#11.2.2.9.1">11.2.2.9.1: sparse_evaluate.cpp</a>
                    Source: sparse_evaluate: <a href="#11.2.2.9.2">11.2.2.9.2: sparse_evaluate.hpp</a>
            Speed Test of Functions in Double: <a href="#11.2.3">11.2.3: speed_double</a>
                Double Speed: Determinant by Minor Expansion: <a href="#11.2.3.1">11.2.3.1: double_det_minor.cpp</a>
                Double Speed: Determinant Using Lu Factorization: <a href="#11.2.3.2">11.2.3.2: double_det_lu.cpp</a>
                CppAD Speed: Matrix Multiplication (Double Version): <a href="#11.2.3.3">11.2.3.3: double_mat_mul.cpp</a>
                Double Speed: Ode Solution: <a href="#11.2.3.4">11.2.3.4: double_ode.cpp</a>
                Double Speed: Evaluate a Polynomial: <a href="#11.2.3.5">11.2.3.5: double_poly.cpp</a>
                Double Speed: Sparse Hessian: <a href="#11.2.3.6">11.2.3.6: double_sparse_hessian.cpp</a>
                Double Speed: Sparse Jacobian: <a href="#11.2.3.7">11.2.3.7: double_sparse_jacobian.cpp</a>
            Speed Test of Derivatives Using Adolc: <a href="#11.2.4">11.2.4: speed_adolc</a>
                Adolc Speed: Gradient of Determinant by Minor Expansion: <a href="#11.2.4.1">11.2.4.1: adolc_det_minor.cpp</a>
                Adolc Speed: Gradient of Determinant Using Lu Factorization: <a href="#11.2.4.2">11.2.4.2: adolc_det_lu.cpp</a>
                Adolc Speed: Matrix Multiplication: <a href="#11.2.4.3">11.2.4.3: adolc_mat_mul.cpp</a>
                Adolc Speed: Ode: <a href="#11.2.4.4">11.2.4.4: adolc_ode.cpp</a>
                Adolc Speed: Second Derivative of a Polynomial: <a href="#11.2.4.5">11.2.4.5: adolc_poly.cpp</a>
                Adolc Speed: Sparse Hessian: <a href="#11.2.4.6">11.2.4.6: adolc_sparse_hessian.cpp</a>
                adolc Speed: sparse_jacobian: <a href="#11.2.4.7">11.2.4.7: adolc_sparse_jacobian.cpp</a>
            Speed Test Derivatives Using CppAD: <a href="#11.2.5">11.2.5: speed_cppad</a>
                CppAD Speed: Gradient of Determinant by Minor Expansion: <a href="#11.2.5.1">11.2.5.1: cppad_det_minor.cpp</a>
                CppAD Speed: Gradient of Determinant Using Lu Factorization: <a href="#11.2.5.2">11.2.5.2: cppad_det_lu.cpp</a>
                CppAD Speed: Matrix Multiplication: <a href="#11.2.5.3">11.2.5.3: cppad_mat_mul.cpp</a>
                CppAD Speed: Gradient of Ode Solution: <a href="#11.2.5.4">11.2.5.4: cppad_ode.cpp</a>
                CppAD Speed: Second Derivative of a Polynomial: <a href="#11.2.5.5">11.2.5.5: cppad_poly.cpp</a>
                CppAD Speed: Sparse Hessian: <a href="#11.2.5.6">11.2.5.6: cppad_sparse_hessian.cpp</a>
                CppAD Speed: Sparse Jacobian: <a href="#11.2.5.7">11.2.5.7: cppad_sparse_jacobian.cpp</a>
            Speed Test Derivatives Using Fadbad: <a href="#11.2.6">11.2.6: speed_fadbad</a>
                Fadbad Speed: Gradient of Determinant by Minor Expansion: <a href="#11.2.6.1">11.2.6.1: fadbad_det_minor.cpp</a>
                Fadbad Speed: Gradient of Determinant Using Lu Factorization: <a href="#11.2.6.2">11.2.6.2: fadbad_det_lu.cpp</a>
                Fadbad Speed: Matrix Multiplication: <a href="#11.2.6.3">11.2.6.3: fadbad_mat_mul.cpp</a>
                Fadbad Speed: Ode: <a href="#11.2.6.4">11.2.6.4: fadbad_ode.cpp</a>
                Fadbad Speed: Second Derivative of a Polynomial: <a href="#11.2.6.5">11.2.6.5: fadbad_poly.cpp</a>
                Fadbad Speed: Sparse Hessian: <a href="#11.2.6.6">11.2.6.6: fadbad_sparse_hessian.cpp</a>
                fadbad Speed: sparse_jacobian: <a href="#11.2.6.7">11.2.6.7: fadbad_sparse_jacobian.cpp</a>
            Speed Test Derivatives Using Sacado: <a href="#11.2.7">11.2.7: speed_sacado</a>
                Sacado Speed: Gradient of Determinant by Minor Expansion: <a href="#11.2.7.1">11.2.7.1: sacado_det_minor.cpp</a>
                Sacado Speed: Gradient of Determinant Using Lu Factorization: <a href="#11.2.7.2">11.2.7.2: sacado_det_lu.cpp</a>
                Sacado Speed: Matrix Multiplication: <a href="#11.2.7.3">11.2.7.3: sacado_mat_mul.cpp</a>
                Sacado Speed: Gradient of Ode Solution: <a href="#11.2.7.4">11.2.7.4: sacado_ode.cpp</a>
                Sacado Speed: Second Derivative of a Polynomial: <a href="#11.2.7.5">11.2.7.5: sacado_poly.cpp</a>
                Sacado Speed: Sparse Hessian: <a href="#11.2.7.6">11.2.7.6: sacado_sparse_hessian.cpp</a>
                sacado Speed: sparse_jacobian: <a href="#11.2.7.7">11.2.7.7: sacado_sparse_jacobian.cpp</a>
        The Theory of Derivative Calculations: <a href="#11.3">11.3: Theory</a>
            The Theory of Forward Mode: <a href="#11.3.1">11.3.1: ForwardTheory</a>
                Exponential Function Forward Taylor Polynomial Theory: <a href="#11.3.1.1">11.3.1.1: ExpForward</a>
                Logarithm Function Forward Taylor Polynomial Theory: <a href="#11.3.1.2">11.3.1.2: LogForward</a>
                Square Root Function Forward Taylor Polynomial Theory: <a href="#11.3.1.3">11.3.1.3: SqrtForward</a>
                Trigonometric and Hyperbolic Sine and Cosine Forward Theory: <a href="#11.3.1.4">11.3.1.4: SinCosForward</a>
                Arctangent Function Forward Taylor Polynomial Theory: <a href="#11.3.1.5">11.3.1.5: AtanForward</a>
                Arcsine Function Forward Taylor Polynomial Theory: <a href="#11.3.1.6">11.3.1.6: AsinForward</a>
                Arccosine Function Forward Taylor Polynomial Theory: <a href="#11.3.1.7">11.3.1.7: AcosForward</a>
                Tangent and Hyperbolic Tangent Forward Taylor Polynomial Theory: <a href="#11.3.1.8">11.3.1.8: tan_forward</a>
            The Theory of Reverse Mode: <a href="#11.3.2">11.3.2: ReverseTheory</a>
                Exponential Function Reverse Mode Theory: <a href="#11.3.2.1">11.3.2.1: ExpReverse</a>
                Logarithm Function Reverse Mode Theory: <a href="#11.3.2.2">11.3.2.2: LogReverse</a>
                Square Root Function Reverse Mode Theory: <a href="#11.3.2.3">11.3.2.3: SqrtReverse</a>
                Trigonometric and Hyperbolic Sine and Cosine Reverse Theory: <a href="#11.3.2.4">11.3.2.4: SinCosReverse</a>
                Arctangent Function Reverse Mode Theory: <a href="#11.3.2.5">11.3.2.5: AtanReverse</a>
                Arcsine Function Reverse Mode Theory: <a href="#11.3.2.6">11.3.2.6: AsinReverse</a>
                Arccosine Function Reverse Mode Theory: <a href="#11.3.2.7">11.3.2.7: AcosReverse</a>
                Tangent and Hyperbolic Tangent Reverse Mode Theory: <a href="#11.3.2.8">11.3.2.8: tan_reverse</a>
            An Important Reverse Mode Identity: <a href="#11.3.3">11.3.3: reverse_identity</a>
        Glossary: <a href="#11.4">11.4: glossary</a>
        Bibliography: <a href="#11.5">11.5: Bib</a>
        Know Bugs and Problems Using CppAD: <a href="#11.6">11.6: Bugs</a>
        The CppAD Wish List: <a href="#11.7">11.7: WishList</a>
        Changes and Additions to CppAD: <a href="#11.8">11.8: whats_new</a>
            CppAD Changes and Additions During 2012: <a href="#11.8.1">11.8.1: whats_new_12</a>
            Changes and Additions to CppAD During 2011: <a href="#11.8.2">11.8.2: whats_new_11</a>
            Changes and Additions to CppAD During 2010: <a href="#11.8.3">11.8.3: whats_new_10</a>
            Changes and Additions to CppAD During 2009: <a href="#11.8.4">11.8.4: whats_new_09</a>
            Changes and Additions to CppAD During 2008: <a href="#11.8.5">11.8.5: whats_new_08</a>
            Changes and Additions to CppAD During 2007: <a href="#11.8.6">11.8.6: whats_new_07</a>
            Changes and Additions to CppAD During 2006: <a href="#11.8.7">11.8.7: whats_new_06</a>
            Changes and Additions to CppAD During 2005: <a href="#11.8.8">11.8.8: whats_new_05</a>
            Changes and Additions to CppAD During 2004: <a href="#11.8.9">11.8.9: whats_new_04</a>
            Changes and Additions to CppAD During 2003: <a href="#11.8.10">11.8.10: whats_new_03</a>
        CppAD Deprecated API Features: <a href="#11.9">11.9: deprecated</a>
            Deprecated Include Files: <a href="#11.9.1">11.9.1: include_deprecated</a>
            ADFun Object Deprecated Member Functions: <a href="#11.9.2">11.9.2: FunDeprecated</a>
            OpenMP Parallel Setup: <a href="#11.9.3">11.9.3: omp_max_thread</a>
            Routines That Track Use of New and Delete: <a href="#11.9.4">11.9.4: TrackNewDel</a>
                Tracking Use of New and Delete: Example and Test: <a href="#11.9.4.1">11.9.4.1: TrackNewDel.cpp</a>
            A Quick OpenMP Memory Allocator Used by CppAD: <a href="#11.9.5">11.9.5: omp_alloc</a>
                Set and Get Maximum Number of Threads for omp_alloc Allocator: <a href="#11.9.5.1">11.9.5.1: omp_max_num_threads</a>
                Is The Current Execution in OpenMP Parallel Mode: <a href="#11.9.5.2">11.9.5.2: omp_in_parallel</a>
                Get the Current OpenMP Thread Number: <a href="#11.9.5.3">11.9.5.3: omp_get_thread_num</a>
                Get At Least A Specified Amount of Memory: <a href="#11.9.5.4">11.9.5.4: omp_get_memory</a>
                Return Memory to omp_alloc: <a href="#11.9.5.5">11.9.5.5: omp_return_memory</a>
                Free Memory Currently Available for Quick Use by a Thread: <a href="#11.9.5.6">11.9.5.6: omp_free_available</a>
                Amount of Memory a Thread is Currently Using: <a href="#11.9.5.7">11.9.5.7: omp_inuse</a>
                Amount of Memory Available for Quick Use by a Thread: <a href="#11.9.5.8">11.9.5.8: omp_available</a>
                Allocate Memory and Create A Raw Array: <a href="#11.9.5.9">11.9.5.9: omp_create_array</a>
                Return A Raw Array to The Available Memory for a Thread: <a href="#11.9.5.10">11.9.5.10: omp_delete_array</a>
                Check If A Memory Allocation is Efficient for Another Use: <a href="#11.9.5.11">11.9.5.11: omp_efficient</a>
                Set Maximum Number of Threads for omp_alloc Allocator: <a href="#11.9.5.12">11.9.5.12: old_max_num_threads</a>
                OpenMP Memory Allocator: Example and Test: <a href="#11.9.5.13">11.9.5.13: omp_alloc.cpp</a>
        Your License for the CppAD Software: <a href="#11.10">11.10: License</a>
    Alphabetic Listing of Cross Reference Tags: <a href="#12">12: _reference</a>
    Keyword Index: <a href="#13">13: _index</a>
    External Internet References: <a href="#14">14: _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;CppAD&#xA0;pkg-config&#xA0;Files</a><br/>
<a href="#2.3" target="_top">2.3:&#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-20120203.cpl.tgz" target="_top"><span style='white-space: nowrap'>cppad-20120203.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-20120203.gpl.tgz" target="_top"><span style='white-space: nowrap'>cppad-20120203.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-20120203.</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-20120203<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-20120203/cppad/cppad.hpp<br/>
</span></font></code>
<br/>
<b><a name="2.1.c.e" id="2.1.c.e">2.1.c.e: Work Directory</a></b>
<br/>
Create the directory <code><font color="blue">cppad-20120203/work</font></code>,
which will be referred to as the work directory below.

<br/>
<br/>
<b><big><a name="2.1.d" id="2.1.d">2.1.d: Configure</a></big></b>
<br/>
Execute the following command in the work directory:


<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;--with-boostvector&#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;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;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;\<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;OPENMP_FLAGS=</span></font><i><font color="black"><span style='white-space: nowrap'>OpenmpFlags</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;\<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;TAPE_ADDR_TYPE=</span></font><i><font color="black"><span style='white-space: nowrap'>TapeAddrType</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
where only the <code><font color="blue">configure</font></code> line need appear; i.e.,
the entries one each of the other lines are optional.
The text in italic is replaced values that you choose;
see discussion below.

<br/>
<br/>
<b><big><a name="2.1.e" id="2.1.e">2.1.e: make</a></big></b>
<br/>
CppAD has some object libraries that are used for its correctness tests.
(Currently, none of these libraries get installed.)
You can build these libraries by executing the command

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;<br/>
</span></font></code>
in the work directory.

<br/>
<br/>
<b><a name="2.1.e.a" id="2.1.e.a">2.1.e.a: Examples and Tests</a></b>
<br/>
Once you have executed the <code><font color="blue">make</font></code> command,
you can run the correctness and speed tests.
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The following command will build all the correctness and speed tests.
In addition, it will run all the correctness tests:
<code><font color='blue'><pre style='display:inline'> 
	make test
</pre></font></code>

<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The following links describe how to build and run subsets of these tests:
<table><tr><td align='left'  valign='top'>

<a href="#3.1.i">3.1.i: <span style='white-space: nowrap'>get_started</span></a>
  
	</td><td align='left'  valign='top'>
 Getting Started Using CppAD to Compute Derivatives 
</td></tr><tr><td align='left'  valign='top'>

<a href="#3.4.a">3.4.a: <span style='white-space: nowrap'>exp_apx_main</span></a>
  
	</td><td align='left'  valign='top'>
 Correctness Tests For Exponential Approximation in Introduction 
</td></tr><tr><td align='left'  valign='top'>

<a href="#9.2.1.a">9.2.1.a: <span style='white-space: nowrap'>example</span></a>
  
	</td><td align='left'  valign='top'>
 CppAD Examples and Tests 
</td></tr><tr><td align='left'  valign='top'>

<a href="#4.3.4.1.a">4.3.4.1.a: <span style='white-space: nowrap'>print_for_cout</span></a>
  
	</td><td align='left'  valign='top'>
 Printing During Forward Mode: Example and Test 
</td></tr><tr><td align='left'  valign='top'>

<a href="#9.2.2.a">9.2.2.a: <span style='white-space: nowrap'>speed_example</span></a>
  
	</td><td align='left'  valign='top'>
 Run the Speed Examples 
</td></tr><tr><td align='left'  valign='top'>

<a href="#11.2.3.b">11.2.3.b: <span style='white-space: nowrap'>speed_double</span></a>
  
	</td><td align='left'  valign='top'>
 Speed Test of Functions in Double 
</td></tr><tr><td align='left'  valign='top'>

<a href="#11.2.4.c">11.2.4.c: <span style='white-space: nowrap'>speed_adolc</span></a>
  
	</td><td align='left'  valign='top'>
 Speed Test of Derivatives Using Adolc 
</td></tr><tr><td align='left'  valign='top'>

<a href="#11.2.5.b">11.2.5.b: <span style='white-space: nowrap'>speed_cppad</span></a>
  
	</td><td align='left'  valign='top'>
 Speed Test Derivatives Using CppAD 
</td></tr><tr><td align='left'  valign='top'>

<a href="#11.2.6.c">11.2.6.c: <span style='white-space: nowrap'>speed_fadbad</span></a>
  
	</td><td align='left'  valign='top'>
 Speed Test Derivatives Using Fadbad 
</td></tr><tr><td align='left'  valign='top'>

<a href="#11.2.7.c">11.2.7.c: <span style='white-space: nowrap'>speed_sacado</span></a>
  
	</td><td align='left'  valign='top'>
 Speed Test Derivatives Using Sacado 
</td></tr>
</table>
In addition,
you can run a large subset of correctness tests 
(that are not intended to be examples)
by executing the following commands starting in the work directory:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;test_more<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.f" id="2.1.f">2.1.f: 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 following commands starting in the work directory:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;speed/profile<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run a profile speed test 
by executing the command <code><font color="blue">./profile</font></code>;
see <a href="#11.2.1">11.2.1: <span style='white-space: nowrap'>speed_main</span></a>
 for the meaning of the command line
options to this program.
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>After you have run a profiling speed test,
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;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 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 profile | sed -f 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 profile.exe | sed -f gprof.sed
</pre></font></code>


<br/>
<br/>
<b><big><a name="2.1.g" id="2.1.g">2.1.g: 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.t">2.1.t: <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.h">2.1.h: <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-20120203<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.h" id="2.1.h">2.1.h: --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-20120203<br/>
</span></font></code>
(see <a href="#2.1.m">2.1.m: <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-20120203/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-20120203/cppad.xml<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.i" id="2.1.i">2.1.i: --with-stdvector</a></big></b>


<br/>
The 
<small><a href="#9.4">9.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><font color="blue">--with-boostvector</font></code> must not also be specified.

<br/>
<br/>
<b><big><a name="2.1.j" id="2.1.j">2.1.j: --with-boostvector</a></big></b>


<br/>
The 
<small><a href="#9.4">9.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-boostvector</font></code> is specified,
the default definition this template class is replaced by
<code><font color='blue'><pre style='display:inline'> 
	boost::numeric::ublas::vector
</pre></font></code>

In this case <code><font color="blue">--with-stdvector</font></code> must not also be specified.
See also, <a href="#2.1.q">2.1.q: <span style='white-space: nowrap'>BoostDir</span></a>


<br/>
<br/>
<b><big><a name="2.1.k" id="2.1.k">2.1.k: 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.l" id="2.1.l">2.1.l: OpenmpFlags</a></big></b>



<br/>
If the command line argument 
<code><i><font color="black"><span style='white-space: nowrap'>OpenmpFlags</span></font></i></code>
 is present,
it specifies the necessary flags so that the compiler will
properly interpret OpenMP directives.
For example, when using the GNU <code><font color="blue">g++</font></code> compiler, 
the following setting includes the OpenMP tests:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;OPENMP_FLAGS=-fopenmp<br/>
</span></font></code>
If you specify configure command,
the CppAD OpenMP correctness and speed tests will be built; see
<a href="#6.3.b.a">6.3.b.a: <span style='white-space: nowrap'>threading</span></a>
 
multi-threading tests.

<br/>
<br/>
<b><big><a name="2.1.m" id="2.1.m">2.1.m: 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.t">2.1.t: <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.h">2.1.h: <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-20120203<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.n" id="2.1.n">2.1.n: 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 following commands starting in the work directory:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;speed/adolc<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run an Adolc speed tests 
by executing the command <code><font color="blue">./adolc</font></code>;
see <a href="#11.2.1">11.2.1: <span style='white-space: nowrap'>speed_main</span></a>
 for the meaning of the command line
options to this program.

<br/>
<br/>
<b><a name="2.1.n.a" id="2.1.n.a">2.1.n.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.n.b" id="2.1.n.b">2.1.n.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.o" id="2.1.o">2.1.o: 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 following commands starting in the work directory:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;speed/fadbad<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run a Fadbad speed tests 
by executing the command <code><font color="blue">./fadbad</font></code>;
see <a href="#11.2.1">11.2.1: <span style='white-space: nowrap'>speed_main</span></a>
 for the meaning of the command line
options to this program.


<br/>
<br/>
<b><big><a name="2.1.p" id="2.1.p">2.1.p: 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 following commands starting in the work directory:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;speed/sacado<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></font></code>
After executing <code><font color="blue">make test</font></code>, you can run a Sacado speed tests 
by executing the command <code><font color="blue">./sacado</font></code>;
see <a href="#11.2.1">11.2.1: <span style='white-space: nowrap'>speed_main</span></a>
 for the meaning of the command line
options to this program.


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

<br/>
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 files

<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/>
&#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/thread.hpp<br/>
</span></font></code>
are present.
In this case, these files will be used by CppAD.
See also, <a href="#2.1.j">2.1.j: <span style='white-space: nowrap'>--with-boostvector</span></a>


<br/>
<br/>
<b><big><a name="2.1.r" id="2.1.r">2.1.r: 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="#8.u">8.u: <span style='white-space: nowrap'>examples</span></a>
 can be built and tested
by executing the following commands starting in the work directory:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;#<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;cppad_ipopt/example<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;#<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;../test<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;#<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;../speed<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></font></code>
Once this has been done, you can execute the program
<code><font color="blue">./speed</font></code> in the <code><font color="blue">work/cppad_ipopt/speed</font></code> directory;
see <a href="#8.4">8.4: <span style='white-space: nowrap'>ipopt_ode_speed.cpp</span></a>
.

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



<br/>
If the command line argument 
<code><i><font color="black"><span style='white-space: nowrap'>TapeAddrType</span></font></i></code>
 is present,
it specifies the type used for address in the AD recordings (tapes).
The valid values for this argument are
<code><font color="blue">unsigned short int</font></code>,
<code><font color="blue">unsigned int</font></code>,
<code><font color="blue">size_t</font></code>.
The smaller the value of 
<code><i><font color="black"><span style='white-space: nowrap'>sizeof(</span></font></i><font color="blue"><span style='white-space: nowrap'>TapeAddrType</span></font><i><font color="black"><span style='white-space: nowrap'>)</span></font></i></code>
,
the less memory is used.
On the other hand, the value

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;std::numeric_limits&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>TapeAddrType</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;::max()<br/>
</span></font></code>
must be larger than any of the following:
<a href="#5.5.i">5.5.i: <span style='white-space: nowrap'>size_op</span></a>
,
<a href="#5.5.j">5.5.j: <span style='white-space: nowrap'>size_op_arg</span></a>
,
<a href="#5.5.k">5.5.k: <span style='white-space: nowrap'>size_par</span></a>
,
<a href="#5.5.h">5.5.h: <span style='white-space: nowrap'>size_par</span></a>
,
<a href="#5.5.l">5.5.l: <span style='white-space: nowrap'>size_par</span></a>
.


<br/>
<br/>
<b><big><a name="2.1.t" id="2.1.t">2.1.t: 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.g">2.1.g: <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><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
where 
<code><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i></code>
 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><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad/cppad.hpp<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.1.e" id="2.1.1.e">2.1.1.e: Stable Versions</a></big></b>
<br/>
Subversion downloads are available for a set of stable versions
(after the specified date, only bug fixes get applied).
The following link will list the available 
<code><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i></code>
 values
corresponding to 
<a href="https://projects.coin-or.org/CppAD/browser/stable" target="_top"><span style='white-space: nowrap'>stable&#xA0;versions</span></a>
 (https://projects.coin-or.org/CppAD/browser/stable) .
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><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><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:

<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'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad/cppad.hpp<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.1.f" id="2.1.1.f">2.1.1.f: Release Versions</a></big></b>
<br/>
Subversion downloads are available for a set of release versions
(no changes are applied).
The following link will list the available 
<code><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i></code>
 values
corresponding to 
<a href="https://projects.coin-or.org/CppAD/browser/releases" target="_top"><span style='white-space: nowrap'>release&#xA0;versions</span></a>
 (https://projects.coin-or.org/CppAD/browser/releases) .
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><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><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:

<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'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'>/cppad/cppad.hpp<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.1.g" id="2.1.1.g">2.1.1.g: 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><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'>/doc<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>dir</span></font></i><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/&#xA0;-xml<br/>
</span></font></code>
<br/>
<b><big><a name="2.1.1.h" id="2.1.1.h">2.1.1.h: 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 file

<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'>dir</span></font></i><font color="blue"><span style='white-space: nowrap'>/doc/index.xml<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.3">2.3: <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: CppAD pkg-config Files</a>
</big></big></b></center>
<br/>
<b><big><a name="2.2.a" id="2.2.a">2.2.a: Purpose</a></big></b>
<br/>
The <code><font color="blue">pkg-config</font></code> package helps with the use of installed libraries; 
see its
<a href="http://people.freedesktop.org/~dbn/pkg-config-guide.html" target="_top"><span style='white-space: nowrap'>guide</span></a>
 (http://people.freedesktop.org/~dbn/pkg-config-guide.html) 
for more information.

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

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


<code><i><font color="black"><span style='white-space: nowrap'>Name</span></font></i></code>
 </td><td align='left'  valign='top'>

	A human-readable name for the CppAD package.
</td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>Description</span></font></i></code>
 </td><td align='left'  valign='top'>

	A brief description of the CppAD package.
</td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>URL</span></font></i></code>
 </td><td align='left'  valign='top'>

	A URL where people can get more information about the CppAD package.
</td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>Version</span></font></i></code>
 </td><td align='left'  valign='top'>

	A string specifically defining the version of the CppAD package.
</td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>Cflags</span></font></i></code>
 </td><td align='left'  valign='top'>

	The necessary flags for using any of the CppAD include files.
</td></tr>
</table>
<br/>
<b><big><a name="2.2.c" id="2.2.c">2.2.c: CppAD Configuration Files</a></big></b>
<br/>
In the table below, 

<code><i><font color="black"><span style='white-space: nowrap'>builddir</span></font></i></code>
 is the build directory; i.e., the directory where
the CppAD
<a href="#2.1.d">2.1.d: <span style='white-space: nowrap'>Configure</span></a>
 command is execute.
The directory 
<code><i><font color="black"><span style='white-space: nowrap'>prefixdir</span></font></i></code>
 is the value of
<a href="#2.1.g">2.1.g: <span style='white-space: nowrap'>PrefixDir</span></a>
 during configuration.
The following configuration files contain the information above
<table><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>File</span></font></i></code>
             </td><td align='left'  valign='top'>
 
	
<code><i><font color="black"><span style='white-space: nowrap'>Description</span></font></i></code>
 </td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>prefixdir</span></font></i><font color="blue"><span style='white-space: nowrap'>/share/pkgconfig/cppad.pc</span></font></code>
              </td><td align='left'  valign='top'>
 
	for use after <a href="#2.1.t">2.1.t: <span style='white-space: nowrap'>make&#xA0;install</span></a>
 
</td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>builddir</span></font></i><font color="blue"><span style='white-space: nowrap'>/pkgconfig/cppad-uninstalled.pc</span></font></code>
       </td><td align='left'  valign='top'>
 
	for testing before <code><font color="blue">make install</font></code>                      
</td></tr>
</table>

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

<hr/>
<center><b><big><big><a name="2.3" id="2.3">2.3: Windows Download and Test</a>
</big></big></b></center>
<br/>
<b><big><a name="2.3.a" id="2.3.a">2.3.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.3.b" id="2.3.b">2.3.b: Download</a></big></b>






<br/>
<br/>
<b><a name="2.3.b.a" id="2.3.b.a">2.3.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.3.b.b" id="2.3.b.b">2.3.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.3.b.c" id="2.3.b.c">2.3.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-20120203.cpl.tgz" target="_top"><span style='white-space: nowrap'>cppad-20120203.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-20120203.gpl.tgz" target="_top"><span style='white-space: nowrap'>cppad-20120203.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-20120203</font></code>
where the files are placed.
</li></ol>


<br/>
<br/>
<b><big><a name="2.3.c" id="2.3.c">2.3.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-20120203\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-20120203 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.3.d" id="2.3.d">2.3.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-20120203\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-20120203 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.3.e" id="2.3.e">2.3.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-20120203\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-20120203 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.3.f" id="2.3.f">2.3.f: More Correctness Testing</a></big></b>

<br/>
Using Microsoft Visual C++,
open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20120203\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-20120203 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.3.g" id="2.3.g">2.3.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-20120203\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-20120203 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.3.h" id="2.3.h">2.3.h: CppAD Speed Test</a></big></b>



<br/>
Using Microsoft Visual C++,
open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20120203\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-20120203 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.3.i" id="2.3.i">2.3.i: Double Speed Test</a></big></b>



<br/>
Using Microsoft Visual C++,
open the workspace 
<code><font color='blue'><pre style='display:inline'> 
	cppad-20120203\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-20120203 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.3.j" id="2.3.j">2.3.j: Speed Utility Example</a></big></b>



<br/>
Using Microsoft Visual C++,
open the workspace 
<code><font color="blue">
	cppad-20120203\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-20120203 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: 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.b" id="3.b">3.b: Preface</a></big></b>


<br/>
<br/>
<b><a name="3.b.a" id="3.b.a">3.b.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.b.b" id="3.b.b">3.b.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.b.c" id="3.b.c">3.b.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.b.d" id="3.b.d">3.b.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.b.e" id="3.b.e">3.b.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.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>Getting&#xA0;Started&#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>Correctness&#xA0;Tests&#xA0;For&#xA0;Exponential&#xA0;Approximation&#xA0;in&#xA0;Introduction</td></tr></table>
<hr/>Input File: omh/introduction.omh

<hr/>
<center><b><big><big><a name="3.1" id="3.1">3.1: Getting Started 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="#7.12">7.12: <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>


<br/>
<br/>
<b><big><a name="3.1.i" id="3.1.i">3.1.i: Running</a></big></b>
<br/>
To build and run this program,
execute the following commands starting in the
<a href="#2.1.c.e">2.1.c.e: <span style='white-space: nowrap'>work&#xA0;directory</span></a>
:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;introduction/get_started<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></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><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;exp_2(</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><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><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><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><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i></code>
 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 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
(see 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>
 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 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 has prototype

<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'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><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 
<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i></code>
 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><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>(</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
 
	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

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


<code><i><font color="black"><span style='white-space: nowrap'>Type&#xA0;u&#xA0;</span></font></i><font color="blue"><span style='white-space: nowrap'>=</span></font><i><font color="black"><span style='white-space: nowrap'>&#xA0;v</span></font></i></code>
 
	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</td><td align='left'  valign='top'>
 construct 
<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i></code>
 with value equal to 
<code><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>
 
</td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;*&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>

	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</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><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;/&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>

	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</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><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;+&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>

	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</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>1</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 as 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="#7.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="#7.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="#7.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="#7.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><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;exp_eps(</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>epsilon</span></font></i><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><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><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><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i></code>
 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 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
(see 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>
 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 
<code><i><font color="black"><span style='white-space: nowrap'>epsilon</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>epsilon</span></font></i><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 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 has prototype

<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'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><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 
<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i></code>
 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><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>(</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
 
	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

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


<code><i><font color="black"><span style='white-space: nowrap'>Type&#xA0;u&#xA0;</span></font></i><font color="blue"><span style='white-space: nowrap'>=</span></font><i><font color="black"><span style='white-space: nowrap'>&#xA0;v</span></font></i></code>
 
	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</td><td align='left'  valign='top'>
 construct 
<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i></code>
 with value equal to 
<code><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>
 
</td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&gt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>

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


<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>

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


<code><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;*&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>

	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</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><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;/&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>

	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</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><i><font color="black"><span style='white-space: nowrap'>u</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;+&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>

	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</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><i><font color="black"><span style='white-space: nowrap'>u</span></font></i></code>

	</td><td align='left'  valign='top'>
 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>

	</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="#11.4.g.b">11.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="#7.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="#7.2">NearEqual</a>(dw[0], check, 1e-10, 1e-10);
	check = 0.;               // partial w.r.t. epsilon
	ok   &amp;= <a href="#7.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="#7.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="#7.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: Correctness Tests For Exponential Approximation in Introduction</a>
</big></big></b></center>
<br/>
<b><big><a name="3.4.a" id="3.4.a">3.4.a: Running Tests</a></big></b>
<br/>
To build this program and run its correctness tests,
execute the following commands starting in the
<a href="#2.1.c.e">2.1.c.e: <span style='white-space: nowrap'>work&#xA0;directory</span></a>
:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;introduction/exp_apx<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></font></code>
<br/>
<b><big><a name="3.4.b" id="3.4.b">3.4.b: main.cpp</a></big></b>

<code><font color="blue">
<br/>
<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="#11.4.b">11.4.b: <span style='white-space: nowrap'>AD&#xA0;of&#xA0;Base</span></a>
 objects.
These objects are used to <a href="#11.4.j">11.4.j: <span style='white-space: nowrap'>tape</span></a>

an AD of <i>Base</i>
<a href="#11.4.g.b">11.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="#11.4.h">11.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="#11.4.j.c">11.4.j.c: <span style='white-space: nowrap'>independent&#xA0;variables</span></a>

(<i>y</i> is a 
<a href="#11.4.l">11.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="#9.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="#9.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="#9.4">CPPAD_TEST_VECTOR</a>&lt;double&gt; dx(n);
	<a href="#9.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="#9.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="#9.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="#9.4">CPPAD_TEST_VECTOR</a>&lt;double&gt; dx(n);
	<a href="#9.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="#9.4">CPPAD_TEST_VECTOR</a>&lt;double&gt;  w(m);
	<a href="#9.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="#11.4.e">11.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="#11.4.b">11.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="#11.4.g.b">11.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="#11.4.l">11.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="#11.4.h">11.4.h: <span style='white-space: nowrap'>parameter</span></a>
; i.e.,
it cannot depend on the current
<a href="#11.4.j.c">11.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="#9.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="#9.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
