
(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 -1.25e+30) (not (<= x 0.012))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -1.25e+30) || !(x <= 0.012)) {
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 <= (-1.25d+30)) .or. (.not. (x <= 0.012d0))) 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 <= -1.25e+30) || !(x <= 0.012)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.25e+30) or not (x <= 0.012): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.25e+30) || !(x <= 0.012)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.25e+30) || ~((x <= 0.012))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.25e+30], N[Not[LessEqual[x, 0.012]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+30} \lor \neg \left(x \leq 0.012\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.25e30 or 0.012 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 82.1%
if -1.25e30 < x < 0.012Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 24.3%
Applied egg-rr78.4%
*-inverses78.4%
Simplified78.4%
Final simplification80.2%
(FPCore (x y) :precision binary64 (if (or (<= x -2.75e+128) (not (<= x 1.3e+125))) (* x x) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -2.75e+128) || !(x <= 1.3e+125)) {
tmp = x * x;
} 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 <= (-2.75d+128)) .or. (.not. (x <= 1.3d+125))) then
tmp = x * x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.75e+128) || !(x <= 1.3e+125)) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.75e+128) or not (x <= 1.3e+125): tmp = x * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.75e+128) || !(x <= 1.3e+125)) tmp = Float64(x * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.75e+128) || ~((x <= 1.3e+125))) tmp = x * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.75e+128], N[Not[LessEqual[x, 1.3e+125]], $MachinePrecision]], N[(x * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+128} \lor \neg \left(x \leq 1.3 \cdot 10^{+125}\right):\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.7499999999999999e128 or 1.30000000000000002e125 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 91.2%
Applied egg-rr39.8%
if -2.7499999999999999e128 < x < 1.30000000000000002e125Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 37.1%
Applied egg-rr65.0%
*-inverses65.0%
Simplified65.0%
Final simplification57.9%
(FPCore (x y) :precision binary64 (if (<= x -2.75e+128) (* x x) (if (<= x 8e+63) 1.0 (/ x y))))
double code(double x, double y) {
double tmp;
if (x <= -2.75e+128) {
tmp = x * x;
} else if (x <= 8e+63) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.75d+128)) then
tmp = x * x
else if (x <= 8d+63) then
tmp = 1.0d0
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.75e+128) {
tmp = x * x;
} else if (x <= 8e+63) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.75e+128: tmp = x * x elif x <= 8e+63: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.75e+128) tmp = Float64(x * x); elseif (x <= 8e+63) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.75e+128) tmp = x * x; elseif (x <= 8e+63) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.75e+128], N[(x * x), $MachinePrecision], If[LessEqual[x, 8e+63], 1.0, N[(x / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+128}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 8 \cdot 10^{+63}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -2.7499999999999999e128Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 86.6%
Applied egg-rr49.6%
if -2.7499999999999999e128 < x < 8.00000000000000046e63Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 32.7%
Applied egg-rr69.5%
*-inverses69.5%
Simplified69.5%
if 8.00000000000000046e63 < x Initial program 100.0%
div-inv99.7%
add-sqr-sqrt90.2%
fabs-sqr90.2%
add-sqr-sqrt90.6%
*-commutative90.6%
add-sqr-sqrt53.5%
fabs-sqr53.5%
add-sqr-sqrt53.8%
Applied egg-rr53.8%
Taylor expanded in x around inf 54.8%
Taylor expanded in y around 0 54.9%
(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 52.3%
Applied egg-rr50.0%
*-inverses50.0%
Simplified50.0%
herbie shell --seed 2024132
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))