![]() |
Stan Math Library
5.4.0
Automatic Differentiation
|
|
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.
| T | a var or a var_value of a matrix type |
| a | The variable. |