Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log_diff_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__FUNCTIONS__LOG_DIFF_EXP_HPP
2 #define STAN__AGRAD__FWD__FUNCTIONS__LOG_DIFF_EXP_HPP
3 
5 #include <stan/meta/traits.hpp>
8 
9 namespace stan{
10 
11  namespace agrad{
12 
13  template <typename T> inline fvar<T>
14  log_diff_exp(const fvar<T>& x1, const fvar<T>& x2) {
17  using std::exp;
18  if (x1.val_ <= x2.val_)
20  return fvar<T>(log_diff_exp(x1.val_, x2.val_),
21  x1.d_ / (1 - exp(x2.val_ - x1.val_) ) + x2.d_ / (1 - exp(x1.val_ - x2.val_) ) );
22  }
23 
24  template <typename T1, typename T2> inline fvar<T2>
25  log_diff_exp(const T1& x1, const fvar<T2>& x2) {
28  using std::exp;
29  if (x1 <= x2.val_)
31  return fvar<T2>(log_diff_exp(x1, x2.val_),
32  x2.d_ / (1 - exp(x1 - x2.val_)));
33  }
34 
35  template <typename T1, typename T2> inline fvar<T1>
36  log_diff_exp(const fvar<T1>& x1, const T2& x2) {
39  using std::exp;
40  if (x1.val_ <= x2)
42  return fvar<T1>(log_diff_exp(x1.val_, x2),
43  x1.d_ / (1 - exp(x2 - x1.val_)));
44  }
45  }
46 }
47 #endif
boost::math::tools::promote_args< T1, T2 >::type log_diff_exp(const T1 x, const T2 y)
The natural logarithm of the difference of the natural exponentiation of x1 and the natural exponenti...
fvar< T > log_diff_exp(const fvar< T > &x1, const fvar< T > &x2)
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:53
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:16

     [ Stan Home Page ] © 2011–2014, Stan Development Team.