# Gentler transformation from real to positive

**URL:** <https://discourse.julialang.org/t/gentler-transformation-from-real-to-positive/33695>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [January 23, 2020, 11:13am UTC](https://discourse.julialang.org/t/gentler-transformation-from-real-to-positive/33695 "2020-01-23T11:13:00Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 23, 2020, 2:21pm UTC](https://discourse.julialang.org/t/gentler-transformation-from-real-to-positive/33695/13 "2020-01-23T14:21:55Z")

</div>

> [@Oscar\_Smith](#):
>
> What about using log(1+exp(x)). Is monotonic, smooth, and never blows up

It still overflows because of the intermediate `exp(x)` calculation: `log(1+exp(710)) === Inf`. It’s also subject to underflow: `log(1+exp(-37)) == 0.0`. It would be better to use `log1p(exp(x))`, but even that eventually underflows: `log1p(exp(-746)) == 0.0`. You could define your own special-function implementation for `f(x) = log1p(exp(x))`, rewritten to avoid spurious overflow — for example, `f(x) = x > 0 ? x + log1p(exp(-x)) : log1p(exp(x))` suffices and is equivalent to `log(1+exp(x))` in exact arithmetic — but the underflow is unavoidable since `f(-746) ≈ 1.03e-324` is not representable as a `Float64`.

I still don’t understand why you need a bijection in a root-finding context, e.g. why `x -> x^2` is not acceptable, since you can flip a negative solution to a positive one _a posteriori_ as I commented [above](https://discourse.julialang.org/t/gentler-transformation-from-real-to-positive/33695/11).

---

_[View the full topic](https://discourse.julialang.org/t/gentler-transformation-from-real-to-positive/33695)._
