Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ erfcx() [6/6]

template<typename T , require_var_t< T > * = nullptr, require_all_not_nonscalar_prim_or_rev_kernel_expression_t< T > * = nullptr>
auto stan::math::erfcx ( T &&  a)
inline

The scaled complementary error function for variables.

The derivative is

\(\frac{d}{dx}\mbox{erfcx}(x) = 2x\,\mbox{erfcx}(x) - \frac{2}{\sqrt{\pi}}\)

which reuses the function value, so no extra exp or erfc evaluation is needed. That difference cancels for x >= 4, so internal::erfcx_derivative takes the derivative from the tail rational there instead. Without that the error reaches 2.55e+11 ulp at x = 1e6.

\[ \mbox{erfcx}(x) = \begin{cases} \exp(x^2)\operatorname{erfc}(x) & \mbox{if } -\infty\leq x \leq \infty \\[6pt] \textrm{NaN} & \mbox{if } x = \textrm{NaN} \end{cases} \]

\[ \frac{\partial\, \mbox{erfcx}(x)}{\partial x} = \begin{cases} 2x\operatorname{erfcx}(x) - \frac{2}{\sqrt{\pi}} & \mbox{if } -\infty\leq x\leq \infty \\[6pt] \textrm{NaN} & \mbox{if } x = \textrm{NaN} \end{cases} \]

One overload covers var and var_value<Matrix>. For a matrix the derivative stays a lazy binaryExpr, so the reverse pass allocates nothing.

Template Parameters
Ta var or a var_value of a matrix type
Parameters
aThe variable.
Returns
Scaled complementary error function applied to the variable, elementwise for a matrix.

Definition at line 57 of file erfcx.hpp.