
(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}
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= y 6e-44) (fabs (/ (- (* x z) (+ x 4.0)) y)) (fabs (fma x (/ z y) (/ (- -4.0 x) y)))))
y = abs(y);
double code(double x, double y, double z) {
double tmp;
if (y <= 6e-44) {
tmp = fabs((((x * z) - (x + 4.0)) / y));
} else {
tmp = fabs(fma(x, (z / y), ((-4.0 - x) / y)));
}
return tmp;
}
y = abs(y) function code(x, y, z) tmp = 0.0 if (y <= 6e-44) tmp = abs(Float64(Float64(Float64(x * z) - Float64(x + 4.0)) / y)); else tmp = abs(fma(x, Float64(z / y), Float64(Float64(-4.0 - x) / y))); end return tmp end
NOTE: y should be positive before calling this function code[x_, y_, z_] := If[LessEqual[y, 6e-44], N[Abs[N[(N[(N[(x * z), $MachinePrecision] - N[(x + 4.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x * N[(z / y), $MachinePrecision] + N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{-44}:\\
\;\;\;\;\left|\frac{x \cdot z - \left(x + 4\right)}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\
\end{array}
\end{array}
if y < 6.0000000000000005e-44Initial program 90.5%
associate-*l/91.7%
sub-div98.9%
Applied egg-rr98.9%
if 6.0000000000000005e-44 < y Initial program 95.5%
fabs-sub95.5%
associate-*l/94.0%
*-commutative94.0%
associate-*l/99.9%
*-commutative99.9%
fma-neg99.9%
distribute-neg-frac99.9%
+-commutative99.9%
distribute-neg-in99.9%
unsub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification99.2%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= x -2.4e+51) (fabs (* z (/ x y))) (if (or (<= x -1.56) (not (<= x 4.0))) (fabs (/ x y)) (fabs (/ 4.0 y)))))
y = abs(y);
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+51) {
tmp = fabs((z * (x / y)));
} else if ((x <= -1.56) || !(x <= 4.0)) {
tmp = fabs((x / y));
} else {
tmp = fabs((4.0 / y));
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-2.4d+51)) then
tmp = abs((z * (x / y)))
else if ((x <= (-1.56d0)) .or. (.not. (x <= 4.0d0))) then
tmp = abs((x / y))
else
tmp = abs((4.0d0 / y))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+51) {
tmp = Math.abs((z * (x / y)));
} else if ((x <= -1.56) || !(x <= 4.0)) {
tmp = Math.abs((x / y));
} else {
tmp = Math.abs((4.0 / y));
}
return tmp;
}
y = abs(y) def code(x, y, z): tmp = 0 if x <= -2.4e+51: tmp = math.fabs((z * (x / y))) elif (x <= -1.56) or not (x <= 4.0): tmp = math.fabs((x / y)) else: tmp = math.fabs((4.0 / y)) return tmp
y = abs(y) function code(x, y, z) tmp = 0.0 if (x <= -2.4e+51) tmp = abs(Float64(z * Float64(x / y))); elseif ((x <= -1.56) || !(x <= 4.0)) tmp = abs(Float64(x / y)); else tmp = abs(Float64(4.0 / y)); end return tmp end
y = abs(y) function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.4e+51) tmp = abs((z * (x / y))); elseif ((x <= -1.56) || ~((x <= 4.0))) tmp = abs((x / y)); else tmp = abs((4.0 / y)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := If[LessEqual[x, -2.4e+51], N[Abs[N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, -1.56], N[Not[LessEqual[x, 4.0]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+51}:\\
\;\;\;\;\left|z \cdot \frac{x}{y}\right|\\
\mathbf{elif}\;x \leq -1.56 \lor \neg \left(x \leq 4\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{4}{y}\right|\\
\end{array}
\end{array}
if x < -2.3999999999999999e51Initial program 86.0%
Simplified91.0%
Taylor expanded in z around inf 60.1%
*-commutative60.1%
associate-*l/75.4%
*-commutative75.4%
Simplified75.4%
if -2.3999999999999999e51 < x < -1.5600000000000001 or 4 < x Initial program 84.8%
Simplified97.0%
Taylor expanded in x around inf 95.3%
Taylor expanded in z around 0 77.3%
associate-*r/77.3%
neg-mul-177.3%
Simplified77.3%
if -1.5600000000000001 < x < 4Initial program 96.5%
Taylor expanded in x around 0 79.3%
Final simplification78.1%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= z -1.75e+160) (fabs (/ (* x z) y)) (if (<= z 2.3e+25) (fabs (/ (- -4.0 x) y)) (fabs (/ x (/ y z))))))
y = abs(y);
double code(double x, double y, double z) {
double tmp;
if (z <= -1.75e+160) {
tmp = fabs(((x * z) / y));
} else if (z <= 2.3e+25) {
tmp = fabs(((-4.0 - x) / y));
} else {
tmp = fabs((x / (y / z)));
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.75d+160)) then
tmp = abs(((x * z) / y))
else if (z <= 2.3d+25) then
tmp = abs((((-4.0d0) - x) / y))
else
tmp = abs((x / (y / z)))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.75e+160) {
tmp = Math.abs(((x * z) / y));
} else if (z <= 2.3e+25) {
tmp = Math.abs(((-4.0 - x) / y));
} else {
tmp = Math.abs((x / (y / z)));
}
return tmp;
}
y = abs(y) def code(x, y, z): tmp = 0 if z <= -1.75e+160: tmp = math.fabs(((x * z) / y)) elif z <= 2.3e+25: tmp = math.fabs(((-4.0 - x) / y)) else: tmp = math.fabs((x / (y / z))) return tmp
y = abs(y) function code(x, y, z) tmp = 0.0 if (z <= -1.75e+160) tmp = abs(Float64(Float64(x * z) / y)); elseif (z <= 2.3e+25) tmp = abs(Float64(Float64(-4.0 - x) / y)); else tmp = abs(Float64(x / Float64(y / z))); end return tmp end
y = abs(y) function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.75e+160) tmp = abs(((x * z) / y)); elseif (z <= 2.3e+25) tmp = abs(((-4.0 - x) / y)); else tmp = abs((x / (y / z))); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := If[LessEqual[z, -1.75e+160], N[Abs[N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 2.3e+25], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{+160}:\\
\;\;\;\;\left|\frac{x \cdot z}{y}\right|\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+25}:\\
\;\;\;\;\left|\frac{-4 - x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\
\end{array}
\end{array}
if z < -1.75000000000000013e160Initial program 92.3%
Simplified96.0%
Taylor expanded in z around inf 83.2%
if -1.75000000000000013e160 < z < 2.2999999999999998e25Initial program 97.7%
Simplified99.3%
Taylor expanded in z around 0 93.0%
associate-*r/93.0%
distribute-lft-in93.0%
metadata-eval93.0%
neg-mul-193.0%
sub-neg93.0%
Simplified93.0%
if 2.2999999999999998e25 < z Initial program 73.8%
Simplified93.3%
Taylor expanded in z around inf 72.6%
associate-*l/75.8%
Simplified75.8%
*-commutative75.8%
clear-num75.8%
un-div-inv77.3%
Applied egg-rr77.3%
Final simplification88.5%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (fabs (/ (- (* x z) (+ x 4.0)) y)))
y = abs(y);
double code(double x, double y, double z) {
return fabs((((x * z) - (x + 4.0)) / y));
}
NOTE: y should be positive before calling this function
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 * z) - (x + 4.0d0)) / y))
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return Math.abs((((x * z) - (x + 4.0)) / y));
}
y = abs(y) def code(x, y, z): return math.fabs((((x * z) - (x + 4.0)) / y))
y = abs(y) function code(x, y, z) return abs(Float64(Float64(Float64(x * z) - Float64(x + 4.0)) / y)) end
y = abs(y) function tmp = code(x, y, z) tmp = abs((((x * z) - (x + 4.0)) / y)); end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[Abs[N[(N[(N[(x * z), $MachinePrecision] - N[(x + 4.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\left|\frac{x \cdot z - \left(x + 4\right)}{y}\right|
\end{array}
Initial program 91.7%
associate-*l/92.3%
sub-div97.7%
Applied egg-rr97.7%
Final simplification97.7%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (if (or (<= x -1.55) (not (<= x 4.0))) (fabs (/ x y)) (fabs (/ 4.0 y))))
y = abs(y);
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55) || !(x <= 4.0)) {
tmp = fabs((x / y));
} else {
tmp = fabs((4.0 / y));
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-1.55d0)) .or. (.not. (x <= 4.0d0))) then
tmp = abs((x / y))
else
tmp = abs((4.0d0 / y))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55) || !(x <= 4.0)) {
tmp = Math.abs((x / y));
} else {
tmp = Math.abs((4.0 / y));
}
return tmp;
}
y = abs(y) def code(x, y, z): tmp = 0 if (x <= -1.55) or not (x <= 4.0): tmp = math.fabs((x / y)) else: tmp = math.fabs((4.0 / y)) return tmp
y = abs(y) function code(x, y, z) tmp = 0.0 if ((x <= -1.55) || !(x <= 4.0)) tmp = abs(Float64(x / y)); else tmp = abs(Float64(4.0 / y)); end return tmp end
y = abs(y) function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.55) || ~((x <= 4.0))) tmp = abs((x / y)); else tmp = abs((4.0 / y)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := If[Or[LessEqual[x, -1.55], N[Not[LessEqual[x, 4.0]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \lor \neg \left(x \leq 4\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{4}{y}\right|\\
\end{array}
\end{array}
if x < -1.55000000000000004 or 4 < x Initial program 85.3%
Simplified94.6%
Taylor expanded in x around inf 93.6%
Taylor expanded in z around 0 67.4%
associate-*r/67.4%
neg-mul-167.4%
Simplified67.4%
if -1.55000000000000004 < x < 4Initial program 96.5%
Taylor expanded in x around 0 79.3%
Final simplification74.2%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (fabs (/ 4.0 y)))
y = abs(y);
double code(double x, double y, double z) {
return fabs((4.0 / y));
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs((4.0d0 / y))
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return Math.abs((4.0 / y));
}
y = abs(y) def code(x, y, z): return math.fabs((4.0 / y))
y = abs(y) function code(x, y, z) return abs(Float64(4.0 / y)) end
y = abs(y) function tmp = code(x, y, z) tmp = abs((4.0 / y)); end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\left|\frac{4}{y}\right|
\end{array}
Initial program 91.7%
Taylor expanded in x around 0 47.8%
Final simplification47.8%
herbie shell --seed 2023240
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))