
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
public static double code(double x, double y, double z) {
return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z): return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z) return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))) end
function tmp = code(x, y, z) tmp = abs((((x + 4.0) / y) - ((x / y) * z))); end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
public static double code(double x, double y, double z) {
return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z): return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z) return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))) end
function tmp = code(x, y, z) tmp = abs((((x + 4.0) / y) - ((x / y) * z))); end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}
y_m = (fabs.f64 y) (FPCore (x y_m z) :precision binary64 (if (<= y_m 2e-29) (fabs (/ (fma x z (- -4.0 x)) y_m)) (fabs (fma (- x) (/ z y_m) (/ (+ x 4.0) y_m)))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
double tmp;
if (y_m <= 2e-29) {
tmp = fabs((fma(x, z, (-4.0 - x)) / y_m));
} else {
tmp = fabs(fma(-x, (z / y_m), ((x + 4.0) / y_m)));
}
return tmp;
}
y_m = abs(y) function code(x, y_m, z) tmp = 0.0 if (y_m <= 2e-29) tmp = abs(Float64(fma(x, z, Float64(-4.0 - x)) / y_m)); else tmp = abs(fma(Float64(-x), Float64(z / y_m), Float64(Float64(x + 4.0) / y_m))); end return tmp end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_] := If[LessEqual[y$95$m, 2e-29], N[Abs[N[(N[(x * z + N[(-4.0 - x), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[((-x) * N[(z / y$95$m), $MachinePrecision] + N[(N[(x + 4.0), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 2 \cdot 10^{-29}:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(x, z, -4 - x\right)}{y\_m}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\mathsf{fma}\left(-x, \frac{z}{y\_m}, \frac{x + 4}{y\_m}\right)\right|\\
\end{array}
\end{array}
if y < 1.99999999999999989e-29Initial program 80.6%
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-/.f64N/A
sub-divN/A
lower-/.f64N/A
sub-negN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
if 1.99999999999999989e-29 < y Initial program 96.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
y_m = (fabs.f64 y)
(FPCore (x y_m z)
:precision binary64
(let* ((t_0 (fabs (- (/ (+ x 4.0) y_m) (* z (/ x y_m))))))
(if (<= t_0 5e-203)
(fabs (* (/ 1.0 y_m) (+ x (- 4.0 (* x z)))))
(if (<= t_0 INFINITY) t_0 (fabs (/ (- x) y_m))))))y_m = fabs(y);
double code(double x, double y_m, double z) {
double t_0 = fabs((((x + 4.0) / y_m) - (z * (x / y_m))));
double tmp;
if (t_0 <= 5e-203) {
tmp = fabs(((1.0 / y_m) * (x + (4.0 - (x * z)))));
} else if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = fabs((-x / y_m));
}
return tmp;
}
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
double t_0 = Math.abs((((x + 4.0) / y_m) - (z * (x / y_m))));
double tmp;
if (t_0 <= 5e-203) {
tmp = Math.abs(((1.0 / y_m) * (x + (4.0 - (x * z)))));
} else if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0;
} else {
tmp = Math.abs((-x / y_m));
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z): t_0 = math.fabs((((x + 4.0) / y_m) - (z * (x / y_m)))) tmp = 0 if t_0 <= 5e-203: tmp = math.fabs(((1.0 / y_m) * (x + (4.0 - (x * z))))) elif t_0 <= math.inf: tmp = t_0 else: tmp = math.fabs((-x / y_m)) return tmp
y_m = abs(y) function code(x, y_m, z) t_0 = abs(Float64(Float64(Float64(x + 4.0) / y_m) - Float64(z * Float64(x / y_m)))) tmp = 0.0 if (t_0 <= 5e-203) tmp = abs(Float64(Float64(1.0 / y_m) * Float64(x + Float64(4.0 - Float64(x * z))))); elseif (t_0 <= Inf) tmp = t_0; else tmp = abs(Float64(Float64(-x) / y_m)); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z) t_0 = abs((((x + 4.0) / y_m) - (z * (x / y_m)))); tmp = 0.0; if (t_0 <= 5e-203) tmp = abs(((1.0 / y_m) * (x + (4.0 - (x * z))))); elseif (t_0 <= Inf) tmp = t_0; else tmp = abs((-x / y_m)); end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := Block[{t$95$0 = N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y$95$m), $MachinePrecision] - N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 5e-203], N[Abs[N[(N[(1.0 / y$95$m), $MachinePrecision] * N[(x + N[(4.0 - N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$0, Infinity], t$95$0, N[Abs[N[((-x) / y$95$m), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_0 := \left|\frac{x + 4}{y\_m} - z \cdot \frac{x}{y\_m}\right|\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{-203}:\\
\;\;\;\;\left|\frac{1}{y\_m} \cdot \left(x + \left(4 - x \cdot z\right)\right)\right|\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{-x}{y\_m}\right|\\
\end{array}
\end{array}
if (fabs.f64 (-.f64 (/.f64 (+.f64 x #s(literal 4 binary64)) y) (*.f64 (/.f64 x y) z))) < 5.0000000000000002e-203Initial program 83.3%
lift--.f64N/A
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-invN/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
if 5.0000000000000002e-203 < (fabs.f64 (-.f64 (/.f64 (+.f64 x #s(literal 4 binary64)) y) (*.f64 (/.f64 x y) z))) < +inf.0Initial program 99.0%
if +inf.0 < (fabs.f64 (-.f64 (/.f64 (+.f64 x #s(literal 4 binary64)) y) (*.f64 (/.f64 x y) z))) Initial program 0.0%
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-/.f64N/A
sub-divN/A
lower-/.f64N/A
sub-negN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
lower--.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in z around 0
distribute-lft-inN/A
metadata-evalN/A
mul-1-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites100.0%
Final simplification99.2%
herbie shell --seed 2024219
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))