1 #ifndef STAN_MATH_REV_FUN_LOG1M_HPP 2 #define STAN_MATH_REV_FUN_LOG1M_HPP 3 4 #include <stan/math/rev/meta.hpp> 5 #include <stan/math/rev/core.hpp> 6 #include <stan/math/prim/fun/log1m.hpp> 7 8 namespace stan { 9 namespace math { 10 11 /** 12 * The log (1 - x) function for variables. 13 * 14 * The derivative is given by 15 * 16 * \f$\frac{d}{dx} \log (1 - x) = -\frac{1}{1 - x}\f$. 17 * 18 * @tparam T Arithmetic or a type inheriting from `EigenBase`. 19 * @param a The variable. 20 * @return The variable representing log of 1 minus the variable. 21 */ 22 template <typename T, require_stan_scalar_or_eigen_t<T>* = nullptr> log1m(const var_value<T> & a)23inline auto log1m(const var_value<T>& a) { 24 return make_callback_var(log1m(a.val()), [a](auto& vi) mutable { 25 as_array_or_scalar(a.adj()) 26 += as_array_or_scalar(vi.adj()) / (as_array_or_scalar(a.val()) - 1.0); 27 }); 28 } 29 30 } // namespace math 31 } // namespace stan 32 #endif 33