(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z) :precision binary64 (if (<= (/ (* x (+ y z)) z) 1e-32) (fma x (/ y z) x) (fma y (/ x z) x)))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= 1e-32) {
tmp = fma(x, (y / z), x);
} else {
tmp = fma(y, (x / z), x);
}
return tmp;
}
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x * Float64(y + z)) / z) <= 1e-32) tmp = fma(x, Float64(y / z), x); else tmp = fma(y, Float64(x / z), x); end return tmp end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 1e-32], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(x / z), $MachinePrecision] + x), $MachinePrecision]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 10^{-32}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\
\end{array}




Bits error versus x




Bits error versus y




Bits error versus z
| Original | 12.3 |
|---|---|
| Target | 3.2 |
| Herbie | 3.5 |
if (/.f64 (*.f64 x (+.f64 y z)) z) < 1.00000000000000006e-32Initial program 11.0
Simplified2.9
if 1.00000000000000006e-32 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 15.3
Simplified4.8
Taylor expanded in x around 0 4.8
Simplified5.0
Final simplification3.5
herbie shell --seed 2022170
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))