CppAD: A C++ Algorithmic Differentiation Package
20130102
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_BOOL_FUN_INCLUDED 00003 # define CPPAD_BOOL_FUN_INCLUDED 00004 00005 /* -------------------------------------------------------------------------- 00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell 00007 00008 CppAD is distributed under multiple licenses. This distribution is under 00009 the terms of the 00010 Eclipse Public License Version 1.0. 00011 00012 A copy of this license is included in the COPYING file of this distribution. 00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00014 -------------------------------------------------------------------------- */ 00015 00016 /* 00017 $begin BoolFun$$ 00018 $spell 00019 namespace 00020 bool 00021 CppAD 00022 const 00023 $$ 00024 00025 $index bool, AD function$$ 00026 $index function, AD bool$$ 00027 $index unary, AD bool$$ 00028 $index binary, AD bool$$ 00029 00030 $section AD Boolean Functions$$ 00031 00032 $head Syntax$$ 00033 $codei%CPPAD_BOOL_UNARY(%Base%, %unary_name%) 00034 %$$ 00035 $icode%b% = %unary_name%(%u%) 00036 %$$ 00037 $icode%b% = %unary_name%(%x%) 00038 %$$ 00039 $codei%CPPAD_BOOL_BINARY(%Base%, %binary_name%) 00040 %$$ 00041 $icode%b% = %binary_name%(%u%, %v%) 00042 %$$ 00043 $icode%b% = %binary_name%(%x%, %y%)%$$ 00044 00045 00046 $head Purpose$$ 00047 Create a $code bool$$ valued function that has $codei%AD<%Base%>%$$ arguments. 00048 00049 $head unary_name$$ 00050 This is the name of the $code bool$$ valued function with one argument 00051 (as it is used in the source code). 00052 The user must provide a version of $icode unary_name$$ where 00053 the argument has type $icode Base$$. 00054 CppAD uses this to create a version of $icode unary_name$$ where the 00055 argument has type $codei%AD<%Base%>%$$. 00056 00057 $head u$$ 00058 The argument $icode u$$ has prototype 00059 $codei% 00060 const %Base% &%u% 00061 %$$ 00062 It is the value at which the user provided version of $icode unary_name$$ 00063 is to be evaluated. 00064 It is also used for the first argument to the 00065 user provided version of $icode binary_name$$. 00066 00067 $head x$$ 00068 The argument $icode x$$ has prototype 00069 $codei% 00070 const AD<%Base%> &%x% 00071 %$$ 00072 It is the value at which the CppAD provided version of $icode unary_name$$ 00073 is to be evaluated. 00074 It is also used for the first argument to the 00075 CppAD provided version of $icode binary_name$$. 00076 00077 $head b$$ 00078 The result $icode b$$ has prototype 00079 $codei% 00080 bool %b% 00081 %$$ 00082 00083 $head Create Unary$$ 00084 $index CPPAD_BOOL_UNARY$$ 00085 The preprocessor macro invocation 00086 $codei% 00087 CPPAD_BOOL_UNARY(%Base%, %unary_name%) 00088 %$$ 00089 defines the version of $icode unary_name$$ with a $codei%AD<%Base%>%$$ 00090 argument. 00091 This can with in a namespace 00092 (not the $code CppAD$$ namespace) 00093 but must be outside of any routine. 00094 00095 $head binary_name$$ 00096 This is the name of the $code bool$$ valued function with two arguments 00097 (as it is used in the source code). 00098 The user must provide a version of $icode binary_name$$ where 00099 the arguments have type $icode Base$$. 00100 CppAD uses this to create a version of $icode binary_name$$ where the 00101 arguments have type $codei%AD<%Base%>%$$. 00102 00103 $head v$$ 00104 The argument $icode v$$ has prototype 00105 $codei% 00106 const %Base% &%v% 00107 %$$ 00108 It is the second argument to 00109 the user provided version of $icode binary_name$$. 00110 00111 $head y$$ 00112 The argument $icode x$$ has prototype 00113 $codei% 00114 const AD<%Base%> &%y% 00115 %$$ 00116 It is the second argument to 00117 the CppAD provided version of $icode binary_name$$. 00118 00119 $head Create Binary$$ 00120 $index CPPAD_BOOL_BINARY$$ 00121 The preprocessor macro invocation 00122 $codei% 00123 CPPAD_BOOL_BINARY(%Base%, %binary_name%) 00124 %$$ 00125 defines the version of $icode binary_name$$ with $codei%AD<%Base%>%$$ 00126 arguments. 00127 This can with in a namespace 00128 (not the $code CppAD$$ namespace) 00129 but must be outside of any routine. 00130 00131 00132 $head Operation Sequence$$ 00133 The result of this operation is not an 00134 $cref/AD of Base/glossary/AD of Base/$$ object. 00135 Thus it will not be recorded as part of an 00136 AD of $icode Base$$ 00137 $cref/operation sequence/glossary/Operation/Sequence/$$. 00138 00139 $head Example$$ 00140 $children% 00141 example/bool_fun.cpp 00142 %$$ 00143 The file 00144 $cref bool_fun.cpp$$ 00145 contains an example and test of these operations. 00146 It returns true if it succeeds and false otherwise. 00147 00148 $head Deprecated$$ 00149 The preprocessor symbols $code CppADCreateUnaryBool$$ 00150 and $code CppADCreateBinaryBool$$ are defined to be the same as 00151 $code CPPAD_BOOL_UNARY$$ and $code CPPAD_BOOL_BINARY$$ respectively 00152 (but their use is deprecated). 00153 00154 $end 00155 */ 00156 00157 CPPAD_BEGIN_NAMESPACE 00158 /*! 00159 \defgroup bool_fun_hpp bool_fun.hpp 00160 \{ 00161 \file bool_fun.hpp 00162 Routines and macros that implement functions from AD<Base> to bool 00163 \ref bool_fun_hpp. 00164 */ 00165 00166 /*! 00167 Macro that defines a unary function <tt>bool F(AD<Base> x)</tt> 00168 using <tt>bool F(Base x)</tt>. 00169 00170 \param Base 00171 base for the AD type of arguments to this unary bool valued function. 00172 00173 \param unary_name 00174 name of this unary function; i.e., \c F. 00175 */ 00176 # define CPPAD_BOOL_UNARY(Base, unary_name) \ 00177 inline bool unary_name (const CppAD::AD<Base> &x) \ 00178 { \ 00179 return CppAD::AD<Base>::UnaryBool(unary_name, x); \ 00180 } 00181 00182 /*! 00183 Deprecated name for CPPAD_BOOL_UNARY 00184 */ 00185 # define CppADCreateUnaryBool CPPAD_BOOL_UNARY 00186 00187 /*! 00188 Link a function name, and AD value pair to function call with base argument 00189 and bool retrun value. 00190 00191 \param FunName 00192 is the name of the function that we are linking. 00193 00194 \param x 00195 is the argument where we are evaluating the function. 00196 */ 00197 template <class Base> 00198 inline bool AD<Base>::UnaryBool( 00199 bool FunName(const Base &x), 00200 const AD<Base> &x 00201 ) 00202 { 00203 return FunName(x.value_); 00204 } 00205 00206 /*! 00207 Macro that defines a binary function <tt>bool F(AD<Base> x, AD<Base> y)</tt> 00208 using <tt>bool F(Base x, Base y)</tt>. 00209 00210 \param Base 00211 base for the AD type of arguments to this binary bool valued function. 00212 00213 \param binary_name 00214 name of this binary function; i.e., \c F. 00215 */ 00216 00217 # define CPPAD_BOOL_BINARY(Base, binary_name) \ 00218 inline bool binary_name ( \ 00219 const CppAD::AD<Base> &x, const CppAD::AD<Base> &y) \ 00220 { \ 00221 return CppAD::AD<Base>::BinaryBool(binary_name, x, y); \ 00222 } 00223 /*! 00224 Deprecated name for CPPAD_BOOL_BINARY 00225 */ 00226 # define CppADCreateBinaryBool CPPAD_BOOL_BINARY 00227 00228 00229 /*! 00230 Link a function name, and two AD values to function call with base arguments 00231 and bool retrun value. 00232 00233 \param FunName 00234 is the name of the function that we are linking. 00235 00236 \param x 00237 is the first argument where we are evaluating the function at. 00238 00239 \param y 00240 is the second argument where we are evaluating the function at. 00241 */ 00242 template <class Base> 00243 inline bool AD<Base>::BinaryBool( 00244 bool FunName(const Base &x, const Base &y), 00245 const AD<Base> &x, const AD<Base> &y 00246 ) 00247 { 00248 return FunName(x.value_, y.value_); 00249 } 00250 00251 /*! \} */ 00252 CPPAD_END_NAMESPACE 00253 # endif