Automatic Differentiation
 
Loading...
Searching...
No Matches
inv_erfc.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_INV_ERFC_HPP
2#define STAN_MATH_REV_FUN_INV_ERFC_HPP
3
10#include <cmath>
11
12namespace stan {
13namespace math {
14
28inline var inv_erfc(const var& a) {
29 auto precomp_inv_erfc = inv_erfc(a.val());
30 return make_callback_var(
31 precomp_inv_erfc, [a, precomp_inv_erfc](auto& vi) mutable {
32 a.adj()
33 -= vi.adj() * exp(LOG_SQRT_PI - LOG_TWO + square(precomp_inv_erfc));
34 });
35}
36
37template <typename T, require_matrix_t<T>* = nullptr>
38inline auto inv_erfc(const var_value<T>& a) {
39 auto precomp_inv_erfc = to_arena(inv_erfc(a.val()));
40 return make_callback_var(
41 precomp_inv_erfc, [a, precomp_inv_erfc](auto& vi) mutable {
42 a.adj().array()
43 -= vi.adj().array()
44 * exp(LOG_SQRT_PI - LOG_TWO + square(precomp_inv_erfc).array());
45 });
46}
47
48} // namespace math
49} // namespace stan
50#endif
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
static constexpr double LOG_TWO
The natural logarithm of 2, .
Definition constants.hpp:80
arena_t< T > to_arena(const T &a)
Converts given argument into a type that either has any dynamic allocation on AD stack or schedules i...
Definition to_arena.hpp:25
static constexpr double LOG_SQRT_PI
The natural logarithm of the square root of , .
fvar< T > inv_erfc(const fvar< T > &x)
Definition inv_erfc.hpp:16
fvar< T > square(const fvar< T > &x)
Definition square.hpp:12
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...