
(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 -7.8e+64) 1.0 (if (<= y 2.45e-141) (fabs (/ x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -7.8e+64) {
tmp = 1.0;
} else if (y <= 2.45e-141) {
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 <= (-7.8d+64)) then
tmp = 1.0d0
else if (y <= 2.45d-141) 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 <= -7.8e+64) {
tmp = 1.0;
} else if (y <= 2.45e-141) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.8e+64: tmp = 1.0 elif y <= 2.45e-141: tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -7.8e+64) tmp = 1.0; elseif (y <= 2.45e-141) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.8e+64) tmp = 1.0; elseif (y <= 2.45e-141) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.8e+64], 1.0, If[LessEqual[y, 2.45e-141], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+64}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{-141}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -7.7999999999999996e64 or 2.45000000000000003e-141 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
Applied egg-rr77.2%
*-inverses77.2%
Simplified77.2%
if -7.7999999999999996e64 < y < 2.45000000000000003e-141Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 81.7%
(FPCore (x y)
:precision binary64
(if (<= y -1260000000000.0)
1.0
(if (<= y -2.7e-236)
(* (+ x -1.0) (+ x -1.0))
(if (<= y 2.6e-143) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1260000000000.0) {
tmp = 1.0;
} else if (y <= -2.7e-236) {
tmp = (x + -1.0) * (x + -1.0);
} else if (y <= 2.6e-143) {
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 <= (-1260000000000.0d0)) then
tmp = 1.0d0
else if (y <= (-2.7d-236)) then
tmp = (x + (-1.0d0)) * (x + (-1.0d0))
else if (y <= 2.6d-143) 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 <= -1260000000000.0) {
tmp = 1.0;
} else if (y <= -2.7e-236) {
tmp = (x + -1.0) * (x + -1.0);
} else if (y <= 2.6e-143) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1260000000000.0: tmp = 1.0 elif y <= -2.7e-236: tmp = (x + -1.0) * (x + -1.0) elif y <= 2.6e-143: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1260000000000.0) tmp = 1.0; elseif (y <= -2.7e-236) tmp = Float64(Float64(x + -1.0) * Float64(x + -1.0)); elseif (y <= 2.6e-143) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1260000000000.0) tmp = 1.0; elseif (y <= -2.7e-236) tmp = (x + -1.0) * (x + -1.0); elseif (y <= 2.6e-143) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1260000000000.0], 1.0, If[LessEqual[y, -2.7e-236], N[(N[(x + -1.0), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.6e-143], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1260000000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{-236}:\\
\;\;\;\;\left(x + -1\right) \cdot \left(x + -1\right)\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-143}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.26e12 or 2.59999999999999987e-143 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
Applied egg-rr71.5%
*-inverses71.5%
Simplified71.5%
if -1.26e12 < y < -2.7e-236Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
clear-num99.7%
inv-pow99.7%
Applied egg-rr99.7%
Applied egg-rr46.6%
if -2.7e-236 < y < 2.59999999999999987e-143Initial 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-sqrt57.8%
fabs-sqr57.8%
add-sqr-sqrt58.1%
associate-*l/58.2%
*-un-lft-identity58.2%
sub-div58.2%
frac-sub31.1%
associate-/r*48.1%
distribute-rgt-out--48.1%
Applied egg-rr48.1%
Taylor expanded in y around 0 58.2%
(FPCore (x y) :precision binary64 (if (<= y -7.2e-20) 1.0 (if (<= y 8.5e-143) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -7.2e-20) {
tmp = 1.0;
} else if (y <= 8.5e-143) {
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 <= (-7.2d-20)) then
tmp = 1.0d0
else if (y <= 8.5d-143) 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 <= -7.2e-20) {
tmp = 1.0;
} else if (y <= 8.5e-143) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.2e-20: tmp = 1.0 elif y <= 8.5e-143: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -7.2e-20) tmp = 1.0; elseif (y <= 8.5e-143) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.2e-20) tmp = 1.0; elseif (y <= 8.5e-143) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.2e-20], 1.0, If[LessEqual[y, 8.5e-143], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-20}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-143}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -7.19999999999999948e-20 or 8.50000000000000072e-143 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
Applied egg-rr69.3%
*-inverses69.3%
Simplified69.3%
if -7.19999999999999948e-20 < y < 8.50000000000000072e-143Initial 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.7%
add-sqr-sqrt45.4%
fabs-sqr45.4%
add-sqr-sqrt45.9%
associate-*l/46.0%
*-un-lft-identity46.0%
sub-div46.0%
frac-sub28.6%
associate-/r*40.6%
distribute-rgt-out--40.6%
Applied egg-rr40.6%
Taylor expanded in y around 0 46.5%
(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%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
Applied egg-rr50.4%
*-inverses50.4%
Simplified50.4%
herbie shell --seed 2024177
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))