\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \left(y - z\right) + 1\\
t_1 := \frac{x \cdot t_0}{z}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, \frac{x}{z}\right) - x\\
\mathbf{elif}\;t_1 \leq 8.648903115752281 \cdot 10^{+273}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{1}{\frac{z}{t_0}}\\
\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (- y z) 1.0)) (t_1 (/ (* x t_0) z)))
(if (<= t_1 (- INFINITY))
(- (fma (/ y z) x (/ x z)) x)
(if (<= t_1 8.648903115752281e+273)
(- (/ (fma x y x) z) x)
(* x (/ 1.0 (/ z t_0)))))))double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
double t_0 = (y - z) + 1.0;
double t_1 = (x * t_0) / z;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = fma((y / z), x, (x / z)) - x;
} else if (t_1 <= 8.648903115752281e+273) {
tmp = (fma(x, y, x) / z) - x;
} else {
tmp = x * (1.0 / (z / t_0));
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
| Original | 10.7 |
|---|---|
| Target | 0.5 |
| Herbie | 0.3 |
if (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < -inf.0Initial program 64.0
Applied egg-rr0.0
Applied egg-rr0.1
Taylor expanded in z around 0 21.3
Simplified0.0
if -inf.0 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < 8.6489031157522806e273Initial program 0.1
Applied egg-rr4.0
Applied egg-rr3.5
Applied egg-rr10.9
Taylor expanded in y around 0 0.1
Simplified0.1
if 8.6489031157522806e273 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) Initial program 52.7
Applied egg-rr2.6
Final simplification0.3
herbie shell --seed 2022130
(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))