Average Error: 21.6 → 0.1
Time: 5.7s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \left(x + \frac{x}{y \cdot y}\right) - \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\\ \mathbf{if}\;y \leq -62022563495.775696:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 227470.4123231271:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x + -1}{y + 1}, 1\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \left(x + \frac{x}{y \cdot y}\right) - \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\\
\mathbf{if}\;y \leq -62022563495.775696:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- (+ x (/ x (* y y))) (+ (/ 1.0 (* y y)) (/ (+ x -1.0) y)))))
   (if (<= y -62022563495.775696)
     t_0
     (if (<= y 227470.4123231271) (fma y (/ (+ x -1.0) (+ y 1.0)) 1.0) t_0))))
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 = (x + (x / (y * y))) - ((1.0 / (y * y)) + ((x + -1.0) / y));
	double tmp;
	if (y <= -62022563495.775696) {
		tmp = t_0;
	} else if (y <= 227470.4123231271) {
		tmp = fma(y, ((x + -1.0) / (y + 1.0)), 1.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Target

Original21.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 y < -62022563495.775696 or 227470.41232312709 < y

    1. Initial program 44.4

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

      \[\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{x}{{y}^{2}} + x\right)\right) - \left(\frac{x}{y} + \frac{1}{{y}^{2}}\right)} \]
    4. Simplified0.0

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

    if -62022563495.775696 < y < 227470.41232312709

    1. Initial program 0.2

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

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

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

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

Reproduce

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