\subsection{autodiff}
\label{labautodiff}
\noindent Name: \textbf{autodiff}\\
\phantom{aaa}Computes the first $n$ derivatives of a function at a point or over an interval.\\[0.2cm]
\noindent Library name:\\
\verb|   sollya_obj_t sollya_lib_autodiff(sollya_obj_t, sollya_obj_t, sollya_obj_t)|\\[0.2cm]
\noindent Usage: 
\begin{center}
\textbf{autodiff}(\emph{f}, \emph{n}, \emph{$x_0$}) : (\textsf{function}, \textsf{integer}, \textsf{constant}) $\rightarrow$ \textsf{list}\\
\textbf{autodiff}(\emph{f}, \emph{n}, \emph{I}) : (\textsf{function}, \textsf{integer}, \textsf{range}) $\rightarrow$ \textsf{list}\\
\end{center}
Parameters: 
\begin{itemize}
\item \emph{f} is the function to be differentiated.
\item \emph{n} is the order of differentiation.
\item \emph{$x_0$} is the point at which the function is differentiated.
\item \emph{I} is the interval over which the function is differentiated.
\end{itemize}
\noindent Description: \begin{itemize}

\item \textbf{autodiff} computes the first $n$ derivatives of $f$ at point $x_0$. The computation
   is performed numerically, without symbolically differentiating the expression
   of $f$. Yet, the computation is safe since small interval enclosures are
   produced. More precisely, \textbf{autodiff} returns a list $[f_0,\,\dots,\,f_n]$ such that,
   for each $i$, $f_i$ is a small interval enclosing the exact value of $f^{(i)}(x_0)$.

\item Since it does not perform any symbolic differentiation, \textbf{autodiff} is much 
   more efficient than \textbf{diff} and should be preferred when only numerical values
   are necessary.

\item If an interval $I$ is provided instead of a point $x_0$, the list returned by
   \textbf{autodiff} satisfies: $\forall i,\, f^{(i)}(I) \subseteq f_i$. A particular use
   is when one wants to know the successive derivatives of a function at a non
   representable point such as $\pi$. In this case, it suffices to call \textbf{autodiff}
   with the (almost) point interval $I = [\textbf{pi}]$.

\item When $I$ is almost a point interval, the returned enclosures $f_i$ are also
   almost point intervals. However, when the interval $I$ begins to be fairly
   large, the enclosures can be deeply overestimated due to the dependency
   phenomenon present with interval arithmetic.

\item As a particular case, $f_0$ is an enclosure of the image of $f$ over $I$.
   However, since the algorithm is not specially designed for this purpose it is
   not very efficient for this particular task. In particular, it is not able to
   return a finite enclosure for functions with removable singularities
   (e.g. $\sin(x)/x$ at $0$). The command \textbf{evaluate} is much more efficient for
   computing an accurate enclosure of the image of a function over an interval.
\end{itemize}
\noindent Example 1: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> L = autodiff(exp(cos(x))+sin(exp(x)), 5, 0);
> midpointmode = on!;
> for f_i in L do f_i;
0.3559752813266941742012789792982961497379810154498~2/4~e1
0.5403023058681397174009366074429766037323104206179~0/3~
-0.3019450507398802024611853185539984893647499733880~6/2~e1
-0.252441295442368951995750696489089699886768918239~6/4~e1
0.31227898756481033145214529184139729746320579069~1/3~e1
-0.16634307959006696033484053579339956883955954978~3/1~e2
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> f = log(cos(x)+x);
> L = autodiff(log(cos(x)+x), 5, [2,4]);
> L[0];
[0;1.27643852425465597132446653114905059102580436018893]
> evaluate(f, [2,4]);
[0.45986058925497069206106494332976097408234056912429;1.207872105899641695959010
37621103012113048821362855]
> fprime = diff(f);
> L[1];
[2.53086745013099407167484456656211083053393118778677e-2;1.756802495307928251372
6390945118290941359128873365]
> evaluate(fprime,[2,4]);
[2.71048755415961996452136364304380881763456815673085e-2;1.109195306639432908373
9722578862353140555843127995]
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 3: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> L = autodiff(sin(x)/x, 0, [-1,1]);
> L[0];
[NaN;NaN]
> evaluate(sin(x)/x, [-1,1]);
[0.5403023058681397174009366074429766037323104206179;1]
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{diff} (\ref{labdiff}), \textbf{evaluate} (\ref{labevaluate})
