x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
t_1 := \left(1 - y\right) + y \cdot e^{z}\\
\mathbf{if}\;t_1 \leq 0.9999999999999987:\\
\;\;\;\;x - \mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right) \cdot \frac{1}{t}\\
\mathbf{elif}\;t_1 \leq 1:\\
\;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt[3]{\mathsf{expm1}\left(z\right)}\\
x - \frac{\mathsf{log1p}\left(t_2 \cdot \left(y \cdot \left(t_2 \cdot t_2\right)\right)\right)}{t}
\end{array}\\
\end{array}
(FPCore (x y z t) :precision binary64 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ (- 1.0 y) (* y (exp z)))))
(if (<= t_1 0.9999999999999987)
(- x (* (log1p (* y (expm1 z))) (/ 1.0 t)))
(if (<= t_1 1.0)
(- x (* (expm1 z) (/ y t)))
(let* ((t_2 (cbrt (expm1 z))))
(- x (/ (log1p (* t_2 (* y (* t_2 t_2)))) t)))))))double code(double x, double y, double z, double t) {
return x - (log((1.0 - y) + (y * exp(z))) / t);
}
double code(double x, double y, double z, double t) {
double t_1 = (1.0 - y) + (y * exp(z));
double tmp;
if (t_1 <= 0.9999999999999987) {
tmp = x - (log1p(y * expm1(z)) * (1.0 / t));
} else if (t_1 <= 1.0) {
tmp = x - (expm1(z) * (y / t));
} else {
double t_2 = cbrt(expm1(z));
tmp = x - (log1p(t_2 * (y * (t_2 * t_2))) / t);
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z




Bits error versus t
Results
| Original | 25.7 |
|---|---|
| Target | 16.7 |
| Herbie | 0.3 |
if (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))) < 0.99999999999999867Initial program 63.0
Simplified0.1
Applied div-inv_binary640.1
if 0.99999999999999867 < (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))) < 1Initial program 13.0
Simplified1.2
Applied add-cube-cbrt_binary641.4
Taylor expanded in y around 0 6.6
Simplified0.1
if 1 < (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z))) Initial program 3.5
Simplified2.2
Applied add-cube-cbrt_binary642.2
Applied associate-*r*_binary642.2
Final simplification0.3
herbie shell --seed 2022077
(FPCore (x y z t)
:name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"
:precision binary64
:herbie-target
(if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))
(- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))