
(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 3 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%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= (/ (fabs (- x y)) (fabs y)) 2.0) (fabs 1.0) (fabs (/ x y))))
double code(double x, double y) {
double tmp;
if ((fabs((x - y)) / fabs(y)) <= 2.0) {
tmp = fabs(1.0);
} else {
tmp = fabs((x / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((abs((x - y)) / abs(y)) <= 2.0d0) then
tmp = abs(1.0d0)
else
tmp = abs((x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.abs((x - y)) / Math.abs(y)) <= 2.0) {
tmp = Math.abs(1.0);
} else {
tmp = Math.abs((x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if (math.fabs((x - y)) / math.fabs(y)) <= 2.0: tmp = math.fabs(1.0) else: tmp = math.fabs((x / y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(abs(Float64(x - y)) / abs(y)) <= 2.0) tmp = abs(1.0); else tmp = abs(Float64(x / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((abs((x - y)) / abs(y)) <= 2.0) tmp = abs(1.0); else tmp = abs((x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision], 2.0], N[Abs[1.0], $MachinePrecision], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left|x - y\right|}{\left|y\right|} \leq 2:\\
\;\;\;\;\left|1\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\end{array}
\end{array}
if (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 2Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites98.8%
if 2 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
lower-neg.f6497.6
Applied rewrites97.6%
Applied rewrites97.6%
(FPCore (x y) :precision binary64 (fabs 1.0))
double code(double x, double y) {
return fabs(1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs(1.0d0)
end function
public static double code(double x, double y) {
return Math.abs(1.0);
}
def code(x, y): return math.fabs(1.0)
function code(x, y) return abs(1.0) end
function tmp = code(x, y) tmp = abs(1.0); end
code[x_, y_] := N[Abs[1.0], $MachinePrecision]
\begin{array}{l}
\\
\left|1\right|
\end{array}
Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites56.0%
herbie shell --seed 2024219
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))