<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>exp_2: First Order Reverse Mode</title>
<meta name="description" id="description" content="exp_2: First Order Reverse Mode"/>
<meta name="keywords" id="keywords" content=" exp_2 reverse mode example first order "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_exp_2_rev1_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="exp_2_for1.cpp.xml" target="_top">Prev</a>
</td><td><a href="exp_2_rev1.cpp.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>Introduction</option>
<option>exp_2</option>
<option>exp_2_rev1</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>preprocessor</option>
<option>multi_thread</option>
<option>library</option>
<option>ipopt_solve</option>
<option>Example</option>
<option>speed</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>Introduction-&gt;</option>
<option>get_started.cpp</option>
<option>exp_2</option>
<option>exp_eps</option>
<option>exp_apx_main.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>exp_2-&gt;</option>
<option>exp_2.hpp</option>
<option>exp_2.cpp</option>
<option>exp_2_for0</option>
<option>exp_2_for1</option>
<option>exp_2_rev1</option>
<option>exp_2_for2</option>
<option>exp_2_rev2</option>
<option>exp_2_cppad</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>exp_2_rev1-&gt;</option>
<option>exp_2_rev1.cpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Purpose</option>
<option>Mathematical Form</option>
<option>f_5</option>
<option>Index 5: f_4</option>
<option>Index 4: f_3</option>
<option>Index 3: f_2</option>
<option>Index 2: f_1</option>
<option>Verification</option>
<option>Exercises</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>exp_2: First Order Reverse Mode</big></big></b></center>
<br/>
<b><big><a name="Purpose" id="Purpose">Purpose</a></big></b>
<br/>
First order reverse mode uses the 
<a href="exp_2_for0.xml#Operation Sequence" target="_top"><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="Mathematical Form" id="Mathematical Form">Mathematical Form</a></big></b>
<br/>
Suppose that we use the algorithm <a href="exp_2.hpp.xml" target="_top"><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="f_5" id="f_5">f_5</a></big></b>
<br/>
For our example, we chose to compute the derivative
of the value returned by <a href="exp_2.hpp.xml" target="_top"><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="exp_2_for0.xml#Operation Sequence" target="_top"><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="Index 5: f_4" id="Index 5: f_4">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="Index 4: f_3" id="Index 4: f_3">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="Index 3: f_2" id="Index 3: f_2">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="Index 2: f_1" id="Index 2: f_1">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="exp_2.hpp.xml" target="_top"><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="Verification" id="Verification">Verification</a></big></b>
<br/>
The file <a href="exp_2_rev1.cpp.xml" target="_top"><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="Exercises" id="Exercises">Exercises</a></big></b>

<ol type="1"><li>
Which statement in the routine defined by <a href="exp_2_rev1.cpp.xml" target="_top"><span style='white-space: nowrap'>exp_2_rev1.cpp</span></a>
 uses 
the values that are calculated by the routine 
defined by <a href="exp_2_for0.cpp.xml" target="_top"><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="exp_2_rev1.cpp.xml" target="_top"><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="exp_2_rev1.cpp.xml" target="_top"><span style='white-space: nowrap'>exp_2_rev1.cpp</span></a>
.
</li></ol>



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

</body>
</html>
