
(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 (- 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%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-div100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
(FPCore (x y)
:precision binary64
(if (<= y -8.5e-54)
1.0
(if (or (<= y 8.4e-77) (and (not (<= y 13000.0)) (<= y 6.2e+68)))
(fabs (/ x y))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= -8.5e-54) {
tmp = 1.0;
} else if ((y <= 8.4e-77) || (!(y <= 13000.0) && (y <= 6.2e+68))) {
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 (y <= (-8.5d-54)) then
tmp = 1.0d0
else if ((y <= 8.4d-77) .or. (.not. (y <= 13000.0d0)) .and. (y <= 6.2d+68)) 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 (y <= -8.5e-54) {
tmp = 1.0;
} else if ((y <= 8.4e-77) || (!(y <= 13000.0) && (y <= 6.2e+68))) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.5e-54: tmp = 1.0 elif (y <= 8.4e-77) or (not (y <= 13000.0) and (y <= 6.2e+68)): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -8.5e-54) tmp = 1.0; elseif ((y <= 8.4e-77) || (!(y <= 13000.0) && (y <= 6.2e+68))) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8.5e-54) tmp = 1.0; elseif ((y <= 8.4e-77) || (~((y <= 13000.0)) && (y <= 6.2e+68))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.5e-54], 1.0, If[Or[LessEqual[y, 8.4e-77], And[N[Not[LessEqual[y, 13000.0]], $MachinePrecision], LessEqual[y, 6.2e+68]]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{-54}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8.4 \cdot 10^{-77} \lor \neg \left(y \leq 13000\right) \land y \leq 6.2 \cdot 10^{+68}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -8.5e-54 or 8.40000000000000061e-77 < y < 13000 or 6.1999999999999997e68 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-div100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in x around 0 80.0%
if -8.5e-54 < y < 8.40000000000000061e-77 or 13000 < y < 6.1999999999999997e68Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-div100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in x around inf 78.2%
mul-1-neg78.2%
distribute-frac-neg278.2%
Simplified78.2%
Final simplification79.2%
(FPCore (x y) :precision binary64 (if (<= y -6e-61) 1.0 (if (<= y 1.8e-210) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -6e-61) {
tmp = 1.0;
} else if (y <= 1.8e-210) {
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 <= (-6d-61)) then
tmp = 1.0d0
else if (y <= 1.8d-210) 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 <= -6e-61) {
tmp = 1.0;
} else if (y <= 1.8e-210) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e-61: tmp = 1.0 elif y <= 1.8e-210: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6e-61) tmp = 1.0; elseif (y <= 1.8e-210) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6e-61) tmp = 1.0; elseif (y <= 1.8e-210) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e-61], 1.0, If[LessEqual[y, 1.8e-210], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-61}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-210}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6.00000000000000024e-61 or 1.7999999999999999e-210 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-div100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in x around 0 69.0%
if -6.00000000000000024e-61 < y < 1.7999999999999999e-210Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
fabs-div100.0%
rem-square-sqrt44.7%
fabs-sqr44.7%
rem-square-sqrt45.3%
div-sub45.3%
sub-neg45.3%
*-inverses45.3%
metadata-eval45.3%
+-commutative45.3%
Simplified45.3%
Taylor expanded in x around inf 46.1%
Final simplification62.8%
(FPCore (x y) :precision binary64 (/ x y))
double code(double x, double y) {
return x / y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / y
end function
public static double code(double x, double y) {
return x / y;
}
def code(x, y): return x / y
function code(x, y) return Float64(x / y) end
function tmp = code(x, y) tmp = x / y; end
code[x_, y_] := N[(x / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y}
\end{array}
Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
fabs-div100.0%
rem-square-sqrt19.8%
fabs-sqr19.8%
rem-square-sqrt20.9%
div-sub20.9%
sub-neg20.9%
*-inverses20.9%
metadata-eval20.9%
+-commutative20.9%
Simplified20.9%
Taylor expanded in x around inf 22.1%
(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%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
fabs-div100.0%
rem-square-sqrt19.8%
fabs-sqr19.8%
rem-square-sqrt20.9%
div-sub20.9%
sub-neg20.9%
*-inverses20.9%
metadata-eval20.9%
+-commutative20.9%
Simplified20.9%
Taylor expanded in x around 0 1.3%
herbie shell --seed 2024091
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))