
(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 5 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 -7.2e-85) (not (<= x 200000000.0))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -7.2e-85) || !(x <= 200000000.0)) {
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 <= (-7.2d-85)) .or. (.not. (x <= 200000000.0d0))) 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 <= -7.2e-85) || !(x <= 200000000.0)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -7.2e-85) or not (x <= 200000000.0): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -7.2e-85) || !(x <= 200000000.0)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -7.2e-85) || ~((x <= 200000000.0))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -7.2e-85], N[Not[LessEqual[x, 200000000.0]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-85} \lor \neg \left(x \leq 200000000\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -7.1999999999999996e-85 or 2e8 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 75.9%
if -7.1999999999999996e-85 < x < 2e8Initial program 99.9%
Taylor expanded in x around -inf 99.9%
Simplified100.0%
Taylor expanded in x around 0 81.1%
Applied egg-rr81.1%
Final simplification78.3%
(FPCore (x y) :precision binary64 (if (or (<= x -3.9e+121) (not (<= x 1.02e+179))) (/ x y) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -3.9e+121) || !(x <= 1.02e+179)) {
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 <= (-3.9d+121)) .or. (.not. (x <= 1.02d+179))) 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 <= -3.9e+121) || !(x <= 1.02e+179)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.9e+121) or not (x <= 1.02e+179): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.9e+121) || !(x <= 1.02e+179)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3.9e+121) || ~((x <= 1.02e+179))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.9e+121], N[Not[LessEqual[x, 1.02e+179]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+121} \lor \neg \left(x \leq 1.02 \cdot 10^{+179}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.89999999999999984e121 or 1.0199999999999999e179 < x Initial program 100.0%
div-inv99.8%
add-sqr-sqrt46.2%
fabs-sqr46.2%
add-sqr-sqrt46.5%
*-commutative46.5%
add-sqr-sqrt27.5%
fabs-sqr27.5%
add-sqr-sqrt52.3%
Applied egg-rr52.3%
Taylor expanded in x around inf 52.3%
Taylor expanded in y around 0 52.5%
if -3.89999999999999984e121 < x < 1.0199999999999999e179Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 66.6%
Applied egg-rr66.6%
Final simplification62.8%
(FPCore (x y) :precision binary64 (if (<= x -1.85e+121) (/ (- x y) y) (if (<= x 1.02e+179) 1.0 (/ x y))))
double code(double x, double y) {
double tmp;
if (x <= -1.85e+121) {
tmp = (x - y) / y;
} else if (x <= 1.02e+179) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.85d+121)) then
tmp = (x - y) / y
else if (x <= 1.02d+179) then
tmp = 1.0d0
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.85e+121) {
tmp = (x - y) / y;
} else if (x <= 1.02e+179) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.85e+121: tmp = (x - y) / y elif x <= 1.02e+179: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.85e+121) tmp = Float64(Float64(x - y) / y); elseif (x <= 1.02e+179) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.85e+121) tmp = (x - y) / y; elseif (x <= 1.02e+179) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.85e+121], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[x, 1.02e+179], 1.0, N[(x / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{+121}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{elif}\;x \leq 1.02 \cdot 10^{+179}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -1.85000000000000006e121Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
*-inverses100.0%
sub-neg100.0%
sub-div100.0%
*-un-lft-identity100.0%
associate-*l/99.8%
add-sqr-sqrt45.7%
fabs-sqr45.7%
add-sqr-sqrt46.2%
associate-*l/46.3%
*-un-lft-identity46.3%
Applied egg-rr46.3%
if -1.85000000000000006e121 < x < 1.0199999999999999e179Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 66.6%
Applied egg-rr66.6%
if 1.0199999999999999e179 < x Initial program 100.0%
div-inv99.7%
add-sqr-sqrt93.4%
fabs-sqr93.4%
add-sqr-sqrt93.5%
*-commutative93.5%
add-sqr-sqrt59.0%
fabs-sqr59.0%
add-sqr-sqrt59.4%
Applied egg-rr59.4%
Taylor expanded in x around inf 59.8%
Taylor expanded in y around 0 60.0%
(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 52.1%
Applied egg-rr52.1%
herbie shell --seed 2024170
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))