<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='pmathml.xsl'?>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Frequently Asked Questions and Answers</title>
<meta name="description" id="description" content="Frequently Asked Questions and Answers"/>
<meta name="keywords" id="keywords" content=" Faq assignment operator independent bugs reporting Comparechange Ndebug complex faq test exception Errorhandler variable tape avoid record speed taping math functions function inverse matrix forward reverse mode namespace Cppad_test_vector preprocessor symbols standard using storage memory disk "/>
<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='_faq_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="appendix.xml" target="_top">Prev</a>
</td><td><a href="speed.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>Appendix</option>
<option>Faq</option>
</select>
</td>
<td>
<select onchange='choose_down2(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_down1(this)'>
<option>Appendix-&gt;</option>
<option>Faq</option>
<option>speed</option>
<option>Theory</option>
<option>glossary</option>
<option>Bib</option>
<option>Bugs</option>
<option>WishList</option>
<option>whats_new</option>
<option>deprecated</option>
<option>License</option>
</select>
</td>
<td>Faq</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Assignment and Independent</option>
<option>Bugs</option>
<option>CompareChange</option>
<option>Complex Types</option>
<option>Exceptions</option>
<option>Independent Variables</option>
<option>Math Functions</option>
<option>Matrix Inverse</option>
<option>Mode: Forward or Reverse</option>
<option>Namespace</option>
<option>---..Test Vector Preprocessor Symbol</option>
<option>---..Using</option>
<option>Speed</option>
<option>---..NDEBUG</option>
<option>---..Optimize</option>
<option>---..Memory Allocation</option>
<option>Tape Storage: Disk or Memory</option>
</select>
</td>
</tr></table><br/>
<center><b><big><big>Frequently Asked Questions and Answers</big></big></b></center>
<br/>
<b><big><a name="Assignment and Independent" id="Assignment and Independent">Assignment and Independent</a></big></b>



