/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell

  CppAD is distributed under the terms of the
               Eclipse Public License Version 2.0.

  This Source Code may also be made available under the following
  Secondary License when the conditions for such availability set forth
  in the Eclipse Public License, Version 2.0 are satisfied:
        GNU General Public License, Version 2.0 or later.
-------------------------------------------------------------------------- */

$begin acos_forward$$
$spell
    acos
    acosh
    Arccosine
    Taylor
$$

$section Inverse Cosine and Hyperbolic Cosine Forward Mode Theory$$

$head Derivatives$$
$latex \[
\begin{array}{rcl}
\R{acos}^{(1)} (x)  & = & - 1 / \sqrt{ 1 - x * x }
\\
\R{acosh}^{(1)} (x) & = & + 1 / \sqrt{ x * x - 1}
\end{array}
\] $$
If $latex F(x)$$ is $latex \R{acos} (x)$$ or $latex \R{acosh} (x)$$
the corresponding derivative satisfies the equation
$latex \[
    \sqrt{ \mp ( x * x - 1 ) } * F^{(1)} (x) - 0 * F (u)  = \mp 1
\] $$
and in the
$cref/standard math function differential equation
    /ForwardTheory
    /Standard Math Functions
    /Differential Equation
/$$,
$latex A(x) = 0$$,
$latex B(x) = \sqrt{ \mp( x * x - 1 ) }$$,
and $latex D(x) = \mp 1$$.
We use $latex a$$, $latex b$$, $latex d$$ and $latex z$$ to denote the
Taylor coefficients for
$latex A [ X (t) ] $$,
$latex B [ X (t) ]$$,
$latex D [ X (t) ] $$,
and $latex F [ X(t) ] $$ respectively.

$head Taylor Coefficients Recursion$$
We define $latex Q(x) = \mp ( x * x - 1 )$$
and let $latex q$$ be the corresponding Taylor coefficients for
$latex Q[ X(t) ]$$.
It follows that
$latex \[
q^{(j)} = \left\{ \begin{array}{ll}
    \mp ( x^{(0)} * x^{(0)} - 1 )      & {\rm if} \; j = 0 \\
    \mp \sum_{k=0}^j x^{(k)} x^{(j-k)} & {\rm otherwise}
\end{array} \right.
\] $$
It follows that
$latex B[ X(t) ] = \sqrt{ Q[ X(t) ] }$$ and
from the equations for the
$cref/square root/sqrt_forward/$$
that for $latex j = 0 , 1, \ldots$$,
$latex \[
\begin{array}{rcl}
b^{(0)}   & = & \sqrt{ q^{(0)} }
\\
b^{(j+1)} & = &
    \frac{1}{j+1} \frac{1}{ b^{(0)} }
    \left(
        \frac{j+1}{2} q^{(j+1) }
        - \sum_{k=1}^j k b^{(k)} b^{(j+1-k)}
    \right)
\end{array}
\] $$
It now follows from the general
$xref/
    ForwardTheory/
    Standard Math Functions/
    Taylor Coefficients Recursion Formula/
    Taylor coefficients recursion formula/
    1
/$$
that for $latex j = 0 , 1, \ldots$$,
$latex \[
\begin{array}{rcl}
z^{(0)} & = & F ( x^{(0)} )
\\
e^{(j)}
& = & d^{(j)} + \sum_{k=0}^{j} a^{(j-k)} * z^{(k)}
\\
& = & \left\{ \begin{array}{ll}
    \mp 1 & {\rm if} \; j = 0 \\
    0 & {\rm otherwise}
\end{array} \right.
\\
z^{(j+1)} & = & \frac{1}{j+1} \frac{1}{ b^{(0)} }
\left(
    \sum_{k=0}^j e^{(k)} (j+1-k) x^{(j+1-k)}
    - \sum_{k=1}^j b^{(k)} (j+1-k) z^{(j+1-k)}
\right)
\\
z^{(j+1)} & = & \frac{1}{j+1} \frac{1}{ b^{(0)} }
\left(
    \mp (j+1) x^{(j+1)}
    - \sum_{k=1}^j k z^{(k)}  b^{(j+1-k)}
\right)
\end{array}
\] $$


$end
