x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\begin{array}{l}
\mathbf{if}\;z \le -4.69725414416607 \cdot 10^{-38}:\\
\;\;\;\;x - \frac{1}{\frac{t}{\log \left(1 + y \cdot \mathsf{expm1}\left(z\right)\right)}}\\
\mathbf{elif}\;z \le 4.71774190635494676 \cdot 10^{-57}:\\
\;\;\;\;x - \mathsf{fma}\left(\frac{z \cdot y}{t}, 1, \mathsf{fma}\left(0.5, \frac{{z}^{2} \cdot y}{t}, \frac{\log 1}{t}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right) + \log \left(\sqrt{1 + y \cdot \mathsf{expm1}\left(z\right)}\right)}{t}\\
\end{array}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 VAR;
if ((z <= -4.6972541441660704e-38)) {
VAR = (x - (1.0 / (t / log((1.0 + (y * expm1(z)))))));
} else {
double VAR_1;
if ((z <= 4.717741906354947e-57)) {
VAR_1 = (x - fma(((z * y) / t), 1.0, fma(0.5, ((pow(z, 2.0) * y) / t), (log(1.0) / t))));
} else {
VAR_1 = (x - ((log(sqrt((1.0 + (y * expm1(z))))) + log(sqrt((1.0 + (y * expm1(z)))))) / t));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x




Bits error versus y




Bits error versus z




Bits error versus t
Results
| Original | 24.4 |
|---|---|
| Target | 15.9 |
| Herbie | 8.2 |
if z < -4.6972541441660704e-38Initial program 12.6
rmApplied sub-neg12.6
Applied associate-+l+12.1
Simplified11.5
rmApplied clear-num11.5
if -4.6972541441660704e-38 < z < 4.717741906354947e-57Initial program 30.3
Taylor expanded around 0 5.7
Simplified5.7
if 4.717741906354947e-57 < z Initial program 28.6
rmApplied sub-neg28.6
Applied associate-+l+21.9
Simplified15.3
rmApplied add-sqr-sqrt15.3
Applied log-prod15.3
Final simplification8.2
herbie shell --seed 2020100 +o rules:numerics
(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 z) (* z z)))) (- x (/ (log (+ 1 (* z y))) t)))
(- x (/ (log (+ (- 1 y) (* y (exp z)))) t)))