# Automatic differentiation via ADOL-C and the Heaviside Function

I am writting a c++ program in which I define a function $$\displaystyle F(t) = \sum_{i}r_i\,H(t-t_i)$$ where $$H$$ is the heaviside function, $$t_i$$ are optimal parameters which are mutable.

The program is derived by automatic differentiation using ADOL-C. I am wondering whether I should be careful when I am implementing the function $$f$$ regarding branching and looping.

I would create the function:

template <class Tdouble> Tdouble myfunF ( Tdouble t, Tdouble *tis, int nbti)
{
Tdouble res = 0.;
double ri = 0.;
for(int id=0;i<nbti;++i)
{
ri = ...;
if (t>ti){
res = res + ri;
}
}
return res ;
}


The Tdouble type is similar to the adouble type in ADOL-C. How to analyze if this construction is suitable for automatic differentiation using ADOL-C and rewrite the code ?

• yikesabee. Does any automatic differentiation package handle distributional derivatives correctly? (Only useful under an integral, right?) IIRC, Griewank only discusses non-differentiable functions like abs. – user14717 May 23 at 19:06