CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
base_std_math.hpp
Go to the documentation of this file.
1 // $Id$
2 # ifndef CPPAD_CORE_BASE_STD_MATH_HPP
3 # define CPPAD_CORE_BASE_STD_MATH_HPP
4 
5 /* --------------------------------------------------------------------------
6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
7 
8 CppAD is distributed under multiple licenses. This distribution is under
9 the terms of the
10  Eclipse Public License Version 1.0.
11 
12 A copy of this license is included in the COPYING file of this distribution.
13 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
14 -------------------------------------------------------------------------- */
15 
16 /*
17 $begin base_std_math$$
18 $spell
19  expm1
20  atanh
21  acosh
22  asinh
23  inline
24  fabs
25  isnan
26  alloc
27  std
28  acos
29  asin
30  atan
31  cos
32  exp
33  sqrt
34  const
35  CppAD
36  namespace
37  erf
38 $$
39 
40 $section Base Type Requirements for Standard Math Functions$$
41 
42 $head Purpose$$
43 These definitions are required for the user's code to use the type
44 $codei%AD<%Base%>%$$:
45 
46 $head Unary Standard Math$$
47 The type $icode Base$$ must support the following functions
48 unary standard math functions (in the CppAD namespace):
49 $table
50 $bold Syntax$$ $cnext $bold Result$$
51 $rnext
52 $icode%y% = abs(%x%)%$$ $cnext absolute value $rnext
53 $icode%y% = acos(%x%)%$$ $cnext inverse cosine $rnext
54 $icode%y% = asin(%x%)%$$ $cnext inverse sine $rnext
55 $icode%y% = atan(%x%)%$$ $cnext inverse tangent $rnext
56 $icode%y% = cos(%x%)%$$ $cnext cosine $rnext
57 $icode%y% = cosh(%x%)%$$ $cnext hyperbolic cosine $rnext
58 $icode%y% = exp(%x%)%$$ $cnext exponential $rnext
59 $icode%y% = fabs(%x%)%$$ $cnext absolute value $rnext
60 $icode%y% = log(%x%)%$$ $cnext natural logarithm $rnext
61 $icode%y% = sin(%x%)%$$ $cnext sine $rnext
62 $icode%y% = sinh(%x%)%$$ $cnext hyperbolic sine $rnext
63 $icode%y% = sqrt(%x%)%$$ $cnext square root $rnext
64 $icode%y% = tan(%x%)%$$ $cnext tangent
65 $tend
66 where the arguments and return value have the prototypes
67 $codei%
68  const %Base%& %x%
69  %Base% %y%
70 %$$
71 For example,
72 $cref/base_alloc/base_alloc.hpp/Unary Standard Math/$$,
73 
74 
75 $head CPPAD_STANDARD_MATH_UNARY$$
76 The macro invocation, within the CppAD namespace,
77 $codei%
78  CPPAD_STANDARD_MATH_UNARY(%Base%, %Fun%)
79 %$$
80 defines the syntax
81 $codei%
82  %y% = CppAD::%Fun%(%x%)
83 %$$
84 This macro uses the functions $codei%std::%Fun%$$ which
85 must be defined and have the same prototype as $codei%CppAD::%Fun%$$.
86 For example,
87 $cref/float/base_float.hpp/Unary Standard Math/$$.
88 
89 $head erf, asinh, acosh, atanh, expm1, log1p$$
90 If this preprocessor symbol
91 $code CPPAD_USE_CPLUSPLUS_2011$$ is true ($code 1$$),
92 when compiling for c++11, the type
93 $code double$$ is supported for the functions listed below.
94 In this case, the type $icode Base$$ must also support these functions:
95 $table
96 $bold Syntax$$ $cnext $bold Result$$
97 $rnext
98 $icode%y% = erf(%x%)%$$ $cnext error function $rnext
99 $icode%y% = asinh(%x%)%$$ $cnext inverse hyperbolic sin $rnext
100 $icode%y% = acosh(%x%)%$$ $cnext inverse hyperbolic cosine $rnext
101 $icode%y% = atanh(%x%)%$$ $cnext inverse hyperbolic tangent $rnext
102 $icode%y% = expm1(%x%)%$$ $cnext exponential of x minus one $rnext
103 $icode%y% = log1p(%x%)%$$ $cnext logarithm of one plus x
104 $tend
105 where the arguments and return value have the prototypes
106 $codei%
107  const %Base%& %x%
108  %Base% %y%
109 %$$
110 
111 $head sign$$
112 The type $icode Base$$ must support the syntax
113 $codei%
114  %y% = CppAD::sign(%x%)
115 %$$
116 which computes
117 $latex \[
118 y = \left\{ \begin{array}{ll}
119  +1 & {\rm if} \; x > 0 \\
120  0 & {\rm if} \; x = 0 \\
121  -1 & {\rm if} \; x < 0
122 \end{array} \right.
123 \] $$
124 where $icode x$$ and $icode y$$ have the same prototype as above.
125 For example, see
126 $cref/base_alloc/base_alloc.hpp/sign/$$.
127 Note that, if ordered comparisons are not defined for the type $icode Base$$,
128 the $code code sign$$ function should generate an assert if it is used; see
129 $cref/complex invalid unary math/base_complex.hpp/Invalid Unary Math/$$.
130 
131 $head pow$$
132 The type $icode Base$$ must support the syntax
133 $codei%
134  %z% = CppAD::pow(%x%, %y%)
135 %$$
136 which computes $latex z = x^y$$.
137 The arguments $icode x$$ and $icode y$$ have prototypes
138 $codei%
139  const %Base%& %x%
140  const %Base%& %y%
141 %$$
142 and the return value $icode z$$ has prototype
143 $codei%
144  %Base% %z%
145 %$$
146 For example, see
147 $cref/base_alloc/base_alloc.hpp/pow/$$.
148 
149 
150 $head isnan$$
151 If $icode Base$$ defines the $code isnan$$ function,
152 you may also have to provide a definition in the CppAD namespace
153 (to avoid a function ambiguity).
154 For example, see
155 $cref/base_complex/base_complex.hpp/isnan/$$.
156 
157 
158 $end
159 -------------------------------------------------------------------------------
160 */
161 
162 # include <cmath>
163 
164 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
165 
166 /*!
167 \file base_std_math.hpp
168 Defintions that aid meeting Base type requirements for standard math functions.
169 */
170 
171 /*!
172 \def CPPAD_STANDARD_MATH_UNARY(Type, Fun)
173 This macro defines the function
174 \verbatim
175  y = CppAD:Fun(x)
176 \endverbatim
177 where the argument \c x and return value \c y have type \c Type
178 using the corresponding function <code>std::Fun</code>.
179 */
180 # define CPPAD_STANDARD_MATH_UNARY(Type, Fun) \
181  inline Type Fun(const Type& x) \
182  { return std::Fun(x); }
183 
184 } // END_CPPAD_NAMESPACE
185 
186 # endif