1 #ifndef STAN_MATH_PRIM_FUN_OWENS_T_HPP
2 #define STAN_MATH_PRIM_FUN_OWENS_T_HPP
3 
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/functor/apply_scalar_binary.hpp>
6 #include <boost/math/special_functions/owens_t.hpp>
7 
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Return the result of applying Owen's T function to the
13  * specified arguments.
14  *
15  * Used to compute the cumulative density function for the skew normal
16  * distribution.
17  *
18    \f[
19    \mbox{owens\_t}(h, a) =
20    \begin{cases}
21      \mbox{owens\_t}(h, a) & \mbox{if } -\infty\leq h, a \leq \infty \\[6pt]
22      \textrm{NaN} & \mbox{if } h = \textrm{NaN or } a = \textrm{NaN}
23    \end{cases}
24    \f]
25 
26    \f[
27    \frac{\partial\, \mbox{owens\_t}(h, a)}{\partial h} =
28    \begin{cases}
29      \frac{\partial\, \mbox{owens\_t}(h, a)}{\partial h} & \mbox{if }
30  -\infty\leq h, a\leq \infty \\[6pt] \textrm{NaN} & \mbox{if } h = \textrm{NaN
31  or } a = \textrm{NaN} \end{cases} \f]
32 
33    \f[
34    \frac{\partial\, \mbox{owens\_t}(h, a)}{\partial a} =
35    \begin{cases}
36      \frac{\partial\, \mbox{owens\_t}(h, a)}{\partial a} & \mbox{if }
37  -\infty\leq h, a\leq \infty \\[6pt] \textrm{NaN} & \mbox{if } h = \textrm{NaN
38  or } a = \textrm{NaN} \end{cases} \f]
39 
40    \f[
41    \mbox{owens\_t}(h, a) = \frac{1}{2\pi} \int_0^a
42  \frac{\exp(-\frac{1}{2}h^2(1+x^2))}{1+x^2}dx \f]
43 
44    \f[
45    \frac{\partial \, \mbox{owens\_t}(h, a)}{\partial h} =
46  -\frac{1}{2\sqrt{2\pi}} \operatorname{erf}\left(\frac{ha}{\sqrt{2}}\right)
47    \exp\left(-\frac{h^2}{2}\right)
48    \f]
49 
50    \f[
51    \frac{\partial \, \mbox{owens\_t}(h, a)}{\partial a} =
52  \frac{\exp\left(-\frac{1}{2}h^2(1+a^2)\right)}{2\pi (1+a^2)} \f]
53  *
54  * @param h First argument
55  * @param a Second argument
56  * @return Owen's T function applied to the arguments.
57  */
owens_t(double h,double a)58 inline double owens_t(double h, double a) { return boost::math::owens_t(h, a); }
59 
60 /**
61  * Enables the vectorised application of the owens_t
62  * function, when the first and/or second arguments are containers.
63  *
64  * @tparam T1 type of first input
65  * @tparam T2 type of second input
66  * @param a First input
67  * @param b Second input
68  * @return owens_t function applied to the two inputs.
69  */
70 template <typename T1, typename T2, require_any_container_t<T1, T2>* = nullptr>
owens_t(const T1 & a,const T2 & b)71 inline auto owens_t(const T1& a, const T2& b) {
72   return apply_scalar_binary(
73       a, b, [&](const auto& c, const auto& d) { return owens_t(c, d); });
74 }
75 
76 }  // namespace math
77 }  // namespace stan
78 
79 #endif
80