$\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }$
Create An Abs-normal Representation of a Function

Syntax
f.abs_normal_fun(g, a)

f
The object f has prototype       const ADFun<Base>& f  It represents a function $f : \B{R}^n \rightarrow \B{R}^m$. We assume that the only non-smooth terms in the representation are absolute value functions and use $s \in \B{Z}_+$ to represent the number of these terms.

n
We use n to denote the dimension of the domain space for f .

m
We use m to denote the dimension of the range space for f .

s
We use s to denote the number of absolute value terms in f .

a
The object a has prototype       ADFun<Base> a  The initial function representation in a is lost. Upon return it represents the result of the absolute terms $a : \B{R}^n \rightarrow \B{R}^s$; see $a(x)$ defined below. Note that a is constructed by copying f and then changing the dependent variables. There may be many calculations in this representation that are not necessary and can be removed using       a.optimize()  This optimization is not done automatically by abs_normal_fun because it may take a significant amount of time.

zeta
Let $\zeta_0 ( x )$ denote the argument for the first absolute value term in $f(x)$, $\zeta_1 ( x , |\zeta_0 (x)| )$ for the second term, and so on.

a(x)
For $i = 0 , \ldots , {s-1}$ define $$a_i (x) = | \zeta_i ( x , a_0 (x) , \ldots , a_{i-1} (x ) ) |$$ This defines $a : \B{R}^n \rightarrow \B{R}^s$.

g
The object g has prototype       ADFun<Base> g  The initial function representation in g is lost. Upon return it represents the smooth function $g : \B{R}^{n + s} \rightarrow \B{R}^{m + s}$ is defined by $$g( x , u ) = \left[ \begin{array}{c} y(x, u) \\ z(x, u) \end{array} \right]$$ were $y(x, u)$ and $z(x, u)$ are defined below.

z(x, u)
Define the smooth function $z : \B{R}^{n + s} \rightarrow \B{R}^s$ by $$z_i ( x , u ) = \zeta_i ( x , u_0 , \ldots , u_{i-1} )$$ Note that the partial of $z_i$ with respect to $u_j$ is zero for $j \geq i$.

y(x, u)
There is a smooth function $y : \B{R}^{n + s} \rightarrow \B{R}^m$ such that $y( x , u ) = f(x)$ whenever $u = a(x)$.

Affine Approximation
We define the affine approximations $$\begin{array}{rcl} y[ \hat{x} ]( x , u ) & = & y ( \hat{x}, a( \hat{x} ) ) + \partial_x y ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) + \partial_u y ( \hat{x}, a( \hat{x} ) ) ( u - a( \hat{x} ) ) \\ z[ \hat{x} ]( x , u ) & = & z ( \hat{x}, a( \hat{x} ) ) + \partial_x z ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) + \partial_u z ( \hat{x}, a( \hat{x} ) ) ( u - a( \hat{x} ) ) \end{array}$$ It follows that $$\begin{array}{rcl} y( x , u ) & = & y[ \hat{x} ]( x , u ) + o ( x - \hat{x}, u - a( \hat{x} ) ) \\ z( x , u ) & = & z[ \hat{x} ]( x , u ) + o ( x - \hat{x}, u - a( \hat{x} ) ) \end{array}$$

Abs-normal Approximation

Approximating a(x)
The function $a(x)$ is not smooth, but it is equal to $| z(x, u) |$ when $u = a(x)$. Furthermore $$z[ \hat{x} ]( x , u ) = z ( \hat{x}, a( \hat{x} ) ) + \partial_x z ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) + \partial_u z ( \hat{x}, a( \hat{x} ) ) ( u - a( \hat{x} ) )$$ The partial of $z_i$ with respect to $u_j$ is zero for $j \geq i$. It follows that $$z_i [ \hat{x} ]( x , u ) = z_i ( \hat{x}, a( \hat{x} ) ) + \partial_x z_i ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) + \sum_{j < i} \partial_{u(j)} z_i ( \hat{x}, a( \hat{x} ) ) ( u_j - a_j ( \hat{x} ) )$$ Considering the case $i = 0$ we define $$a_0 [ \hat{x} ]( x ) = | z_0 [ \hat{x} ]( x , u ) | = \left| z_0 ( \hat{x}, a( \hat{x} ) ) + \partial_x z_0 ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) \right|$$ It follows that $$a_0 (x) = a_0 [ \hat{x} ]( x ) + o ( x - \hat{x} )$$ In general, we define $a_i [ \hat{x} ]$ using $a_j [ \hat{x} ]$ for $j < i$ as follows: $$a_i [ \hat{x} ]( x ) = \left | z_i ( \hat{x}, a( \hat{x} ) ) + \partial_x z_i ( \hat{x}, a( \hat{x} ) ) ( x - \hat{x} ) + \sum_{j < i} \partial_{u(j)} z_i ( \hat{x}, a( \hat{x} ) ) ( a_j [ \hat{x} ] ( x ) - a_j ( \hat{x} ) ) \right|$$ It follows that $$a (x) = a[ \hat{x} ]( x ) + o ( x - \hat{x} )$$ Note that in the case where $z(x, u)$ and $y(x, u)$ are affine, $$a[ \hat{x} ]( x ) = a( x )$$

Approximating f(x)
$$f(x) = y ( x , a(x ) ) = y [ \hat{x} ] ( x , a[ \hat{x} ] ( x ) ) + o( \Delta x )$$
Correspondence to Literature
Using the notation $Z = \partial_x z(\hat{x}, \hat{u})$, $L = \partial_u z(\hat{x}, \hat{u})$, $J = \partial_x y(\hat{x}, \hat{u})$, $Y = \partial_u y(\hat{x}, \hat{u})$, the approximation for $z$ and $y$ are $$\begin{array}{rcl} z[ \hat{x} ]( x , u ) & = & z ( \hat{x}, a( \hat{x} ) ) + Z ( x - \hat{x} ) + L ( u - a( \hat{x} ) ) \\ y[ \hat{x} ]( x , u ) & = & y ( \hat{x}, a( \hat{x} ) ) + J ( x - \hat{x} ) + Y ( u - a( \hat{x} ) ) \end{array}$$ Moving the terms with $\hat{x}$ together, we have $$\begin{array}{rcl} z[ \hat{x} ]( x , u ) & = & z ( \hat{x}, a( \hat{x} ) ) - Z \hat{x} - L a( \hat{x} ) + Z x + L u \\ y[ \hat{x} ]( x , u ) & = & y ( \hat{x}, a( \hat{x} ) ) - J \hat{x} - Y a( \hat{x} ) + J x + Y u \end{array}$$ Using the notation $c = z ( \hat{x}, \hat{u} ) - Z \hat{x} - L \hat{u}$, $b = y ( \hat{x}, \hat{u} ) - J \hat{x} - Y \hat{u}$, we have $$\begin{array}{rcl} z[ \hat{x} ]( x , u ) & = & c + Z x + L u \\ y[ \hat{x} ]( x , u ) & = & b + J x + Y u \end{array}$$ Considering the affine case, where the approximations are exact, and choosing $u = a(x) = |z(x, u)|$, we obtain $$\begin{array}{rcl} z( x , a(x ) ) & = & c + Z x + L |z( x , a(x ) )| \\ y( x , a(x ) ) & = & b + J x + Y |z( x , a(x ) )| \end{array}$$ This is Equation (2) of the reference .

Example
The file abs_get_started.cpp contains an example and test using this operation.