/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/near_equal_ext.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_NEAR_EQUAL_EXT_INCLUDED
00002 # define CPPAD_NEAR_EQUAL_EXT_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Common Public License Version 1.0.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 /*
00015 $begin NearEqualExt$$
00016 $spell
00017         cout
00018         endl
00019         Microsoft
00020         std
00021         Cpp
00022         namespace
00023         const
00024         bool
00025 $$
00026 
00027 $section Compare AD and Base Objects for Nearly Equal$$
00028 
00029 $index NearEqual, AD with Base$$
00030 
00031 $head Syntax$$
00032 $syntax%%b% = NearEqual(%x%, %y%, %r%, %a%)%$$
00033 
00034 
00035 $head Purpose$$
00036 The routine $xref/NearEqual/$$ determines if two objects of
00037 the same type are nearly.
00038 This routine is extended to the case where one object can have type
00039 $italic Type$$ while the other can have type
00040 $syntax%AD<%Type%>%$$ or
00041 $syntax%AD< std::complex<%Type%> >%$$.
00042 
00043 $head x$$
00044 The arguments $italic x$$ 
00045 has one of the following possible prototypes:
00046 $syntax%
00047         const %Type%                     &%x%
00048         const AD<%Type%>                 &%x%
00049         const AD< std::complex<%Type%> > &%x%
00050 %$$
00051 
00052 $head y$$
00053 The arguments $italic y$$ 
00054 has one of the following possible prototypes:
00055 $syntax%
00056         const %Type%                     &%y%
00057         const AD<%Type%>                 &%y%
00058         const AD< std::complex<%Type%> > &%x%
00059 %$$
00060 
00061 
00062 $head r$$
00063 The relative error criteria $italic r$$ has prototype
00064 $syntax%
00065         const %Type% &%r%
00066 %$$
00067 It must be greater than or equal to zero.
00068 The relative error condition is defined as:
00069 $latex \[
00070         \frac{ | x - y | } { |x| + |y| } \leq r
00071 \] $$
00072 
00073 $head a$$
00074 The absolute error criteria $italic a$$ has prototype
00075 $syntax%
00076         const %Type% &%a%
00077 %$$
00078 It must be greater than or equal to zero.
00079 The absolute error condition is defined as:
00080 $latex \[
00081         | x - y | \leq a
00082 \] $$
00083 
00084 $head b$$
00085 The return value $italic b$$ has prototype
00086 $syntax%
00087         bool %b%
00088 %$$
00089 If either $italic x$$ or $italic y$$ is infinite or not a number, 
00090 the return value is false.
00091 Otherwise, if either the relative or absolute error 
00092 condition (defined above) is satisfied, the return value is true.
00093 Otherwise, the return value is false.
00094 
00095 $head Type$$
00096 The type $italic Type$$ must be a
00097 $xref/NumericType/$$.
00098 The routine $xref/CheckNumericType/$$ will generate
00099 an error message if this is not the case.
00100 If $italic a$$ and $italic b$$ have type $italic Type$$,
00101 the following operation must be defined 
00102 $table
00103 $bold Operation$$     $cnext 
00104         $bold Description$$ $rnext
00105 $syntax%%a% <= %b%$$  $cnext 
00106         less that or equal operator (returns a $code bool$$ object)
00107 $tend
00108 
00109 $head Operation Sequence$$
00110 The result of this operation is not an
00111 $xref/glossary/AD of Base/AD of Base/$$ object.
00112 Thus it will not be recorded as part of an
00113 AD of $italic Base$$
00114 $xref/glossary/Operation/Sequence/operation sequence/1/$$.
00115 
00116 $head Example$$
00117 $children%
00118         example/near_equal_ext.cpp
00119 %$$
00120 The file $xref/NearEqualExt.cpp/$$ contains an example
00121 and test of this extension of $xref/NearEqual/$$.
00122 It return true if it succeeds and false otherwise.
00123 
00124 $end
00125 
00126 */
00127 // BEGIN CppAD namespace
00128 namespace CppAD {
00129 // ------------------------------------------------------------------------
00130 
00131 // fold into base type and then use <cppad/near_equal.hpp>
00132 template <class Base>
00133 inline bool NearEqual(
00134 const AD<Base> &x, const AD<Base> &y, const Base &r, const Base &a)
00135 {       return NearEqual(x.value_, y.value_, r, a);
00136 }
00137 
00138 template <class Base>
00139 inline bool NearEqual(
00140 const Base &x, const AD<Base> &y, const Base &r, const Base &a)
00141 {       return NearEqual(x, y.value_, r, a);
00142 }
00143 
00144 template <class Base>
00145 inline bool NearEqual(
00146 const AD<Base> &x, const Base &y, const Base &r, const Base &a)
00147 {       return NearEqual(x.value_, y, r, a);
00148 }
00149 
00150 // fold into AD type and then use cases above
00151 template <class Base>
00152 inline bool NearEqual(
00153         const VecAD_reference<Base> &x, const VecAD_reference<Base> &y, 
00154         const Base &r, const Base &a)
00155 {       return NearEqual(x.ADBase(), y.ADBase(), r, a);
00156 }
00157 template <class Base>
00158 inline bool NearEqual(const VecAD_reference<Base> &x, const AD<Base> &y, 
00159         const Base &r, const Base &a)
00160 {       return NearEqual(x.ADBase(), y, r, a);
00161 }
00162 template <class Base>
00163 inline bool NearEqual(const VecAD_reference<Base> &x, const Base &y, 
00164         const Base &r, const Base &a)
00165 {       return NearEqual(x.ADBase(), y, r, a);
00166 }
00167 template <class Base>
00168 inline bool NearEqual(const AD<Base> &x, const VecAD_reference<Base> &y, 
00169         const Base &r, const Base &a)
00170 {       return NearEqual(x, y.ADBase(), r, a);
00171 }
00172 template <class Base>
00173 inline bool NearEqual(const Base &x, const VecAD_reference<Base> &y, 
00174         const Base &r, const Base &a)
00175 {       return NearEqual(x, y.ADBase(), r, a);
00176 }
00177 
00178 } // END CppAD namespace
00179 
00180 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7