
(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 24 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}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (/ (* (/ (/ y (+ (+ y x) 1.0)) (+ y x)) x) (+ y x)))
assert(x < y);
double code(double x, double y) {
return (((y / ((y + x) + 1.0)) / (y + x)) * x) / (y + x);
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (((y / ((y + x) + 1.0d0)) / (y + x)) * x) / (y + x)
end function
assert x < y;
public static double code(double x, double y) {
return (((y / ((y + x) + 1.0)) / (y + x)) * x) / (y + x);
}
[x, y] = sort([x, y]) def code(x, y): return (((y / ((y + x) + 1.0)) / (y + x)) * x) / (y + x)
x, y = sort([x, y]) function code(x, y) return Float64(Float64(Float64(Float64(y / Float64(Float64(y + x) + 1.0)) / Float64(y + x)) * x) / Float64(y + x)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = (((y / ((y + x) + 1.0)) / (y + x)) * x) / (y + x);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(N[(N[(y / N[(N[(y + x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{\frac{\frac{y}{\left(y + x\right) + 1}}{y + x} \cdot x}{y + x}
\end{array}
Initial program 67.4%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
*-commutativeN/A
lift-*.f64N/A
associate-/r*N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites99.8%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
frac-timesN/A
*-commutativeN/A
*-lft-identityN/A
div-invN/A
clear-numN/A
lift-/.f64N/A
div-invN/A
clear-numN/A
lower-*.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Final simplification99.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 9.5e+159) (/ (* (/ y (+ y x)) x) (* (+ (+ 1.0 x) y) (+ y x))) (/ (/ x (+ y x)) (fma (+ 2.0 (/ 1.0 y)) x (+ 1.0 y)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 9.5e+159) {
tmp = ((y / (y + x)) * x) / (((1.0 + x) + y) * (y + x));
} else {
tmp = (x / (y + x)) / fma((2.0 + (1.0 / y)), x, (1.0 + y));
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 9.5e+159) tmp = Float64(Float64(Float64(y / Float64(y + x)) * x) / Float64(Float64(Float64(1.0 + x) + y) * Float64(y + x))); else tmp = Float64(Float64(x / Float64(y + x)) / fma(Float64(2.0 + Float64(1.0 / y)), x, Float64(1.0 + y))); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 9.5e+159], N[(N[(N[(y / N[(y + x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] / N[(N[(N[(1.0 + x), $MachinePrecision] + y), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision] / N[(N[(2.0 + N[(1.0 / y), $MachinePrecision]), $MachinePrecision] * x + N[(1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.5 \cdot 10^{+159}:\\
\;\;\;\;\frac{\frac{y}{y + x} \cdot x}{\left(\left(1 + x\right) + y\right) \cdot \left(y + x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{y + x}}{\mathsf{fma}\left(2 + \frac{1}{y}, x, 1 + y\right)}\\
\end{array}
\end{array}
if y < 9.5000000000000003e159Initial program 70.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
times-fracN/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6496.1
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f6496.1
lift-+.f64N/A
+-commutativeN/A
lower-+.f6496.1
Applied rewrites96.1%
if 9.5000000000000003e159 < y Initial program 63.9%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
*-commutativeN/A
lift-*.f64N/A
associate-/r*N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites99.9%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
frac-timesN/A
*-commutativeN/A
*-lft-identityN/A
div-invN/A
clear-numN/A
lift-/.f64N/A
div-invN/A
clear-numN/A
lower-*.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-+.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
lift-+.f64N/A
*-commutativeN/A
lift-*.f64N/A
Applied rewrites99.6%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f6493.4
Applied rewrites93.4%
Final simplification95.5%
(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 2024230
(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))))