
(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 -3700000.0) (not (<= x 2.8e+18))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -3700000.0) || !(x <= 2.8e+18)) {
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 <= (-3700000.0d0)) .or. (.not. (x <= 2.8d+18))) 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 <= -3700000.0) || !(x <= 2.8e+18)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3700000.0) or not (x <= 2.8e+18): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -3700000.0) || !(x <= 2.8e+18)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3700000.0) || ~((x <= 2.8e+18))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3700000.0], N[Not[LessEqual[x, 2.8e+18]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3700000 \lor \neg \left(x \leq 2.8 \cdot 10^{+18}\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.7e6 or 2.8e18 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 78.9%
if -3.7e6 < x < 2.8e18Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 78.3%
Applied egg-rr78.3%
Final simplification78.6%
(FPCore (x y) :precision binary64 (if (or (<= x -6.5e+37) (not (<= x 2e+186))) (/ x y) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -6.5e+37) || !(x <= 2e+186)) {
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 <= (-6.5d+37)) .or. (.not. (x <= 2d+186))) 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 <= -6.5e+37) || !(x <= 2e+186)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -6.5e+37) or not (x <= 2e+186): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -6.5e+37) || !(x <= 2e+186)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -6.5e+37) || ~((x <= 2e+186))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -6.5e+37], N[Not[LessEqual[x, 2e+186]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+37} \lor \neg \left(x \leq 2 \cdot 10^{+186}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -6.4999999999999998e37 or 1.99999999999999996e186 < x Initial program 99.9%
div-inv99.7%
add-sqr-sqrt41.3%
fabs-sqr41.3%
add-sqr-sqrt41.7%
*-commutative41.7%
add-sqr-sqrt22.1%
fabs-sqr22.1%
add-sqr-sqrt45.5%
Applied egg-rr45.5%
Taylor expanded in x around inf 45.9%
Taylor expanded in y around 0 46.0%
if -6.4999999999999998e37 < x < 1.99999999999999996e186Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 69.0%
Applied egg-rr69.0%
Final simplification61.6%
(FPCore (x y) :precision binary64 (if (<= x 5.6e+160) 1.0 (* x x)))
double code(double x, double y) {
double tmp;
if (x <= 5.6e+160) {
tmp = 1.0;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 5.6d+160) then
tmp = 1.0d0
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 5.6e+160) {
tmp = 1.0;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 5.6e+160: tmp = 1.0 else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= 5.6e+160) tmp = 1.0; else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 5.6e+160) tmp = 1.0; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 5.6e+160], 1.0, N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.6 \cdot 10^{+160}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 5.5999999999999999e160Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 58.9%
Applied egg-rr58.9%
if 5.5999999999999999e160 < x Initial program 100.0%
add-log-exp52.8%
*-un-lft-identity52.8%
log-prod52.8%
metadata-eval52.8%
add-log-exp100.0%
add-sqr-sqrt96.7%
fabs-sqr96.7%
add-sqr-sqrt52.7%
fabs-sqr52.7%
add-sqr-sqrt53.1%
add-sqr-sqrt53.3%
Applied egg-rr53.3%
Taylor expanded in x around inf 53.6%
Applied egg-rr41.4%
(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 53.1%
Applied egg-rr53.1%
herbie shell --seed 2024110
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))