
(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 (<= y -5.6e+21)
1.0
(if (<= y -2.4e-213)
(/ x y)
(if (<= y 2.7e-237) (/ (- x) y) (if (<= y 3e-86) (/ x y) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -5.6e+21) {
tmp = 1.0;
} else if (y <= -2.4e-213) {
tmp = x / y;
} else if (y <= 2.7e-237) {
tmp = -x / y;
} else if (y <= 3e-86) {
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 <= (-5.6d+21)) then
tmp = 1.0d0
else if (y <= (-2.4d-213)) then
tmp = x / y
else if (y <= 2.7d-237) then
tmp = -x / y
else if (y <= 3d-86) 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 <= -5.6e+21) {
tmp = 1.0;
} else if (y <= -2.4e-213) {
tmp = x / y;
} else if (y <= 2.7e-237) {
tmp = -x / y;
} else if (y <= 3e-86) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.6e+21: tmp = 1.0 elif y <= -2.4e-213: tmp = x / y elif y <= 2.7e-237: tmp = -x / y elif y <= 3e-86: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -5.6e+21) tmp = 1.0; elseif (y <= -2.4e-213) tmp = Float64(x / y); elseif (y <= 2.7e-237) tmp = Float64(Float64(-x) / y); elseif (y <= 3e-86) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5.6e+21) tmp = 1.0; elseif (y <= -2.4e-213) tmp = x / y; elseif (y <= 2.7e-237) tmp = -x / y; elseif (y <= 3e-86) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.6e+21], 1.0, If[LessEqual[y, -2.4e-213], N[(x / y), $MachinePrecision], If[LessEqual[y, 2.7e-237], N[((-x) / y), $MachinePrecision], If[LessEqual[y, 3e-86], N[(x / y), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.6 \cdot 10^{+21}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -2.4 \cdot 10^{-213}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-237}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-86}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.6e21 or 3.0000000000000001e-86 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
sub-neg100.0%
fabs-sub100.0%
*-inverses100.0%
div-sub100.0%
add-sqr-sqrt90.0%
fabs-sqr90.0%
add-sqr-sqrt90.3%
div-sub90.3%
*-inverses90.3%
Applied egg-rr90.3%
Taylor expanded in x around 0 72.0%
if -5.6e21 < y < -2.39999999999999996e-213 or 2.69999999999999984e-237 < y < 3.0000000000000001e-86Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
sub-neg100.0%
metadata-eval100.0%
rem-square-sqrt48.4%
fabs-sqr48.4%
rem-square-sqrt49.2%
Simplified49.2%
Taylor expanded in x around inf 49.5%
if -2.39999999999999996e-213 < y < 2.69999999999999984e-237Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
sub-neg100.0%
fabs-sub100.0%
*-inverses100.0%
div-sub100.0%
add-sqr-sqrt66.5%
fabs-sqr66.5%
add-sqr-sqrt66.8%
div-sub66.7%
*-inverses66.7%
Applied egg-rr66.7%
Taylor expanded in x around inf 62.1%
mul-1-neg62.1%
distribute-frac-neg62.1%
Simplified62.1%
(FPCore (x y) :precision binary64 (if (<= y -1.76e+25) 1.0 (if (<= y 3e-88) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.76e+25) {
tmp = 1.0;
} else if (y <= 3e-88) {
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 <= (-1.76d+25)) then
tmp = 1.0d0
else if (y <= 3d-88) 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 <= -1.76e+25) {
tmp = 1.0;
} else if (y <= 3e-88) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.76e+25: tmp = 1.0 elif y <= 3e-88: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.76e+25) tmp = 1.0; elseif (y <= 3e-88) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.76e+25) tmp = 1.0; elseif (y <= 3e-88) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.76e+25], 1.0, If[LessEqual[y, 3e-88], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.76 \cdot 10^{+25}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-88}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.76000000000000001e25 or 2.9999999999999999e-88 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
sub-neg100.0%
fabs-sub100.0%
*-inverses100.0%
div-sub100.0%
add-sqr-sqrt90.0%
fabs-sqr90.0%
add-sqr-sqrt90.3%
div-sub90.3%
*-inverses90.3%
Applied egg-rr90.3%
Taylor expanded in x around 0 72.0%
if -1.76000000000000001e25 < y < 2.9999999999999999e-88Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
sub-neg100.0%
metadata-eval100.0%
rem-square-sqrt43.2%
fabs-sqr43.2%
rem-square-sqrt43.8%
Simplified43.8%
Taylor expanded in x around inf 44.1%
(FPCore (x y) :precision binary64 (if (<= x -1.4e+214) (/ x y) (- 1.0 (/ x y))))
double code(double x, double y) {
double tmp;
if (x <= -1.4e+214) {
tmp = x / y;
} else {
tmp = 1.0 - (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.4d+214)) then
tmp = x / y
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.4e+214) {
tmp = x / y;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.4e+214: tmp = x / y else: tmp = 1.0 - (x / y) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.4e+214) tmp = Float64(x / y); else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.4e+214) tmp = x / y; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.4e+214], N[(x / y), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+214}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if x < -1.3999999999999999e214Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
sub-neg100.0%
metadata-eval100.0%
rem-square-sqrt63.4%
fabs-sqr63.4%
rem-square-sqrt63.8%
Simplified63.8%
Taylor expanded in x around inf 64.0%
if -1.3999999999999999e214 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
sub-neg100.0%
fabs-sub100.0%
*-inverses100.0%
div-sub100.0%
add-sqr-sqrt78.9%
fabs-sqr78.9%
add-sqr-sqrt79.2%
div-sub79.2%
*-inverses79.2%
Applied egg-rr79.2%
(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%
metadata-eval100.0%
sub-neg100.0%
fabs-sub100.0%
*-inverses100.0%
div-sub100.0%
add-sqr-sqrt75.2%
fabs-sqr75.2%
add-sqr-sqrt75.5%
div-sub75.5%
*-inverses75.5%
Applied egg-rr75.5%
Taylor expanded in x around 0 48.4%
herbie shell --seed 2024144
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))