x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\begin{array}{l}
\mathbf{if}\;e^{z} \leq 0:\\
\;\;\;\;x - \frac{\log \left(1 + y \cdot \left(e^{z} + -1\right)\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \frac{z}{t}\\
\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 (if (<= (exp z) 0.0) (- x (/ (log (+ 1.0 (* y (+ (exp z) -1.0)))) t)) (- x (* y (/ z 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 tmp;
if (exp(z) <= 0.0) {
tmp = x - (log(1.0 + (y * (exp(z) + -1.0))) / t);
} else {
tmp = x - (y * (z / t));
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z




Bits error versus t
Results
| Original | 25.2 |
|---|---|
| Target | 16.2 |
| Herbie | 8.5 |
if (exp.f64 z) < 0.0Initial program 12.0
Simplified12.0
Taylor expanded around 0 12.0
if 0.0 < (exp.f64 z) Initial program 30.7
Simplified15.9
Taylor expanded around 0 7.7
Simplified7.0
Final simplification8.5
herbie shell --seed 2021176
(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)))