
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs((x - y)) / abs(y)
end function
public static double code(double x, double y) {
return Math.abs((x - y)) / Math.abs(y);
}
def code(x, y): return math.fabs((x - y)) / math.fabs(y)
function code(x, y) return Float64(abs(Float64(x - y)) / abs(y)) end
function tmp = code(x, y) tmp = abs((x - y)) / abs(y); end
code[x_, y_] := N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs((x - y)) / abs(y)
end function
public static double code(double x, double y) {
return Math.abs((x - y)) / Math.abs(y);
}
def code(x, y): return math.fabs((x - y)) / math.fabs(y)
function code(x, y) return Float64(abs(Float64(x - y)) / abs(y)) end
function tmp = code(x, y) tmp = abs((x - y)) / abs(y); end
code[x_, y_] := N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}
(FPCore (x y) :precision binary64 (fabs (+ (/ x y) -1.0)))
double code(double x, double y) {
return fabs(((x / y) + -1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs(((x / y) + (-1.0d0)))
end function
public static double code(double x, double y) {
return Math.abs(((x / y) + -1.0));
}
def code(x, y): return math.fabs(((x / y) + -1.0))
function code(x, y) return abs(Float64(Float64(x / y) + -1.0)) end
function tmp = code(x, y) tmp = abs(((x / y) + -1.0)); end
code[x_, y_] := N[Abs[N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x}{y} + -1\right|
\end{array}
Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -8.8e-73) (not (<= x 9.5e+71))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -8.8e-73) || !(x <= 9.5e+71)) {
tmp = fabs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-8.8d-73)) .or. (.not. (x <= 9.5d+71))) then
tmp = abs((x / y))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -8.8e-73) || !(x <= 9.5e+71)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -8.8e-73) or not (x <= 9.5e+71): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -8.8e-73) || !(x <= 9.5e+71)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -8.8e-73) || ~((x <= 9.5e+71))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -8.8e-73], N[Not[LessEqual[x, 9.5e+71]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.8 \cdot 10^{-73} \lor \neg \left(x \leq 9.5 \cdot 10^{+71}\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -8.8000000000000001e-73 or 9.50000000000000015e71 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 80.2%
if -8.8000000000000001e-73 < x < 9.50000000000000015e71Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 22.5%
Applied egg-rr79.7%
*-inverses79.7%
Simplified79.7%
Final simplification80.0%
(FPCore (x y) :precision binary64 (if (<= y -3.4e+44) 1.0 (if (<= y 1.45e+50) (* (+ x -1.0) (+ x (+ x -1.0))) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.4e+44) {
tmp = 1.0;
} else if (y <= 1.45e+50) {
tmp = (x + -1.0) * (x + (x + -1.0));
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-3.4d+44)) then
tmp = 1.0d0
else if (y <= 1.45d+50) then
tmp = (x + (-1.0d0)) * (x + (x + (-1.0d0)))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.4e+44) {
tmp = 1.0;
} else if (y <= 1.45e+50) {
tmp = (x + -1.0) * (x + (x + -1.0));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.4e+44: tmp = 1.0 elif y <= 1.45e+50: tmp = (x + -1.0) * (x + (x + -1.0)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.4e+44) tmp = 1.0; elseif (y <= 1.45e+50) tmp = Float64(Float64(x + -1.0) * Float64(x + Float64(x + -1.0))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.4e+44) tmp = 1.0; elseif (y <= 1.45e+50) tmp = (x + -1.0) * (x + (x + -1.0)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.4e+44], 1.0, If[LessEqual[y, 1.45e+50], N[(N[(x + -1.0), $MachinePrecision] * N[(x + N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+44}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+50}:\\
\;\;\;\;\left(x + -1\right) \cdot \left(x + \left(x + -1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.4e44 or 1.45e50 < y Initial program 99.9%
Taylor expanded in x around -inf 99.9%
Simplified100.0%
Taylor expanded in x around inf 19.5%
Applied egg-rr82.0%
*-inverses82.0%
Simplified82.0%
if -3.4e44 < y < 1.45e50Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
*-inverses100.0%
sub-neg100.0%
sub-div100.0%
add-sqr-sqrt34.1%
fabs-sqr34.1%
add-sqr-sqrt34.8%
Applied egg-rr34.8%
Applied egg-rr49.5%
Final simplification62.7%
(FPCore (x y) :precision binary64 (if (<= x -1.4e+128) (* x x) (if (<= x -1.1e+21) (/ x y) (if (<= x 4.9e+156) 1.0 (* x x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.4e+128) {
tmp = x * x;
} else if (x <= -1.1e+21) {
tmp = x / y;
} else if (x <= 4.9e+156) {
tmp = 1.0;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.4d+128)) then
tmp = x * x
else if (x <= (-1.1d+21)) then
tmp = x / y
else if (x <= 4.9d+156) then
tmp = 1.0d0
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.4e+128) {
tmp = x * x;
} else if (x <= -1.1e+21) {
tmp = x / y;
} else if (x <= 4.9e+156) {
tmp = 1.0;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.4e+128: tmp = x * x elif x <= -1.1e+21: tmp = x / y elif x <= 4.9e+156: tmp = 1.0 else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.4e+128) tmp = Float64(x * x); elseif (x <= -1.1e+21) tmp = Float64(x / y); elseif (x <= 4.9e+156) tmp = 1.0; else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.4e+128) tmp = x * x; elseif (x <= -1.1e+21) tmp = x / y; elseif (x <= 4.9e+156) tmp = 1.0; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.4e+128], N[(x * x), $MachinePrecision], If[LessEqual[x, -1.1e+21], N[(x / y), $MachinePrecision], If[LessEqual[x, 4.9e+156], 1.0, N[(x * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+128}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq -1.1 \cdot 10^{+21}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 4.9 \cdot 10^{+156}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -1.39999999999999991e128 or 4.89999999999999969e156 < x Initial program 99.9%
Taylor expanded in x around -inf 99.9%
Simplified100.0%
Taylor expanded in x around inf 83.2%
Applied egg-rr44.4%
if -1.39999999999999991e128 < x < -1.1e21Initial program 100.0%
div-inv99.6%
add-sqr-sqrt7.9%
fabs-sqr7.9%
add-sqr-sqrt8.4%
*-commutative8.4%
add-sqr-sqrt0.3%
fabs-sqr0.3%
add-sqr-sqrt52.2%
Applied egg-rr52.2%
Taylor expanded in x around inf 52.5%
Taylor expanded in y around 0 52.7%
if -1.1e21 < x < 4.89999999999999969e156Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 31.7%
Applied egg-rr70.9%
*-inverses70.9%
Simplified70.9%
(FPCore (x y) :precision binary64 (if (<= y -3.4e+44) 1.0 (if (<= y 1.4e+50) (* (+ x -1.0) (+ x -1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.4e+44) {
tmp = 1.0;
} else if (y <= 1.4e+50) {
tmp = (x + -1.0) * (x + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-3.4d+44)) then
tmp = 1.0d0
else if (y <= 1.4d+50) then
tmp = (x + (-1.0d0)) * (x + (-1.0d0))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.4e+44) {
tmp = 1.0;
} else if (y <= 1.4e+50) {
tmp = (x + -1.0) * (x + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.4e+44: tmp = 1.0 elif y <= 1.4e+50: tmp = (x + -1.0) * (x + -1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.4e+44) tmp = 1.0; elseif (y <= 1.4e+50) tmp = Float64(Float64(x + -1.0) * Float64(x + -1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.4e+44) tmp = 1.0; elseif (y <= 1.4e+50) tmp = (x + -1.0) * (x + -1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.4e+44], 1.0, If[LessEqual[y, 1.4e+50], N[(N[(x + -1.0), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+44}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+50}:\\
\;\;\;\;\left(x + -1\right) \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.4e44 or 1.3999999999999999e50 < y Initial program 99.9%
Taylor expanded in x around -inf 99.9%
Simplified100.0%
Taylor expanded in x around inf 19.5%
Applied egg-rr82.0%
*-inverses82.0%
Simplified82.0%
if -3.4e44 < y < 1.3999999999999999e50Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
*-inverses100.0%
sub-neg100.0%
sub-div100.0%
add-sqr-sqrt34.1%
fabs-sqr34.1%
add-sqr-sqrt34.8%
Applied egg-rr34.8%
Applied egg-rr49.5%
(FPCore (x y) :precision binary64 (if (or (<= x -4e+164) (not (<= x 4.6e+157))) (* x x) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -4e+164) || !(x <= 4.6e+157)) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-4d+164)) .or. (.not. (x <= 4.6d+157))) then
tmp = x * x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -4e+164) || !(x <= 4.6e+157)) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4e+164) or not (x <= 4.6e+157): tmp = x * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -4e+164) || !(x <= 4.6e+157)) tmp = Float64(x * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4e+164) || ~((x <= 4.6e+157))) tmp = x * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4e+164], N[Not[LessEqual[x, 4.6e+157]], $MachinePrecision]], N[(x * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+164} \lor \neg \left(x \leq 4.6 \cdot 10^{+157}\right):\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4e164 or 4.60000000000000008e157 < x Initial program 99.9%
Taylor expanded in x around -inf 99.9%
Simplified100.0%
Taylor expanded in x around inf 85.1%
Applied egg-rr48.2%
if -4e164 < x < 4.60000000000000008e157Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 40.1%
Applied egg-rr62.3%
*-inverses62.3%
Simplified62.3%
Final simplification58.5%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 52.1%
Applied egg-rr50.1%
*-inverses50.1%
Simplified50.1%
herbie shell --seed 2024141
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))