
(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 6 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 -155000000000.0) (not (<= x 4.3e+43))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -155000000000.0) || !(x <= 4.3e+43)) {
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 <= (-155000000000.0d0)) .or. (.not. (x <= 4.3d+43))) 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 <= -155000000000.0) || !(x <= 4.3e+43)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -155000000000.0) or not (x <= 4.3e+43): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -155000000000.0) || !(x <= 4.3e+43)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -155000000000.0) || ~((x <= 4.3e+43))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -155000000000.0], N[Not[LessEqual[x, 4.3e+43]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -155000000000 \lor \neg \left(x \leq 4.3 \cdot 10^{+43}\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.55e11 or 4.3e43 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 81.6%
if -1.55e11 < x < 4.3e43Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 76.3%
Applied egg-rr76.3%
Final simplification78.6%
(FPCore (x y) :precision binary64 (if (or (<= x -3700000000000.0) (not (<= x 4.6e+48))) (/ (- x y) y) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -3700000000000.0) || !(x <= 4.6e+48)) {
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 ((x <= (-3700000000000.0d0)) .or. (.not. (x <= 4.6d+48))) 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 ((x <= -3700000000000.0) || !(x <= 4.6e+48)) {
tmp = (x - y) / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3700000000000.0) or not (x <= 4.6e+48): tmp = (x - y) / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -3700000000000.0) || !(x <= 4.6e+48)) tmp = Float64(Float64(x - y) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3700000000000.0) || ~((x <= 4.6e+48))) tmp = (x - y) / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3700000000000.0], N[Not[LessEqual[x, 4.6e+48]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3700000000000 \lor \neg \left(x \leq 4.6 \cdot 10^{+48}\right):\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.7e12 or 4.6e48 < x Initial 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-sqrt42.9%
fabs-sqr42.9%
add-sqr-sqrt43.7%
Applied egg-rr43.7%
if -3.7e12 < x < 4.6e48Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 75.8%
Applied egg-rr75.8%
Final simplification61.8%
(FPCore (x y) :precision binary64 (if (or (<= x -3700000000000.0) (not (<= x 3.1e+49))) (/ x y) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -3700000000000.0) || !(x <= 3.1e+49)) {
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 ((x <= (-3700000000000.0d0)) .or. (.not. (x <= 3.1d+49))) 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 ((x <= -3700000000000.0) || !(x <= 3.1e+49)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3700000000000.0) or not (x <= 3.1e+49): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -3700000000000.0) || !(x <= 3.1e+49)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3700000000000.0) || ~((x <= 3.1e+49))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3700000000000.0], N[Not[LessEqual[x, 3.1e+49]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3700000000000 \lor \neg \left(x \leq 3.1 \cdot 10^{+49}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.7e12 or 3.09999999999999992e49 < x Initial program 100.0%
div-inv99.7%
add-sqr-sqrt49.2%
fabs-sqr49.2%
add-sqr-sqrt49.7%
*-commutative49.7%
add-sqr-sqrt19.0%
fabs-sqr19.0%
add-sqr-sqrt43.5%
Applied egg-rr43.5%
Taylor expanded in x around inf 42.1%
Taylor expanded in y around 0 42.2%
if -3.7e12 < x < 3.09999999999999992e49Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 75.8%
Applied egg-rr75.8%
Final simplification61.2%
(FPCore (x y) :precision binary64 (if (<= y -6.1e-147) 1.0 (if (<= y 7.2e-154) (* x x) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -6.1e-147) {
tmp = 1.0;
} else if (y <= 7.2e-154) {
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 (y <= (-6.1d-147)) then
tmp = 1.0d0
else if (y <= 7.2d-154) 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 (y <= -6.1e-147) {
tmp = 1.0;
} else if (y <= 7.2e-154) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.1e-147: tmp = 1.0 elif y <= 7.2e-154: tmp = x * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6.1e-147) tmp = 1.0; elseif (y <= 7.2e-154) tmp = Float64(x * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.1e-147) tmp = 1.0; elseif (y <= 7.2e-154) tmp = x * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.1e-147], 1.0, If[LessEqual[y, 7.2e-154], N[(x * x), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.1 \cdot 10^{-147}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-154}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6.1000000000000005e-147 or 7.2000000000000006e-154 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 64.6%
Applied egg-rr64.6%
if -6.1000000000000005e-147 < y < 7.2000000000000006e-154Initial program 100.0%
add-log-exp48.6%
*-un-lft-identity48.6%
log-prod48.6%
metadata-eval48.6%
add-log-exp100.0%
add-sqr-sqrt47.3%
fabs-sqr47.3%
add-sqr-sqrt15.7%
fabs-sqr15.7%
add-sqr-sqrt16.0%
add-sqr-sqrt40.0%
Applied egg-rr40.0%
Taylor expanded in x around inf 39.8%
Applied egg-rr35.8%
(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 0 51.5%
Applied egg-rr51.5%
herbie shell --seed 2024145
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))