
(FPCore (x y) :precision binary64 (/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))
double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0d0))
end function
public static double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
def code(x, y): return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0))
function code(x, y) return Float64(Float64(x * y) / Float64(Float64(Float64(x + y) * Float64(x + y)) * Float64(Float64(x + y) + 1.0))) end
function tmp = code(x, y) tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0)); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))
double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0d0))
end function
public static double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
def code(x, y): return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0))
function code(x, y) return Float64(Float64(x * y) / Float64(Float64(Float64(x + y) * Float64(x + y)) * Float64(Float64(x + y) + 1.0))) end
function tmp = code(x, y) tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0)); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (+ x y) (+ x y)))
(t_1 (+ (+ x y) 1.0))
(t_2 (/ (* x y) (* t_0 t_1))))
(if (<= t_2 5e-9) t_2 (/ t_1 (* (+ x y) t_0)))))
double code(double x, double y) {
double t_0 = (x + y) * (x + y);
double t_1 = (x + y) + 1.0;
double t_2 = (x * y) / (t_0 * t_1);
double tmp;
if (t_2 <= 5e-9) {
tmp = t_2;
} else {
tmp = t_1 / ((x + y) * 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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = (x + y) * (x + y)
t_1 = (x + y) + 1.0d0
t_2 = (x * y) / (t_0 * t_1)
if (t_2 <= 5d-9) then
tmp = t_2
else
tmp = t_1 / ((x + y) * t_0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x + y) * (x + y);
double t_1 = (x + y) + 1.0;
double t_2 = (x * y) / (t_0 * t_1);
double tmp;
if (t_2 <= 5e-9) {
tmp = t_2;
} else {
tmp = t_1 / ((x + y) * t_0);
}
return tmp;
}
def code(x, y): t_0 = (x + y) * (x + y) t_1 = (x + y) + 1.0 t_2 = (x * y) / (t_0 * t_1) tmp = 0 if t_2 <= 5e-9: tmp = t_2 else: tmp = t_1 / ((x + y) * t_0) return tmp
function code(x, y) t_0 = Float64(Float64(x + y) * Float64(x + y)) t_1 = Float64(Float64(x + y) + 1.0) t_2 = Float64(Float64(x * y) / Float64(t_0 * t_1)) tmp = 0.0 if (t_2 <= 5e-9) tmp = t_2; else tmp = Float64(t_1 / Float64(Float64(x + y) * t_0)); end return tmp end
function tmp_2 = code(x, y) t_0 = (x + y) * (x + y); t_1 = (x + y) + 1.0; t_2 = (x * y) / (t_0 * t_1); tmp = 0.0; if (t_2 <= 5e-9) tmp = t_2; else tmp = t_1 / ((x + y) * t_0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] / N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, 5e-9], t$95$2, N[(t$95$1 / N[(N[(x + y), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) \cdot \left(x + y\right)\\
t_1 := \left(x + y\right) + 1\\
t_2 := \frac{x \cdot y}{t\_0 \cdot t\_1}\\
\mathbf{if}\;t\_2 \leq 5 \cdot 10^{-9}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\left(x + y\right) \cdot t\_0}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x y) (*.f64 (*.f64 (+.f64 x y) (+.f64 x y)) (+.f64 (+.f64 x y) #s(literal 1 binary64)))) < 5.0000000000000001e-9Initial program 83.2%
if 5.0000000000000001e-9 < (/.f64 (*.f64 x y) (*.f64 (*.f64 (+.f64 x y) (+.f64 x y)) (+.f64 (+.f64 x y) #s(literal 1 binary64)))) Initial program 0.0%
Taylor expanded in x around 0
Applied rewrites46.5%
Taylor expanded in x around 0
Applied rewrites46.5%
Taylor expanded in x around 0
Applied rewrites46.5%
(FPCore (x y) :precision binary64 (/ (+ (+ x y) 1.0) (* (+ x y) (* (+ x y) (+ x y)))))
double code(double x, double y) {
return ((x + y) + 1.0) / ((x + y) * ((x + y) * (x + y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + y) + 1.0d0) / ((x + y) * ((x + y) * (x + y)))
end function
public static double code(double x, double y) {
return ((x + y) + 1.0) / ((x + y) * ((x + y) * (x + y)));
}
def code(x, y): return ((x + y) + 1.0) / ((x + y) * ((x + y) * (x + y)))
function code(x, y) return Float64(Float64(Float64(x + y) + 1.0) / Float64(Float64(x + y) * Float64(Float64(x + y) * Float64(x + y)))) end
function tmp = code(x, y) tmp = ((x + y) + 1.0) / ((x + y) * ((x + y) * (x + y))); end
code[x_, y_] := N[(N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(N[(x + y), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) + 1}{\left(x + y\right) \cdot \left(\left(x + y\right) \cdot \left(x + y\right)\right)}
\end{array}
Initial program 70.5%
Taylor expanded in x around 0
Applied rewrites43.6%
Taylor expanded in x around 0
Applied rewrites37.0%
Taylor expanded in x around 0
Applied rewrites43.5%
(FPCore (x y) :precision binary64 (/ (+ (+ x y) 1.0) (* (+ x y) (+ x y))))
double code(double x, double y) {
return ((x + y) + 1.0) / ((x + y) * (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + y) + 1.0d0) / ((x + y) * (x + y))
end function
public static double code(double x, double y) {
return ((x + y) + 1.0) / ((x + y) * (x + y));
}
def code(x, y): return ((x + y) + 1.0) / ((x + y) * (x + y))
function code(x, y) return Float64(Float64(Float64(x + y) + 1.0) / Float64(Float64(x + y) * Float64(x + y))) end
function tmp = code(x, y) tmp = ((x + y) + 1.0) / ((x + y) * (x + y)); end
code[x_, y_] := N[(N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) + 1}{\left(x + y\right) \cdot \left(x + y\right)}
\end{array}
Initial program 70.5%
Taylor expanded in x around 0
Applied rewrites43.6%
Taylor expanded in x around 0
Applied rewrites37.0%
(FPCore (x y) :precision binary64 (* x y))
double code(double x, double y) {
return x * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * y
end function
public static double code(double x, double y) {
return x * y;
}
def code(x, y): return x * y
function code(x, y) return Float64(x * y) end
function tmp = code(x, y) tmp = x * y; end
code[x_, y_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 70.5%
Taylor expanded in x around 0
Applied rewrites3.7%
(FPCore (x y) :precision binary64 (+ x y))
double code(double x, double y) {
return x + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + y
end function
public static double code(double x, double y) {
return x + y;
}
def code(x, y): return x + y
function code(x, y) return Float64(x + y) end
function tmp = code(x, y) tmp = x + y; end
code[x_, y_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
\\
x + y
\end{array}
Initial program 70.5%
Taylor expanded in x around 0
Applied rewrites2.4%
Taylor expanded in x around 0
Applied rewrites2.7%
(FPCore (x y) :precision binary64 (/ (/ (/ x (+ (+ y 1.0) x)) (+ y x)) (/ 1.0 (/ y (+ y x)))))
double code(double x, double y) {
return ((x / ((y + 1.0) + x)) / (y + x)) / (1.0 / (y / (y + x)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x / ((y + 1.0d0) + x)) / (y + x)) / (1.0d0 / (y / (y + x)))
end function
public static double code(double x, double y) {
return ((x / ((y + 1.0) + x)) / (y + x)) / (1.0 / (y / (y + x)));
}
def code(x, y): return ((x / ((y + 1.0) + x)) / (y + x)) / (1.0 / (y / (y + x)))
function code(x, y) return Float64(Float64(Float64(x / Float64(Float64(y + 1.0) + x)) / Float64(y + x)) / Float64(1.0 / Float64(y / Float64(y + x)))) end
function tmp = code(x, y) tmp = ((x / ((y + 1.0) + x)) / (y + x)) / (1.0 / (y / (y + x))); end
code[x_, y_] := N[(N[(N[(x / N[(N[(y + 1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision] / N[(1.0 / N[(y / N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{x}{\left(y + 1\right) + x}}{y + x}}{\frac{1}{\frac{y}{y + x}}}
\end{array}
herbie shell --seed 2024313
(FPCore (x y)
:name "Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, A"
:precision binary64
:alt
(! :herbie-platform default (/ (/ (/ x (+ (+ y 1) x)) (+ y x)) (/ 1 (/ y (+ y x)))))
(/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))