
(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 (- 1.0 (/ x y))))
double code(double x, double y) {
return fabs((1.0 - (x / y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs((1.0d0 - (x / y)))
end function
public static double code(double x, double y) {
return Math.abs((1.0 - (x / y)));
}
def code(x, y): return math.fabs((1.0 - (x / y)))
function code(x, y) return abs(Float64(1.0 - Float64(x / y))) end
function tmp = code(x, y) tmp = abs((1.0 - (x / y))); end
code[x_, y_] := N[Abs[N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|1 - \frac{x}{y}\right|
\end{array}
Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-div100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x x) (* y y))))
(if (<= x -9.5e+76)
t_0
(if (<= x 7.5e+79)
(/ y (+ x y))
(if (<= x 1.18e+243) (+ (/ x y) -1.0) t_0)))))
double code(double x, double y) {
double t_0 = (x * x) / (y * y);
double tmp;
if (x <= -9.5e+76) {
tmp = t_0;
} else if (x <= 7.5e+79) {
tmp = y / (x + y);
} else if (x <= 1.18e+243) {
tmp = (x / y) + -1.0;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = (x * x) / (y * y)
if (x <= (-9.5d+76)) then
tmp = t_0
else if (x <= 7.5d+79) then
tmp = y / (x + y)
else if (x <= 1.18d+243) then
tmp = (x / y) + (-1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x * x) / (y * y);
double tmp;
if (x <= -9.5e+76) {
tmp = t_0;
} else if (x <= 7.5e+79) {
tmp = y / (x + y);
} else if (x <= 1.18e+243) {
tmp = (x / y) + -1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x * x) / (y * y) tmp = 0 if x <= -9.5e+76: tmp = t_0 elif x <= 7.5e+79: tmp = y / (x + y) elif x <= 1.18e+243: tmp = (x / y) + -1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x * x) / Float64(y * y)) tmp = 0.0 if (x <= -9.5e+76) tmp = t_0; elseif (x <= 7.5e+79) tmp = Float64(y / Float64(x + y)); elseif (x <= 1.18e+243) tmp = Float64(Float64(x / y) + -1.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x * x) / (y * y); tmp = 0.0; if (x <= -9.5e+76) tmp = t_0; elseif (x <= 7.5e+79) tmp = y / (x + y); elseif (x <= 1.18e+243) tmp = (x / y) + -1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9.5e+76], t$95$0, If[LessEqual[x, 7.5e+79], N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.18e+243], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot x}{y \cdot y}\\
\mathbf{if}\;x \leq -9.5 \cdot 10^{+76}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+79}:\\
\;\;\;\;\frac{y}{x + y}\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{+243}:\\
\;\;\;\;\frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -9.5000000000000003e76 or 1.1799999999999999e243 < x Initial program 100.0%
div-inv99.8%
add-sqr-sqrt38.8%
fabs-sqr38.8%
add-sqr-sqrt39.1%
*-commutative39.1%
add-sqr-sqrt15.0%
fabs-sqr15.0%
add-sqr-sqrt39.2%
Applied egg-rr39.2%
flip--33.5%
associate-*r/33.5%
+-commutative33.5%
Applied egg-rr33.5%
Taylor expanded in y around 0 33.2%
unpow233.2%
associate-/l*35.3%
associate-/r/35.3%
Simplified35.3%
Taylor expanded in x around 0 57.6%
unpow257.6%
unpow257.6%
Simplified57.6%
if -9.5000000000000003e76 < x < 7.49999999999999967e79Initial program 100.0%
div-inv99.7%
add-sqr-sqrt57.4%
fabs-sqr57.4%
add-sqr-sqrt58.3%
*-commutative58.3%
add-sqr-sqrt8.3%
fabs-sqr8.3%
add-sqr-sqrt16.4%
Applied egg-rr16.4%
flip--13.3%
associate-*r/12.7%
+-commutative12.7%
Applied egg-rr12.7%
Taylor expanded in x around 0 1.8%
unpow21.8%
mul-1-neg1.8%
distribute-rgt-neg-out1.8%
Simplified1.8%
associate-*r*2.0%
lft-mult-inverse2.0%
*-un-lft-identity2.0%
neg-sub02.0%
metadata-eval2.0%
sub-neg2.0%
metadata-eval2.0%
add-sqr-sqrt1.2%
sqrt-unprod14.4%
sqr-neg14.4%
sqrt-unprod28.3%
add-sqr-sqrt67.9%
Applied egg-rr67.9%
+-lft-identity67.9%
Simplified67.9%
if 7.49999999999999967e79 < x < 1.1799999999999999e243Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
fabs-div100.0%
rem-square-sqrt52.3%
fabs-sqr52.3%
rem-square-sqrt53.0%
div-sub53.0%
sub-neg53.0%
*-inverses53.0%
metadata-eval53.0%
+-commutative53.0%
Simplified53.0%
Final simplification63.5%
(FPCore (x y) :precision binary64 (if (or (<= y -1.1e-159) (not (<= y 1.7e-102))) (/ y (+ x y)) (+ (/ x y) -1.0)))
double code(double x, double y) {
double tmp;
if ((y <= -1.1e-159) || !(y <= 1.7e-102)) {
tmp = y / (x + y);
} 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 ((y <= (-1.1d-159)) .or. (.not. (y <= 1.7d-102))) then
tmp = y / (x + y)
else
tmp = (x / y) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.1e-159) || !(y <= 1.7e-102)) {
tmp = y / (x + y);
} else {
tmp = (x / y) + -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.1e-159) or not (y <= 1.7e-102): tmp = y / (x + y) else: tmp = (x / y) + -1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.1e-159) || !(y <= 1.7e-102)) tmp = Float64(y / Float64(x + y)); else tmp = Float64(Float64(x / y) + -1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.1e-159) || ~((y <= 1.7e-102))) tmp = y / (x + y); else tmp = (x / y) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.1e-159], N[Not[LessEqual[y, 1.7e-102]], $MachinePrecision]], N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-159} \lor \neg \left(y \leq 1.7 \cdot 10^{-102}\right):\\
\;\;\;\;\frac{y}{x + y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} + -1\\
\end{array}
\end{array}
if y < -1.1e-159 or 1.70000000000000006e-102 < y Initial program 100.0%
div-inv99.7%
add-sqr-sqrt63.8%
fabs-sqr63.8%
add-sqr-sqrt64.6%
*-commutative64.6%
add-sqr-sqrt10.1%
fabs-sqr10.1%
add-sqr-sqrt16.6%
Applied egg-rr16.6%
flip--10.1%
associate-*r/10.1%
+-commutative10.1%
Applied egg-rr10.1%
Taylor expanded in x around 0 1.6%
unpow21.6%
mul-1-neg1.6%
distribute-rgt-neg-out1.6%
Simplified1.6%
associate-*r*2.0%
lft-mult-inverse2.0%
*-un-lft-identity2.0%
neg-sub02.0%
metadata-eval2.0%
sub-neg2.0%
metadata-eval2.0%
add-sqr-sqrt1.2%
sqrt-unprod13.4%
sqr-neg13.4%
sqrt-unprod24.4%
add-sqr-sqrt65.2%
Applied egg-rr65.2%
+-lft-identity65.2%
Simplified65.2%
if -1.1e-159 < y < 1.70000000000000006e-102Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
fabs-div100.0%
rem-square-sqrt47.3%
fabs-sqr47.3%
rem-square-sqrt47.9%
div-sub47.9%
sub-neg47.9%
*-inverses47.9%
metadata-eval47.9%
+-commutative47.9%
Simplified47.9%
Final simplification59.7%
(FPCore (x y) :precision binary64 (+ (/ x y) -1.0))
double code(double x, double y) {
return (x / y) + -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / y) + (-1.0d0)
end function
public static double code(double x, double y) {
return (x / y) + -1.0;
}
def code(x, y): return (x / y) + -1.0
function code(x, y) return Float64(Float64(x / y) + -1.0) end
function tmp = code(x, y) tmp = (x / y) + -1.0; end
code[x_, y_] := N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y} + -1
\end{array}
Initial program 100.0%
Taylor expanded in x around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
fabs-div100.0%
rem-square-sqrt25.6%
fabs-sqr25.6%
rem-square-sqrt26.7%
div-sub26.7%
sub-neg26.7%
*-inverses26.7%
metadata-eval26.7%
+-commutative26.7%
Simplified26.7%
Final simplification26.7%
(FPCore (x y) :precision binary64 (/ x y))
double code(double x, double y) {
return x / y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / y
end function
public static double code(double x, double y) {
return x / y;
}
def code(x, y): return x / y
function code(x, y) return Float64(x / y) end
function tmp = code(x, y) tmp = x / y; end
code[x_, y_] := N[(x / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y}
\end{array}
Initial program 100.0%
div-inv99.7%
add-sqr-sqrt58.5%
fabs-sqr58.5%
add-sqr-sqrt59.2%
*-commutative59.2%
add-sqr-sqrt16.3%
fabs-sqr16.3%
add-sqr-sqrt26.6%
Applied egg-rr26.6%
Taylor expanded in y around 0 26.4%
Final simplification26.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%
div-inv99.7%
add-sqr-sqrt58.5%
fabs-sqr58.5%
add-sqr-sqrt59.2%
*-commutative59.2%
add-sqr-sqrt16.3%
fabs-sqr16.3%
add-sqr-sqrt26.6%
Applied egg-rr26.6%
Taylor expanded in y around inf 1.3%
Final simplification1.3%
herbie shell --seed 2023171
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))