
(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}
(FPCore (x y)
:precision binary64
(if (or (<= x -2.2e+195)
(not
(or (<= x -230000.0)
(and (not (<= x 2.45e-247))
(or (<= x 1.5e-41)
(and (not (<= x 4.1e+45)) (<= x 2.9e+259)))))))
(- 1.0 (/ x y))
(/ (+ x y) y)))
double code(double x, double y) {
double tmp;
if ((x <= -2.2e+195) || !((x <= -230000.0) || (!(x <= 2.45e-247) && ((x <= 1.5e-41) || (!(x <= 4.1e+45) && (x <= 2.9e+259)))))) {
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.2d+195)) .or. (.not. (x <= (-230000.0d0)) .or. (.not. (x <= 2.45d-247)) .and. (x <= 1.5d-41) .or. (.not. (x <= 4.1d+45)) .and. (x <= 2.9d+259))) 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.2e+195) || !((x <= -230000.0) || (!(x <= 2.45e-247) && ((x <= 1.5e-41) || (!(x <= 4.1e+45) && (x <= 2.9e+259)))))) {
tmp = 1.0 - (x / y);
} else {
tmp = (x + y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.2e+195) or not ((x <= -230000.0) or (not (x <= 2.45e-247) and ((x <= 1.5e-41) or (not (x <= 4.1e+45) and (x <= 2.9e+259))))): tmp = 1.0 - (x / y) else: tmp = (x + y) / y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.2e+195) || !((x <= -230000.0) || (!(x <= 2.45e-247) && ((x <= 1.5e-41) || (!(x <= 4.1e+45) && (x <= 2.9e+259)))))) 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.2e+195) || ~(((x <= -230000.0) || (~((x <= 2.45e-247)) && ((x <= 1.5e-41) || (~((x <= 4.1e+45)) && (x <= 2.9e+259))))))) tmp = 1.0 - (x / y); else tmp = (x + y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.2e+195], N[Not[Or[LessEqual[x, -230000.0], And[N[Not[LessEqual[x, 2.45e-247]], $MachinePrecision], Or[LessEqual[x, 1.5e-41], And[N[Not[LessEqual[x, 4.1e+45]], $MachinePrecision], LessEqual[x, 2.9e+259]]]]]], $MachinePrecision]], 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.2 \cdot 10^{+195} \lor \neg \left(x \leq -230000 \lor \neg \left(x \leq 2.45 \cdot 10^{-247}\right) \land \left(x \leq 1.5 \cdot 10^{-41} \lor \neg \left(x \leq 4.1 \cdot 10^{+45}\right) \land x \leq 2.9 \cdot 10^{+259}\right)\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{y}\\
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x) y)))
(if (<= x -4.6e+113)
t_0
(if (<= x 2.5e+57)
1.0
(if (<= x 3.3e+84)
(/ x y)
(if (<= x 4.6e+141) 1.0 (if (<= x 9.5e+259) (/ x y) t_0)))))))
double code(double x, double y) {
double t_0 = -x / y;
double tmp;
if (x <= -4.6e+113) {
tmp = t_0;
} else if (x <= 2.5e+57) {
tmp = 1.0;
} else if (x <= 3.3e+84) {
tmp = x / y;
} else if (x <= 4.6e+141) {
tmp = 1.0;
} else if (x <= 9.5e+259) {
tmp = x / y;
} 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 / y
if (x <= (-4.6d+113)) then
tmp = t_0
else if (x <= 2.5d+57) then
tmp = 1.0d0
else if (x <= 3.3d+84) then
tmp = x / y
else if (x <= 4.6d+141) then
tmp = 1.0d0
else if (x <= 9.5d+259) then
tmp = x / y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = -x / y;
double tmp;
if (x <= -4.6e+113) {
tmp = t_0;
} else if (x <= 2.5e+57) {
tmp = 1.0;
} else if (x <= 3.3e+84) {
tmp = x / y;
} else if (x <= 4.6e+141) {
tmp = 1.0;
} else if (x <= 9.5e+259) {
tmp = x / y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = -x / y tmp = 0 if x <= -4.6e+113: tmp = t_0 elif x <= 2.5e+57: tmp = 1.0 elif x <= 3.3e+84: tmp = x / y elif x <= 4.6e+141: tmp = 1.0 elif x <= 9.5e+259: tmp = x / y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(-x) / y) tmp = 0.0 if (x <= -4.6e+113) tmp = t_0; elseif (x <= 2.5e+57) tmp = 1.0; elseif (x <= 3.3e+84) tmp = Float64(x / y); elseif (x <= 4.6e+141) tmp = 1.0; elseif (x <= 9.5e+259) tmp = Float64(x / y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = -x / y; tmp = 0.0; if (x <= -4.6e+113) tmp = t_0; elseif (x <= 2.5e+57) tmp = 1.0; elseif (x <= 3.3e+84) tmp = x / y; elseif (x <= 4.6e+141) tmp = 1.0; elseif (x <= 9.5e+259) tmp = x / y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[((-x) / y), $MachinePrecision]}, If[LessEqual[x, -4.6e+113], t$95$0, If[LessEqual[x, 2.5e+57], 1.0, If[LessEqual[x, 3.3e+84], N[(x / y), $MachinePrecision], If[LessEqual[x, 4.6e+141], 1.0, If[LessEqual[x, 9.5e+259], N[(x / y), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{y}\\
\mathbf{if}\;x \leq -4.6 \cdot 10^{+113}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+57}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{+84}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{+141}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{+259}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(if (or (<= x 2.4e+60)
(and (not (<= x 2.55e+79))
(or (<= x 1.75e+143) (not (<= x 9.4e+257)))))
(- 1.0 (/ x y))
(/ x y)))
double code(double x, double y) {
double tmp;
if ((x <= 2.4e+60) || (!(x <= 2.55e+79) && ((x <= 1.75e+143) || !(x <= 9.4e+257)))) {
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 <= 2.4d+60) .or. (.not. (x <= 2.55d+79)) .and. (x <= 1.75d+143) .or. (.not. (x <= 9.4d+257))) 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 <= 2.4e+60) || (!(x <= 2.55e+79) && ((x <= 1.75e+143) || !(x <= 9.4e+257)))) {
tmp = 1.0 - (x / y);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= 2.4e+60) or (not (x <= 2.55e+79) and ((x <= 1.75e+143) or not (x <= 9.4e+257))): tmp = 1.0 - (x / y) else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if ((x <= 2.4e+60) || (!(x <= 2.55e+79) && ((x <= 1.75e+143) || !(x <= 9.4e+257)))) 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 <= 2.4e+60) || (~((x <= 2.55e+79)) && ((x <= 1.75e+143) || ~((x <= 9.4e+257))))) tmp = 1.0 - (x / y); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, 2.4e+60], And[N[Not[LessEqual[x, 2.55e+79]], $MachinePrecision], Or[LessEqual[x, 1.75e+143], N[Not[LessEqual[x, 9.4e+257]], $MachinePrecision]]]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.4 \cdot 10^{+60} \lor \neg \left(x \leq 2.55 \cdot 10^{+79}\right) \land \left(x \leq 1.75 \cdot 10^{+143} \lor \neg \left(x \leq 9.4 \cdot 10^{+257}\right)\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(if (or (<= x -3e+97)
(and (not (<= x 2.8e+54)) (or (<= x 3.9e+84) (not (<= x 1.6e+141)))))
(/ x y)
1.0))
double code(double x, double y) {
double tmp;
if ((x <= -3e+97) || (!(x <= 2.8e+54) && ((x <= 3.9e+84) || !(x <= 1.6e+141)))) {
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 <= (-3d+97)) .or. (.not. (x <= 2.8d+54)) .and. (x <= 3.9d+84) .or. (.not. (x <= 1.6d+141))) 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 <= -3e+97) || (!(x <= 2.8e+54) && ((x <= 3.9e+84) || !(x <= 1.6e+141)))) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3e+97) or (not (x <= 2.8e+54) and ((x <= 3.9e+84) or not (x <= 1.6e+141))): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -3e+97) || (!(x <= 2.8e+54) && ((x <= 3.9e+84) || !(x <= 1.6e+141)))) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3e+97) || (~((x <= 2.8e+54)) && ((x <= 3.9e+84) || ~((x <= 1.6e+141))))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3e+97], And[N[Not[LessEqual[x, 2.8e+54]], $MachinePrecision], Or[LessEqual[x, 3.9e+84], N[Not[LessEqual[x, 1.6e+141]], $MachinePrecision]]]], N[(x / y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+97} \lor \neg \left(x \leq 2.8 \cdot 10^{+54}\right) \land \left(x \leq 3.9 \cdot 10^{+84} \lor \neg \left(x \leq 1.6 \cdot 10^{+141}\right)\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
(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}
(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}
herbie shell --seed 2023350
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))