
(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 (+ 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 -7.8e+46)
(/ x y)
(if (<= y -2.9e+31)
1.0
(if (<= y -3.8e-70)
(/ x y)
(if (<= y 450.0)
1.0
(if (<= y 3.1e+29) (/ x y) (if (<= y 1e+78) 1.0 (/ x y))))))))
double code(double x, double y) {
double tmp;
if (y <= -7.8e+46) {
tmp = x / y;
} else if (y <= -2.9e+31) {
tmp = 1.0;
} else if (y <= -3.8e-70) {
tmp = x / y;
} else if (y <= 450.0) {
tmp = 1.0;
} else if (y <= 3.1e+29) {
tmp = x / y;
} else if (y <= 1e+78) {
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 <= (-7.8d+46)) then
tmp = x / y
else if (y <= (-2.9d+31)) then
tmp = 1.0d0
else if (y <= (-3.8d-70)) then
tmp = x / y
else if (y <= 450.0d0) then
tmp = 1.0d0
else if (y <= 3.1d+29) then
tmp = x / y
else if (y <= 1d+78) 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 <= -7.8e+46) {
tmp = x / y;
} else if (y <= -2.9e+31) {
tmp = 1.0;
} else if (y <= -3.8e-70) {
tmp = x / y;
} else if (y <= 450.0) {
tmp = 1.0;
} else if (y <= 3.1e+29) {
tmp = x / y;
} else if (y <= 1e+78) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.8e+46: tmp = x / y elif y <= -2.9e+31: tmp = 1.0 elif y <= -3.8e-70: tmp = x / y elif y <= 450.0: tmp = 1.0 elif y <= 3.1e+29: tmp = x / y elif y <= 1e+78: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.8e+46) tmp = Float64(x / y); elseif (y <= -2.9e+31) tmp = 1.0; elseif (y <= -3.8e-70) tmp = Float64(x / y); elseif (y <= 450.0) tmp = 1.0; elseif (y <= 3.1e+29) tmp = Float64(x / y); elseif (y <= 1e+78) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.8e+46) tmp = x / y; elseif (y <= -2.9e+31) tmp = 1.0; elseif (y <= -3.8e-70) tmp = x / y; elseif (y <= 450.0) tmp = 1.0; elseif (y <= 3.1e+29) tmp = x / y; elseif (y <= 1e+78) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.8e+46], N[(x / y), $MachinePrecision], If[LessEqual[y, -2.9e+31], 1.0, If[LessEqual[y, -3.8e-70], N[(x / y), $MachinePrecision], If[LessEqual[y, 450.0], 1.0, If[LessEqual[y, 3.1e+29], N[(x / y), $MachinePrecision], If[LessEqual[y, 1e+78], 1.0, N[(x / y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+46}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq -2.9 \cdot 10^{+31}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -3.8 \cdot 10^{-70}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 450:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+29}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 10^{+78}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if y < -7.7999999999999999e46 or -2.9e31 < y < -3.7999999999999998e-70 or 450 < y < 3.0999999999999999e29 or 1.00000000000000001e78 < y Initial program 100.0%
Taylor expanded in x around 0 85.6%
if -7.7999999999999999e46 < y < -2.9e31 or -3.7999999999999998e-70 < y < 450 or 3.0999999999999999e29 < y < 1.00000000000000001e78Initial program 100.0%
Taylor expanded in x around inf 80.2%
Final simplification82.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ y x))))
(if (<= y -6.3e+46)
(/ x y)
(if (<= y -6.2e+31)
t_0
(if (<= y -3.9e-70)
(/ x y)
(if (<= y 40.0)
t_0
(if (<= y 2.3e+28) (/ x y) (if (<= y 2.2e+80) 1.0 (/ x y)))))))))
double code(double x, double y) {
double t_0 = 1.0 - (y / x);
double tmp;
if (y <= -6.3e+46) {
tmp = x / y;
} else if (y <= -6.2e+31) {
tmp = t_0;
} else if (y <= -3.9e-70) {
tmp = x / y;
} else if (y <= 40.0) {
tmp = t_0;
} else if (y <= 2.3e+28) {
tmp = x / y;
} else if (y <= 2.2e+80) {
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 = 1.0d0 - (y / x)
if (y <= (-6.3d+46)) then
tmp = x / y
else if (y <= (-6.2d+31)) then
tmp = t_0
else if (y <= (-3.9d-70)) then
tmp = x / y
else if (y <= 40.0d0) then
tmp = t_0
else if (y <= 2.3d+28) then
tmp = x / y
else if (y <= 2.2d+80) 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 = 1.0 - (y / x);
double tmp;
if (y <= -6.3e+46) {
tmp = x / y;
} else if (y <= -6.2e+31) {
tmp = t_0;
} else if (y <= -3.9e-70) {
tmp = x / y;
} else if (y <= 40.0) {
tmp = t_0;
} else if (y <= 2.3e+28) {
tmp = x / y;
} else if (y <= 2.2e+80) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (y / x) tmp = 0 if y <= -6.3e+46: tmp = x / y elif y <= -6.2e+31: tmp = t_0 elif y <= -3.9e-70: tmp = x / y elif y <= 40.0: tmp = t_0 elif y <= 2.3e+28: tmp = x / y elif y <= 2.2e+80: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(y / x)) tmp = 0.0 if (y <= -6.3e+46) tmp = Float64(x / y); elseif (y <= -6.2e+31) tmp = t_0; elseif (y <= -3.9e-70) tmp = Float64(x / y); elseif (y <= 40.0) tmp = t_0; elseif (y <= 2.3e+28) tmp = Float64(x / y); elseif (y <= 2.2e+80) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - (y / x); tmp = 0.0; if (y <= -6.3e+46) tmp = x / y; elseif (y <= -6.2e+31) tmp = t_0; elseif (y <= -3.9e-70) tmp = x / y; elseif (y <= 40.0) tmp = t_0; elseif (y <= 2.3e+28) tmp = x / y; elseif (y <= 2.2e+80) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.3e+46], N[(x / y), $MachinePrecision], If[LessEqual[y, -6.2e+31], t$95$0, If[LessEqual[y, -3.9e-70], N[(x / y), $MachinePrecision], If[LessEqual[y, 40.0], t$95$0, If[LessEqual[y, 2.3e+28], N[(x / y), $MachinePrecision], If[LessEqual[y, 2.2e+80], 1.0, N[(x / y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{y}{x}\\
\mathbf{if}\;y \leq -6.3 \cdot 10^{+46}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq -6.2 \cdot 10^{+31}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3.9 \cdot 10^{-70}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 40:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+28}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+80}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if y < -6.3e46 or -6.2000000000000004e31 < y < -3.90000000000000019e-70 or 40 < y < 2.29999999999999984e28 or 2.20000000000000003e80 < y Initial program 100.0%
Taylor expanded in x around 0 85.6%
if -6.3e46 < y < -6.2000000000000004e31 or -3.90000000000000019e-70 < y < 40Initial program 100.0%
Taylor expanded in x around inf 82.2%
mul-1-neg82.2%
unsub-neg82.2%
Simplified82.2%
if 2.29999999999999984e28 < y < 2.20000000000000003e80Initial program 100.0%
Taylor expanded in x around inf 66.0%
Final simplification83.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%
Taylor expanded in x around inf 49.1%
Final simplification49.1%
herbie shell --seed 2023297
(FPCore (x y)
:name "AI.Clustering.Hierarchical.Internal:average from clustering-0.2.1, B"
:precision binary64
(/ x (+ y x)))