Average Error: 22.6 → 0.1
Time: 4.1s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\ t_1 := \mathsf{fma}\left(1 - x, \frac{y}{-1 - y}, 1\right)\\ \mathbf{if}\;t_0 \leq 0.46900552544123797:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 1.0000021235299896:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} + \left(\mathsf{fma}\left(x, {y}^{-2}, x\right) + {y}^{-3}\right), \frac{-x}{y} - \mathsf{fma}\left(x, {y}^{-3}, {y}^{-2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (- 1.0 x) y) (+ 1.0 y)))
        (t_1 (fma (- 1.0 x) (/ y (- -1.0 y)) 1.0)))
   (if (<= t_0 0.46900552544123797)
     t_1
     (if (<= t_0 1.0000021235299896)
       (fma
        1.0
        (+ (/ 1.0 y) (+ (fma x (pow y -2.0) x) (pow y -3.0)))
        (- (/ (- x) y) (fma x (pow y -3.0) (pow y -2.0))))
       t_1))))
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 = ((1.0 - x) * y) / (1.0 + y);
	double t_1 = fma((1.0 - x), (y / (-1.0 - y)), 1.0);
	double tmp;
	if (t_0 <= 0.46900552544123797) {
		tmp = t_1;
	} else if (t_0 <= 1.0000021235299896) {
		tmp = fma(1.0, ((1.0 / y) + (fma(x, pow(y, -2.0), x) + pow(y, -3.0))), ((-x / y) - fma(x, pow(y, -3.0), pow(y, -2.0))));
	} else {
		tmp = t_1;
	}
	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(Float64(Float64(1.0 - x) * y) / Float64(1.0 + y))
	t_1 = fma(Float64(1.0 - x), Float64(y / Float64(-1.0 - y)), 1.0)
	tmp = 0.0
	if (t_0 <= 0.46900552544123797)
		tmp = t_1;
	elseif (t_0 <= 1.0000021235299896)
		tmp = fma(1.0, Float64(Float64(1.0 / y) + Float64(fma(x, (y ^ -2.0), x) + (y ^ -3.0))), Float64(Float64(Float64(-x) / y) - fma(x, (y ^ -3.0), (y ^ -2.0))));
	else
		tmp = t_1;
	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[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 - x), $MachinePrecision] * N[(y / N[(-1.0 - y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[t$95$0, 0.46900552544123797], t$95$1, If[LessEqual[t$95$0, 1.0000021235299896], N[(1.0 * N[(N[(1.0 / y), $MachinePrecision] + N[(N[(x * N[Power[y, -2.0], $MachinePrecision] + x), $MachinePrecision] + N[Power[y, -3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[((-x) / y), $MachinePrecision] - N[(x * N[Power[y, -3.0], $MachinePrecision] + N[Power[y, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
t_1 := \mathsf{fma}\left(1 - x, \frac{y}{-1 - y}, 1\right)\\
\mathbf{if}\;t_0 \leq 0.46900552544123797:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 1.0000021235299896:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} + \left(\mathsf{fma}\left(x, {y}^{-2}, x\right) + {y}^{-3}\right), \frac{-x}{y} - \mathsf{fma}\left(x, {y}^{-3}, {y}^{-2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Target

Original22.6
Target0.2
Herbie0.1
\[\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.46900552544123797 or 1.0000021235299896 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1))

    1. Initial program 11.1

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

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

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

    1. Initial program 58.3

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

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

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

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

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

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

Reproduce

herbie shell --seed 2022153 
(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))))