
(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%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.32e-15) 1.0 (if (<= y 5.6e+83) (fabs (/ x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.32e-15) {
tmp = 1.0;
} else if (y <= 5.6e+83) {
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 <= (-1.32d-15)) then
tmp = 1.0d0
else if (y <= 5.6d+83) 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 <= -1.32e-15) {
tmp = 1.0;
} else if (y <= 5.6e+83) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.32e-15: tmp = 1.0 elif y <= 5.6e+83: tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.32e-15) tmp = 1.0; elseif (y <= 5.6e+83) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.32e-15) tmp = 1.0; elseif (y <= 5.6e+83) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.32e-15], 1.0, If[LessEqual[y, 5.6e+83], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.32 \cdot 10^{-15}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{+83}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.31999999999999995e-15 or 5.6000000000000001e83 < y Initial program 99.9%
Taylor expanded in x around -inf 99.9%
fabs-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
fabs-div99.9%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in x around 0 78.9%
if -1.31999999999999995e-15 < y < 5.6000000000000001e83Initial 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.8%
associate-*r/78.8%
neg-mul-178.8%
Simplified78.8%
Final simplification78.8%
(FPCore (x y) :precision binary64 (if (<= y -1.7e-64) 1.0 (if (<= y 1.26e-107) (+ (/ x y) -1.0) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.7e-64) {
tmp = 1.0;
} else if (y <= 1.26e-107) {
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 <= (-1.7d-64)) then
tmp = 1.0d0
else if (y <= 1.26d-107) 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 <= -1.7e-64) {
tmp = 1.0;
} else if (y <= 1.26e-107) {
tmp = (x / y) + -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.7e-64: tmp = 1.0 elif y <= 1.26e-107: tmp = (x / y) + -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.7e-64) tmp = 1.0; elseif (y <= 1.26e-107) 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 <= -1.7e-64) tmp = 1.0; elseif (y <= 1.26e-107) tmp = (x / y) + -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.7e-64], 1.0, If[LessEqual[y, 1.26e-107], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-64}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.26 \cdot 10^{-107}:\\
\;\;\;\;\frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.70000000000000006e-64 or 1.2599999999999999e-107 < 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 65.4%
if -1.70000000000000006e-64 < y < 1.2599999999999999e-107Initial 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-sqrt48.0%
fabs-sqr48.0%
rem-square-sqrt48.5%
div-sub48.5%
sub-neg48.5%
*-inverses48.5%
metadata-eval48.5%
+-commutative48.5%
Simplified48.5%
Final simplification58.0%
(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%
div-inv99.7%
add-sqr-sqrt48.0%
fabs-sqr48.0%
add-sqr-sqrt48.8%
*-commutative48.8%
add-sqr-sqrt16.7%
fabs-sqr16.7%
add-sqr-sqrt31.6%
Applied egg-rr31.6%
Taylor expanded in y around 0 32.0%
Final simplification32.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%
div-inv99.7%
add-sqr-sqrt48.0%
fabs-sqr48.0%
add-sqr-sqrt48.8%
*-commutative48.8%
add-sqr-sqrt16.7%
fabs-sqr16.7%
add-sqr-sqrt31.6%
Applied egg-rr31.6%
Taylor expanded in y around inf 1.2%
Final simplification1.2%
herbie shell --seed 2024071
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))