<br/>
Why does the code sequence
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;Independent(</span></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>);<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>[0];<br/>
</span></font></code>behave differently from the code sequence
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font></code><i><span style='white-space: nowrap'>v</span></i><code><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>[0];<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;Independent(</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>Before the call to <a href="independent.xml" target="_top"><span style='white-space: nowrap'>Independent</span></a>
,
<code><font color="blue"></font></code><i><span style='white-space: nowrap'>u[</span></i><code><font color="blue"><span style='white-space: nowrap'>0</span></font></code><i><span style='white-space: nowrap'>]</span></i> is a <a href="glossary.xml#Parameter" target="_top"><span style='white-space: nowrap'>parameter</span></a>

and after the call it is a variable.
Thus in the first case, <i>v</i> is a variable
and in the second case it is a parameter.

<br/>
<br/>
<b><big><a name="Bugs" id="Bugs">Bugs</a></big></b>

<br/>
What should I do if I suspect that there is a bug in CppAD ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code><ol type="1"><li>The first step is to search this page for mention of
some feature that perhaps you interpreting as a bug
(and is not).
If this does not solve your problem, continue
to the next step.
</li><li>

The second step is to check the 
<a href="whats_new.xml" target="_top"><span style='white-space: nowrap'>whats_new</span></a>
 messages from the date 
of the release that you are using to the current date.
If the bug has been mentioned and fixed,
then <a href="install.xml" target="_top"><span style='white-space: nowrap'>install</span></a>
 the current version of CppAD.
If this does not solve your problem, continue
to the next step.
</li><li>

Send an e-mail message to the mailing list 
<a href="http://list.coin-or.org/mailman/listinfo/cppad" target="_top"><span style='white-space: nowrap'>cppad@list.coin-or.org</span></a>

with a description of the bug.
Attaching a small source code sample program that 
demonstrates the bug is always helpful.
The smaller the program, the better the bug report.
</li></ol>


<br/>
<br/>
<b><big><a name="CompareChange" id="CompareChange">CompareChange</a></big></b>


<br/>
If you attempt to use the 
<a href="comparechange.xml" target="_top"><span style='white-space: nowrap'>CompareChange</span></a>

function when <code><font color="blue">NDEBUG</font></code> is true,
you will get an error message stating that
<code><font color="blue">CompareChange</font></code> is not a member of the
<a href="adfun.xml" target="_top"><span style='white-space: nowrap'>ADFun</span></a>
 template class.

<br/>
<br/>
<b><big><a name="Complex Types" id="Complex Types">Complex Types</a></big></b>

<br/>
Which of the following complex types is better:
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;AD&lt;&#xA0;std::complex&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;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;std::complex&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;<br/>
</span></font></code>Some functions are real differentiable than are not complex differentiable
(for example, the <a href="abs.xml#Complex Types" target="_top"><span style='white-space: nowrap'>complex&#xA0;abs&#xA0;function</span></a>
).
If you have to differentiate such functions, you should use
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;std::complex&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;<br/>
</span></font></code>If you are sure that you will not need to take any real partials
of complex valued function, it is more efficient to use
<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;AD&lt;&#xA0;std::complex&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;<br/>
</span></font></code><br/>
<b><big><a name="Exceptions" id="Exceptions">Exceptions</a></big></b>



<br/>
Why, in all the examples, do you pass back a boolean variable instead
of throwing an exception ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The examples are also used to test the correctness of CppAD
and to check your installation.
For these two uses, it is helpful to run all the tests
and to know which ones failed.
The actual code in CppAD uses the <a href="errorhandler.xml" target="_top"><span style='white-space: nowrap'>ErrorHandler</span></a>
 utility
to signal exceptions.
Specifications for redefining this action are provided.

<br/>
<br/>
<b><big><a name="Independent Variables" id="Independent Variables">Independent Variables</a></big></b>




<br/>
Is it possible to evaluate the same tape recording with different values 
for the independent variables ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>Yes (see <a href="forwardzero.xml" target="_top"><span style='white-space: nowrap'>ForwardZero</span></a>
). 

<br/>
<br/>
<b><big><a name="Math Functions" id="Math Functions">Math Functions</a></big></b>


<br/>
Are there plans to add more math functions to CppAD ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>Yes. The <a href="std_math_ad.xml" target="_top"><span style='white-space: nowrap'>std_math_ad</span></a>
 and <a href="mathother.xml" target="_top"><span style='white-space: nowrap'>MathOther</span></a>
 section contains
a list of the math functions included so far.
Contact the mailing list 
<a href="http://list.coin-or.org/mailman/listinfo/cppad" target="_top"><span style='white-space: nowrap'>cppad@list.coin-or.org</span></a>

if you need a math function that is has not yet been included.



<br/>
<br/>
<b><big><a name="Matrix Inverse" id="Matrix Inverse">Matrix Inverse</a></big></b>


<br/>
Is it possible to differentiate (with respect to the matrix elements)
the computation of the inverse of a matrix 
where the computation of the inverse uses pivoting ? 
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The example routine <a href="lusolve.xml" target="_top"><span style='white-space: nowrap'>LuSolve</span></a>
 can be used to do this
because the inverse is a special case of the solution of linear equations.
The examples 
<a href="jacludet.cpp.xml" target="_top"><span style='white-space: nowrap'>JacLuDet.cpp</span></a>
 and <a href="hesludet.cpp.xml" target="_top"><span style='white-space: nowrap'>HesLuDet.cpp</span></a>

use LuSolve to compute derivatives of the 
determinant with respect to the components of the matrix.

<br/>
<br/>
<b><big><a name="Mode: Forward or Reverse" id="Mode: Forward or Reverse">Mode: Forward or Reverse</a></big></b>



<br/>
When evaluating derivatives, 
one always has a choice between 
forward and reverse mode.
How does one decide which mode to use ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>In general, the best mode depends on the number of domain and range
components in the function that your are differentiating.
Each call to <a href="forward.xml" target="_top"><span style='white-space: nowrap'>Forward</span></a>
 computes the derivative of all 
the range directions with respect to one domain direction.
Each call to <a href="reverse.xml" target="_top"><span style='white-space: nowrap'>Reverse</span></a>
 computes the derivative of one 
range direction with respect to all the domain directions.
The times required for (speed of) 
calls <code><font color="blue">Forward</font></code> and <code><font color="blue">Reverse</font></code> are about equal.  
The <a href="seq_property.xml#Parameter" target="_top"><span style='white-space: nowrap'>Parameter</span></a>
 
function can be used to quickly determine that 
some range directions have derivative zero.



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




<br/>
<br/>
<b><a name="Namespace.Test Vector Preprocessor Symbol" id="Namespace.Test Vector Preprocessor Symbol">Test Vector Preprocessor Symbol</a></b>



<br/>
Why do you use <code><font color="blue">CPPAD_TEST_VECTOR</font></code> instead of a namespace for
the CppAD <a href="test_vector.xml" target="_top"><span style='white-space: nowrap'>test_vector</span></a>
 class ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The preprocessor symbol 
<small><a href="test_vector.xml" target="_top"><span style='white-space: nowrap'>CPPAD_TEST_VECTOR</span></a>
 </small>
determines which
<a href="simplevector.xml" target="_top"><span style='white-space: nowrap'>SimpleVector</span></a>
 template class is used for extensive testing.
The default definition for <code><font color="blue">CPPAD_TEST_VECTOR</font></code> is the
<a href="cppad_vector.xml" target="_top"><span style='white-space: nowrap'>CppAD::vector</span></a>
 template class, but it can be changed.
Note that all the preprocessor symbols that are defined or used
by CppAD begin with either <code><font color="blue">CPPAD</font></code>
(some old deprecated symbols begin with <code><font color="blue">CppAD</font></code>).

<br/>
<br/>
<b><a name="Namespace.Using" id="Namespace.Using">Using</a></b>



<br/>
Why do I have trouble when the following command
<code><font color='blue'><pre style='display:inline'> 
	using namespace CppAD
</pre></font></code>

is at the global level 
(not within a function or some other limited scope).
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>Some versions of <code><font color="blue"># include &lt;cmath&gt;</font></code> for
gcc and Visual C++ define the standard math functions,
(for example <code><font color="blue"><span style='white-space: nowrap'>double&#xA0;sqrt(double&#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>)
at the global level.
It is necessary to put your <code><font color="blue">using</font></code> commands within the scope
of a function,
or some other limited scope,
in order to shadow these improper global definitions.

<br/>
<br/>
<b><big><a name="Speed" id="Speed">Speed</a></big></b>


<br/>
How do I get the best speed performance out of CppAD ?

<br/>
<br/>
<b><a name="Speed.NDEBUG" id="Speed.NDEBUG">NDEBUG</a></b>
<br/>
You should compile your code with optimization, without debugging,
and with the preprocessor symbol <code><font color="blue">NDEBUG</font></code> defined.
(The <a href="speed_cppad.xml" target="_top"><span style='white-space: nowrap'>speed_cppad</span></a>
 tests do this.)
Note that defining <code><font color="blue">NDEBUG</font></code>
will turn off all of the error checking and reporting that
is done using <a href="errorhandler.xml" target="_top"><span style='white-space: nowrap'>ErrorHandler</span></a>
. 

<br/>
<br/>
<b><a name="Speed.Optimize" id="Speed.Optimize">Optimize</a></b>
<br/>
It is also possible that preforming a tape 
<a href="optimize.xml" target="_top"><span style='white-space: nowrap'>optimization</span></a>
 will improve the speed of evaluation
more than the time required for the optimization.

<br/>
<br/>
<b><a name="Speed.Memory Allocation" id="Speed.Memory Allocation">Memory Allocation</a></b>
<br/>
You may also increase execution speed
by calling <code><font color="blue">hold_memory</font></code> with
<a href="ta_hold_memory.xml#value" target="_top"><span style='white-space: nowrap'>value</span></a>
 equal to true.

<br/>
<br/>
<b><big><a name="Tape Storage: Disk or Memory" id="Tape Storage: Disk or Memory">Tape Storage: Disk or Memory</a></big></b>




<br/>
Does CppAD store the tape on disk or in memory ?
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>CppAD uses memory to store a different tape for recording operations
for each <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> type that is used.
If you have a very large number calculations that are recorded
on a tape, the tape will keep growing to hold the necessary information.
Eventually, virtual memory may be used to store the tape 
and the calculations may slow down because of necessary disk access.



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

</body>
</html>

