
(FPCore (x y) :precision binary64 (/ x (+ y x)))
double code(double x, double y) {
return x / (y + x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (y + x)
end function
public static double code(double x, double y) {
return x / (y + x);
}
def code(x, y): return x / (y + x)
function code(x, y) return Float64(x / Float64(y + x)) end
function tmp = code(x, y) tmp = x / (y + x); end
code[x_, y_] := N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y + x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ x (+ y x)))
double code(double x, double y) {
return x / (y + x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (y + x)
end function
public static double code(double x, double y) {
return x / (y + x);
}
def code(x, y): return x / (y + x)
function code(x, y) return Float64(x / Float64(y + x)) end
function tmp = code(x, y) tmp = x / (y + x); end
code[x_, y_] := N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y + x}
\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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -4.6e+108)
(/ x y)
(if (<= y -4.6e+38)
1.0
(if (<= y -4.8e-64)
(/ x y)
(if (<= y 4e-14)
1.0
(if (and (not (<= y 7.8e+28)) (<= y 4.2e+55)) 1.0 (/ x y)))))))
double code(double x, double y) {
double tmp;
if (y <= -4.6e+108) {
tmp = x / y;
} else if (y <= -4.6e+38) {
tmp = 1.0;
} else if (y <= -4.8e-64) {
tmp = x / y;
} else if (y <= 4e-14) {
tmp = 1.0;
} else if (!(y <= 7.8e+28) && (y <= 4.2e+55)) {
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) :: tmp
if (y <= (-4.6d+108)) then
tmp = x / y
else if (y <= (-4.6d+38)) then
tmp = 1.0d0
else if (y <= (-4.8d-64)) then
tmp = x / y
else if (y <= 4d-14) then
tmp = 1.0d0
else if ((.not. (y <= 7.8d+28)) .and. (y <= 4.2d+55)) then
tmp = 1.0d0
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.6e+108) {
tmp = x / y;
} else if (y <= -4.6e+38) {
tmp = 1.0;
} else if (y <= -4.8e-64) {
tmp = x / y;
} else if (y <= 4e-14) {
tmp = 1.0;
} else if (!(y <= 7.8e+28) && (y <= 4.2e+55)) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.6e+108: tmp = x / y elif y <= -4.6e+38: tmp = 1.0 elif y <= -4.8e-64: tmp = x / y elif y <= 4e-14: tmp = 1.0 elif not (y <= 7.8e+28) and (y <= 4.2e+55): tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.6e+108) tmp = Float64(x / y); elseif (y <= -4.6e+38) tmp = 1.0; elseif (y <= -4.8e-64) tmp = Float64(x / y); elseif (y <= 4e-14) tmp = 1.0; elseif (!(y <= 7.8e+28) && (y <= 4.2e+55)) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.6e+108) tmp = x / y; elseif (y <= -4.6e+38) tmp = 1.0; elseif (y <= -4.8e-64) tmp = x / y; elseif (y <= 4e-14) tmp = 1.0; elseif (~((y <= 7.8e+28)) && (y <= 4.2e+55)) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.6e+108], N[(x / y), $MachinePrecision], If[LessEqual[y, -4.6e+38], 1.0, If[LessEqual[y, -4.8e-64], N[(x / y), $MachinePrecision], If[LessEqual[y, 4e-14], 1.0, If[And[N[Not[LessEqual[y, 7.8e+28]], $MachinePrecision], LessEqual[y, 4.2e+55]], 1.0, N[(x / y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{+108}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq -4.6 \cdot 10^{+38}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -4.8 \cdot 10^{-64}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-14}:\\
\;\;\;\;1\\
\mathbf{elif}\;\neg \left(y \leq 7.8 \cdot 10^{+28}\right) \land y \leq 4.2 \cdot 10^{+55}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if y < -4.5999999999999998e108 or -4.6000000000000002e38 < y < -4.79999999999999997e-64 or 4e-14 < y < 7.7999999999999997e28 or 4.2000000000000001e55 < y Initial program 100.0%
Taylor expanded in x around 0 82.3%
if -4.5999999999999998e108 < y < -4.6000000000000002e38 or -4.79999999999999997e-64 < y < 4e-14 or 7.7999999999999997e28 < y < 4.2000000000000001e55Initial program 100.0%
Taylor expanded in x around inf 82.5%
Final simplification82.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%
Taylor expanded in x around inf 51.6%
Final simplification51.6%
herbie shell --seed 2023199
(FPCore (x y)
:name "AI.Clustering.Hierarchical.Internal:average from clustering-0.2.1, B"
:precision binary64
(/ x (+ y x)))