
(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 6 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.2e-77) 1.0 (if (<= y 1.06e+34) (fabs (/ x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.2e-77) {
tmp = 1.0;
} else if (y <= 1.06e+34) {
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.2d-77)) then
tmp = 1.0d0
else if (y <= 1.06d+34) 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.2e-77) {
tmp = 1.0;
} else if (y <= 1.06e+34) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.2e-77: tmp = 1.0 elif y <= 1.06e+34: tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.2e-77) tmp = 1.0; elseif (y <= 1.06e+34) 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.2e-77) tmp = 1.0; elseif (y <= 1.06e+34) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.2e-77], 1.0, If[LessEqual[y, 1.06e+34], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-77}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{+34}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.2e-77 or 1.06000000000000005e34 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 80.9%
Applied egg-rr80.9%
if -3.2e-77 < y < 1.06000000000000005e34Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 78.7%
(FPCore (x y)
:precision binary64
(if (<= y -4.5e-123)
1.0
(if (<= y 3.1e-301)
(/ x y)
(if (<= y 1.06e+34) (* (+ x -1.0) (+ x -1.0)) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -4.5e-123) {
tmp = 1.0;
} else if (y <= 3.1e-301) {
tmp = x / y;
} else if (y <= 1.06e+34) {
tmp = (x + -1.0) * (x + -1.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 <= (-4.5d-123)) then
tmp = 1.0d0
else if (y <= 3.1d-301) then
tmp = x / y
else if (y <= 1.06d+34) then
tmp = (x + (-1.0d0)) * (x + (-1.0d0))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.5e-123) {
tmp = 1.0;
} else if (y <= 3.1e-301) {
tmp = x / y;
} else if (y <= 1.06e+34) {
tmp = (x + -1.0) * (x + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.5e-123: tmp = 1.0 elif y <= 3.1e-301: tmp = x / y elif y <= 1.06e+34: tmp = (x + -1.0) * (x + -1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.5e-123) tmp = 1.0; elseif (y <= 3.1e-301) tmp = Float64(x / y); elseif (y <= 1.06e+34) tmp = Float64(Float64(x + -1.0) * Float64(x + -1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.5e-123) tmp = 1.0; elseif (y <= 3.1e-301) tmp = x / y; elseif (y <= 1.06e+34) tmp = (x + -1.0) * (x + -1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.5e-123], 1.0, If[LessEqual[y, 3.1e-301], N[(x / y), $MachinePrecision], If[LessEqual[y, 1.06e+34], N[(N[(x + -1.0), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-123}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-301}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{+34}:\\
\;\;\;\;\left(x + -1\right) \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.49999999999999993e-123 or 1.06000000000000005e34 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 78.0%
Applied egg-rr78.0%
if -4.49999999999999993e-123 < y < 3.10000000000000014e-301Initial program 100.0%
div-inv99.7%
add-sqr-sqrt47.5%
fabs-sqr47.5%
add-sqr-sqrt47.9%
*-commutative47.9%
add-sqr-sqrt2.3%
fabs-sqr2.3%
add-sqr-sqrt52.4%
Applied egg-rr52.4%
Taylor expanded in x around inf 52.5%
Taylor expanded in y around 0 52.6%
if 3.10000000000000014e-301 < y < 1.06000000000000005e34Initial program 100.0%
add-sqr-sqrt30.6%
fabs-sqr30.6%
add-sqr-sqrt30.6%
fabs-sqr30.6%
add-sqr-sqrt30.6%
add-sqr-sqrt31.4%
div-sub31.4%
Applied egg-rr31.4%
Taylor expanded in y around 0 31.4%
Applied egg-rr48.8%
+-commutative48.8%
+-commutative48.8%
Simplified48.8%
(FPCore (x y) :precision binary64 (if (or (<= x -4.5e+157) (not (<= x 6.2e+149))) (* x x) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -4.5e+157) || !(x <= 6.2e+149)) {
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 <= (-4.5d+157)) .or. (.not. (x <= 6.2d+149))) 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 <= -4.5e+157) || !(x <= 6.2e+149)) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.5e+157) or not (x <= 6.2e+149): tmp = x * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.5e+157) || !(x <= 6.2e+149)) tmp = Float64(x * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4.5e+157) || ~((x <= 6.2e+149))) tmp = x * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.5e+157], N[Not[LessEqual[x, 6.2e+149]], $MachinePrecision]], N[(x * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+157} \lor \neg \left(x \leq 6.2 \cdot 10^{+149}\right):\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.49999999999999985e157 or 6.19999999999999974e149 < x Initial program 100.0%
add-log-exp51.6%
*-un-lft-identity51.6%
log-prod51.6%
metadata-eval51.6%
add-log-exp100.0%
add-sqr-sqrt48.7%
fabs-sqr48.7%
add-sqr-sqrt16.9%
fabs-sqr16.9%
add-sqr-sqrt17.2%
add-sqr-sqrt36.5%
Applied egg-rr36.5%
Taylor expanded in x around inf 36.8%
Applied egg-rr43.4%
if -4.49999999999999985e157 < x < 6.19999999999999974e149Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 61.5%
Applied egg-rr61.5%
Final simplification58.2%
(FPCore (x y) :precision binary64 (if (<= y -7.2e-126) 1.0 (if (<= y 3.1e-179) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -7.2e-126) {
tmp = 1.0;
} else if (y <= 3.1e-179) {
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 <= (-7.2d-126)) then
tmp = 1.0d0
else if (y <= 3.1d-179) 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 <= -7.2e-126) {
tmp = 1.0;
} else if (y <= 3.1e-179) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.2e-126: tmp = 1.0 elif y <= 3.1e-179: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -7.2e-126) tmp = 1.0; elseif (y <= 3.1e-179) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.2e-126) tmp = 1.0; elseif (y <= 3.1e-179) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.2e-126], 1.0, If[LessEqual[y, 3.1e-179], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-126}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-179}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -7.1999999999999999e-126 or 3.1000000000000002e-179 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 67.9%
Applied egg-rr67.9%
if -7.1999999999999999e-126 < y < 3.1000000000000002e-179Initial program 100.0%
div-inv99.7%
add-sqr-sqrt46.2%
fabs-sqr46.2%
add-sqr-sqrt46.7%
*-commutative46.7%
add-sqr-sqrt18.4%
fabs-sqr18.4%
add-sqr-sqrt49.4%
Applied egg-rr49.4%
Taylor expanded in x around inf 49.6%
Taylor expanded in y around 0 49.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 52.2%
Applied egg-rr52.2%
herbie shell --seed 2024163
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))