\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \leq 1.7035116322509249 \cdot 10^{-37}:\\
\;\;\;\;x \cdot \left(-1 + \frac{y + 1}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, \frac{x}{z}\right) - x\\
\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z) :precision binary64 (if (<= (/ (* x (+ (- y z) 1.0)) z) 1.7035116322509249e-37) (* x (+ -1.0 (/ (+ y 1.0) z))) (- (fma (/ x z) y (/ 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 (((x * ((y - z) + 1.0)) / z) <= 1.7035116322509249e-37) {
tmp = x * (-1.0 + ((y + 1.0) / z));
} else {
tmp = fma((x / z), y, (x / z)) - x;
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
| Original | 10.7 |
|---|---|
| Target | 0.5 |
| Herbie | 1.8 |
if (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < 1.70351163225092485e-37Initial program 8.0
Simplified8.0
Taylor expanded in y around 0 2.9
Simplified2.5
Taylor expanded in x around 0 2.7
Applied *-un-lft-identity_binary642.7
Applied associate-*r*_binary642.7
Simplified2.7
if 1.70351163225092485e-37 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) Initial program 15.9
Simplified15.9
Taylor expanded in y around 0 5.3
Simplified0.1
Final simplification1.8
herbie shell --seed 2022063
(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))