
(FPCore (x y) :precision binary64 (/ x (+ x y)))
double code(double x, double y) {
return x / (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (x + y)
end function
public static double code(double x, double y) {
return x / (x + y);
}
def code(x, y): return x / (x + y)
function code(x, y) return Float64(x / Float64(x + y)) end
function tmp = code(x, y) tmp = x / (x + y); end
code[x_, y_] := N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ x (+ x y)))
double code(double x, double y) {
return x / (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (x + y)
end function
public static double code(double x, double y) {
return x / (x + y);
}
def code(x, y): return x / (x + y)
function code(x, y) return Float64(x / Float64(x + y)) end
function tmp = code(x, y) tmp = x / (x + y); end
code[x_, y_] := N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + y}
\end{array}
(FPCore (x y) :precision binary64 (/ x (+ x y)))
double code(double x, double y) {
return x / (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (x + y)
end function
public static double code(double x, double y) {
return x / (x + y);
}
def code(x, y): return x / (x + y)
function code(x, y) return Float64(x / Float64(x + y)) end
function tmp = code(x, y) tmp = x / (x + y); end
code[x_, y_] := N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + y}
\end{array}
(FPCore (x y)
:precision binary64
(if (or (<= y -1.35e-40)
(not
(or (<= y -2.1e-88)
(and (not (<= y -6.6e-108))
(or (<= y 1.8e-75)
(and (not (<= y 1.5e-50)) (<= y 2.2e+25)))))))
(/ x y)
1.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.35e-40) || !((y <= -2.1e-88) || (!(y <= -6.6e-108) && ((y <= 1.8e-75) || (!(y <= 1.5e-50) && (y <= 2.2e+25)))))) {
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 <= (-1.35d-40)) .or. (.not. (y <= (-2.1d-88)) .or. (.not. (y <= (-6.6d-108))) .and. (y <= 1.8d-75) .or. (.not. (y <= 1.5d-50)) .and. (y <= 2.2d+25))) 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 <= -1.35e-40) || !((y <= -2.1e-88) || (!(y <= -6.6e-108) && ((y <= 1.8e-75) || (!(y <= 1.5e-50) && (y <= 2.2e+25)))))) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.35e-40) or not ((y <= -2.1e-88) or (not (y <= -6.6e-108) and ((y <= 1.8e-75) or (not (y <= 1.5e-50) and (y <= 2.2e+25))))): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.35e-40) || !((y <= -2.1e-88) || (!(y <= -6.6e-108) && ((y <= 1.8e-75) || (!(y <= 1.5e-50) && (y <= 2.2e+25)))))) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.35e-40) || ~(((y <= -2.1e-88) || (~((y <= -6.6e-108)) && ((y <= 1.8e-75) || (~((y <= 1.5e-50)) && (y <= 2.2e+25))))))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.35e-40], N[Not[Or[LessEqual[y, -2.1e-88], And[N[Not[LessEqual[y, -6.6e-108]], $MachinePrecision], Or[LessEqual[y, 1.8e-75], And[N[Not[LessEqual[y, 1.5e-50]], $MachinePrecision], LessEqual[y, 2.2e+25]]]]]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-40} \lor \neg \left(y \leq -2.1 \cdot 10^{-88} \lor \neg \left(y \leq -6.6 \cdot 10^{-108}\right) \land \left(y \leq 1.8 \cdot 10^{-75} \lor \neg \left(y \leq 1.5 \cdot 10^{-50}\right) \land y \leq 2.2 \cdot 10^{+25}\right)\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(if (<= y -1e-40)
(/ x y)
(if (<= y -2.6e-88)
1.0
(if (<= y -8.5e-108)
(/ x y)
(if (<= y 1.26e-76)
(- 1.0 (/ y x))
(if (or (<= y 4.8e-51) (not (<= y 3e+25))) (/ x y) 1.0))))))
double code(double x, double y) {
double tmp;
if (y <= -1e-40) {
tmp = x / y;
} else if (y <= -2.6e-88) {
tmp = 1.0;
} else if (y <= -8.5e-108) {
tmp = x / y;
} else if (y <= 1.26e-76) {
tmp = 1.0 - (y / x);
} else if ((y <= 4.8e-51) || !(y <= 3e+25)) {
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 <= (-1d-40)) then
tmp = x / y
else if (y <= (-2.6d-88)) then
tmp = 1.0d0
else if (y <= (-8.5d-108)) then
tmp = x / y
else if (y <= 1.26d-76) then
tmp = 1.0d0 - (y / x)
else if ((y <= 4.8d-51) .or. (.not. (y <= 3d+25))) 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 <= -1e-40) {
tmp = x / y;
} else if (y <= -2.6e-88) {
tmp = 1.0;
} else if (y <= -8.5e-108) {
tmp = x / y;
} else if (y <= 1.26e-76) {
tmp = 1.0 - (y / x);
} else if ((y <= 4.8e-51) || !(y <= 3e+25)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1e-40: tmp = x / y elif y <= -2.6e-88: tmp = 1.0 elif y <= -8.5e-108: tmp = x / y elif y <= 1.26e-76: tmp = 1.0 - (y / x) elif (y <= 4.8e-51) or not (y <= 3e+25): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1e-40) tmp = Float64(x / y); elseif (y <= -2.6e-88) tmp = 1.0; elseif (y <= -8.5e-108) tmp = Float64(x / y); elseif (y <= 1.26e-76) tmp = Float64(1.0 - Float64(y / x)); elseif ((y <= 4.8e-51) || !(y <= 3e+25)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1e-40) tmp = x / y; elseif (y <= -2.6e-88) tmp = 1.0; elseif (y <= -8.5e-108) tmp = x / y; elseif (y <= 1.26e-76) tmp = 1.0 - (y / x); elseif ((y <= 4.8e-51) || ~((y <= 3e+25))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1e-40], N[(x / y), $MachinePrecision], If[LessEqual[y, -2.6e-88], 1.0, If[LessEqual[y, -8.5e-108], N[(x / y), $MachinePrecision], If[LessEqual[y, 1.26e-76], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 4.8e-51], N[Not[LessEqual[y, 3e+25]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-40}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{-88}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -8.5 \cdot 10^{-108}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 1.26 \cdot 10^{-76}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{-51} \lor \neg \left(y \leq 3 \cdot 10^{+25}\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}
herbie shell --seed 2023350
(FPCore (x y)
:name "AI.Clustering.Hierarchical.Internal:average from clustering-0.2.1, A"
:precision binary64
(/ x (+ x y)))