x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\begin{array}{l}
\mathbf{if}\;z \leq -7.016385981623024 \cdot 10^{-06}:\\
\;\;\;\;x - \frac{\log \left(\sqrt{y \cdot e^{z} + \left(1 - y\right)}\right) + \log \left(\sqrt{y \cdot e^{z} + \left(1 - y\right)}\right)}{t}\\
\mathbf{elif}\;z \leq -1.846117810869202 \cdot 10^{-215}:\\
\;\;\;\;x - \frac{\log \left(1 + y \cdot \left(z + 0.5 \cdot \left(z \cdot z\right)\right)\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \left(\frac{y}{\sqrt[3]{t}} \cdot \frac{z + \left(1 - y\right) \cdot \left(0.5 \cdot \left(z \cdot z\right)\right)}{\sqrt[3]{t}}\right) \cdot \frac{1}{\sqrt[3]{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 (<= z -7.016385981623024e-06)
(-
x
(/
(+
(log (sqrt (+ (* y (exp z)) (- 1.0 y))))
(log (sqrt (+ (* y (exp z)) (- 1.0 y)))))
t))
(if (<= z -1.846117810869202e-215)
(- x (/ (log (+ 1.0 (* y (+ z (* 0.5 (* z z)))))) t))
(-
x
(*
(* (/ y (cbrt t)) (/ (+ z (* (- 1.0 y) (* 0.5 (* z z)))) (cbrt t)))
(/ 1.0 (cbrt 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 (z <= -7.016385981623024e-06) {
tmp = x - ((log(sqrt((y * exp(z)) + (1.0 - y))) + log(sqrt((y * exp(z)) + (1.0 - y)))) / t);
} else if (z <= -1.846117810869202e-215) {
tmp = x - (log(1.0 + (y * (z + (0.5 * (z * z))))) / t);
} else {
tmp = x - (((y / cbrt(t)) * ((z + ((1.0 - y) * (0.5 * (z * z)))) / cbrt(t))) * (1.0 / cbrt(t)));
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z




Bits error versus t
Results
| Original | 24.4 |
|---|---|
| Target | 16.4 |
| Herbie | 9.4 |
if z < -7.01638598162302422e-6Initial program 10.9
rmApplied add-sqr-sqrt_binary6410.9
Applied log-prod_binary6410.9
Simplified10.9
Simplified10.9
if -7.01638598162302422e-6 < z < -1.846117810869202e-215Initial program 30.3
Taylor expanded around 0 12.2
Simplified12.2
if -1.846117810869202e-215 < z Initial program 30.3
Taylor expanded around 0 14.8
Simplified7.4
rmApplied add-cube-cbrt_binary647.5
Applied associate-/r*_binary647.5
Simplified7.1
rmApplied div-inv_binary647.1
Final simplification9.4
herbie shell --seed 2020260
(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)))