/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/sqrt_op.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_SQRT_OP_INCLUDED
00002 # define CPPAD_SQRT_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 ForSqrtOp$$ $comment CppAD Developer Documentation$$
00017 $spell
00018         Sqrt
00019         Taylor
00020         const
00021         inline
00022         Op
00023 $$
00024 
00025 $index forward, sqrt$$
00026 $index sqrt, forward$$
00027 $index ForSqrtOp$$
00028 
00029 $section Forward Mode Square Root Function$$
00030 
00031 $head Syntax$$
00032 
00033 $syntax%inline void ForSqrtOp(size_t %d%,
00034         %Base% *%z%, const %Base% *%x%)%$$
00035 
00036 $head Description$$
00037 Computes the $italic d$$ order Taylor coefficient for $latex Z$$ where
00038 $syntax%
00039         %Z% = Sqrt(%X%)
00040 %$$
00041 
00042 $head x$$
00043 The vector $italic x$$ has length $latex d+1$$ and contains the
00044 $th d$$ order Taylor coefficient row vector for $italic X$$.
00045 
00046 $head z$$
00047 The vector $italic z$$ has length $latex d+1$$.
00048 On input it contains the
00049 $th d-1$$ order Taylor coefficient row vector for $italic Z$$.
00050 On output it contains the
00051 $th d$$ order Taylor coefficient row vector for $italic Z$$; i.e.,
00052 $syntax%%z%[%d%]%$$ is set equal to the $th d$$ Taylor coefficient for
00053 the function $italic Z$$.
00054 
00055 $end
00056 ------------------------------------------------------------------------------
00057 $begin RevSqrtOp$$ $comment CppAD Developer Documentation$$
00058 $spell
00059         Sqrt
00060         Taylor
00061         const
00062         inline
00063         Op
00064         px
00065         py
00066         pz
00067 $$
00068 
00069 $index forward, sqrt$$
00070 $index sqrt, forward$$
00071 $index ForSqrtOp$$
00072 
00073 $section Reverse Mode Square Root Function$$
00074 
00075 $head Syntax$$
00076 
00077 $syntax%inline void RevSqrtOp(size_t %d%,
00078         const %Base% *%z%, const %Base% *%x%,
00079          %Base% *%pz%, %Base% *%px%)%$$
00080 
00081 $head Description$$
00082 We are given the partial derivatives for a function
00083 $latex G(z, x)$$ and we wish to compute the partial derivatives for
00084 the function
00085 $latex \[
00086         H(x) = G [ Z(x) , x ]
00087 \]$$
00088 where $latex Z(x)$$ is defined as the 
00089 $th d$$ order Taylor coefficient row vector for $italic Z$$ as
00090 a function of the corresponding row vector for $italic X$$ 
00091 and
00092 $latex \[
00093         Z = Sqrt(X)
00094 \]$$
00095 Note that $italic Z$$ has been used both the original square root 
00096 function and for the corresponding mapping of Taylor coefficients.
00097 
00098 $head x$$
00099 The vector $italic x$$ has length $latex d+1$$ and contains the
00100 $th d$$ order Taylor coefficient row vector for $italic X$$.
00101 
00102 
00103 $head z$$
00104 The vector $italic z$$ has length $latex d+1$$ and contains
00105 $th d$$ order Taylor coefficient row vector for $italic Z$$.
00106 
00107 
00108 $head On Input$$
00109 
00110 $subhead px$$
00111 The vector $italic px$$ has length $latex d+1$$ and 
00112 $syntax%%px%[%j%]%$$ contains the partial for $italic G$$
00113 with respect to the $th j$$ order Taylor coefficient for $italic X$$.
00114 
00115 $subhead pz$$
00116 The vector $italic pz$$ has length $latex d+1$$ and 
00117 $syntax%%pz%[%j%]%$$ contains the partial for $italic G$$
00118 with respect to the $th j$$ order Taylor coefficient for $italic Z$$.
00119 
00120 $head On Output$$
00121 
00122 $subhead px$$
00123 The vector $italic px$$ has length $latex d+1$$ and 
00124 $syntax%%px%[%j%]%$$ contains the partial for $italic H$$
00125 with respect to the $th j$$ order Taylor coefficient for $italic X$$.
00126 
00127 $subhead pz$$
00128 The vector $italic pz$$ has length $latex d+1$$ and 
00129 its contents are no longer specified; i.e., it has
00130 been used for work space.
00131 
00132 $end
00133 ------------------------------------------------------------------------------
00134 */
00135 
00136 // BEGIN CppAD namespace
00137 namespace CppAD {
00138 
00139 template <class Base>
00140 inline void ForSqrtOp(size_t j, 
00141         Base *z, const Base *x)
00142 {       size_t k;
00143 
00144         if( j == 0 )
00145                 z[j] = sqrt( x[0] );
00146         else
00147         {
00148                 z[j] = Base(0);
00149                 for(k = 1; k < j; k++)
00150                         z[j] -= Base(k) * z[k] * z[j-k];
00151                 z[j] /= Base(j);
00152                 z[j] += x[j] / Base(2);
00153                 z[j] /= z[0];
00154         }
00155 }
00156 
00157 template <class Base>
00158 inline void RevSqrtOp(size_t d, 
00159         const Base  *z, const Base *x,
00160               Base *pz,      Base *px)
00161 {       size_t k;
00162 
00163         // number of indices to access
00164         size_t j = d;
00165 
00166         while(j)
00167         {       // scale partial w.r.t. z[j]
00168                 pz[j]   /= z[0];
00169 
00170                 pz[0]   -= pz[j] * z[j];
00171                 px[j]   += pz[j] / Base(2);
00172                 for(k = 1; k < j; k++)
00173                         pz[k]   -= pz[j] * z[j-k];
00174                 --j;
00175         }
00176         px[0] += pz[0] / (Base(2) * z[0]);
00177 }
00178 
00179 } // END CppAD namespace
00180 
00181 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7