Average Error: 21.5 → 0.1
Time: 6.4s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := 1 - \frac{\left(1 - x\right) \cdot y}{1 + y}\\ t_1 := \frac{y}{1 + y}\\ \mathbf{if}\;t_0 \leq -0.00029284299176612905:\\ \;\;\;\;\begin{array}{l} t_2 := \sqrt[3]{1 + y}\\ \mathsf{fma}\left(1, \mathsf{fma}\left(t_1, x, 1\right), -\frac{\sqrt[3]{y}}{t_2} \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{t_2 \cdot t_2}\right) + \sqrt[3]{0} \end{array}\\ \mathbf{elif}\;t_0 \leq 3.736924492070415 \cdot 10^{-8}:\\ \;\;\;\;\left(\left(x + \frac{x}{y \cdot y}\right) + \frac{1}{{y}^{3}}\right) - \left(\frac{x}{{y}^{3}} + \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot t_1 + \left(1 - t_1\right)\\ \end{array} \]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := 1 - \frac{\left(1 - x\right) \cdot y}{1 + y}\\
t_1 := \frac{y}{1 + y}\\
\mathbf{if}\;t_0 \leq -0.00029284299176612905:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt[3]{1 + y}\\
\mathsf{fma}\left(1, \mathsf{fma}\left(t_1, x, 1\right), -\frac{\sqrt[3]{y}}{t_2} \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{t_2 \cdot t_2}\right) + \sqrt[3]{0}
\end{array}\\

\mathbf{elif}\;t_0 \leq 3.736924492070415 \cdot 10^{-8}:\\
\;\;\;\;\left(\left(x + \frac{x}{y \cdot y}\right) + \frac{1}{{y}^{3}}\right) - \left(\frac{x}{{y}^{3}} + \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot t_1 + \left(1 - t_1\right)\\


\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 (/ (* (- 1.0 x) y) (+ 1.0 y)))) (t_1 (/ y (+ 1.0 y))))
   (if (<= t_0 -0.00029284299176612905)
     (let* ((t_2 (cbrt (+ 1.0 y))))
       (+
        (fma
         1.0
         (fma t_1 x 1.0)
         (- (* (/ (cbrt y) t_2) (/ (* (cbrt y) (cbrt y)) (* t_2 t_2)))))
        (cbrt 0.0)))
     (if (<= t_0 3.736924492070415e-8)
       (-
        (+ (+ x (/ x (* y y))) (/ 1.0 (pow y 3.0)))
        (+ (/ x (pow y 3.0)) (+ (/ 1.0 (* y y)) (/ (+ x -1.0) y))))
       (+ (* x t_1) (- 1.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 - (((1.0 - x) * y) / (1.0 + y));
	double t_1 = y / (1.0 + y);
	double tmp;
	if (t_0 <= -0.00029284299176612905) {
		double t_2_1 = cbrt(1.0 + y);
		tmp = fma(1.0, fma(t_1, x, 1.0), -((cbrt(y) / t_2_1) * ((cbrt(y) * cbrt(y)) / (t_2_1 * t_2_1)))) + cbrt(0.0);
	} else if (t_0 <= 3.736924492070415e-8) {
		tmp = ((x + (x / (y * y))) + (1.0 / pow(y, 3.0))) - ((x / pow(y, 3.0)) + ((1.0 / (y * y)) + ((x + -1.0) / y)));
	} else {
		tmp = (x * t_1) + (1.0 - t_1);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Target

Original21.5
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 3 regimes
  2. if (-.f64 1 (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1))) < -2.9284299176613e-4

    1. Initial program 20.2

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{1 + y}, x, 1\right) - \frac{y}{1 + y}} \]
    5. Applied add-cube-cbrt_binary640.1

      \[\leadsto \mathsf{fma}\left(\frac{y}{1 + y}, x, 1\right) - \frac{y}{\color{blue}{\left(\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}\right) \cdot \sqrt[3]{1 + y}}} \]
    6. Applied add-cube-cbrt_binary640.1

      \[\leadsto \mathsf{fma}\left(\frac{y}{1 + y}, x, 1\right) - \frac{\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}}{\left(\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}\right) \cdot \sqrt[3]{1 + y}} \]
    7. Applied times-frac_binary640.1

      \[\leadsto \mathsf{fma}\left(\frac{y}{1 + y}, x, 1\right) - \color{blue}{\frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}} \cdot \frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}}} \]
    8. Applied *-un-lft-identity_binary640.1

      \[\leadsto \color{blue}{1 \cdot \mathsf{fma}\left(\frac{y}{1 + y}, x, 1\right)} - \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}} \cdot \frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}} \]
    9. Applied prod-diff_binary640.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \mathsf{fma}\left(\frac{y}{1 + y}, x, 1\right), -\frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}} \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}\right) + \mathsf{fma}\left(-\frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}}, \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}, \frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}} \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}\right)} \]
    10. Applied add-cbrt-cube_binary640.1

      \[\leadsto \mathsf{fma}\left(1, \mathsf{fma}\left(\frac{y}{1 + y}, x, 1\right), -\frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}} \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}\right) + \color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(-\frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}}, \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}, \frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}} \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}\right) \cdot \mathsf{fma}\left(-\frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}}, \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}, \frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}} \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}\right)\right) \cdot \mathsf{fma}\left(-\frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}}, \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}, \frac{\sqrt[3]{y}}{\sqrt[3]{1 + y}} \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{1 + y} \cdot \sqrt[3]{1 + y}}\right)}} \]
    11. Simplified0.1

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

    if -2.9284299176613e-4 < (-.f64 1 (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1))) < 3.7369244921e-8

    1. Initial program 59.1

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

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

      \[\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. Simplified0.0

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

    if 3.7369244921e-8 < (-.f64 1 (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)))

    1. Initial program 6.4

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{y}{1 + y} \cdot x + 1\right)} - \frac{y}{1 + y} \]
    6. Applied associate--l+_binary640.1

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

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

Reproduce

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