Average Error: 20.0 → 4.4
Time: 5.2s
Precision: binary64
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2.325223106310958 \cdot 10^{+87}:\\ \;\;\;\;\frac{y}{x \cdot x}\\ \mathbf{elif}\;x \leq -5.005665752085898 \cdot 10^{+33}:\\ \;\;\;\;y \cdot \frac{x}{{\left(x + y\right)}^{3} + {\left(x + y\right)}^{2}}\\ \mathbf{elif}\;x \leq 6.342776204927889 \cdot 10^{-11}:\\ \;\;\;\;\frac{x}{\left(\mathsf{fma}\left(y, y, \frac{x}{\frac{y}{x}}\right) + \left(\mathsf{fma}\left(3, x \cdot x, x \cdot 2\right) + x \cdot \frac{x \cdot x}{y}\right)\right) + \mathsf{fma}\left(3, x \cdot y, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{y}\\ \end{array} \]
(FPCore (x y)
 :precision binary64
 (/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))
(FPCore (x y)
 :precision binary64
 (if (<= x -2.325223106310958e+87)
   (/ y (* x x))
   (if (<= x -5.005665752085898e+33)
     (* y (/ x (+ (pow (+ x y) 3.0) (pow (+ x y) 2.0))))
     (if (<= x 6.342776204927889e-11)
       (/
        x
        (+
         (+
          (fma y y (/ x (/ y x)))
          (+ (fma 3.0 (* x x) (* x 2.0)) (* x (/ (* x x) y))))
         (fma 3.0 (* x y) y)))
       (/ (/ x y) y)))))
double code(double x, double y) {
	return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
double code(double x, double y) {
	double tmp;
	if (x <= -2.325223106310958e+87) {
		tmp = y / (x * x);
	} else if (x <= -5.005665752085898e+33) {
		tmp = y * (x / (pow((x + y), 3.0) + pow((x + y), 2.0)));
	} else if (x <= 6.342776204927889e-11) {
		tmp = x / ((fma(y, y, (x / (y / x))) + (fma(3.0, (x * x), (x * 2.0)) + (x * ((x * x) / y)))) + fma(3.0, (x * y), y));
	} else {
		tmp = (x / y) / y;
	}
	return tmp;
}
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 code(x, y)
	tmp = 0.0
	if (x <= -2.325223106310958e+87)
		tmp = Float64(y / Float64(x * x));
	elseif (x <= -5.005665752085898e+33)
		tmp = Float64(y * Float64(x / Float64((Float64(x + y) ^ 3.0) + (Float64(x + y) ^ 2.0))));
	elseif (x <= 6.342776204927889e-11)
		tmp = Float64(x / Float64(Float64(fma(y, y, Float64(x / Float64(y / x))) + Float64(fma(3.0, Float64(x * x), Float64(x * 2.0)) + Float64(x * Float64(Float64(x * x) / y)))) + fma(3.0, Float64(x * y), y)));
	else
		tmp = Float64(Float64(x / y) / y);
	end
	return tmp
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]
code[x_, y_] := If[LessEqual[x, -2.325223106310958e+87], N[(y / N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -5.005665752085898e+33], N[(y * N[(x / N[(N[Power[N[(x + y), $MachinePrecision], 3.0], $MachinePrecision] + N[Power[N[(x + y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.342776204927889e-11], N[(x / N[(N[(N[(y * y + N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(3.0 * N[(x * x), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] + N[(x * N[(N[(x * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(3.0 * N[(x * y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision]]]]
\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)}
\begin{array}{l}
\mathbf{if}\;x \leq -2.325223106310958 \cdot 10^{+87}:\\
\;\;\;\;\frac{y}{x \cdot x}\\

\mathbf{elif}\;x \leq -5.005665752085898 \cdot 10^{+33}:\\
\;\;\;\;y \cdot \frac{x}{{\left(x + y\right)}^{3} + {\left(x + y\right)}^{2}}\\

\mathbf{elif}\;x \leq 6.342776204927889 \cdot 10^{-11}:\\
\;\;\;\;\frac{x}{\left(\mathsf{fma}\left(y, y, \frac{x}{\frac{y}{x}}\right) + \left(\mathsf{fma}\left(3, x \cdot x, x \cdot 2\right) + x \cdot \frac{x \cdot x}{y}\right)\right) + \mathsf{fma}\left(3, x \cdot y, y\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{y}}{y}\\


\end{array}

Error

Bits error versus x

Bits error versus y

Target

Original20.0
Target0.1
Herbie4.4
\[\frac{\frac{\frac{x}{\left(y + 1\right) + x}}{y + x}}{\frac{1}{\frac{y}{y + x}}} \]

Derivation

  1. Split input into 4 regimes
  2. if x < -2.32522310631095813e87

    1. Initial program 25.3

      \[\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)} \]
    2. Simplified14.5

      \[\leadsto \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x + y, x + y, {\left(x + y\right)}^{3}\right)}{y}}} \]
    3. Taylor expanded in x around 0 62.5

      \[\leadsto \frac{x}{\color{blue}{3 \cdot \left(y \cdot x\right) + \left(\frac{{x}^{3}}{y} + \left(y + \left({y}^{2} + \left(\frac{{x}^{2}}{y} + \left(3 \cdot {x}^{2} + 2 \cdot x\right)\right)\right)\right)\right)}} \]
    4. Simplified62.3

      \[\leadsto \frac{x}{\color{blue}{\left(\mathsf{fma}\left(y, y, \frac{x}{\frac{y}{x}}\right) + \left(\mathsf{fma}\left(3, x \cdot x, 2 \cdot x\right) + \frac{{x}^{3}}{y}\right)\right) + \mathsf{fma}\left(3, y \cdot x, y\right)}} \]
    5. Taylor expanded in x around inf 10.9

      \[\leadsto \color{blue}{\frac{y}{{x}^{2}}} \]
    6. Simplified10.9

      \[\leadsto \color{blue}{\frac{y}{x \cdot x}} \]

    if -2.32522310631095813e87 < x < -5.00566575208589783e33

    1. Initial program 9.7

      \[\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)} \]
    2. Simplified13.6

      \[\leadsto \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x + y, x + y, {\left(x + y\right)}^{3}\right)}{y}}} \]
    3. Applied egg-rr6.1

      \[\leadsto \color{blue}{y \cdot \frac{x}{{\left(x + y\right)}^{3} + {\left(x + y\right)}^{2}}} \]

    if -5.00566575208589783e33 < x < 6.3427762049278892e-11

    1. Initial program 15.3

      \[\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)} \]
    2. Simplified8.9

      \[\leadsto \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x + y, x + y, {\left(x + y\right)}^{3}\right)}{y}}} \]
    3. Taylor expanded in x around 0 4.0

      \[\leadsto \frac{x}{\color{blue}{3 \cdot \left(y \cdot x\right) + \left(\frac{{x}^{3}}{y} + \left(y + \left({y}^{2} + \left(\frac{{x}^{2}}{y} + \left(3 \cdot {x}^{2} + 2 \cdot x\right)\right)\right)\right)\right)}} \]
    4. Simplified0.5

      \[\leadsto \frac{x}{\color{blue}{\left(\mathsf{fma}\left(y, y, \frac{x}{\frac{y}{x}}\right) + \left(\mathsf{fma}\left(3, x \cdot x, 2 \cdot x\right) + \frac{{x}^{3}}{y}\right)\right) + \mathsf{fma}\left(3, y \cdot x, y\right)}} \]
    5. Applied egg-rr0.5

      \[\leadsto \frac{x}{\left(\mathsf{fma}\left(y, y, \frac{x}{\frac{y}{x}}\right) + \left(\mathsf{fma}\left(3, x \cdot x, 2 \cdot x\right) + \color{blue}{\frac{x}{1} \cdot \frac{x \cdot x}{y}}\right)\right) + \mathsf{fma}\left(3, y \cdot x, y\right)} \]

    if 6.3427762049278892e-11 < x

    1. Initial program 42.9

      \[\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)} \]
    2. Simplified23.1

      \[\leadsto \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x + y, x + y, {\left(x + y\right)}^{3}\right)}{y}}} \]
    3. Taylor expanded in x around 0 16.0

      \[\leadsto \frac{x}{\color{blue}{3 \cdot \left(y \cdot x\right) + \left(\frac{{x}^{3}}{y} + \left(y + \left({y}^{2} + \left(\frac{{x}^{2}}{y} + \left(3 \cdot {x}^{2} + 2 \cdot x\right)\right)\right)\right)\right)}} \]
    4. Simplified16.0

      \[\leadsto \frac{x}{\color{blue}{\left(\mathsf{fma}\left(y, y, \frac{x}{\frac{y}{x}}\right) + \left(\mathsf{fma}\left(3, x \cdot x, 2 \cdot x\right) + \frac{{x}^{3}}{y}\right)\right) + \mathsf{fma}\left(3, y \cdot x, y\right)}} \]
    5. Taylor expanded in y around inf 15.9

      \[\leadsto \color{blue}{\frac{x}{{y}^{2}}} \]
    6. Simplified2.6

      \[\leadsto \color{blue}{\frac{\frac{x}{y}}{y}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification4.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.325223106310958 \cdot 10^{+87}:\\ \;\;\;\;\frac{y}{x \cdot x}\\ \mathbf{elif}\;x \leq -5.005665752085898 \cdot 10^{+33}:\\ \;\;\;\;y \cdot \frac{x}{{\left(x + y\right)}^{3} + {\left(x + y\right)}^{2}}\\ \mathbf{elif}\;x \leq 6.342776204927889 \cdot 10^{-11}:\\ \;\;\;\;\frac{x}{\left(\mathsf{fma}\left(y, y, \frac{x}{\frac{y}{x}}\right) + \left(\mathsf{fma}\left(3, x \cdot x, x \cdot 2\right) + x \cdot \frac{x \cdot x}{y}\right)\right) + \mathsf{fma}\left(3, x \cdot y, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{y}\\ \end{array} \]

Reproduce

herbie shell --seed 2022150 
(FPCore (x y)
  :name "Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, A"
  :precision binary64

  :herbie-target
  (/ (/ (/ x (+ (+ y 1.0) x)) (+ y x)) (/ 1.0 (/ y (+ y x))))

  (/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))