00001 # ifndef CPPAD_ATAN_OP_INCLUDED 00002 # define CPPAD_ATAN_OP_INCLUDED 00003 00004 /* -------------------------------------------------------------------------- 00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell 00006 00007 CppAD is distributed under multiple licenses. This distribution is under 00008 the terms of the 00009 Common Public License Version 1.0. 00010 00011 A copy of this license is included in the COPYING file of this distribution. 00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00013 -------------------------------------------------------------------------- */ 00014 00015 /* 00016 $begin ForAtanOp$$ $comment CppAD Developer Documentation$$ 00017 $spell 00018 atan 00019 Taylor 00020 const 00021 inline 00022 Op 00023 $$ 00024 00025 $index forward, atan$$ 00026 $index atan, forward$$ 00027 $index ForAtanOp$$ 00028 00029 $section Forward Mode Atan Function$$ 00030 00031 $head Syntax$$ 00032 00033 $syntax%inline void ForAtanOp(size_t %d%, 00034 %Base% *%z%, %Base% *%b%, const %Base% *%x%)%$$ 00035 00036 $head Description$$ 00037 Computes the $italic d$$ order Taylor coefficient for 00038 $latex Z$$ and $latex B$$ where 00039 $syntax% 00040 %Z% = atan(%X%) 00041 %B% = 1 + %X% * %X% 00042 %$$ 00043 00044 $head x$$ 00045 The vector $italic x$$ has length $latex d+1$$ and contains the 00046 $th d$$ order Taylor coefficient row vector for $italic X$$. 00047 00048 $head z$$ 00049 The vector $italic z$$ has length $latex d+1$$. 00050 On input it contains the 00051 $th d-1$$ order Taylor coefficient row vector for $italic Z$$. 00052 On output it contains the 00053 $th d$$ order Taylor coefficient row vector for $italic Z$$; i.e., 00054 $syntax%%z%[%d%]%$$ is set equal to the $th d$$ Taylor coefficient for 00055 the function $italic S$$. 00056 00057 $head b$$ 00058 The vector $italic c$$ has length $latex d+1$$. 00059 On input it contains the 00060 $th d-1$$ order Taylor coefficient row vector for $italic B$$. 00061 On output it contains the 00062 $th d$$ order Taylor coefficient row vector for $italic B$$; i.e., 00063 $syntax%%b%[%d%]%$$ is set equal to the $th d$$ Taylor coefficient for 00064 the function $italic B$$. 00065 00066 $end 00067 ------------------------------------------------------------------------------ 00068 $begin RevAtanOp$$ $comment CppAD Developer Documentation$$ 00069 $spell 00070 ps 00071 Atan 00072 pb 00073 Sin 00074 Taylor 00075 const 00076 inline 00077 Op 00078 px 00079 py 00080 pz 00081 $$ 00082 00083 00084 $index reverse, atan$$ 00085 $index atan, reverse$$ 00086 $index RevAtanOp$$ 00087 00088 $section Reverse Mode Atan Function$$ 00089 00090 $head Syntax$$ 00091 00092 $syntax%inline void RevAtanOp(size_t %d%, 00093 const %Base% *%z%, const %Base% *%b%, const %Base% *%x%, 00094 %Base% *%pz%, %Base% *%pb%, %Base% *%px%)%$$ 00095 00096 $head Description$$ 00097 We are given the partial derivatives for a function 00098 $latex G(z, b, x)$$ and we wish to compute the partial derivatives for 00099 the function 00100 $latex \[ 00101 H(x) = G [ Z(x) , B(x) , x ] 00102 \] $$ 00103 where $latex Z(x)$$ and $latex B(x)$$ are defined as the 00104 $th d$$ order Taylor coefficient row vector for $latex \arctan(x)$$ 00105 and $latex 1 + x * x$$ 00106 as a function of the corresponding row vector for $italic X$$; i.e., 00107 $latex \[ 00108 \begin{array}{rcl} 00109 Z & = & \arctan(X) \\ 00110 B & = & 1 + X * X 00111 \end{array} 00112 \]$$ 00113 Note that $italic Z$$ and $latex B$$ have 00114 been used both the original 00115 functions and for the corresponding mapping of Taylor coefficients. 00116 00117 $head x$$ 00118 The vector $italic x$$ has length $latex d+1$$ and contains the 00119 $th d$$ order Taylor coefficient row vector for $italic X$$. 00120 00121 00122 $head z$$ 00123 The vector $italic z$$ has length $latex d+1$$ and contains 00124 $th d$$ order Taylor coefficient row vector for $italic z$$. 00125 00126 $head b$$ 00127 The vector $italic b$$ has length $latex d+1$$ and contains 00128 $th d$$ order Taylor coefficient row vector for $italic B$$. 00129 00130 00131 $head On Input$$ 00132 00133 $subhead px$$ 00134 The vector $italic px$$ has length $latex d+1$$ and 00135 $syntax%%px%[%j%]%$$ contains the partial for $italic G$$ 00136 with respect to the $th j$$ order Taylor coefficient for $italic X$$. 00137 00138 $subhead pz$$ 00139 The vector $italic pz$$ has length $latex d+1$$ and 00140 $syntax%%pz%[%j%]%$$ contains the partial for $italic G$$ 00141 with respect to the $th j$$ order Taylor coefficient for $italic Z$$. 00142 00143 $subhead pb$$ 00144 The vector $italic pb$$ has length $latex d+1$$ and 00145 $syntax%%pb%[%j%]%$$ contains the partial for $italic G$$ 00146 with respect to the $th j$$ order Taylor coefficient for $italic B$$. 00147 00148 $head On Output$$ 00149 00150 $subhead px$$ 00151 The vector $italic px$$ has length $latex d+1$$ and 00152 $syntax%%px%[%j%]%$$ contains the partial for $italic H$$ 00153 with respect to the $th j$$ order Taylor coefficient for $italic X$$. 00154 00155 $subhead pz$$ 00156 The vector $italic ps$$ has length $latex d+1$$ and 00157 its contents are no longer specified; i.e., it has 00158 been used for work space. 00159 00160 $subhead pb$$ 00161 The vector $italic pb$$ has length $latex d+1$$ and 00162 its contents are no longer specified; i.e., it has 00163 been used for work space. 00164 00165 $end 00166 ------------------------------------------------------------------------------ 00167 */ 00168 00169 // BEGIN CppAD namespace 00170 namespace CppAD { 00171 00172 template <class Base> 00173 inline void ForAtanOp(size_t j, 00174 Base *z, Base *b, const Base *x) 00175 { size_t k; 00176 00177 if( j == 0 ) 00178 { z[j] = atan( x[0] ); 00179 b[j] = Base(1) + x[0] * x[0]; 00180 } 00181 else 00182 { 00183 b[j] = Base(2) * x[0] * x[j]; 00184 z[j] = Base(0); 00185 for(k = 1; k < j; k++) 00186 { b[j] += x[k] * x[j-k]; 00187 z[j] -= Base(k) * z[k] * b[j-k]; 00188 } 00189 z[j] /= Base(j); 00190 z[j] += x[j]; 00191 z[j] /= b[0]; 00192 } 00193 } 00194 00195 template <class Base> 00196 inline void RevAtanOp(size_t d, 00197 const Base *z, const Base *b, const Base *x, 00198 Base *pz, Base *pb, Base *px) 00199 { size_t k; 00200 00201 // number of indices to access 00202 size_t j = d; 00203 00204 while(j) 00205 { // scale partials w.r.t z[j] and b[j] 00206 pz[j] /= b[0]; 00207 pb[j] *= Base(2); 00208 00209 pb[0] -= pz[j] * z[j]; 00210 px[j] += pz[j] + pb[j] * x[0]; 00211 px[0] += pb[j] * x[j]; 00212 00213 // more scaling of partials w.r.t z[j] 00214 pz[j] /= Base(j); 00215 00216 for(k = 1; k < j; k++) 00217 { pb[j-k] -= pz[j] * Base(k) * z[k]; 00218 pz[k] -= pz[j] * Base(k) * b[j-k]; 00219 px[k] += pb[j] * x[j-k]; 00220 } 00221 --j; 00222 } 00223 px[0] += pz[0] / b[0] + pb[0] * Base(2) * x[0]; 00224 } 00225 00226 } // END CppAD namespace 00227 00228 # endif