
(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 (or (<= x -46000.0) (not (<= x 12500.0))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -46000.0) || !(x <= 12500.0)) {
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 ((x <= (-46000.0d0)) .or. (.not. (x <= 12500.0d0))) 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 ((x <= -46000.0) || !(x <= 12500.0)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -46000.0) or not (x <= 12500.0): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -46000.0) || !(x <= 12500.0)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -46000.0) || ~((x <= 12500.0))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -46000.0], N[Not[LessEqual[x, 12500.0]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -46000 \lor \neg \left(x \leq 12500\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -46000 or 12500 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 79.6%
if -46000 < x < 12500Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 84.4%
Applied egg-rr84.4%
Final simplification82.3%
(FPCore (x y) :precision binary64 (if (<= x -3.1e+81) (/ x y) (if (<= x 4e+21) 1.0 (+ (/ x y) -1.0))))
double code(double x, double y) {
double tmp;
if (x <= -3.1e+81) {
tmp = x / y;
} else if (x <= 4e+21) {
tmp = 1.0;
} else {
tmp = (x / y) + -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.1d+81)) then
tmp = x / y
else if (x <= 4d+21) then
tmp = 1.0d0
else
tmp = (x / y) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.1e+81) {
tmp = x / y;
} else if (x <= 4e+21) {
tmp = 1.0;
} else {
tmp = (x / y) + -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.1e+81: tmp = x / y elif x <= 4e+21: tmp = 1.0 else: tmp = (x / y) + -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.1e+81) tmp = Float64(x / y); elseif (x <= 4e+21) tmp = 1.0; else tmp = Float64(Float64(x / y) + -1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.1e+81) tmp = x / y; elseif (x <= 4e+21) tmp = 1.0; else tmp = (x / y) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.1e+81], N[(x / y), $MachinePrecision], If[LessEqual[x, 4e+21], 1.0, N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+81}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+21}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} + -1\\
\end{array}
\end{array}
if x < -3.1e81Initial program 100.0%
div-inv99.6%
add-sqr-sqrt9.2%
fabs-sqr9.2%
add-sqr-sqrt9.7%
*-commutative9.7%
add-sqr-sqrt0.2%
fabs-sqr0.2%
add-sqr-sqrt42.0%
Applied egg-rr42.0%
Taylor expanded in x around inf 42.4%
Taylor expanded in y around 0 42.6%
if -3.1e81 < x < 4e21Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 79.8%
Applied egg-rr79.8%
if 4e21 < x Initial program 99.9%
add-sqr-sqrt91.3%
fabs-sqr91.3%
add-sqr-sqrt46.5%
fabs-sqr46.5%
add-sqr-sqrt46.9%
add-sqr-sqrt47.4%
div-sub47.4%
Applied egg-rr47.4%
Taylor expanded in y around 0 47.4%
Final simplification67.4%
(FPCore (x y) :precision binary64 (if (or (<= x -8.6e+76) (not (<= x 1.26e+22))) (/ x y) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -8.6e+76) || !(x <= 1.26e+22)) {
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 ((x <= (-8.6d+76)) .or. (.not. (x <= 1.26d+22))) 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 ((x <= -8.6e+76) || !(x <= 1.26e+22)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -8.6e+76) or not (x <= 1.26e+22): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -8.6e+76) || !(x <= 1.26e+22)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -8.6e+76) || ~((x <= 1.26e+22))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -8.6e+76], N[Not[LessEqual[x, 1.26e+22]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{+76} \lor \neg \left(x \leq 1.26 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -8.59999999999999957e76 or 1.26e22 < x Initial program 99.9%
div-inv99.7%
add-sqr-sqrt52.9%
fabs-sqr52.9%
add-sqr-sqrt53.4%
*-commutative53.4%
add-sqr-sqrt25.0%
fabs-sqr25.0%
add-sqr-sqrt44.8%
Applied egg-rr44.8%
Taylor expanded in x around inf 43.4%
Taylor expanded in y around 0 43.5%
if -8.59999999999999957e76 < x < 1.26e22Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 79.8%
Applied egg-rr79.8%
Final simplification66.8%
(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 0 57.4%
Applied egg-rr57.4%
herbie shell --seed 2024186
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))