
(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 -2.9e-11) 1.0 (if (<= y 1.15e-71) (fabs (/ x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.9e-11) {
tmp = 1.0;
} else if (y <= 1.15e-71) {
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 <= (-2.9d-11)) then
tmp = 1.0d0
else if (y <= 1.15d-71) 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 <= -2.9e-11) {
tmp = 1.0;
} else if (y <= 1.15e-71) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.9e-11: tmp = 1.0 elif y <= 1.15e-71: tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.9e-11) tmp = 1.0; elseif (y <= 1.15e-71) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.9e-11) tmp = 1.0; elseif (y <= 1.15e-71) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.9e-11], 1.0, If[LessEqual[y, 1.15e-71], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-11}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-71}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.9e-11 or 1.1499999999999999e-71 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 25.4%
Applied egg-rr38.4%
*-inverses78.4%
Simplified78.4%
if -2.9e-11 < y < 1.1499999999999999e-71Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 84.5%
(FPCore (x y)
:precision binary64
(if (<= y -1.5e-66)
1.0
(if (<= y 1.85e-212)
(/ x y)
(if (<= y 1.15e+58) (+ 1.0 (* x (+ x -2.0))) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.5e-66) {
tmp = 1.0;
} else if (y <= 1.85e-212) {
tmp = x / y;
} else if (y <= 1.15e+58) {
tmp = 1.0 + (x * (x + -2.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.5d-66)) then
tmp = 1.0d0
else if (y <= 1.85d-212) then
tmp = x / y
else if (y <= 1.15d+58) then
tmp = 1.0d0 + (x * (x + (-2.0d0)))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.5e-66) {
tmp = 1.0;
} else if (y <= 1.85e-212) {
tmp = x / y;
} else if (y <= 1.15e+58) {
tmp = 1.0 + (x * (x + -2.0));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.5e-66: tmp = 1.0 elif y <= 1.85e-212: tmp = x / y elif y <= 1.15e+58: tmp = 1.0 + (x * (x + -2.0)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.5e-66) tmp = 1.0; elseif (y <= 1.85e-212) tmp = Float64(x / y); elseif (y <= 1.15e+58) tmp = Float64(1.0 + Float64(x * Float64(x + -2.0))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.5e-66) tmp = 1.0; elseif (y <= 1.85e-212) tmp = x / y; elseif (y <= 1.15e+58) tmp = 1.0 + (x * (x + -2.0)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.5e-66], 1.0, If[LessEqual[y, 1.85e-212], N[(x / y), $MachinePrecision], If[LessEqual[y, 1.15e+58], N[(1.0 + N[(x * N[(x + -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-66}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{-212}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+58}:\\
\;\;\;\;1 + x \cdot \left(x + -2\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.5000000000000001e-66 or 1.15000000000000001e58 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 25.6%
Applied egg-rr40.9%
*-inverses78.1%
Simplified78.1%
if -1.5000000000000001e-66 < y < 1.84999999999999995e-212Initial program 100.0%
div-inv99.7%
add-sqr-sqrt44.1%
fabs-sqr44.1%
add-sqr-sqrt44.6%
*-commutative44.6%
add-sqr-sqrt15.9%
fabs-sqr15.9%
add-sqr-sqrt58.9%
Applied egg-rr58.9%
Taylor expanded in x around inf 59.2%
Taylor expanded in y around 0 59.3%
if 1.84999999999999995e-212 < y < 1.15000000000000001e58Initial program 100.0%
add-sqr-sqrt29.1%
fabs-sqr29.1%
add-sqr-sqrt28.9%
fabs-sqr28.9%
add-sqr-sqrt29.1%
add-sqr-sqrt29.9%
div-sub29.9%
Applied egg-rr29.9%
Taylor expanded in y around 0 29.9%
Applied egg-rr51.3%
distribute-lft-in51.3%
*-commutative51.3%
neg-mul-151.3%
distribute-neg-in51.3%
metadata-eval51.3%
associate-+r+51.3%
+-commutative51.3%
neg-mul-151.3%
distribute-rgt-out51.3%
metadata-eval51.3%
associate-+l+51.3%
associate-+l+51.3%
metadata-eval51.3%
+-rgt-identity51.3%
Simplified51.3%
(FPCore (x y) :precision binary64 (if (<= y -2.8e-64) 1.0 (if (<= y 1.0885e-89) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.8e-64) {
tmp = 1.0;
} else if (y <= 1.0885e-89) {
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 <= (-2.8d-64)) then
tmp = 1.0d0
else if (y <= 1.0885d-89) 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 <= -2.8e-64) {
tmp = 1.0;
} else if (y <= 1.0885e-89) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.8e-64: tmp = 1.0 elif y <= 1.0885e-89: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.8e-64) tmp = 1.0; elseif (y <= 1.0885e-89) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.8e-64) tmp = 1.0; elseif (y <= 1.0885e-89) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.8e-64], 1.0, If[LessEqual[y, 1.0885e-89], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-64}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.0885 \cdot 10^{-89}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.80000000000000004e-64 or 1.0885e-89 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 30.7%
Applied egg-rr37.2%
*-inverses73.3%
Simplified73.3%
if -2.80000000000000004e-64 < y < 1.0885e-89Initial program 100.0%
div-inv99.8%
add-sqr-sqrt40.5%
fabs-sqr40.5%
add-sqr-sqrt41.0%
*-commutative41.0%
add-sqr-sqrt22.5%
fabs-sqr22.5%
add-sqr-sqrt50.3%
Applied egg-rr50.3%
Taylor expanded in x around inf 50.6%
Taylor expanded in y around 0 50.7%
(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%
Taylor expanded in x around inf 53.6%
Applied egg-rr26.3%
*-inverses50.6%
Simplified50.6%
herbie shell --seed 2024180
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))