<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='pmathml.xsl'?>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>exp_eps: Operation Sequence and Zero Order Forward Sweep</title>
<meta name="description" id="description" content="exp_eps: Operation Sequence and Zero Order Forward Sweep"/>
<meta name="keywords" id="keywords" content=" exp_eps operation sequence example zero order forward "/>
<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_eps_for0_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_eps.cpp.xml" target="_top">Prev</a>
</td><td><a href="exp_eps_for0.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_eps</option>
<option>exp_eps_for0</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>multi_thread</option>
<option>library</option>
<option>cppad_ipopt_nlp</option>
<option>Example</option>
<option>preprocessor</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_eps-&gt;</option>
<option>exp_eps.hpp</option>
<option>exp_eps.cpp</option>
<option>exp_eps_for0</option>
<option>exp_eps_for1</option>
<option>exp_eps_rev1</option>
<option>exp_eps_for2</option>
<option>exp_eps_rev2</option>
<option>exp_eps_cppad</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>exp_eps_for0-&gt;</option>
<option>exp_eps_for0.cpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Mathematical Form</option>
<option>Operation Sequence</option>
<option>---..Variable</option>
<option>---..Parameter</option>
<option>---..Index</option>
<option>---..Code</option>
<option>---..Operation</option>
<option>---..Zero Order</option>
<option>---..Sweep</option>
<option>Return Value</option>
<option>Comparisons</option>
<option>Verification</option>
<option>Exercises</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>exp_eps: Operation Sequence and Zero Order Forward Sweep</big></big></b></center>
<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_eps.hpp.xml" target="_top"><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="exp_2_for0.xml#Mathematical Form" target="_top"><span style='white-space: nowrap'>exp_2</span></a>
.


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

corresponding to the algorithm <a href="exp_eps.hpp.xml" target="_top"><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="Operation Sequence.Variable" id="Operation Sequence.Variable">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="Operation Sequence.Parameter" id="Operation Sequence.Parameter">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="Operation Sequence.Index" id="Operation Sequence.Index">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="Operation Sequence.Code" id="Operation Sequence.Code">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="Operation Sequence.Operation" id="Operation Sequence.Operation">Operation</a></b>
<br/>
The Operation column contains the 
mathematical function corresponding to each atomic operation in the sequence.

<br/>
<br/>
<b><a name="Operation Sequence.Zero Order" id="Operation Sequence.Zero Order">Zero Order</a></b>
<br/>
The Zero Order column contains the 
<a href="exp_2_for0.xml#Zero Order Expansion" target="_top"><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="Operation Sequence.Sweep" id="Operation Sequence.Sweep">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="Return Value" id="Return Value">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="Comparisons" id="Comparisons">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="exp_eps.hpp.xml" target="_top"><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="Verification" id="Verification">Verification</a></big></b>
<br/>
The file <a href="exp_eps_for0.cpp.xml" target="_top"><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="Exercises" id="Exercises">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="exp_eps_for0.cpp.xml" target="_top"><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="exp_eps_for0.cpp.xml" target="_top"><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

</body>
</html>

