
(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 6 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 2.1e-64) (fabs (/ (- (+ 4.0 x) (* x z)) y_m)) (fabs (- (/ (+ 4.0 x) y_m) (/ x (/ y_m z))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
double tmp;
if (y_m <= 2.1e-64) {
tmp = fabs((((4.0 + x) - (x * z)) / y_m));
} else {
tmp = fabs((((4.0 + x) / y_m) - (x / (y_m / z))));
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: tmp
if (y_m <= 2.1d-64) then
tmp = abs((((4.0d0 + x) - (x * z)) / y_m))
else
tmp = abs((((4.0d0 + x) / y_m) - (x / (y_m / z))))
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
double tmp;
if (y_m <= 2.1e-64) {
tmp = Math.abs((((4.0 + x) - (x * z)) / y_m));
} else {
tmp = Math.abs((((4.0 + x) / y_m) - (x / (y_m / z))));
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z): tmp = 0 if y_m <= 2.1e-64: tmp = math.fabs((((4.0 + x) - (x * z)) / y_m)) else: tmp = math.fabs((((4.0 + x) / y_m) - (x / (y_m / z)))) return tmp
y_m = abs(y) function code(x, y_m, z) tmp = 0.0 if (y_m <= 2.1e-64) tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(x * z)) / y_m)); else tmp = abs(Float64(Float64(Float64(4.0 + x) / y_m) - Float64(x / Float64(y_m / z)))); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z) tmp = 0.0; if (y_m <= 2.1e-64) tmp = abs((((4.0 + x) - (x * z)) / y_m)); else tmp = abs((((4.0 + x) / y_m) - (x / (y_m / z)))); end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_] := If[LessEqual[y$95$m, 2.1e-64], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] / y$95$m), $MachinePrecision] - N[(x / N[(y$95$m / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y_m \leq 2.1 \cdot 10^{-64}:\\
\;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y_m}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{4 + x}{y_m} - \frac{x}{\frac{y_m}{z}}\right|\\
\end{array}
\end{array}
y_m = (fabs.f64 y)
(FPCore (x y_m z)
:precision binary64
(let* ((t_0 (fabs (* z (/ x y_m))))
(t_1 (fabs (/ x y_m)))
(t_2 (fabs (/ 4.0 y_m))))
(if (<= x -10.5)
t_1
(if (<= x 5.2e-149)
t_2
(if (<= x 3e-74)
t_0
(if (<= x 4.0)
t_2
(if (or (<= x 8.6e+111) (not (<= x 1.5e+229))) t_1 t_0)))))))y_m = fabs(y);
double code(double x, double y_m, double z) {
double t_0 = fabs((z * (x / y_m)));
double t_1 = fabs((x / y_m));
double t_2 = fabs((4.0 / y_m));
double tmp;
if (x <= -10.5) {
tmp = t_1;
} else if (x <= 5.2e-149) {
tmp = t_2;
} else if (x <= 3e-74) {
tmp = t_0;
} else if (x <= 4.0) {
tmp = t_2;
} else if ((x <= 8.6e+111) || !(x <= 1.5e+229)) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = abs((z * (x / y_m)))
t_1 = abs((x / y_m))
t_2 = abs((4.0d0 / y_m))
if (x <= (-10.5d0)) then
tmp = t_1
else if (x <= 5.2d-149) then
tmp = t_2
else if (x <= 3d-74) then
tmp = t_0
else if (x <= 4.0d0) then
tmp = t_2
else if ((x <= 8.6d+111) .or. (.not. (x <= 1.5d+229))) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
double t_0 = Math.abs((z * (x / y_m)));
double t_1 = Math.abs((x / y_m));
double t_2 = Math.abs((4.0 / y_m));
double tmp;
if (x <= -10.5) {
tmp = t_1;
} else if (x <= 5.2e-149) {
tmp = t_2;
} else if (x <= 3e-74) {
tmp = t_0;
} else if (x <= 4.0) {
tmp = t_2;
} else if ((x <= 8.6e+111) || !(x <= 1.5e+229)) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z): t_0 = math.fabs((z * (x / y_m))) t_1 = math.fabs((x / y_m)) t_2 = math.fabs((4.0 / y_m)) tmp = 0 if x <= -10.5: tmp = t_1 elif x <= 5.2e-149: tmp = t_2 elif x <= 3e-74: tmp = t_0 elif x <= 4.0: tmp = t_2 elif (x <= 8.6e+111) or not (x <= 1.5e+229): tmp = t_1 else: tmp = t_0 return tmp
y_m = abs(y) function code(x, y_m, z) t_0 = abs(Float64(z * Float64(x / y_m))) t_1 = abs(Float64(x / y_m)) t_2 = abs(Float64(4.0 / y_m)) tmp = 0.0 if (x <= -10.5) tmp = t_1; elseif (x <= 5.2e-149) tmp = t_2; elseif (x <= 3e-74) tmp = t_0; elseif (x <= 4.0) tmp = t_2; elseif ((x <= 8.6e+111) || !(x <= 1.5e+229)) tmp = t_1; else tmp = t_0; end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z) t_0 = abs((z * (x / y_m))); t_1 = abs((x / y_m)); t_2 = abs((4.0 / y_m)); tmp = 0.0; if (x <= -10.5) tmp = t_1; elseif (x <= 5.2e-149) tmp = t_2; elseif (x <= 3e-74) tmp = t_0; elseif (x <= 4.0) tmp = t_2; elseif ((x <= 8.6e+111) || ~((x <= 1.5e+229))) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := Block[{t$95$0 = N[Abs[N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Abs[N[(4.0 / y$95$m), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -10.5], t$95$1, If[LessEqual[x, 5.2e-149], t$95$2, If[LessEqual[x, 3e-74], t$95$0, If[LessEqual[x, 4.0], t$95$2, If[Or[LessEqual[x, 8.6e+111], N[Not[LessEqual[x, 1.5e+229]], $MachinePrecision]], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_0 := \left|z \cdot \frac{x}{y_m}\right|\\
t_1 := \left|\frac{x}{y_m}\right|\\
t_2 := \left|\frac{4}{y_m}\right|\\
\mathbf{if}\;x \leq -10.5:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-149}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-74}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 4:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{+111} \lor \neg \left(x \leq 1.5 \cdot 10^{+229}\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
y_m = (fabs.f64 y) (FPCore (x y_m z) :precision binary64 (if (<= x 4e+22) (fabs (/ (- (+ 4.0 x) (* x z)) y_m)) (fabs (* x (/ (+ z -1.0) y_m)))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
double tmp;
if (x <= 4e+22) {
tmp = fabs((((4.0 + x) - (x * z)) / y_m));
} else {
tmp = fabs((x * ((z + -1.0) / y_m)));
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: tmp
if (x <= 4d+22) then
tmp = abs((((4.0d0 + x) - (x * z)) / y_m))
else
tmp = abs((x * ((z + (-1.0d0)) / y_m)))
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
double tmp;
if (x <= 4e+22) {
tmp = Math.abs((((4.0 + x) - (x * z)) / y_m));
} else {
tmp = Math.abs((x * ((z + -1.0) / y_m)));
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z): tmp = 0 if x <= 4e+22: tmp = math.fabs((((4.0 + x) - (x * z)) / y_m)) else: tmp = math.fabs((x * ((z + -1.0) / y_m))) return tmp
y_m = abs(y) function code(x, y_m, z) tmp = 0.0 if (x <= 4e+22) tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(x * z)) / y_m)); else tmp = abs(Float64(x * Float64(Float64(z + -1.0) / y_m))); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z) tmp = 0.0; if (x <= 4e+22) tmp = abs((((4.0 + x) - (x * z)) / y_m)); else tmp = abs((x * ((z + -1.0) / y_m))); end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_] := If[LessEqual[x, 4e+22], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x * N[(N[(z + -1.0), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{+22}:\\
\;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y_m}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|x \cdot \frac{z + -1}{y_m}\right|\\
\end{array}
\end{array}
y_m = (fabs.f64 y) (FPCore (x y_m z) :precision binary64 (if (<= z -6.4e+23) (fabs (/ x (/ y_m z))) (if (<= z 3.5e+52) (fabs (/ (- -4.0 x) y_m)) (fabs (* z (/ x y_m))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
double tmp;
if (z <= -6.4e+23) {
tmp = fabs((x / (y_m / z)));
} else if (z <= 3.5e+52) {
tmp = fabs(((-4.0 - x) / y_m));
} else {
tmp = fabs((z * (x / y_m)));
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-6.4d+23)) then
tmp = abs((x / (y_m / z)))
else if (z <= 3.5d+52) then
tmp = abs((((-4.0d0) - x) / y_m))
else
tmp = abs((z * (x / y_m)))
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
double tmp;
if (z <= -6.4e+23) {
tmp = Math.abs((x / (y_m / z)));
} else if (z <= 3.5e+52) {
tmp = Math.abs(((-4.0 - x) / y_m));
} else {
tmp = Math.abs((z * (x / y_m)));
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z): tmp = 0 if z <= -6.4e+23: tmp = math.fabs((x / (y_m / z))) elif z <= 3.5e+52: tmp = math.fabs(((-4.0 - x) / y_m)) else: tmp = math.fabs((z * (x / y_m))) return tmp
y_m = abs(y) function code(x, y_m, z) tmp = 0.0 if (z <= -6.4e+23) tmp = abs(Float64(x / Float64(y_m / z))); elseif (z <= 3.5e+52) tmp = abs(Float64(Float64(-4.0 - x) / y_m)); else tmp = abs(Float64(z * Float64(x / y_m))); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z) tmp = 0.0; if (z <= -6.4e+23) tmp = abs((x / (y_m / z))); elseif (z <= 3.5e+52) tmp = abs(((-4.0 - x) / y_m)); else tmp = abs((z * (x / y_m))); end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_] := If[LessEqual[z, -6.4e+23], N[Abs[N[(x / N[(y$95$m / z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 3.5e+52], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.4 \cdot 10^{+23}:\\
\;\;\;\;\left|\frac{x}{\frac{y_m}{z}}\right|\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+52}:\\
\;\;\;\;\left|\frac{-4 - x}{y_m}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|z \cdot \frac{x}{y_m}\right|\\
\end{array}
\end{array}
y_m = (fabs.f64 y) (FPCore (x y_m z) :precision binary64 (if (or (<= x -10.5) (not (<= x 4.0))) (fabs (/ x y_m)) (fabs (/ 4.0 y_m))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
double tmp;
if ((x <= -10.5) || !(x <= 4.0)) {
tmp = fabs((x / y_m));
} else {
tmp = fabs((4.0 / y_m));
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-10.5d0)) .or. (.not. (x <= 4.0d0))) then
tmp = abs((x / y_m))
else
tmp = abs((4.0d0 / y_m))
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
double tmp;
if ((x <= -10.5) || !(x <= 4.0)) {
tmp = Math.abs((x / y_m));
} else {
tmp = Math.abs((4.0 / y_m));
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m, z): tmp = 0 if (x <= -10.5) or not (x <= 4.0): tmp = math.fabs((x / y_m)) else: tmp = math.fabs((4.0 / y_m)) return tmp
y_m = abs(y) function code(x, y_m, z) tmp = 0.0 if ((x <= -10.5) || !(x <= 4.0)) tmp = abs(Float64(x / y_m)); else tmp = abs(Float64(4.0 / y_m)); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m, z) tmp = 0.0; if ((x <= -10.5) || ~((x <= 4.0))) tmp = abs((x / y_m)); else tmp = abs((4.0 / y_m)); end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_] := If[Or[LessEqual[x, -10.5], N[Not[LessEqual[x, 4.0]], $MachinePrecision]], N[Abs[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(4.0 / y$95$m), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10.5 \lor \neg \left(x \leq 4\right):\\
\;\;\;\;\left|\frac{x}{y_m}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{4}{y_m}\right|\\
\end{array}
\end{array}
y_m = (fabs.f64 y) (FPCore (x y_m z) :precision binary64 (fabs (/ 4.0 y_m)))
y_m = fabs(y);
double code(double x, double y_m, double z) {
return fabs((4.0 / y_m));
}
y_m = abs(y)
real(8) function code(x, y_m, z)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
code = abs((4.0d0 / y_m))
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
return Math.abs((4.0 / y_m));
}
y_m = math.fabs(y) def code(x, y_m, z): return math.fabs((4.0 / y_m))
y_m = abs(y) function code(x, y_m, z) return abs(Float64(4.0 / y_m)) end
y_m = abs(y); function tmp = code(x, y_m, z) tmp = abs((4.0 / y_m)); end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_, z_] := N[Abs[N[(4.0 / y$95$m), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
\left|\frac{4}{y_m}\right|
\end{array}
herbie shell --seed 2023348
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))