1 #ifndef STAN_MATH_REV_FUN_LOG1M_INV_LOGIT_HPP
2 #define STAN_MATH_REV_FUN_LOG1M_INV_LOGIT_HPP
3 
4 #include <stan/math/rev/meta.hpp>
5 #include <stan/math/prim/fun/log1m_inv_logit.hpp>
6 #include <stan/math/prim/fun/inv_logit.hpp>
7 #include <stan/math/rev/core.hpp>
8 
9 namespace stan {
10 namespace math {
11 
12 /**
13  * Return the natural logarithm of one minus the inverse logit of
14  * the specified argument.
15  *
16  * @tparam T Arithmetic or a type inheriting from `EigenBase`.
17  * @param u argument
18  * @return log of one minus the inverse logit of the argument
19  */
20 template <typename T, require_stan_scalar_or_eigen_t<T>* = nullptr>
log1m_inv_logit(const var_value<T> & u)21 inline auto log1m_inv_logit(const var_value<T>& u) {
22   auto precomp_inv_logit = to_arena(as_array_or_scalar(-inv_logit(u.val())));
23   return make_callback_var(
24       log1m_inv_logit(u.val()), [u, precomp_inv_logit](auto& vi) mutable {
25         as_array_or_scalar(u.adj())
26             += as_array_or_scalar(vi.adj()) * precomp_inv_logit;
27       });
28 }
29 
30 }  // namespace math
31 }  // namespace stan
32 #endif
33