Codebase list cppad / upstream/2015.00.00.7 doc / bool_fun.cpp.xml
upstream/2015.00.00.7

Tree @upstream/2015.00.00.7 (Download .tar.gz)

bool_fun.cpp.xml @upstream/2015.00.00.7raw · history · blame

<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>AD Boolean Functions: Example and Test</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="AD Boolean Functions: Example and Test"/>
<meta name="keywords" id="keywords" content=" ad boolean functions: example and test Ad bool "/>
<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='_bool_fun.cpp_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="boolfun.xml" target="_top">Prev</a>
</td><td><a href="parvar.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>BoolValued</option>
<option>BoolFun</option>
<option>bool_fun.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(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_down2(this)'>
<option>BoolValued-&gt;</option>
<option>Compare</option>
<option>NearEqualExt</option>
<option>BoolFun</option>
<option>ParVar</option>
<option>EqualOpSeq</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>BoolFun-&gt;</option>
<option>bool_fun.cpp</option>
</select>
</td>
<td>bool_fun.cpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>AD Boolean Functions: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;
# include &lt;complex&gt;


// define abbreviation for double precision complex 
typedef std::complex&lt;double&gt; Complex;

namespace {
	// a unary bool function with Complex argument
	static bool IsReal(const Complex &amp;x)
	{	return x.imag() == 0.; }

	// a binary bool function with Complex arguments
	static bool AbsGeq(const Complex &amp;x, const Complex &amp;y)
	{	double axsq = x.real() * x.real() + x.imag() * x.imag();
		double aysq = y.real() * y.real() + y.imag() * y.imag();

		return axsq &gt;= aysq;
	}

	// Create version of IsReal with <a href="ad.xml" target="_top">AD</a>&lt;Complex&gt; argument
	// inside of namespace and outside of any other function.
	CPPAD_BOOL_UNARY(Complex, IsReal)

	// Create version of AbsGeq with <a href="ad.xml" target="_top">AD</a>&lt;Complex&gt; arguments
	// inside of namespace and outside of any other function.
	CPPAD_BOOL_BINARY(Complex, AbsGeq)

}
bool BoolFun(void)
{	bool ok = true;

	CppAD::<a href="ad.xml" target="_top">AD</a>&lt;Complex&gt; x = Complex(1.,  0.);
	CppAD::<a href="ad.xml" target="_top">AD</a>&lt;Complex&gt; y = Complex(1.,  1.);

	ok &amp;= IsReal(x);
	ok &amp;= ! AbsGeq(x, y);

	return ok;
}

</pre>

</font></code>


<hr/>Input File: example/bool_fun.cpp

</body>
</html>