CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bool_fun.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_BOOL_FUN_HPP
2 # define CPPAD_CORE_BOOL_FUN_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 /*
16 $begin BoolFun$$
17 $spell
18  namespace
19  bool
20  CppAD
21  const
22 $$
23 
24 
25 $section AD Boolean Functions$$
26 $mindex bool CPPAD_BOOL_UNARY CPPAD_BOOL_BINARY$$
27 
28 $head Syntax$$
29 $codei%CPPAD_BOOL_UNARY(%Base%, %unary_name%)
30 %$$
31 $icode%b% = %unary_name%(%u%)
32 %$$
33 $icode%b% = %unary_name%(%x%)
34 %$$
35 $codei%CPPAD_BOOL_BINARY(%Base%, %binary_name%)
36 %$$
37 $icode%b% = %binary_name%(%u%, %v%)
38 %$$
39 $icode%b% = %binary_name%(%x%, %y%)%$$
40 
41 
42 $head Purpose$$
43 Create a $code bool$$ valued function that has $codei%AD<%Base%>%$$ arguments.
44 
45 $head unary_name$$
46 This is the name of the $code bool$$ valued function with one argument
47 (as it is used in the source code).
48 The user must provide a version of $icode unary_name$$ where
49 the argument has type $icode Base$$.
50 CppAD uses this to create a version of $icode unary_name$$ where the
51 argument has type $codei%AD<%Base%>%$$.
52 
53 $head u$$
54 The argument $icode u$$ has prototype
55 $codei%
56  const %Base% &%u%
57 %$$
58 It is the value at which the user provided version of $icode unary_name$$
59 is to be evaluated.
60 It is also used for the first argument to the
61 user provided version of $icode binary_name$$.
62 
63 $head x$$
64 The argument $icode x$$ has prototype
65 $codei%
66  const AD<%Base%> &%x%
67 %$$
68 It is the value at which the CppAD provided version of $icode unary_name$$
69 is to be evaluated.
70 It is also used for the first argument to the
71 CppAD provided version of $icode binary_name$$.
72 
73 $head b$$
74 The result $icode b$$ has prototype
75 $codei%
76  bool %b%
77 %$$
78 
79 $head Create Unary$$
80 The preprocessor macro invocation
81 $codei%
82  CPPAD_BOOL_UNARY(%Base%, %unary_name%)
83 %$$
84 defines the version of $icode unary_name$$ with a $codei%AD<%Base%>%$$
85 argument.
86 This can with in a namespace
87 (not the $code CppAD$$ namespace)
88 but must be outside of any routine.
89 
90 $head binary_name$$
91 This is the name of the $code bool$$ valued function with two arguments
92 (as it is used in the source code).
93 The user must provide a version of $icode binary_name$$ where
94 the arguments have type $icode Base$$.
95 CppAD uses this to create a version of $icode binary_name$$ where the
96 arguments have type $codei%AD<%Base%>%$$.
97 
98 $head v$$
99 The argument $icode v$$ has prototype
100 $codei%
101  const %Base% &%v%
102 %$$
103 It is the second argument to
104 the user provided version of $icode binary_name$$.
105 
106 $head y$$
107 The argument $icode x$$ has prototype
108 $codei%
109  const AD<%Base%> &%y%
110 %$$
111 It is the second argument to
112 the CppAD provided version of $icode binary_name$$.
113 
114 $head Create Binary$$
115 The preprocessor macro invocation
116 $codei%
117  CPPAD_BOOL_BINARY(%Base%, %binary_name%)
118 %$$
119 defines the version of $icode binary_name$$ with $codei%AD<%Base%>%$$
120 arguments.
121 This can with in a namespace
122 (not the $code CppAD$$ namespace)
123 but must be outside of any routine.
124 
125 
126 $head Operation Sequence$$
127 The result of this operation is not an
128 $cref/AD of Base/glossary/AD of Base/$$ object.
129 Thus it will not be recorded as part of an
130 AD of $icode Base$$
131 $cref/operation sequence/glossary/Operation/Sequence/$$.
132 
133 $head Example$$
134 $children%
135  example/general/bool_fun.cpp
136 %$$
137 The file
138 $cref bool_fun.cpp$$
139 contains an example and test of these operations.
140 It returns true if it succeeds and false otherwise.
141 
142 $head Deprecated 2007-07-31$$
143 The preprocessor symbols $code CppADCreateUnaryBool$$
144 and $code CppADCreateBinaryBool$$ are defined to be the same as
145 $code CPPAD_BOOL_UNARY$$ and $code CPPAD_BOOL_BINARY$$ respectively
146 (but their use is deprecated).
147 
148 $end
149 */
150 
151 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
152 /*!
153 \file bool_fun.hpp
154 Routines and macros that implement functions from AD<Base> to bool.
155 */
156 
157 /*!
158 Macro that defines a unary function <tt>bool F(AD<Base> x)</tt>
159 using <tt>bool F(Base x)</tt>.
160 
161 \param Base
162 base for the AD type of arguments to this unary bool valued function.
163 
164 \param unary_name
165 name of this unary function; i.e., \c F.
166 */
167 # define CPPAD_BOOL_UNARY(Base, unary_name) \
168  inline bool unary_name (const CppAD::AD<Base> &x) \
169  { \
170  return CppAD::AD<Base>::UnaryBool(unary_name, x); \
171  }
172 
173 /*!
174 Deprecated name for CPPAD_BOOL_UNARY
175 */
176 # define CppADCreateUnaryBool CPPAD_BOOL_UNARY
177 
178 /*!
179 Link a function name, and AD value pair to function call with base argument
180 and bool retrun value.
181 
182 \param FunName
183 is the name of the function that we are linking.
184 
185 \param x
186 is the argument where we are evaluating the function.
187 */
188 template <class Base>
190  bool FunName(const Base &x),
191  const AD<Base> &x
192 )
193 {
194  return FunName(x.value_);
195 }
196 
197 /*!
198 Macro that defines a binary function <tt>bool F(AD<Base> x, AD<Base> y)</tt>
199 using <tt>bool F(Base x, Base y)</tt>.
200 
201 \param Base
202 base for the AD type of arguments to this binary bool valued function.
203 
204 \param binary_name
205 name of this binary function; i.e., \c F.
206 */
207 
208 # define CPPAD_BOOL_BINARY(Base, binary_name) \
209  inline bool binary_name ( \
210  const CppAD::AD<Base> &x, const CppAD::AD<Base> &y) \
211  { \
212  return CppAD::AD<Base>::BinaryBool(binary_name, x, y); \
213  }
214 /*!
215 Deprecated name for CPPAD_BOOL_BINARY
216 */
217 # define CppADCreateBinaryBool CPPAD_BOOL_BINARY
218 
219 
220 /*!
221 Link a function name, and two AD values to function call with base arguments
222 and bool retrun value.
223 
224 \param FunName
225 is the name of the function that we are linking.
226 
227 \param x
228 is the first argument where we are evaluating the function at.
229 
230 \param y
231 is the second argument where we are evaluating the function at.
232 */
233 template <class Base>
235  bool FunName(const Base &x, const Base &y),
236  const AD<Base> &x, const AD<Base> &y
237 )
238 {
239  return FunName(x.value_, y.value_);
240 }
241 
242 } // END_CPPAD_NAMESPACE
243 # endif
Base value_
Definition: ad.hpp:38
Definition: ad.hpp:34
static bool UnaryBool(bool FunName(const Base &x), const AD< Base > &x)
Link a function name, and AD value pair to function call with base argument and bool retrun value...
Definition: bool_fun.hpp:189
static bool BinaryBool(bool FunName(const Base &x, const Base &y), const AD< Base > &x, const AD< Base > &y)
Link a function name, and two AD values to function call with base arguments and bool retrun value...
Definition: bool_fun.hpp:234