Sure.

I needed to calculate \frac x {1 - x} or \exp(\mbox{logit}(x)) in a hot path, but could not find it in the Stan math library. It has derivative \frac 1 {(1-x)^2}

So I added this code to a separate .hpp

and included it as described in the tutorial.

```
inline double exp_logit(double u) {
return u / (1 - u);
}
inline var exp_logit(const var& u) {
const double uv = u.val();
const double m_u = (1-uv);
const double m_u_sq = m_u * m_u;
return var(new precomp_v_vari(exp_logit(u.val()),
u.vi_,
1 / m_u_sq));
}
struct exp_logit_fun {
template <typename T>
static inline T fun(const T& x) {
return exp_logit(x);
}
};
template <typename T>
inline typename apply_scalar_unary<exp_logit_fun, T>::return_t
exp_logit(const T& x) {
return apply_scalar_unary<exp_logit_fun, T>::apply(x);
}
template <typename T0__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type,
Eigen::Dynamic,1>
exp_logit(const Eigen::Matrix<T0__, Eigen::Dynamic,1>& x, std::ostream*
pstream__) {
return exp_logit(x);
}
struct exp_logit_functor__ {
template <typename T0__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type,
Eigen::Dynamic,1>
operator()(const Eigen::Matrix<T0__, Eigen::Dynamic,1>& x, std::ostream*
pstream__) const {
return exp_logit(x, pstream__);
}
};
```

This is pretty much all the Stan C++ code I’ve ever written, so by no means take this to be best practices!