
(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 7 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%
div-fabs100.0%
div-sub100.0%
pow1100.0%
pow1100.0%
pow-div100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= x -2.1e+114)
(and (not (<= x -780000000.0))
(or (<= x -6.5e-236)
(and (not (<= x 8.6e-103)) (<= x 3.4e+85)))))
(- 1.0 (/ x y))
(/ (+ x y) y)))
double code(double x, double y) {
double tmp;
if ((x <= -2.1e+114) || (!(x <= -780000000.0) && ((x <= -6.5e-236) || (!(x <= 8.6e-103) && (x <= 3.4e+85))))) {
tmp = 1.0 - (x / y);
} else {
tmp = (x + y) / 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.1d+114)) .or. (.not. (x <= (-780000000.0d0))) .and. (x <= (-6.5d-236)) .or. (.not. (x <= 8.6d-103)) .and. (x <= 3.4d+85)) then
tmp = 1.0d0 - (x / y)
else
tmp = (x + y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.1e+114) || (!(x <= -780000000.0) && ((x <= -6.5e-236) || (!(x <= 8.6e-103) && (x <= 3.4e+85))))) {
tmp = 1.0 - (x / y);
} else {
tmp = (x + y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.1e+114) or (not (x <= -780000000.0) and ((x <= -6.5e-236) or (not (x <= 8.6e-103) and (x <= 3.4e+85)))): tmp = 1.0 - (x / y) else: tmp = (x + y) / y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.1e+114) || (!(x <= -780000000.0) && ((x <= -6.5e-236) || (!(x <= 8.6e-103) && (x <= 3.4e+85))))) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(Float64(x + y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.1e+114) || (~((x <= -780000000.0)) && ((x <= -6.5e-236) || (~((x <= 8.6e-103)) && (x <= 3.4e+85))))) tmp = 1.0 - (x / y); else tmp = (x + y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.1e+114], And[N[Not[LessEqual[x, -780000000.0]], $MachinePrecision], Or[LessEqual[x, -6.5e-236], And[N[Not[LessEqual[x, 8.6e-103]], $MachinePrecision], LessEqual[x, 3.4e+85]]]]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+114} \lor \neg \left(x \leq -780000000\right) \land \left(x \leq -6.5 \cdot 10^{-236} \lor \neg \left(x \leq 8.6 \cdot 10^{-103}\right) \land x \leq 3.4 \cdot 10^{+85}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{y}\\
\end{array}
\end{array}
if x < -2.1e114 or -7.8e8 < x < -6.5000000000000001e-236 or 8.60000000000000045e-103 < x < 3.4000000000000003e85Initial program 99.9%
add-sqr-sqrt32.3%
fabs-sqr32.3%
add-sqr-sqrt7.1%
fabs-sqr7.1%
add-sqr-sqrt7.7%
add-sqr-sqrt22.3%
clear-num22.3%
associate-/r/22.3%
Applied egg-rr22.3%
associate-*l/22.3%
*-un-lft-identity22.3%
frac-2neg22.3%
sub-neg22.3%
distribute-neg-in22.3%
remove-double-neg22.3%
add-sqr-sqrt14.6%
sqrt-unprod45.0%
sqr-neg45.0%
sqrt-unprod53.0%
add-sqr-sqrt78.7%
Applied egg-rr78.7%
Taylor expanded in x around 0 78.7%
mul-1-neg78.7%
unsub-neg78.7%
Simplified78.7%
if -2.1e114 < x < -7.8e8 or -6.5000000000000001e-236 < x < 8.60000000000000045e-103 or 3.4000000000000003e85 < x Initial program 100.0%
add-sqr-sqrt54.4%
fabs-sqr54.4%
add-sqr-sqrt27.5%
fabs-sqr27.5%
add-sqr-sqrt28.1%
add-sqr-sqrt38.5%
clear-num38.4%
associate-/r/38.4%
Applied egg-rr38.4%
associate-*l/38.5%
*-un-lft-identity38.5%
sub-neg38.5%
add-sqr-sqrt10.3%
sqrt-unprod50.7%
sqr-neg50.7%
sqrt-unprod58.9%
add-sqr-sqrt85.1%
Applied egg-rr85.1%
Final simplification81.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x) y)))
(if (<= x -2.95e+118)
t_0
(if (<= x -440000000.0)
(/ x y)
(if (<= x -3.25e-12) t_0 (if (<= x 4e+89) 1.0 (/ x y)))))))
double code(double x, double y) {
double t_0 = -x / y;
double tmp;
if (x <= -2.95e+118) {
tmp = t_0;
} else if (x <= -440000000.0) {
tmp = x / y;
} else if (x <= -3.25e-12) {
tmp = t_0;
} else if (x <= 4e+89) {
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) :: t_0
real(8) :: tmp
t_0 = -x / y
if (x <= (-2.95d+118)) then
tmp = t_0
else if (x <= (-440000000.0d0)) then
tmp = x / y
else if (x <= (-3.25d-12)) then
tmp = t_0
else if (x <= 4d+89) then
tmp = 1.0d0
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = -x / y;
double tmp;
if (x <= -2.95e+118) {
tmp = t_0;
} else if (x <= -440000000.0) {
tmp = x / y;
} else if (x <= -3.25e-12) {
tmp = t_0;
} else if (x <= 4e+89) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = -x / y tmp = 0 if x <= -2.95e+118: tmp = t_0 elif x <= -440000000.0: tmp = x / y elif x <= -3.25e-12: tmp = t_0 elif x <= 4e+89: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) t_0 = Float64(Float64(-x) / y) tmp = 0.0 if (x <= -2.95e+118) tmp = t_0; elseif (x <= -440000000.0) tmp = Float64(x / y); elseif (x <= -3.25e-12) tmp = t_0; elseif (x <= 4e+89) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) t_0 = -x / y; tmp = 0.0; if (x <= -2.95e+118) tmp = t_0; elseif (x <= -440000000.0) tmp = x / y; elseif (x <= -3.25e-12) tmp = t_0; elseif (x <= 4e+89) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[((-x) / y), $MachinePrecision]}, If[LessEqual[x, -2.95e+118], t$95$0, If[LessEqual[x, -440000000.0], N[(x / y), $MachinePrecision], If[LessEqual[x, -3.25e-12], t$95$0, If[LessEqual[x, 4e+89], 1.0, N[(x / y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{y}\\
\mathbf{if}\;x \leq -2.95 \cdot 10^{+118}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -440000000:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq -3.25 \cdot 10^{-12}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+89}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -2.9499999999999999e118 or -4.4e8 < x < -3.2500000000000001e-12Initial program 99.9%
add-sqr-sqrt6.2%
fabs-sqr6.2%
add-sqr-sqrt0.0%
fabs-sqr0.0%
add-sqr-sqrt0.4%
add-sqr-sqrt25.5%
clear-num25.4%
associate-/r/25.4%
Applied egg-rr25.4%
associate-*l/25.5%
*-un-lft-identity25.5%
frac-2neg25.5%
sub-neg25.5%
distribute-neg-in25.5%
remove-double-neg25.5%
add-sqr-sqrt25.0%
sqrt-unprod78.1%
sqr-neg78.1%
sqrt-unprod68.4%
add-sqr-sqrt74.9%
Applied egg-rr74.9%
Taylor expanded in x around inf 60.5%
associate-*r/60.5%
mul-1-neg60.5%
Simplified60.5%
if -2.9499999999999999e118 < x < -4.4e8 or 3.99999999999999998e89 < x Initial program 100.0%
add-sqr-sqrt61.2%
fabs-sqr61.2%
add-sqr-sqrt38.4%
fabs-sqr38.4%
add-sqr-sqrt38.8%
add-sqr-sqrt55.1%
clear-num55.0%
associate-/r/54.9%
Applied egg-rr54.9%
Taylor expanded in y around 0 55.4%
if -3.2500000000000001e-12 < x < 3.99999999999999998e89Initial program 100.0%
add-sqr-sqrt47.1%
fabs-sqr47.1%
add-sqr-sqrt11.9%
fabs-sqr11.9%
add-sqr-sqrt12.7%
add-sqr-sqrt18.5%
clear-num18.5%
associate-/r/18.5%
Applied egg-rr18.5%
associate-*l/18.5%
*-un-lft-identity18.5%
sub-neg18.5%
add-sqr-sqrt5.7%
sqrt-unprod39.5%
sqr-neg39.5%
sqrt-unprod53.9%
add-sqr-sqrt82.6%
Applied egg-rr82.6%
Taylor expanded in x around 0 68.8%
Final simplification63.3%
(FPCore (x y) :precision binary64 (if (or (<= x -2.9e+79) (not (<= x 2.2e+87))) (/ x y) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -2.9e+79) || !(x <= 2.2e+87)) {
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 <= (-2.9d+79)) .or. (.not. (x <= 2.2d+87))) 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 <= -2.9e+79) || !(x <= 2.2e+87)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.9e+79) or not (x <= 2.2e+87): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.9e+79) || !(x <= 2.2e+87)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.9e+79) || ~((x <= 2.2e+87))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.9e+79], N[Not[LessEqual[x, 2.2e+87]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+79} \lor \neg \left(x \leq 2.2 \cdot 10^{+87}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.89999999999999992e79 or 2.2000000000000001e87 < x Initial program 99.9%
add-sqr-sqrt48.2%
fabs-sqr48.2%
add-sqr-sqrt30.3%
fabs-sqr30.3%
add-sqr-sqrt30.6%
add-sqr-sqrt47.7%
clear-num47.6%
associate-/r/47.6%
Applied egg-rr47.6%
Taylor expanded in y around 0 48.3%
if -2.89999999999999992e79 < x < 2.2000000000000001e87Initial program 100.0%
add-sqr-sqrt40.7%
fabs-sqr40.7%
add-sqr-sqrt9.9%
fabs-sqr9.9%
add-sqr-sqrt10.6%
add-sqr-sqrt20.4%
clear-num20.4%
associate-/r/20.3%
Applied egg-rr20.3%
associate-*l/20.4%
*-un-lft-identity20.4%
sub-neg20.4%
add-sqr-sqrt9.7%
sqrt-unprod39.0%
sqr-neg39.0%
sqrt-unprod48.2%
add-sqr-sqrt78.6%
Applied egg-rr78.6%
Taylor expanded in x around 0 62.9%
Final simplification57.5%
(FPCore (x y) :precision binary64 (if (<= x 3.1e+165) (- 1.0 (/ x y)) (/ x y)))
double code(double x, double y) {
double tmp;
if (x <= 3.1e+165) {
tmp = 1.0 - (x / y);
} 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 <= 3.1d+165) then
tmp = 1.0d0 - (x / y)
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 3.1e+165) {
tmp = 1.0 - (x / y);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 3.1e+165: tmp = 1.0 - (x / y) else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (x <= 3.1e+165) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 3.1e+165) tmp = 1.0 - (x / y); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 3.1e+165], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.1 \cdot 10^{+165}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < 3.1000000000000002e165Initial program 100.0%
add-sqr-sqrt36.1%
fabs-sqr36.1%
add-sqr-sqrt10.7%
fabs-sqr10.7%
add-sqr-sqrt11.3%
add-sqr-sqrt25.6%
clear-num25.5%
associate-/r/25.5%
Applied egg-rr25.5%
associate-*l/25.6%
*-un-lft-identity25.6%
frac-2neg25.6%
sub-neg25.6%
distribute-neg-in25.6%
remove-double-neg25.6%
add-sqr-sqrt14.2%
sqrt-unprod39.2%
sqr-neg39.2%
sqrt-unprod49.5%
add-sqr-sqrt75.5%
Applied egg-rr75.5%
Taylor expanded in x around 0 75.5%
mul-1-neg75.5%
unsub-neg75.5%
Simplified75.5%
if 3.1000000000000002e165 < x Initial program 100.0%
add-sqr-sqrt93.8%
fabs-sqr93.8%
add-sqr-sqrt63.4%
fabs-sqr63.4%
add-sqr-sqrt63.5%
add-sqr-sqrt63.8%
clear-num63.7%
associate-/r/63.7%
Applied egg-rr63.7%
Taylor expanded in y around 0 64.3%
Final simplification74.0%
(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%
add-sqr-sqrt43.5%
fabs-sqr43.5%
add-sqr-sqrt17.5%
fabs-sqr17.5%
add-sqr-sqrt18.0%
add-sqr-sqrt30.5%
clear-num30.5%
associate-/r/30.4%
Applied egg-rr30.4%
Taylor expanded in y around inf 1.2%
Final simplification1.2%
(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%
add-sqr-sqrt43.5%
fabs-sqr43.5%
add-sqr-sqrt17.5%
fabs-sqr17.5%
add-sqr-sqrt18.0%
add-sqr-sqrt30.5%
clear-num30.5%
associate-/r/30.4%
Applied egg-rr30.4%
associate-*l/30.5%
*-un-lft-identity30.5%
sub-neg30.5%
add-sqr-sqrt12.4%
sqrt-unprod42.4%
sqr-neg42.4%
sqrt-unprod45.5%
add-sqr-sqrt72.1%
Applied egg-rr72.1%
Taylor expanded in x around 0 45.9%
Final simplification45.9%
herbie shell --seed 2023322
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))