Average Error: 22.2 → 0.3
Time: 4.2s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{y}{1 + y}\\ t_1 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\ t_2 := \frac{1}{1 + y} + \mathsf{fma}\left(-2, t_0, \mathsf{fma}\left(2, y \cdot {\left(1 + y\right)}^{-2}, \mathsf{fma}\left(2, {t_0}^{2}, x \cdot t_0\right)\right)\right)\\ \mathbf{if}\;t_1 \leq 0.98:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 1:\\ \;\;\;\;\left(\frac{1}{y} + \left(x + \frac{x}{{y}^{2}}\right)\right) - \left(\frac{x}{y} + \sqrt[3]{{y}^{-6}}\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ y (+ 1.0 y)))
        (t_1 (/ (* (- 1.0 x) y) (+ 1.0 y)))
        (t_2
         (+
          (/ 1.0 (+ 1.0 y))
          (fma
           -2.0
           t_0
           (fma
            2.0
            (* y (pow (+ 1.0 y) -2.0))
            (fma 2.0 (pow t_0 2.0) (* x t_0)))))))
   (if (<= t_1 0.98)
     t_2
     (if (<= t_1 1.0)
       (-
        (+ (/ 1.0 y) (+ x (/ x (pow y 2.0))))
        (+ (/ x y) (cbrt (pow y -6.0))))
       t_2))))
double code(double x, double y) {
	return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
double code(double x, double y) {
	double t_0 = y / (1.0 + y);
	double t_1 = ((1.0 - x) * y) / (1.0 + y);
	double t_2 = (1.0 / (1.0 + y)) + fma(-2.0, t_0, fma(2.0, (y * pow((1.0 + y), -2.0)), fma(2.0, pow(t_0, 2.0), (x * t_0))));
	double tmp;
	if (t_1 <= 0.98) {
		tmp = t_2;
	} else if (t_1 <= 1.0) {
		tmp = ((1.0 / y) + (x + (x / pow(y, 2.0)))) - ((x / y) + cbrt(pow(y, -6.0)));
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(x, y)
	return Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0)))
end
function code(x, y)
	t_0 = Float64(y / Float64(1.0 + y))
	t_1 = Float64(Float64(Float64(1.0 - x) * y) / Float64(1.0 + y))
	t_2 = Float64(Float64(1.0 / Float64(1.0 + y)) + fma(-2.0, t_0, fma(2.0, Float64(y * (Float64(1.0 + y) ^ -2.0)), fma(2.0, (t_0 ^ 2.0), Float64(x * t_0)))))
	tmp = 0.0
	if (t_1 <= 0.98)
		tmp = t_2;
	elseif (t_1 <= 1.0)
		tmp = Float64(Float64(Float64(1.0 / y) + Float64(x + Float64(x / (y ^ 2.0)))) - Float64(Float64(x / y) + cbrt((y ^ -6.0))));
	else
		tmp = t_2;
	end
	return tmp
end
code[x_, y_] := N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(1.0 / N[(1.0 + y), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * t$95$0 + N[(2.0 * N[(y * N[Power[N[(1.0 + y), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[Power[t$95$0, 2.0], $MachinePrecision] + N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.98], t$95$2, If[LessEqual[t$95$1, 1.0], N[(N[(N[(1.0 / y), $MachinePrecision] + N[(x + N[(x / N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] + N[Power[N[Power[y, -6.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{y}{1 + y}\\
t_1 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
t_2 := \frac{1}{1 + y} + \mathsf{fma}\left(-2, t_0, \mathsf{fma}\left(2, y \cdot {\left(1 + y\right)}^{-2}, \mathsf{fma}\left(2, {t_0}^{2}, x \cdot t_0\right)\right)\right)\\
\mathbf{if}\;t_1 \leq 0.98:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 1:\\
\;\;\;\;\left(\frac{1}{y} + \left(x + \frac{x}{{y}^{2}}\right)\right) - \left(\frac{x}{y} + \sqrt[3]{{y}^{-6}}\right)\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Bits error versus x

Bits error versus y

Target

Original22.2
Target0.2
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;y < -3693.8482788297247:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y < 6799310503.41891:\\ \;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 0.97999999999999998 or 1 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1))

    1. Initial program 10.7

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

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

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

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

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

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

    if 0.97999999999999998 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 1

    1. Initial program 59.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1 - x, \frac{y}{-1 - y}, 1\right)} \]
    3. Taylor expanded in y around inf 0.3

      \[\leadsto \color{blue}{\left(\frac{1}{y} + \left(\frac{x}{{y}^{2}} + x\right)\right) - \left(\frac{x}{y} + \frac{1}{{y}^{2}}\right)} \]
    4. Applied egg-rr0.3

      \[\leadsto \left(\frac{1}{y} + \left(\frac{x}{{y}^{2}} + x\right)\right) - \left(\frac{x}{y} + \color{blue}{\sqrt[3]{{y}^{-6}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 0.98:\\ \;\;\;\;\frac{1}{1 + y} + \mathsf{fma}\left(-2, \frac{y}{1 + y}, \mathsf{fma}\left(2, y \cdot {\left(1 + y\right)}^{-2}, \mathsf{fma}\left(2, {\left(\frac{y}{1 + y}\right)}^{2}, x \cdot \frac{y}{1 + y}\right)\right)\right)\\ \mathbf{elif}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 1:\\ \;\;\;\;\left(\frac{1}{y} + \left(x + \frac{x}{{y}^{2}}\right)\right) - \left(\frac{x}{y} + \sqrt[3]{{y}^{-6}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + y} + \mathsf{fma}\left(-2, \frac{y}{1 + y}, \mathsf{fma}\left(2, y \cdot {\left(1 + y\right)}^{-2}, \mathsf{fma}\left(2, {\left(\frac{y}{1 + y}\right)}^{2}, x \cdot \frac{y}{1 + y}\right)\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022156 
(FPCore (x y)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, D"
  :precision binary64

  :herbie-target
  (if (< y -3693.8482788297247) (- (/ 1.0 y) (- (/ x y) x)) (if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) (- (/ 1.0 y) (- (/ x y) x))))

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