
(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 22 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 (/ (* (/ y (+ y (+ 1.0 x))) (/ x (+ y x))) (+ y x)))
double code(double x, double y) {
return ((y / (y + (1.0 + x))) * (x / (y + x))) / (y + x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((y / (y + (1.0d0 + x))) * (x / (y + x))) / (y + x)
end function
public static double code(double x, double y) {
return ((y / (y + (1.0 + x))) * (x / (y + x))) / (y + x);
}
def code(x, y): return ((y / (y + (1.0 + x))) * (x / (y + x))) / (y + x)
function code(x, y) return Float64(Float64(Float64(y / Float64(y + Float64(1.0 + x))) * Float64(x / Float64(y + x))) / Float64(y + x)) end
function tmp = code(x, y) tmp = ((y / (y + (1.0 + x))) * (x / (y + x))) / (y + x); end
code[x_, y_] := N[(N[(N[(y / N[(y + N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{y}{y + \left(1 + x\right)} \cdot \frac{x}{y + x}}{y + x}
\end{array}
Initial program 64.7%
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
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (+ y x))) (t_1 (+ y (+ 1.0 x))))
(if (<= x -1.4e+154)
(/ (* (/ y t_1) 1.0) (+ y x))
(if (<= x -4e-239)
(* t_0 (/ y (* t_1 (+ y x))))
(/ t_0 (+ 1.0 (fma x (+ 2.0 (/ 1.0 y)) y)))))))
double code(double x, double y) {
double t_0 = x / (y + x);
double t_1 = y + (1.0 + x);
double tmp;
if (x <= -1.4e+154) {
tmp = ((y / t_1) * 1.0) / (y + x);
} else if (x <= -4e-239) {
tmp = t_0 * (y / (t_1 * (y + x)));
} else {
tmp = t_0 / (1.0 + fma(x, (2.0 + (1.0 / y)), y));
}
return tmp;
}
function code(x, y) t_0 = Float64(x / Float64(y + x)) t_1 = Float64(y + Float64(1.0 + x)) tmp = 0.0 if (x <= -1.4e+154) tmp = Float64(Float64(Float64(y / t_1) * 1.0) / Float64(y + x)); elseif (x <= -4e-239) tmp = Float64(t_0 * Float64(y / Float64(t_1 * Float64(y + x)))); else tmp = Float64(t_0 / Float64(1.0 + fma(x, Float64(2.0 + Float64(1.0 / y)), y))); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y + N[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.4e+154], N[(N[(N[(y / t$95$1), $MachinePrecision] * 1.0), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -4e-239], N[(t$95$0 * N[(y / N[(t$95$1 * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(1.0 + N[(x * N[(2.0 + N[(1.0 / y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y + x}\\
t_1 := y + \left(1 + x\right)\\
\mathbf{if}\;x \leq -1.4 \cdot 10^{+154}:\\
\;\;\;\;\frac{\frac{y}{t\_1} \cdot 1}{y + x}\\
\mathbf{elif}\;x \leq -4 \cdot 10^{-239}:\\
\;\;\;\;t\_0 \cdot \frac{y}{t\_1 \cdot \left(y + x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{1 + \mathsf{fma}\left(x, 2 + \frac{1}{y}, y\right)}\\
\end{array}
\end{array}
if x < -1.4e154Initial program 56.7%
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
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites87.0%
if -1.4e154 < x < -4.0000000000000003e-239Initial program 75.5%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-/.f6497.9
Applied rewrites97.9%
if -4.0000000000000003e-239 < x Initial program 68.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
lower-*.f64N/A
lower-/.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
clear-numN/A
frac-timesN/A
lift-/.f64N/A
clear-numN/A
div-invN/A
clear-numN/A
lift-/.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f6499.4
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.4
Applied rewrites99.4%
Taylor expanded in x around 0
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-/.f6477.7
Applied rewrites77.7%
Final simplification85.3%
(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 2024228
(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))))