
(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 4 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 (+ 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}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= y -2.8e+69) (/ x y) (if (<= y 4.6e+62) (- 1.0 (/ y x)) (/ x y))))
double code(double x, double y) {
double tmp;
if (y <= -2.8e+69) {
tmp = x / y;
} else if (y <= 4.6e+62) {
tmp = 1.0 - (y / x);
} 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 <= (-2.8d+69)) then
tmp = x / y
else if (y <= 4.6d+62) then
tmp = 1.0d0 - (y / x)
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.8e+69) {
tmp = x / y;
} else if (y <= 4.6e+62) {
tmp = 1.0 - (y / x);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.8e+69: tmp = x / y elif y <= 4.6e+62: tmp = 1.0 - (y / x) else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.8e+69) tmp = Float64(x / y); elseif (y <= 4.6e+62) tmp = Float64(1.0 - Float64(y / x)); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.8e+69) tmp = x / y; elseif (y <= 4.6e+62) tmp = 1.0 - (y / x); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.8e+69], N[(x / y), $MachinePrecision], If[LessEqual[y, 4.6e+62], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+69}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{+62}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if y < -2.79999999999999982e69 or 4.59999999999999968e62 < y Initial program 100.0%
Taylor expanded in x around 0 0
Simplified0
if -2.79999999999999982e69 < y < 4.59999999999999968e62Initial program 100.0%
Taylor expanded in x around inf 0
Simplified0
(FPCore (x y) :precision binary64 (if (<= y -2.1e+68) (/ x y) (if (<= y 5.7e+63) 1.0 (/ x y))))
double code(double x, double y) {
double tmp;
if (y <= -2.1e+68) {
tmp = x / y;
} else if (y <= 5.7e+63) {
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 <= (-2.1d+68)) then
tmp = x / y
else if (y <= 5.7d+63) 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 <= -2.1e+68) {
tmp = x / y;
} else if (y <= 5.7e+63) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.1e+68: tmp = x / y elif y <= 5.7e+63: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.1e+68) tmp = Float64(x / y); elseif (y <= 5.7e+63) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.1e+68) tmp = x / y; elseif (y <= 5.7e+63) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.1e+68], N[(x / y), $MachinePrecision], If[LessEqual[y, 5.7e+63], 1.0, N[(x / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{+68}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 5.7 \cdot 10^{+63}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if y < -2.10000000000000001e68 or 5.7000000000000002e63 < y Initial program 100.0%
Taylor expanded in x around 0 0
Simplified0
if -2.10000000000000001e68 < y < 5.7000000000000002e63Initial program 100.0%
Taylor expanded in x around inf 0
Simplified0
(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 0
Simplified0
herbie shell --seed 2024110
(FPCore (x y)
:name "AI.Clustering.Hierarchical.Internal:average from clustering-0.2.1, B"
:precision binary64
(/ x (+ y x)))