CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
near_equal_ext.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_NEAR_EQUAL_EXT_HPP
2 # define CPPAD_CORE_NEAR_EQUAL_EXT_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 /*
15 $begin NearEqualExt$$
16 $spell
17  cout
18  endl
19  Microsoft
20  std
21  Cpp
22  namespace
23  const
24  bool
25 $$
26 
27 $section Compare AD and Base Objects for Nearly Equal$$
28 $mindex NearEqual with$$
29 
30 
31 $head Syntax$$
32 $icode%b% = NearEqual(%x%, %y%, %r%, %a%)%$$
33 
34 
35 $head Purpose$$
36 The routine $cref NearEqual$$ determines if two objects of
37 the same type are nearly.
38 This routine is extended to the case where one object can have type
39 $icode Type$$ while the other can have type
40 $codei%AD<%Type%>%$$ or
41 $codei%AD< std::complex<%Type%> >%$$.
42 
43 $head x$$
44 The arguments $icode x$$
45 has one of the following possible prototypes:
46 $codei%
47  const %Type% &%x%
48  const AD<%Type%> &%x%
49  const AD< std::complex<%Type%> > &%x%
50 %$$
51 
52 $head y$$
53 The arguments $icode y$$
54 has one of the following possible prototypes:
55 $codei%
56  const %Type% &%y%
57  const AD<%Type%> &%y%
58  const AD< std::complex<%Type%> > &%x%
59 %$$
60 
61 
62 $head r$$
63 The relative error criteria $icode r$$ has prototype
64 $codei%
65  const %Type% &%r%
66 %$$
67 It must be greater than or equal to zero.
68 The relative error condition is defined as:
69 $latex \[
70  \frac{ | x - y | } { |x| + |y| } \leq r
71 \] $$
72 
73 $head a$$
74 The absolute error criteria $icode a$$ has prototype
75 $codei%
76  const %Type% &%a%
77 %$$
78 It must be greater than or equal to zero.
79 The absolute error condition is defined as:
80 $latex \[
81  | x - y | \leq a
82 \] $$
83 
84 $head b$$
85 The return value $icode b$$ has prototype
86 $codei%
87  bool %b%
88 %$$
89 If either $icode x$$ or $icode y$$ is infinite or not a number,
90 the return value is false.
91 Otherwise, if either the relative or absolute error
92 condition (defined above) is satisfied, the return value is true.
93 Otherwise, the return value is false.
94 
95 $head Type$$
96 The type $icode Type$$ must be a
97 $cref NumericType$$.
98 The routine $cref CheckNumericType$$ will generate
99 an error message if this is not the case.
100 If $icode a$$ and $icode b$$ have type $icode Type$$,
101 the following operation must be defined
102 $table
103 $bold Operation$$ $cnext
104  $bold Description$$ $rnext
105 $icode%a% <= %b%$$ $cnext
106  less that or equal operator (returns a $code bool$$ object)
107 $tend
108 
109 $head Operation Sequence$$
110 The result of this operation is not an
111 $cref/AD of Base/glossary/AD of Base/$$ object.
112 Thus it will not be recorded as part of an
113 AD of $icode Base$$
114 $cref/operation sequence/glossary/Operation/Sequence/$$.
115 
116 $head Example$$
117 $children%
118  example/general/near_equal_ext.cpp
119 %$$
120 The file $cref near_equal_ext.cpp$$ contains an example
121 and test of this extension of $cref NearEqual$$.
122 It return true if it succeeds and false otherwise.
123 
124 $end
125 
126 */
127 // BEGIN CppAD namespace
128 namespace CppAD {
129 // ------------------------------------------------------------------------
130 
131 // fold into base type and then use <cppad/near_equal.hpp>
132 template <class Base>
135 const AD<Base> &x, const AD<Base> &y, const Base &r, const Base &a)
136 { return NearEqual(x.value_, y.value_, r, a);
137 }
138 
139 template <class Base>
142 const Base &x, const AD<Base> &y, const Base &r, const Base &a)
143 { return NearEqual(x, y.value_, r, a);
144 }
145 
146 template <class Base>
149 const AD<Base> &x, const Base &y, const Base &r, const Base &a)
150 { return NearEqual(x.value_, y, r, a);
151 }
152 
153 // fold into AD type and then use cases above
154 template <class Base>
157  const VecAD_reference<Base> &x, const VecAD_reference<Base> &y,
158  const Base &r, const Base &a)
159 { return NearEqual(x.ADBase(), y.ADBase(), r, a);
160 }
161 template <class Base>
163 bool NearEqual(const VecAD_reference<Base> &x, const AD<Base> &y,
164  const Base &r, const Base &a)
165 { return NearEqual(x.ADBase(), y, r, a);
166 }
167 template <class Base>
169 bool NearEqual(const VecAD_reference<Base> &x, const Base &y,
170  const Base &r, const Base &a)
171 { return NearEqual(x.ADBase(), y, r, a);
172 }
173 template <class Base>
175 bool NearEqual(const AD<Base> &x, const VecAD_reference<Base> &y,
176  const Base &r, const Base &a)
177 { return NearEqual(x, y.ADBase(), r, a);
178 }
179 template <class Base>
181 bool NearEqual(const Base &x, const VecAD_reference<Base> &y,
182  const Base &r, const Base &a)
183 { return NearEqual(x, y.ADBase(), r, a);
184 }
185 
186 } // END CppAD namespace
187 
188 # endif
Base value_
Definition: ad.hpp:38
Definition: ad.hpp:34
#define CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
A version of the inline command that works with MC compiler.
Definition: define.hpp:43
AD< Base > ADBase(void) const
Conversion from VecAD_reference to AD&lt;Base&gt;. puts the correspond vecad load instruction in the tape...
Definition: vec_ad.hpp:392
bool NearEqual(const Type &x, const Type &y, const Type &r, const Type &a)
Definition: near_equal.hpp:168
Class used to hold a reference to an element of a VecAD object.
Definition: vec_ad.hpp:352