
(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 (- 1.0 (/ x y))))
double code(double x, double y) {
return fabs((1.0 - (x / y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs((1.0d0 - (x / y)))
end function
public static double code(double x, double y) {
return Math.abs((1.0 - (x / y)));
}
def code(x, y): return math.fabs((1.0 - (x / y)))
function code(x, y) return abs(Float64(1.0 - Float64(x / y))) end
function tmp = code(x, y) tmp = abs((1.0 - (x / y))); end
code[x_, y_] := N[Abs[N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|1 - \frac{x}{y}\right|
\end{array}
Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -3.6e-81) (not (<= x 1.62e+19))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -3.6e-81) || !(x <= 1.62e+19)) {
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 <= (-3.6d-81)) .or. (.not. (x <= 1.62d+19))) 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 <= -3.6e-81) || !(x <= 1.62e+19)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.6e-81) or not (x <= 1.62e+19): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.6e-81) || !(x <= 1.62e+19)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3.6e-81) || ~((x <= 1.62e+19))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.6e-81], N[Not[LessEqual[x, 1.62e+19]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-81} \lor \neg \left(x \leq 1.62 \cdot 10^{+19}\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.5999999999999999e-81 or 1.62e19 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 75.9%
if -3.5999999999999999e-81 < x < 1.62e19Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 24.3%
Applied egg-rr78.0%
*-inverses78.0%
Simplified78.0%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (<= y -4.1e-66) 1.0 (if (<= y 3.4e-99) (/ (- x y) y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -4.1e-66) {
tmp = 1.0;
} else if (y <= 3.4e-99) {
tmp = (x - y) / 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 (y <= (-4.1d-66)) then
tmp = 1.0d0
else if (y <= 3.4d-99) then
tmp = (x - y) / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.1e-66) {
tmp = 1.0;
} else if (y <= 3.4e-99) {
tmp = (x - y) / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.1e-66: tmp = 1.0 elif y <= 3.4e-99: tmp = (x - y) / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.1e-66) tmp = 1.0; elseif (y <= 3.4e-99) tmp = Float64(Float64(x - y) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.1e-66) tmp = 1.0; elseif (y <= 3.4e-99) tmp = (x - y) / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.1e-66], 1.0, If[LessEqual[y, 3.4e-99], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-66}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-99}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.09999999999999998e-66 or 3.40000000000000007e-99 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 36.6%
Applied egg-rr67.6%
*-inverses67.6%
Simplified67.6%
if -4.09999999999999998e-66 < y < 3.40000000000000007e-99Initial program 100.0%
add-log-exp52.5%
*-un-lft-identity52.5%
log-prod52.5%
metadata-eval52.5%
add-log-exp100.0%
add-sqr-sqrt52.8%
fabs-sqr52.8%
add-sqr-sqrt23.2%
fabs-sqr23.2%
add-sqr-sqrt23.5%
add-sqr-sqrt54.7%
Applied egg-rr54.7%
Final simplification62.8%
(FPCore (x y) :precision binary64 (if (<= y -4.2e-65) 1.0 (if (<= y 2.9e-96) (+ (/ x y) -1.0) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -4.2e-65) {
tmp = 1.0;
} else if (y <= 2.9e-96) {
tmp = (x / y) + -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 <= (-4.2d-65)) then
tmp = 1.0d0
else if (y <= 2.9d-96) then
tmp = (x / y) + (-1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.2e-65) {
tmp = 1.0;
} else if (y <= 2.9e-96) {
tmp = (x / y) + -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.2e-65: tmp = 1.0 elif y <= 2.9e-96: tmp = (x / y) + -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.2e-65) tmp = 1.0; elseif (y <= 2.9e-96) tmp = Float64(Float64(x / y) + -1.0); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.2e-65) tmp = 1.0; elseif (y <= 2.9e-96) tmp = (x / y) + -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.2e-65], 1.0, If[LessEqual[y, 2.9e-96], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{-65}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-96}:\\
\;\;\;\;\frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.20000000000000006e-65 or 2.89999999999999994e-96 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 36.6%
Applied egg-rr67.6%
*-inverses67.6%
Simplified67.6%
if -4.20000000000000006e-65 < y < 2.89999999999999994e-96Initial program 100.0%
add-sqr-sqrt52.8%
fabs-sqr52.8%
add-sqr-sqrt23.2%
fabs-sqr23.2%
add-sqr-sqrt23.5%
add-sqr-sqrt54.7%
div-sub54.7%
Applied egg-rr54.7%
Taylor expanded in y around 0 54.7%
Final simplification62.8%
(FPCore (x y) :precision binary64 (if (or (<= x -2.55e+178) (not (<= x 2.7e+218))) (* x x) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -2.55e+178) || !(x <= 2.7e+218)) {
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 <= (-2.55d+178)) .or. (.not. (x <= 2.7d+218))) 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 <= -2.55e+178) || !(x <= 2.7e+218)) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.55e+178) or not (x <= 2.7e+218): tmp = x * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.55e+178) || !(x <= 2.7e+218)) tmp = Float64(x * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.55e+178) || ~((x <= 2.7e+218))) tmp = x * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.55e+178], N[Not[LessEqual[x, 2.7e+218]], $MachinePrecision]], N[(x * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.55 \cdot 10^{+178} \lor \neg \left(x \leq 2.7 \cdot 10^{+218}\right):\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.5499999999999998e178 or 2.70000000000000013e218 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 91.4%
Applied egg-rr48.0%
if -2.5499999999999998e178 < x < 2.70000000000000013e218Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 44.1%
Applied egg-rr59.2%
*-inverses59.2%
Simplified59.2%
Final simplification56.9%
(FPCore (x y) :precision binary64 (if (<= y -2.15e-66) 1.0 (if (<= y 4e-98) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.15e-66) {
tmp = 1.0;
} else if (y <= 4e-98) {
tmp = 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 (y <= (-2.15d-66)) then
tmp = 1.0d0
else if (y <= 4d-98) then
tmp = x / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.15e-66) {
tmp = 1.0;
} else if (y <= 4e-98) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.15e-66: tmp = 1.0 elif y <= 4e-98: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.15e-66) tmp = 1.0; elseif (y <= 4e-98) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.15e-66) tmp = 1.0; elseif (y <= 4e-98) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.15e-66], 1.0, If[LessEqual[y, 4e-98], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{-66}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-98}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.15000000000000007e-66 or 3.99999999999999976e-98 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 36.6%
Applied egg-rr67.6%
*-inverses67.6%
Simplified67.6%
if -2.15000000000000007e-66 < y < 3.99999999999999976e-98Initial program 100.0%
div-inv99.7%
add-sqr-sqrt52.8%
fabs-sqr52.8%
add-sqr-sqrt53.3%
*-commutative53.3%
add-sqr-sqrt23.4%
fabs-sqr23.4%
add-sqr-sqrt54.5%
Applied egg-rr54.5%
Taylor expanded in x around inf 53.6%
Taylor expanded in y around 0 53.7%
(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 53.9%
Applied egg-rr49.4%
*-inverses49.4%
Simplified49.4%
herbie shell --seed 2024116
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))