<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Base Type Requirements for Conditional Expressions</title>
<meta name="description" id="description" content="Base Type Requirements for Conditional Expressions"/>
<meta name="keywords" id="keywords" content=" Condexp base require Cppad_cond_exp_rel "/>
<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='_base_cond_exp_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="base_member.xml" target="_top">Prev</a>
</td><td><a href="base_identical.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>AD</option>
<option>base_require</option>
<option>base_cond_exp</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>AD-&gt;</option>
<option>ad_ctor</option>
<option>ad_assign</option>
<option>Convert</option>
<option>ADValued</option>
<option>BoolValued</option>
<option>VecAD</option>
<option>base_require</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>base_require-&gt;</option>
<option>base_member</option>
<option>base_cond_exp</option>
<option>base_identical</option>
<option>base_ordered</option>
<option>base_std_math</option>
<option>base_example</option>
</select>
</td>
<td>base_cond_exp</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Purpose</option>
<option>CompareOp</option>
<option>CondExpTemplate</option>
<option>---..Ordered Type</option>
<option>---..Not Ordered</option>
<option>CondExpRel</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>Base Type Requirements for Conditional Expressions</big></big></b></center>
<br/>
<b><big><a name="Purpose" id="Purpose">Purpose</a></big></b>
<br/>
These definitions are required by the user's code to support the 

<code><font color="blue"><span style='white-space: nowrap'>AD&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 type for <a href="condexp.xml" target="_top"><span style='white-space: nowrap'>CondExp</span></a>
 operations:

<br/>
<br/>
<b><big><a name="CompareOp" id="CompareOp">CompareOp</a></big></b>
<br/>
The following <code><font color="blue">enum</font></code> type is used in the specifications below:
<code><font color='blue'><pre style='display:inline'> 
namespace CppAD {
	// The conditional expression operator enum type
	enum CompareOp 
	{	CompareLt, // less than
		CompareLe, // less than or equal
		CompareEq, // equal
		CompareGe, // greater than or equal
		CompareGt, // greater than
		CompareNe  // not equal
	};
}
</pre></font></code>


<br/>
<br/>
<b><big><a name="CondExpTemplate" id="CondExpTemplate">CondExpTemplate</a></big></b>
<br/>
The type 
<code><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i></code>
 must support the syntax

<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'>result</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;CppAD::CondExpOp(<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>cop</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>left</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>right</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_true</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_false</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;)<br/>
</span></font></code>
which computes implements the corresponding <a href="condexp.xml" target="_top"><span style='white-space: nowrap'>CondExp</span></a>
 
function when the result 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'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>result</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
The argument 
<code><i><font color="black"><span style='white-space: nowrap'>cop</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;enum&#xA0;CppAD::CompareOp&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>cop</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
The other arguments have the 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'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&amp;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>left</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&amp;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>right</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&amp;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_true</span></font></i><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'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&amp;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_false</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;<br/>
</span></font></code>
<br/>
<b><a name="CondExpTemplate.Ordered Type" id="CondExpTemplate.Ordered Type">Ordered Type</a></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i></code>
 is a relatively simple type
that supports
<code><font color="blue">&lt;</font></code>, <code><font color="blue">&lt;=</font></code>, <code><font color="blue">==</font></code>, <code><font color="blue">&gt;=</font></code>, and <code><font color="blue">&gt;</font></code> operators
its <code><font color="blue">CondExpOp</font></code> function can be defined by

<code><font color="blue"><span style='white-space: nowrap'><br/>
namespace&#xA0;CppAD&#xA0;{<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;inline&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;CondExpOp(<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;enum&#xA0;CppAD::CompareOp&#xA0;&#xA0;cop&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;,<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;left&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;,<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;right&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;,<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;exp_if_true&#xA0;&#xA0;&#xA0;,<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;exp_if_false&#xA0;&#xA0;)<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;{&#xA0;&#xA0;&#xA0;&#xA0;return&#xA0;CondExpTemplate(<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cop,&#xA0;left,&#xA0;right,&#xA0;trueCase,&#xA0;falseCase);<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;}<br/>
}<br/>
</span></font></code>
For example, see 
<a href="base_alloc.hpp.xml#CondExpOp" target="_top"><span style='white-space: nowrap'>double&#xA0;CondExpOp</span></a>
.
For an example of and implementation of <code><font color="blue">CondExpOp</font></code> with
a more involved 
<code><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i></code>
 type see
<a href="base_adolc.hpp.xml#CondExpOp" target="_top"><span style='white-space: nowrap'>adolc&#xA0;CondExpOp</span></a>
.
 

<br/>
<br/>
<b><a name="CondExpTemplate.Not Ordered" id="CondExpTemplate.Not Ordered">Not Ordered</a></b>
<br/>
If the type 
<code><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i></code>
 does not support ordering,
the <code><font color="blue">CondExpOp</font></code> function does not make sense.
In this case one might (but need not) define <code><font color="blue">CondExpOp</font></code> as follows:

<code><font color="blue"><span style='white-space: nowrap'><br/>
namespace&#xA0;CppAD&#xA0;{<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;inline&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;CondExpOp(<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;enum&#xA0;CompareOp&#xA0;cop&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;,<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&amp;left&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;,<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&amp;right&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;,<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&amp;exp_if_true&#xA0;&#xA0;,<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&amp;exp_if_false&#xA0;)<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;{&#xA0;&#xA0;&#xA0;&#xA0;//&#xA0;attempt&#xA0;to&#xA0;use&#xA0;CondExp&#xA0;with&#xA0;a&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;argument<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;assert(0);<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;return&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>(0);<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;}<br/>
}<br/>
</span></font></code>
For example, see
<a href="base_complex.hpp.xml#CondExpOp" target="_top"><span style='white-space: nowrap'>complex&#xA0;CondExpOp</span></a>
.
 
<br/>
<br/>
<b><big><a name="CondExpRel" id="CondExpRel">CondExpRel</a></big></b>

<br/>
The macro invocation

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CPPAD_COND_EXP_REL(</span></font><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
uses <code><font color="blue">CondExpOp</font></code> above to define the following functions

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CondExpLt(</span></font><i><font color="black"><span style='white-space: nowrap'>left</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>right</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_true</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_false</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CondExpLe(</span></font><i><font color="black"><span style='white-space: nowrap'>left</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>right</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_true</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_false</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CondExpEq(</span></font><i><font color="black"><span style='white-space: nowrap'>left</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>right</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_true</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_false</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CondExpGe(</span></font><i><font color="black"><span style='white-space: nowrap'>left</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>right</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_true</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_false</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CondExpGt(</span></font><i><font color="black"><span style='white-space: nowrap'>left</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>right</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_true</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>exp_if_false</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
where the arguments have type 
<code><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i></code>
.
This should be done inside of the CppAD namespace.
For example, see
<a href="base_alloc.hpp.xml#CondExpRel" target="_top"><span style='white-space: nowrap'>base_alloc</span></a>
.


<hr/>Input File: cppad/local/base_cond_exp.hpp

</body>
</html>
