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