Prev Next ForwardAny

Any Order Forward Mode

Syntax
y_p = f.Forward(px_p )

Purpose
We use  F : B^n \rightarrow B^m to denote the AD function corresponding to f. Given a function  X : B \rightarrow B^n , defined by its Taylor coefficients , forward mode computes the Taylor coefficients for the function  \[
     Y (t) = F [ X(t) ]
\] 
.

Function Values
If you are using forward mode to compute values for  F(x) , ForwardZero is simpler to understand than this explanation of the general case.

Derivative Values
If you are using forward mode to compute values for  F^{(1)} (x) * dx , ForwardOne is simpler to understand than this explanation of the general case.

X(t)
The function  X : B \rightarrow B^n is defined using a sequence of Taylor coefficients  x^{(k)} \in B^n :  \[
     X(t) = x^{(0)} + x^{(1)} * t + \cdots + x^{(p)} * t^p 
\] 
For  k = 0, \ldots , p , the vector  x^{(k)} above is defined as the value of x_k in the previous call (counting this call) of the form
     
f.Forward(kx_k)
If there is no previous call with  k = 0 ,  x^{(0)} is the value of the independent variables when the corresponding AD of Base operation sequence was recorded. Note that  x^{(k)} is related to the k-th derivative of  X(t) by  \[
     x^{(k)} = \frac{1}{k !} X^{(k)} (0) 
\] 


Y(t)
The function  Y : B \rightarrow B^m is defined by  Y(t) = F[ X(t) ]  . We use  y^{(k)} \in B^m to denote the k-th order Taylor coefficient of  Y(t) ; i.e.,  \[
     Y(t) = y^{(0)} + y^{(1)} * t + \cdots, + y^{(p)} * t^p + o( t^p ) 
\] 
where  o( t^p ) * t^{-p} \rightarrow 0 as  t \rightarrow 0 . Note that  y^{(k)} is related to the k-th derivative of  Y(t) by  \[
     y^{(k)} = \frac{1}{k !} Y^{(k)} (0) 
\] 


f
The ADFun object f has prototype
     ADFun<
Basef
Note that the ADFun object f is not const. Before this call to Forward, the value returned by
     
f.size_taylor()
must be greater than or equal  p . After this call it will be will be  p+1 (see size_taylor ).

p
The argument p has prototype
     size_t 
p
and specifies the order of the Taylor coefficients to be calculated.

x_p
The argument x_p has prototype
     const 
Vector &x_p
(see Vector below) and its size must be equal to n, the dimension of the domain space for f. The p-th order Taylor coefficient for  X(t) is defined by this value; i.e.,  x^{(p)} = x\_p . (The lower order Taylor coefficients for  X(t) are defined by previous calls to Forward.)

y_p
The return value y_p has prototype
     
Vector y_p
(see Vector below) and its value is The p-th order Taylor coefficient for  Y(t) ; i.e.,  y^{(p)} = y\_p . The size of y_p is equal to m, the dimension of the range space for f.

Vector
The type Vector must be a SimpleVector class with elements of type Base. The routine CheckSimpleVector will generate an error message if this is not the case.

Zero Order
In the case where  p = 0 , the result y_p is given by  \[
\begin{array}{rcl}
y^{(0)} & = & (F \circ X) ( 0 ) \\
     & = & F[ x^{(0)} ]
\end{array}
\] 
The agrees with the simplification where  p ,  x^{(0)} , and  y^{(0)} above are replaced by 0, x, and y in ForwardZero .

First Order
In the case where  p = 1 , the result y_p is given by  \[
\begin{array}{rcl}
y^{(1)} & = & (F \circ X)^{(1)} ( 0 ) \\
     & = & F^{(1)} [ X(0) ] *  X^{(1)} (0) \\
     & = & F^{(1)} ( x^{(0)} ) *  x^{(1)}
\end{array}
\] 
The agrees with the simplification where  p ,  x^{(0)} ,  x^{(1)} , and  y^{(1)} above are replaced by 1, x, dx, and dy in ForwardOne .

Note that if  x^{(1)} is the j-th elementary vector  \[
y^{(1)} = \D{F}{x_j} ( x^{(0)} ) 
\] 


Second Order
In the case where  p = 2 , the i-th element of the result y_p is given by  \[
\begin{array}{rcl}
y_i^{(2)} 
& = & \frac{1}{2} (F_i \circ X)^{(2)} ( 0 ) 
\\
& = & \frac{1}{2} \left[ F_i^{(1)} [ X(0) ] * X^{(2)} (0) 
  + X^{(1)} (0)^T * F_i^{(2)} [ X(0) ] * X^{(1)} (0) \right]
\\
& = & \frac{1}{2}  \left[
     2 * F_i^{(1)} ( x^{(0)} ) * x^{(2)}
     +
     ( x^{(1)} )^T * F_i^{(2)} ( x^{(0)} ) * x^{(1)}
\right  ]
\end{array}
\] 
Note that if  x^{(1)} is the j-th elementary vector and  x^{(2)} is zero,  \[
\begin{array}{rcl}
     \DD{F_i}{x_j}{x_j} ( x^{(0)} ) = 2 y_i^{(2)} 
\end{array}
\] 
If  x^{(1)} is the sum of the j-th and l-th elementary vectors and  x^{(2)} is zero,  \[
\begin{array}{rcl}
     y_i^{(2)} 
     & = & \frac{1}{2} \left[
          \DD{F_i}{x_j}{x_j} ( x^{(0)} )
          +
          \DD{F_i}{x_j}{x_\ell} ( x^{(0)} )
          +
          \DD{F_i}{x_\ell}{x_j} ( x^{(0)} )
          +
          \DD{F_i}{x_\ell}{x_\ell} ( x^{(0)} )
     \right]
     \\
     \DD{F_i}{x_\ell}{x_j} ( x^{(0)} )
     & = & 
     y_i^{(2)} 
     -
     \frac{1}{2} \DD{F_i}{x_j}{x_j} ( x^{(0)} )
     -
     \frac{1}{2} \DD{F_i}{x_\ell}{x_\ell} ( x^{(0)} )
\end{array} 
\] 


Example
The file Forward.cpp contains an example and test of this operation. It returns true if it succeeds and false otherwise.
Input File: omh/forward.omh