Prev Next

AD Absolute Value Function

Syntax
y = abs(x)

Purpose
Evaluates the absolute value function.

x
The argument x has one of the following prototypes
     const AD<
Base>               &x
     const VecAD<
Base>::reference &x

y
The result y has prototype
     AD<
Basey

Operation Sequence
This is an AD of Base atomic operation and hence is part of the current AD of Base operation sequence .

Complex Types
The function abs is not defined for the AD type sequences above std::complex<float> or std::complex<double> because the complex abs function is not complex differentiable (see complex types faq ).

Directional Derivative
The derivative of the absolute value function is one for  x > 0 and minus one for  x < 0 . The subtitle issue is how to compute its directional derivative what  x = 0 .

The function corresponding to the argument x and the result y are represented by their Taylor coefficients; i.e.,  \[
\begin{array}{rcl}
     X(t) & = & x^{(0)} (t) + x^{(1)} t + \cdots + x^{(p)} t^p
     \\
     Y(t) & = & y^{(0)} (t) + y^{(1)} t + \cdots + y^{(p)} t^p
\end{array}
\] 
Note that  x^{(0)} = X(0) is the value of x and  y^{(0)} = Y(0) is the value of y. In the equations above, the order  p is specified by a call to Forward or Reverse as follows:
     
f.Forward(pdx)
     
f.Reverse(p+1, w)
If all of the Taylor coefficients of  X(t) are zero, we define  k = p . Otherwise, we define  k to be the minimal index such that  x^{(k)} \neq 0 . Note that if  x \neq 0 ,  k = 0 . The Taylor coefficient representation of  Y(t) (and hence it's derivatives) are computed as  \[
y^{(\ell)}
=
\left\{ \begin{array}{ll} 
      x^{(\ell)}   & {\rm if} \; x^{(k)} > 0         \\
      0                    & {\rm if} \; x^{(k)} = 0 \\
     - x^{(\ell)}  & {\rm if} \; x^{(k)} < 0
\end{array} \right.
\] 


Example
The file Abs.cpp contains an example and test of this function. It returns true if it succeeds and false otherwise.
Input File: cppad/local/abs.hpp