Average Error: 22.5 → 0.1
Time: 17.1s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{1}{y \cdot y}\\ t_1 := \frac{x}{{y}^{3}} + \left(t_0 + \frac{x + -1}{y}\right)\\ \mathbf{if}\;y \leq -115615.37911247845:\\ \;\;\;\;\left(\left(x + \frac{x}{y \cdot y}\right) + \frac{1}{{y}^{3}}\right) - t_1\\ \mathbf{elif}\;y \leq 225276.2828618436:\\ \;\;\;\;1 + \frac{y - y \cdot x}{\mathsf{fma}\left(y, y, -1\right)} \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + t_0\right) - t_1\\ \end{array} \]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{1}{y \cdot y}\\
t_1 := \frac{x}{{y}^{3}} + \left(t_0 + \frac{x + -1}{y}\right)\\
\mathbf{if}\;y \leq -115615.37911247845:\\
\;\;\;\;\left(\left(x + \frac{x}{y \cdot y}\right) + \frac{1}{{y}^{3}}\right) - t_1\\

\mathbf{elif}\;y \leq 225276.2828618436:\\
\;\;\;\;1 + \frac{y - y \cdot x}{\mathsf{fma}\left(y, y, -1\right)} \cdot \left(1 - y\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + t_0\right) - 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 (* y y)))
        (t_1 (+ (/ x (pow y 3.0)) (+ t_0 (/ (+ x -1.0) y)))))
   (if (<= y -115615.37911247845)
     (- (+ (+ x (/ x (* y y))) (/ 1.0 (pow y 3.0))) t_1)
     (if (<= y 225276.2828618436)
       (+ 1.0 (* (/ (- y (* y x)) (fma y y -1.0)) (- 1.0 y)))
       (- (* x (+ 1.0 t_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 / (y * y);
	double t_1 = (x / pow(y, 3.0)) + (t_0 + ((x + -1.0) / y));
	double tmp;
	if (y <= -115615.37911247845) {
		tmp = ((x + (x / (y * y))) + (1.0 / pow(y, 3.0))) - t_1;
	} else if (y <= 225276.2828618436) {
		tmp = 1.0 + (((y - (y * x)) / fma(y, y, -1.0)) * (1.0 - y));
	} else {
		tmp = (x * (1.0 + t_0)) - t_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.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 y < -115615.379112478447

    1. Initial program 45.6

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

      \[\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 -115615.379112478447 < y < 225276.28286184359

    1. Initial program 0.1

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

      \[\leadsto 1 - \frac{\left(1 - x\right) \cdot y}{\color{blue}{\frac{y \cdot y - 1 \cdot 1}{y - 1}}} \]
    3. Applied associate-/r/_binary640.1

      \[\leadsto 1 - \color{blue}{\frac{\left(1 - x\right) \cdot y}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right)} \]
    4. Applied add-cube-cbrt_binary640.1

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

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

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

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

    if 225276.28286184359 < y

    1. Initial program 45.5

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

      \[\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)} \]
    5. Taylor expanded in x around inf 0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -115615.37911247845:\\ \;\;\;\;\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{elif}\;y \leq 225276.2828618436:\\ \;\;\;\;1 + \frac{y - y \cdot x}{\mathsf{fma}\left(y, y, -1\right)} \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + \frac{1}{y \cdot y}\right) - \left(\frac{x}{{y}^{3}} + \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\right)\\ \end{array} \]

Reproduce

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