1 #ifndef STAN_MATH_REV_FUN_LOG10_HPP
2 #define STAN_MATH_REV_FUN_LOG10_HPP
3 
4 #include <stan/math/prim/core.hpp>
5 #include <stan/math/prim/fun/constants.hpp>
6 #include <stan/math/prim/fun/log10.hpp>
7 #include <stan/math/rev/meta.hpp>
8 #include <stan/math/rev/core.hpp>
9 #include <stan/math/rev/fun/atan2.hpp>
10 #include <stan/math/rev/fun/hypot.hpp>
11 #include <stan/math/rev/fun/log.hpp>
12 #include <cmath>
13 #include <complex>
14 
15 namespace stan {
16 namespace math {
17 
18 /**
19  * Return the base 10 log of the specified variable (cmath).
20  *
21  * The derivative is defined by
22  *
23  * \f$\frac{d}{dx} \log_{10} x = \frac{1}{x \log 10}\f$.
24  *
25  *
26    \f[
27    \mbox{log10}(x) =
28    \begin{cases}
29      \textrm{NaN} & \mbox{if } x < 0\\
30      \log_{10}(x) & \mbox{if } x \geq 0 \\[6pt]
31      \textrm{NaN} & \mbox{if } x = \textrm{NaN}
32    \end{cases}
33    \f]
34 
35    \f[
36    \frac{\partial\, \mbox{log10}(x)}{\partial x} =
37    \begin{cases}
38      \textrm{NaN} & \mbox{if } x < 0\\
39      \frac{1}{x \ln10} & \mbox{if } x\geq 0 \\[6pt]
40      \textrm{NaN} & \mbox{if } x = \textrm{NaN}
41    \end{cases}
42    \f]
43  *
44  * @tparam T Arithmetic or a type inheriting from `EigenBase`.
45  * @param a Variable whose log is taken.
46  * @return Base 10 log of variable.
47  */
48 template <typename T, require_stan_scalar_or_eigen_t<T>* = nullptr>
log10(const var_value<T> & a)49 inline auto log10(const var_value<T>& a) {
50   return make_callback_var(log10(a.val()), [a](auto& vi) mutable {
51     as_array_or_scalar(a.adj()) += as_array_or_scalar(vi.adj())
52                                    / (LOG_TEN * as_array_or_scalar(a.val()));
53   });
54 }
55 
56 /**
57  * Return the base 10 logarithm of the specified complex number.
58  *
59  * @param z complex argument
60  * @return base 10 log of argument
61  */
log10(const std::complex<var> & z)62 inline std::complex<var> log10(const std::complex<var>& z) {
63   return internal::complex_log10(z);
64 }
65 
66 }  // namespace math
67 }  // namespace stan
68 #endif
69