
(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 -3.7e+53) 1.0 (if (<= y 6.4e+83) (fabs (/ x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.7e+53) {
tmp = 1.0;
} else if (y <= 6.4e+83) {
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 <= (-3.7d+53)) then
tmp = 1.0d0
else if (y <= 6.4d+83) 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 <= -3.7e+53) {
tmp = 1.0;
} else if (y <= 6.4e+83) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.7e+53: tmp = 1.0 elif y <= 6.4e+83: tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.7e+53) tmp = 1.0; elseif (y <= 6.4e+83) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.7e+53) tmp = 1.0; elseif (y <= 6.4e+83) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.7e+53], 1.0, If[LessEqual[y, 6.4e+83], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{+53}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+83}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.7e53 or 6.3999999999999998e83 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 89.4%
Applied egg-rr89.4%
if -3.7e53 < y < 6.3999999999999998e83Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 72.2%
(FPCore (x y) :precision binary64 (if (<= x -1.32e+253) (* x x) (if (or (<= x -1.25e+145) (not (<= x 4.1e+105))) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.32e+253) {
tmp = x * x;
} else if ((x <= -1.25e+145) || !(x <= 4.1e+105)) {
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 <= (-1.32d+253)) then
tmp = x * x
else if ((x <= (-1.25d+145)) .or. (.not. (x <= 4.1d+105))) 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 <= -1.32e+253) {
tmp = x * x;
} else if ((x <= -1.25e+145) || !(x <= 4.1e+105)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.32e+253: tmp = x * x elif (x <= -1.25e+145) or not (x <= 4.1e+105): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.32e+253) tmp = Float64(x * x); elseif ((x <= -1.25e+145) || !(x <= 4.1e+105)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.32e+253) tmp = x * x; elseif ((x <= -1.25e+145) || ~((x <= 4.1e+105))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.32e+253], N[(x * x), $MachinePrecision], If[Or[LessEqual[x, -1.25e+145], N[Not[LessEqual[x, 4.1e+105]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.32 \cdot 10^{+253}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{+145} \lor \neg \left(x \leq 4.1 \cdot 10^{+105}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.32e253Initial program 100.0%
add-log-exp74.8%
*-un-lft-identity74.8%
log-prod74.8%
metadata-eval74.8%
add-log-exp100.0%
add-sqr-sqrt0.0%
fabs-sqr0.0%
add-sqr-sqrt0.0%
fabs-sqr0.0%
add-sqr-sqrt0.0%
add-sqr-sqrt33.4%
Applied egg-rr33.4%
Taylor expanded in x around inf 33.4%
Applied egg-rr74.8%
if -1.32e253 < x < -1.24999999999999992e145 or 4.1000000000000002e105 < x Initial program 99.9%
div-inv99.8%
add-sqr-sqrt69.0%
fabs-sqr69.0%
add-sqr-sqrt69.5%
*-commutative69.5%
add-sqr-sqrt42.7%
fabs-sqr42.7%
add-sqr-sqrt61.5%
Applied egg-rr61.5%
Taylor expanded in x around inf 62.3%
Taylor expanded in y around 0 62.3%
if -1.24999999999999992e145 < x < 4.1000000000000002e105Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 66.8%
Applied egg-rr66.8%
Final simplification66.4%
(FPCore (x y) :precision binary64 (if (or (<= x -2.9e+172) (not (<= x 6.5e+174))) (* x x) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -2.9e+172) || !(x <= 6.5e+174)) {
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.9d+172)) .or. (.not. (x <= 6.5d+174))) 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.9e+172) || !(x <= 6.5e+174)) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.9e+172) or not (x <= 6.5e+174): tmp = x * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.9e+172) || !(x <= 6.5e+174)) tmp = Float64(x * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.9e+172) || ~((x <= 6.5e+174))) tmp = x * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.9e+172], N[Not[LessEqual[x, 6.5e+174]], $MachinePrecision]], N[(x * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+172} \lor \neg \left(x \leq 6.5 \cdot 10^{+174}\right):\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.8999999999999999e172 or 6.5000000000000001e174 < x Initial program 99.9%
add-log-exp49.5%
*-un-lft-identity49.5%
log-prod49.5%
metadata-eval49.5%
add-log-exp99.9%
add-sqr-sqrt46.4%
fabs-sqr46.4%
add-sqr-sqrt30.8%
fabs-sqr30.8%
add-sqr-sqrt31.0%
add-sqr-sqrt58.0%
Applied egg-rr58.0%
Taylor expanded in x around inf 58.2%
Applied egg-rr45.2%
if -2.8999999999999999e172 < x < 6.5000000000000001e174Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 63.9%
Applied egg-rr63.9%
Final simplification60.6%
(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 54.0%
Applied egg-rr54.0%
herbie shell --seed 2024170
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))