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

Go to the documentation of this file.
00001 # ifndef CPPAD_BASE_COMPLEX_INCLUDED
00002 # define CPPAD_BASE_COMPLEX_INCLUDED
00003 /* --------------------------------------------------------------------------
00004 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00005 
00006 CppAD is distributed under multiple licenses. This distribution is under
00007 the terms of the
00008                     Common Public License Version 1.0.
00009 
00010 A copy of this license is included in the COPYING file of this distribution.
00011 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00012 -------------------------------------------------------------------------- */
00013 /*
00014 $begin base_complex.hpp$$
00015 $spell
00016         sqrt
00017         exp
00018         cos
00019         std
00020         const
00021         CppAD
00022         Op
00023         inline
00024         enum
00025         undef
00026         acos
00027         asin
00028         atan
00029         erf
00030         Cond
00031         namespace
00032         bool
00033 $$
00034 
00035 $index complex, double Base$$
00036 $index Base, double complex$$
00037 $index double, complex Base$$
00038 
00039 $section Enable use of AD<Base> where Base is std::complex<double>$$
00040 
00041 $children%
00042         example/complex_poly.cpp%
00043         example/not_complex_ad.cpp
00044 %$$
00045 
00046 $head Example$$
00047 The file $cref/ComplexPoly.cpp/$$ contains an example use of
00048 $code std::complex<double>$$ type for a CppAD $italic Base$$ type.
00049 It returns true if it succeeds and false otherwise.
00050 
00051 $head See Also$$
00052 The file $cref/not_complex_ad.cpp/$$ contains an example using
00053 complex arithmetic where the function is not complex differentiable.
00054 
00055 
00056 $head CondExpOp$$
00057 The conditional expressions $cref/CondExp/$$ 
00058 requires ordered comparisons (e.g., $code <$$)
00059 and the C++ standard complex types do not allow for ordered comparisons.
00060 Thus, we make it an error to use the conditional comparisons 
00061 with complex types:
00062 $codep */
00063 namespace CppAD {
00064         inline std::complex<double> CondExpOp(
00065                 enum CppAD::CompareOp      cop        ,
00066                 const std::complex<double> &left      ,
00067                 const std::complex<double> &right     ,
00068                 const std::complex<double> &trueCase  ,
00069                 const std::complex<double> &falseCase )
00070         {       CppAD::ErrorHandler::Call(
00071                         true     , __LINE__ , __FILE__ ,
00072                         "std::complex<float> CondExpOp(...)",
00073                         "Error: cannot use CondExp with a complex type"
00074                 );
00075                 return std::complex<double>(0);
00076         }
00077 }
00078 /* $$
00079 
00080 $head EqualOpSeq$$
00081 Complex numbers do not carry operation sequence information. 
00082 Thus they are equal in this sense if and only if there values are equal.  
00083 $codep */
00084 namespace CppAD {
00085         inline bool EqualOpSeq(
00086                 const std::complex<double> &x , 
00087                 const std::complex<double> &y )
00088         {       return x == y; 
00089         }
00090 }
00091 /* $$
00092 
00093 $head Identical$$
00094 Complex numbers do not carry operation sequence information. 
00095 Thus they are all parameters so the identical functions just check values.
00096 $codep */
00097 namespace CppAD {
00098         inline bool IdenticalPar(const std::complex<double> &x)
00099         {       return true; }
00100         inline bool IdenticalZero(const std::complex<double> &x)
00101         {       return (x == std::complex<double>(0., 0.) ); }
00102         inline bool IdenticalOne(const std::complex<double> &x)
00103         {       return (x == std::complex<double>(1., 0.) ); }
00104         inline bool IdenticalEqualPar(
00105                 const std::complex<double> &x, const std::complex<double> &y)
00106         {       return (x == y); }
00107 }
00108 /* $$
00109 
00110 $head Ordered$$
00111 
00112 $codep */
00113 namespace CppAD {
00114         inline bool GreaterThanZero(const std::complex<double> &x)
00115         {       CppAD::ErrorHandler::Call(
00116                         true     , __LINE__ , __FILE__ ,
00117                         "GreaterThanZero(x)",
00118                         "Error: cannot use GreaterThanZero with complex"
00119                 );
00120                 return false;
00121         }
00122         inline bool GreaterThanOrZero(const std::complex<double> &x)
00123         {       CppAD::ErrorHandler::Call(
00124                         true     , __LINE__ , __FILE__ ,
00125                         "GreaterThanZero(x)",
00126                         "Error: cannot use GreaterThanZero with complex"
00127                 );
00128                 return false;
00129         }
00130         inline bool LessThanZero(const std::complex<double> &x)
00131         {       CppAD::ErrorHandler::Call(
00132                         true     , __LINE__ , __FILE__ ,
00133                         "LessThanZero(x)",
00134                         "Error: cannot use LessThanZero with complex"
00135                 );
00136                 return false;
00137         }
00138         inline bool LessThanOrZero(const std::complex<double> &x)
00139         {       CppAD::ErrorHandler::Call(
00140                         true     , __LINE__ , __FILE__ ,
00141                         "LessThanZero(x)",
00142                         "Error: cannot use LessThanZero with complex"
00143                 );
00144                 return false;
00145         }
00146 }
00147 /* $$
00148 
00149 $head Integer$$
00150 The implementation of this function must agree
00151 with the CppAD user specifications for complex arguments to the
00152 $cref/Integer/Integer/x/Complex Types/$$ function:
00153 $codep */
00154 namespace CppAD {
00155         inline int Integer(const std::complex<double> &x)
00156         {       return static_cast<int>( x.real() ); }
00157 }
00158 /* $$
00159 
00160 $head Standard Functions$$
00161 The following standard math functions,
00162 that are required by $cref/base_require/$$,
00163 are defined by 
00164 $code std::complex$$:
00165 $code cos$$,
00166 $code cosh$$,
00167 $code exp$$,
00168 $code log$$,
00169 $code pow$$,
00170 $code sin$$,
00171 $code sinh$$,
00172 $code sqrt$$.
00173 The other standard math functions,
00174 (and $code abs$$) required by $cref/base_require/$$
00175 are not defined for complex types
00176 (see $cref/abs/abs/Complex Types/$$ and $cref/StdMathUnary/StdMathUnary/fun/$$).
00177 Hence we make it an error to use them.
00178 $codep */
00179 # define CPPAD_INVALID_COMPLEX_CASE(function)                                 \
00180 inline std::complex<double> function(const std::complex<double> &x)           \
00181 {       CppAD::ErrorHandler::Call(                                            \
00182                 true     , __LINE__ , __FILE__ ,                              \
00183                 "std::complex<double>",                                       \
00184                         "Error: cannot use " #function " with a complex type" \
00185         );                                                                    \
00186         return std::complex<double>(0);                                       \
00187 }
00188 namespace CppAD {
00189         CPPAD_INVALID_COMPLEX_CASE(abs)
00190         CPPAD_INVALID_COMPLEX_CASE(acos)
00191         CPPAD_INVALID_COMPLEX_CASE(asin)
00192         CPPAD_INVALID_COMPLEX_CASE(atan)
00193         CPPAD_INVALID_COMPLEX_CASE(erf)
00194 }
00195 # undef CPPAD_INVALID_COMPLEX_CASE
00196 /* $$
00197 $end
00198 */
00199 # define CPPAD_INVALID_COMPLEX_CASE(function)                                 \
00200 inline std::complex<float> function(const std::complex<float> &x)             \
00201 {       CppAD::ErrorHandler::Call(                                            \
00202                 true     , __LINE__ , __FILE__ ,                              \
00203                 "std::complex<float>",                                        \
00204                         "Error: cannot use " #function " with a complex type" \
00205         );                                                                    \
00206         return std::complex<float>(0);                                        \
00207 }
00208 namespace CppAD {
00209         // CondExpOp ------------------------------------------------------
00210         inline std::complex<float> CondExpOp(
00211                 enum CppAD::CompareOp      cop       ,
00212                 const std::complex<float> &left      ,
00213                 const std::complex<float> &right     ,
00214                 const std::complex<float> &trueCase  ,
00215                 const std::complex<float> &falseCase )
00216         {       CppAD::ErrorHandler::Call(
00217                         true     , __LINE__ , __FILE__ ,
00218                         "std::complex<float> CondExpOp(...)",
00219                         "Error: cannot use CondExp with a complex type"
00220                 );
00221                 return std::complex<float>(0);
00222         }
00223         // EqualOpSeq -----------------------------------------------------
00224         inline bool EqualOpSeq(
00225                 const std::complex<float> &x , 
00226                 const std::complex<float> &y )
00227         {       return x == y; 
00228         }
00229         // Identical ------------------------------------------------------
00230         inline bool IdenticalPar(const std::complex<float> &x)
00231         {       return true; }
00232         inline bool IdenticalZero(const std::complex<float> &x)
00233         {       return (x == std::complex<float>(0., 0.) ); }
00234         inline bool IdenticalOne(const std::complex<float> &x)
00235         {       return (x == std::complex<float>(1., 0.) ); }
00236         inline bool IdenticalEqualPar(
00237                 const std::complex<float> &x, const std::complex<float> &y)
00238         {       return (x == y); }
00239         // Ordered --------------------------------------------------------
00240         inline bool GreaterThanZero(const std::complex<float> &x)
00241         {       CppAD::ErrorHandler::Call(
00242                         true     , __LINE__ , __FILE__ ,
00243                         "GreaterThanZero(x)",
00244                         "Error: cannot use GreaterThanZero with complex"
00245                 );
00246                 return false;
00247         }
00248         inline bool GreaterThanOrZero(const std::complex<float> &x)
00249         {       CppAD::ErrorHandler::Call(
00250                         true     , __LINE__ , __FILE__ ,
00251                         "GreaterThanOrZero(x)",
00252                         "Error: cannot use GreaterThanOrZero with complex"
00253                 );
00254                 return false;
00255         }
00256         inline bool LessThanZero(const std::complex<float> &x)
00257         {       CppAD::ErrorHandler::Call(
00258                         true     , __LINE__ , __FILE__ ,
00259                         "LessThanZero(x)",
00260                         "Error: cannot use LessThanZero with complex"
00261                 );
00262                 return false;
00263         }
00264         inline bool LessThanOrZero(const std::complex<float> &x)
00265         {       CppAD::ErrorHandler::Call(
00266                         true     , __LINE__ , __FILE__ ,
00267                         "LessThanOrZero(x)",
00268                         "Error: cannot use LessThanOrZero with complex"
00269                 );
00270                 return false;
00271         }
00272         // Integer ------------------------------------------------------
00273         inline int Integer(const std::complex<float> &x)
00274         {       return static_cast<int>( x.real() ); }
00275         // Invalid standrd math functions -------------------------------
00276         CPPAD_INVALID_COMPLEX_CASE(abs)
00277         CPPAD_INVALID_COMPLEX_CASE(acos)
00278         CPPAD_INVALID_COMPLEX_CASE(asin)
00279         CPPAD_INVALID_COMPLEX_CASE(atan)
00280         CPPAD_INVALID_COMPLEX_CASE(erf)
00281 }
00282 # undef CPPAD_INVALID_COMPLEX_CASE
00283 
00284 # endif

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