CppAD: A C++ Algorithmic Differentiation Package  20130102
base_std_math.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_BASE_STD_MATH_INCLUDED
00003 # define CPPAD_BASE_STD_MATH_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 base_std_math$$
00018 $spell
00019      inline
00020      fabs
00021      isnan
00022      alloc
00023      std
00024      acos
00025      asin
00026      atan
00027      cos
00028      exp
00029      sqrt
00030      const
00031      CppAD
00032      namespace
00033 $$
00034 
00035 $section Base Type Requirements for Standard Math Functions$$
00036 $index math, base require$$
00037 $index base, math require$$
00038 $index require, base math$$
00039 
00040 $head Purpose$$
00041 These definitions are required for the user's code to use the type
00042 $codei%AD<%Base%>%$$:
00043 
00044 $head Unary Standard Math$$ 
00045 $index math, base unary$$
00046 $index base, unary math$$
00047 $index unary, base math$$
00048 The type $icode Base$$ must support the following functions
00049 unary standard math functions (in the CppAD namespace):
00050 $table
00051 $bold Syntax$$ $cnext $bold Result$$ 
00052 $rnext
00053 $icode%y% = abs(%x%)%$$  $cnext absolute value     $rnext
00054 $icode%y% = acos(%x%)%$$ $cnext inverse cosine     $rnext
00055 $icode%y% = asin(%x%)%$$ $cnext inverse sine       $rnext
00056 $icode%y% = atan(%x%)%$$ $cnext inverse tangent    $rnext
00057 $icode%y% = cos(%x%)%$$  $cnext cosine             $rnext
00058 $icode%y% = cosh(%x%)%$$ $cnext hyperbolic cosine  $rnext
00059 $icode%y% = exp(%x%)%$$  $cnext exponential        $rnext
00060 $icode%y% = fabs(%x%)%$$ $cnext absolute value     $rnext
00061 $icode%y% = log(%x%)%$$  $cnext natural logarithm  $rnext
00062 $icode%y% = sin(%x%)%$$  $cnext sine               $rnext
00063 $icode%y% = sinh(%x%)%$$ $cnext hyperbolic sine    $rnext
00064 $icode%y% = sqrt(%x%)%$$ $cnext square root        $rnext
00065 $icode%y% = tan(%x%)%$$  $cnext tangent           
00066 $tend
00067 where the arguments and return value have the prototypes
00068 $codei%
00069      const %Base%& %x%
00070      %Base%        %y%
00071 %$$
00072 For example,
00073 $cref/base_alloc/base_alloc.hpp/Unary Standard Math/$$,
00074 
00075 
00076 $head CPPAD_STANDARD_MATH_UNARY$$
00077 $index CPPAD_STANDARD_MATH_UNARY$$
00078 The macro invocation, within the CppAD namespace,
00079 $codei%
00080      CPPAD_STANDARD_MATH_UNARY(%Base%, %Fun%)
00081 %$$
00082 defines the syntax
00083 $codei%
00084      %y% = CppAD::%Fun%(%x%)
00085 %$$
00086 This macro uses the functions $codei%std::%Fun%$$ which
00087 must be defined and have the same prototype as $codei%CppAD::%Fun%$$.
00088 For example, 
00089 $cref/float/base_float.hpp/Unary Standard Math/$$.
00090 
00091 $head sign$$
00092 $index sign, base require$$
00093 $index base, sign require$$
00094 $index require, base sign$$
00095 The type $icode Base$$ must support the syntax
00096 $codei%
00097      %y% = CppAD::sign(%x%)
00098 %$$
00099 which computes
00100 $latex \[
00101 z = \left\{ \begin{array}{ll} 
00102      +1 & {\rm if} \; x > 0 \\
00103       0 & {\rm if} \; x = 0 \\
00104      -1 & {\rm if} \; x < 0
00105 \end{array} \right.
00106 \] $$
00107 The arguments $icode x$$ has prototype
00108 $codei%
00109      const %Base%& %x%
00110 %$$
00111 and the return value $icode z$$ has prototype
00112 $codei%
00113      %Base% %z%
00114 %$$
00115 For example, see
00116 $cref/base_alloc/base_alloc.hpp/sign/$$.
00117 Note that, if ordered comparisons are not defined for the type $icode Base$$,
00118 the $code code sign$$ function should generate an assert if it is used; see
00119 $cref/complex invalid unary math/base_complex.hpp/Invalid Unary Math/$$.
00120 
00121 $head pow$$
00122 $index pow, base require$$
00123 $index base, pow require$$
00124 $index require, base pow$$
00125 The type $icode Base$$ must support the syntax
00126 $codei%
00127      %z% = CppAD::pow(%x%, %y%)
00128 %$$
00129 which computes $latex z = x^y$$.
00130 The arguments $icode x$$ and $icode y$$ have prototypes
00131 $codei%
00132      const %Base%& %x%
00133      const %Base%& %y%
00134 %$$
00135 and the return value $icode z$$ has prototype
00136 $codei%
00137      %Base% %z%
00138 %$$
00139 For example, see
00140 $cref/base_alloc/base_alloc.hpp/pow/$$.
00141 
00142 
00143 $head isnan$$
00144 $index isnan, base type$$
00145 $index base, isnan$$ 
00146 If $icode Base$$ defines the $code isnan$$ function,
00147 you may also have to provide a definition in the CppAD namespace
00148 (to avoid a function ambiguity).
00149 For example, see
00150 $cref/base_complex/base_complex.hpp/isnan/$$.
00151 
00152 
00153 $head limits$$
00154 $index numeric, limits Base$$
00155 $index limits, numeric Base$$
00156 $index Base, numeric_limits$$
00157 The $cref/numeric_limits/limits/$$ functions
00158 $codei%
00159      %Base% CppAD::numeric_limits<%Base%>::epsilon()
00160      %Base% CppAD::numeric_limits<%Base%>::min()
00161      %Base% CppAD::numeric_limits<%Base%>::max()
00162 %$$
00163 must return machine epsilon,
00164 minimum positive normalize value,
00165 and maximum finite value for the type $icode Base$$.
00166 
00167 $subhead epsilon$$
00168 The deprecated function $cref epsilon$$ function
00169 must also be included. It can be implemented using
00170 $codei%
00171 namespace CppAD {
00172      template <> inline %Base% epsilon<%Base%>(void)
00173      {    return numeric_limits<%Base%>::epsilon(); }
00174 }
00175 %$$
00176 
00177 $end
00178 -------------------------------------------------------------------------------
00179 */
00180 
00181 # include <cmath>
00182 
00183 CPPAD_BEGIN_NAMESPACE
00184 
00185 /*!
00186 \defgroup base_std_math_hpp base_std_math.hpp
00187 \{
00188 \file base_std_math.hpp
00189 Defintions that aid meeting Base type requirements for standard math functions.
00190 */
00191 
00192 /*!
00193 \def CPPAD_STANDARD_MATH_UNARY(Type, Fun)
00194 This macro defines the function
00195 \verbatim
00196      y = CppAD:Fun(x)
00197 \endverbatim
00198 where the argument \c x and return value \c y have type \c Type
00199 using the corresponding function <code>std::Fun</code>.
00200 */
00201 # define CPPAD_STANDARD_MATH_UNARY(Type, Fun) \
00202      inline Type Fun(const Type& x)           \
00203      {    return std::Fun(x); }
00204 
00205 /*! \} */
00206 CPPAD_END_NAMESPACE
00207 
00208 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines