00001 # ifndef CPPAD_ADD_OP_INCLUDED 00002 # define CPPAD_ADD_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 ForAddOp$$ $comment CppAD Developer Documentation$$ 00017 $spell 00018 Addpv 00019 Addvp 00020 Addvv 00021 Taylor 00022 const 00023 inline 00024 Op 00025 $$ 00026 00027 $index add, forward operator$$ 00028 $index forward, add operator$$ 00029 $index operator, add forward$$ 00030 $index ForAdd$$ 00031 00032 $section Forward Mode Addition Operators$$ 00033 00034 $head Syntax$$ 00035 00036 $syntax%inline void ForAddvvOp(size_t %d%, 00037 %Base% *%z%, const %Base% *%x%, const %Base% *%y%)%$$ 00038 $pre 00039 $$ 00040 $syntax%inline void ForAddpvOp(size_t %d%, 00041 %Base% *%z%, const %Base% *%p%, const %Base% *%x%)%$$ 00042 $pre 00043 $$ 00044 $syntax%inline void ForAddvpOp(size_t %d%, 00045 %Base% *%z%, const %Base% *%x%, const %Base% *%p%)%$$ 00046 00047 00048 $head Description$$ 00049 Computes the $italic d$$ order Taylor coefficient for $latex Z$$ where 00050 $table 00051 Operation $cnext Value $rnext 00052 Addvv $cnext $latex Z = X + Y$$ $rnext 00053 Addpv $cnext $latex Z = P + Y$$ $rnext 00054 Addvp $cnext $latex Z = X + P$$ 00055 $tend 00056 00057 $head x$$ 00058 The vector $italic x$$ has length $latex d+1$$ and contains the 00059 $th d$$ order Taylor coefficient row vector for $italic X$$. 00060 00061 $head y$$ 00062 The vector $italic y$$ has length $latex d+1$$ and contains the 00063 $th d$$ order Taylor coefficient row vector for $italic Y$$. 00064 00065 $head p$$ 00066 The scalar $syntax%*%p%$$ contains the value of the parameter $italic P$$. 00067 00068 00069 $head z$$ 00070 The vector $italic z$$ has length $latex d+1$$. 00071 On input it contains the 00072 $th d-1$$ order Taylor coefficient row vector for $italic Z$$. 00073 On output it contains the 00074 $th d$$ order Taylor coefficient row vector for $italic Z$$; i.e., 00075 $syntax%%z%[%d%]%$$ is set equal to the $th d$$ Taylor coefficient for 00076 the function $italic Z$$. 00077 00078 $end 00079 ------------------------------------------------------------------------------ 00080 $begin RevAddOp$$ $comment CppAD Developer Documentation$$ 00081 $spell 00082 Addpv 00083 Addvp 00084 Addvv 00085 Taylor 00086 const 00087 inline 00088 Op 00089 px 00090 py 00091 pz 00092 $$ 00093 00094 00095 $index add, reverse operator$$ 00096 $index reverse, add operator$$ 00097 $index operator, add reverse$$ 00098 $index RevAdd$$ 00099 $section Reverse Mode Addition Operator$$ 00100 00101 $head Syntax$$ 00102 00103 $syntax%inline void RevAddvvOp(size_t %d%, 00104 const %Base% *%pz%, %Base% *%px%, %Base% *%py%)%$$ 00105 $pre 00106 $$ 00107 $syntax%inline void RevAddpvOp(size_t %d%, 00108 const %Base% *%pz%, %Base% *%px%)%$$ 00109 $pre 00110 $$ 00111 $syntax%inline void RevAddvpOp(size_t %d%, 00112 const %Base% *%pz%, %Base% *%py%)%$$ 00113 00114 $head Description$$ 00115 We are given the partial derivatives for a function 00116 $latex G(z, x, y)$$ and we wish to compute the partial derivatives for 00117 the function 00118 $latex \[ 00119 H(x, y) = G [ Z(x, y) , x , y ] 00120 \]$$ 00121 where $latex Z(x, y)$$ is defined as the 00122 $th d$$ order Taylor coefficient row vector for $italic Z$$ as 00123 a function of the corresponding vectors for 00124 $italic X$$ and $italic Y$$ where 00125 00126 $table 00127 Operation $cnext Value $rnext 00128 Addvv $cnext $latex Z = X + Y$$ $rnext 00129 Addpv $cnext $latex Z = P + Y$$ $rnext 00130 Addvp $cnext $latex Z = X + P$$ 00131 $tend 00132 00133 Note that $italic Z$$ has been used both the original addition 00134 function and for the corresponding mapping of Taylor coefficients. 00135 00136 $head pz$$ 00137 The vector $italic pz$$ has length $latex d+1$$ and 00138 $syntax%%pz%[%j%]%$$ contains the partial for $italic G$$ 00139 with respect to the $th j$$ order Taylor coefficient for $italic Z$$. 00140 00141 $head On Input$$ 00142 00143 $subhead px$$ 00144 The vector $italic px$$ has length $latex d+1$$ and 00145 $syntax%%px%[%j%]%$$ contains the partial for $italic G$$ 00146 with respect to the $th j$$ order Taylor coefficient for $italic X$$. 00147 00148 $subhead py$$ 00149 The vector $italic py$$ has length $latex d+1$$ and 00150 $syntax%%py%[%j%]%$$ contains the partial for $italic G$$ 00151 with respect to the $th j$$ order Taylor coefficient for $italic Y$$. 00152 00153 $head On Output$$ 00154 00155 $subhead px$$ 00156 If present, 00157 the vector $italic px$$ has length $latex d+1$$ and 00158 $syntax%%px%[%j%]%$$ contains the partial for $italic H$$ 00159 with respect to the $th j$$ order Taylor coefficient for $italic X$$. 00160 00161 $subhead py$$ 00162 If present, 00163 the vector $italic py$$ has length $latex d+1$$ and 00164 $syntax%%py%[%j%]%$$ contains the partial for $italic H$$ 00165 with respect to the $th j$$ order Taylor coefficient for $italic Y$$. 00166 00167 00168 $end 00169 ------------------------------------------------------------------------------ 00170 */ 00171 00172 // BEGIN CppAD namespace 00173 namespace CppAD { 00174 00175 // --------------------------- Addvv ----------------------------------------- 00176 00177 template <class Base> 00178 inline void ForAddvvOp(size_t d, 00179 Base *z, const Base *x, const Base *y) 00180 { 00181 z[d] = x[d] + y[d]; 00182 } 00183 00184 template <class Base> 00185 inline void RevAddvvOp(size_t d, 00186 const Base *pz, Base *px, Base *py) 00187 { 00188 // number of indices to access 00189 size_t i = d + 1; 00190 00191 while(i) 00192 { --i; 00193 px[i] += pz[i]; 00194 py[i] += pz[i]; 00195 } 00196 } 00197 00198 // --------------------------- Addpv ----------------------------------------- 00199 00200 template <class Base> 00201 inline void ForAddpvOp(size_t d, 00202 Base *z, const Base *p, const Base *y) 00203 { 00204 if( d == 0 ) 00205 z[d] = (*p) + y[d]; 00206 else z[d] = y[d]; 00207 00208 } 00209 00210 template <class Base> 00211 inline void RevAddpvOp(size_t d, 00212 const Base *pz, Base *py) 00213 { 00214 // number of indices to access 00215 size_t i = d + 1; 00216 00217 while(i) 00218 { --i; 00219 py[i] += pz[i]; 00220 } 00221 } 00222 00223 // --------------------------- Addvp ----------------------------------------- 00224 00225 template <class Base> 00226 inline void ForAddvpOp(size_t d, 00227 Base *z, const Base *x, const Base *p) 00228 { 00229 if( d == 0 ) 00230 z[d] = x[d] + (*p); 00231 else z[d] = x[d]; 00232 00233 } 00234 00235 template <class Base> 00236 inline void RevAddvpOp(size_t d, 00237 const Base *pz, Base *px) 00238 { 00239 // number of indices to access 00240 size_t i = d + 1; 00241 00242 while(i) 00243 { --i; 00244 px[i] += pz[i]; 00245 } 00246 } 00247 00248 } // END CppAD namespace 00249 00250 # endif