CppAD: A C++ Algorithmic Differentiation Package
20130918
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_BOOL_FUN_INCLUDED 00003 # define CPPAD_BOOL_FUN_INCLUDED 00004 00005 /* -------------------------------------------------------------------------- 00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 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 namespace CppAD { // BEGIN_CPPAD_NAMESPACE 00158 /*! 00159 \file bool_fun.hpp 00160 Routines and macros that implement functions from AD<Base> to bool. 00161 */ 00162 00163 /*! 00164 Macro that defines a unary function <tt>bool F(AD<Base> x)</tt> 00165 using <tt>bool F(Base x)</tt>. 00166 00167 \param Base 00168 base for the AD type of arguments to this unary bool valued function. 00169 00170 \param unary_name 00171 name of this unary function; i.e., \c F. 00172 */ 00173 # define CPPAD_BOOL_UNARY(Base, unary_name) \ 00174 inline bool unary_name (const CppAD::AD<Base> &x) \ 00175 { \ 00176 return CppAD::AD<Base>::UnaryBool(unary_name, x); \ 00177 } 00178 00179 /*! 00180 Deprecated name for CPPAD_BOOL_UNARY 00181 */ 00182 # define CppADCreateUnaryBool CPPAD_BOOL_UNARY 00183 00184 /*! 00185 Link a function name, and AD value pair to function call with base argument 00186 and bool retrun value. 00187 00188 \param FunName 00189 is the name of the function that we are linking. 00190 00191 \param x 00192 is the argument where we are evaluating the function. 00193 */ 00194 template <class Base> 00195 inline bool AD<Base>::UnaryBool( 00196 bool FunName(const Base &x), 00197 const AD<Base> &x 00198 ) 00199 { 00200 return FunName(x.value_); 00201 } 00202 00203 /*! 00204 Macro that defines a binary function <tt>bool F(AD<Base> x, AD<Base> y)</tt> 00205 using <tt>bool F(Base x, Base y)</tt>. 00206 00207 \param Base 00208 base for the AD type of arguments to this binary bool valued function. 00209 00210 \param binary_name 00211 name of this binary function; i.e., \c F. 00212 */ 00213 00214 # define CPPAD_BOOL_BINARY(Base, binary_name) \ 00215 inline bool binary_name ( \ 00216 const CppAD::AD<Base> &x, const CppAD::AD<Base> &y) \ 00217 { \ 00218 return CppAD::AD<Base>::BinaryBool(binary_name, x, y); \ 00219 } 00220 /*! 00221 Deprecated name for CPPAD_BOOL_BINARY 00222 */ 00223 # define CppADCreateBinaryBool CPPAD_BOOL_BINARY 00224 00225 00226 /*! 00227 Link a function name, and two AD values to function call with base arguments 00228 and bool retrun value. 00229 00230 \param FunName 00231 is the name of the function that we are linking. 00232 00233 \param x 00234 is the first argument where we are evaluating the function at. 00235 00236 \param y 00237 is the second argument where we are evaluating the function at. 00238 */ 00239 template <class Base> 00240 inline bool AD<Base>::BinaryBool( 00241 bool FunName(const Base &x, const Base &y), 00242 const AD<Base> &x, const AD<Base> &y 00243 ) 00244 { 00245 return FunName(x.value_, y.value_); 00246 } 00247 00248 } // END_CPPAD_NAMESPACE 00249 # endif