CppAD: A C++ Algorithmic Differentiation Package
20130102
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_COSH_OP_INCLUDED 00003 # define CPPAD_COSH_OP_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 CPPAD_BEGIN_NAMESPACE 00018 /*! 00019 \defgroup cosh_op_hpp cosh_op.hpp 00020 \{ 00021 \file cosh_op.hpp 00022 Forward and reverse mode calculations for z = cosh(x). 00023 */ 00024 00025 00026 /*! 00027 Compute forward mode Taylor coefficient for result of op = CoshOp. 00028 00029 The C++ source code corresponding to this operation is 00030 \verbatim 00031 z = cosh(x) 00032 \endverbatim 00033 The auxillary result is 00034 \verbatim 00035 y = sinh(x) 00036 \endverbatim 00037 The value of y, and its derivatives, are computed along with the value 00038 and derivatives of z. 00039 00040 \copydetails forward_unary2_op 00041 */ 00042 template <class Base> 00043 inline void forward_cosh_op( 00044 size_t j , 00045 size_t i_z , 00046 size_t i_x , 00047 size_t nc_taylor , 00048 Base* taylor ) 00049 { 00050 // check assumptions 00051 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 ); 00052 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 ); 00053 CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z ); 00054 CPPAD_ASSERT_UNKNOWN( j < nc_taylor ); 00055 00056 // Taylor coefficients corresponding to argument and result 00057 Base* x = taylor + i_x * nc_taylor; 00058 Base* c = taylor + i_z * nc_taylor; 00059 Base* s = c - nc_taylor; 00060 00061 // rest of this routine is identical for the following cases: 00062 // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op. 00063 size_t k; 00064 if( j == 0 ) 00065 { s[j] = sinh( x[0] ); 00066 c[j] = cosh( x[0] ); 00067 } 00068 else 00069 { 00070 s[j] = Base(0); 00071 c[j] = Base(0); 00072 for(k = 1; k <= j; k++) 00073 { s[j] += Base(k) * x[k] * c[j-k]; 00074 c[j] += Base(k) * x[k] * s[j-k]; 00075 } 00076 s[j] /= Base(j); 00077 c[j] /= Base(j); 00078 } 00079 } 00080 00081 /*! 00082 Compute zero order forward mode Taylor coefficient for result of op = CoshOp. 00083 00084 The C++ source code corresponding to this operation is 00085 \verbatim 00086 z = cosh(x) 00087 \endverbatim 00088 The auxillary result is 00089 \verbatim 00090 y = sinh(x) 00091 \endverbatim 00092 The value of y is computed along with the value of z. 00093 00094 \copydetails forward_unary2_op_0 00095 */ 00096 template <class Base> 00097 inline void forward_cosh_op_0( 00098 size_t i_z , 00099 size_t i_x , 00100 size_t nc_taylor , 00101 Base* taylor ) 00102 { 00103 // check assumptions 00104 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 ); 00105 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 ); 00106 CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z ); 00107 CPPAD_ASSERT_UNKNOWN( 0 < nc_taylor ); 00108 00109 // Taylor coefficients corresponding to argument and result 00110 Base* x = taylor + i_x * nc_taylor; 00111 Base* c = taylor + i_z * nc_taylor; // called z in documentation 00112 Base* s = c - nc_taylor; // called y in documentation 00113 00114 c[0] = cosh( x[0] ); 00115 s[0] = sinh( x[0] ); 00116 } 00117 /*! 00118 Compute reverse mode partial derivatives for result of op = CoshOp. 00119 00120 The C++ source code corresponding to this operation is 00121 \verbatim 00122 z = cosh(x) 00123 \endverbatim 00124 The auxillary result is 00125 \verbatim 00126 y = sinh(x) 00127 \endverbatim 00128 The value of y is computed along with the value of z. 00129 00130 \copydetails reverse_unary2_op 00131 */ 00132 00133 template <class Base> 00134 inline void reverse_cosh_op( 00135 size_t d , 00136 size_t i_z , 00137 size_t i_x , 00138 size_t nc_taylor , 00139 const Base* taylor , 00140 size_t nc_partial , 00141 Base* partial ) 00142 { 00143 // check assumptions 00144 CPPAD_ASSERT_UNKNOWN( NumArg(CoshOp) == 1 ); 00145 CPPAD_ASSERT_UNKNOWN( NumRes(CoshOp) == 2 ); 00146 CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z ); 00147 CPPAD_ASSERT_UNKNOWN( d < nc_taylor ); 00148 CPPAD_ASSERT_UNKNOWN( d < nc_partial ); 00149 00150 // Taylor coefficients and partials corresponding to argument 00151 const Base* x = taylor + i_x * nc_taylor; 00152 Base* px = partial + i_x * nc_partial; 00153 00154 // Taylor coefficients and partials corresponding to first result 00155 const Base* c = taylor + i_z * nc_taylor; // called z in doc 00156 Base* pc = partial + i_z * nc_partial; 00157 00158 // Taylor coefficients and partials corresponding to auxillary result 00159 const Base* s = c - nc_taylor; // called y in documentation 00160 Base* ps = pc - nc_partial; 00161 00162 // rest of this routine is identical for the following cases: 00163 // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op. 00164 size_t j = d; 00165 size_t k; 00166 while(j) 00167 { 00168 ps[j] /= Base(j); 00169 pc[j] /= Base(j); 00170 for(k = 1; k <= j; k++) 00171 { 00172 px[k] += ps[j] * Base(k) * c[j-k]; 00173 px[k] += pc[j] * Base(k) * s[j-k]; 00174 00175 ps[j-k] += pc[j] * Base(k) * x[k]; 00176 pc[j-k] += ps[j] * Base(k) * x[k]; 00177 00178 } 00179 --j; 00180 } 00181 px[0] += ps[0] * c[0]; 00182 px[0] += pc[0] * s[0]; 00183 } 00184 00185 /*! \} */ 00186 CPPAD_END_NAMESPACE 00187 # endif