\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\begin{array}{l}
\mathbf{if}\;z \leq -1.4932932283986656 \cdot 10^{+36} \lor \neg \left(z \leq 3.425357687924926 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot \frac{y + 1}{z} - x\\
\mathbf{else}:\\
\;\;\;\;\left(y + 1\right) \cdot \frac{x}{z} - x\\
\end{array}(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z) :precision binary64 (if (or (<= z -1.4932932283986656e+36) (not (<= z 3.425357687924926e-15))) (- (* x (/ (+ y 1.0) z)) x) (- (* (+ y 1.0) (/ x z)) x)))
double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4932932283986656e+36) || !(z <= 3.425357687924926e-15)) {
tmp = (x * ((y + 1.0) / z)) - x;
} else {
tmp = ((y + 1.0) * (x / z)) - x;
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 10.3 |
|---|---|
| Target | 0.5 |
| Herbie | 0.1 |
if z < -1.49329322839866555e36 or 3.42535768792492597e-15 < z Initial program 17.4
Simplified0.1
if -1.49329322839866555e36 < z < 3.42535768792492597e-15Initial program 0.3
Simplified0.3
Taylor expanded around 0 0.2
Simplified0.2
Final simplification0.1
herbie shell --seed 2021176
(FPCore (x y z)
:name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))
(/ (* x (+ (- y z) 1.0)) z))