Average Error: 22.2 → 7.8
Time: 5.5s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \leq -3.599159768620087 \cdot 10^{+23}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.8902435904584662 \cdot 10^{+30}:\\ \;\;\;\;1 - \frac{y \cdot \left(1 - x\right)}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -3.599159768620087 \cdot 10^{+23}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 1.8902435904584662 \cdot 10^{+30}:\\
\;\;\;\;1 - \frac{y \cdot \left(1 - x\right)}{y + 1}\\

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (if (<= y -3.599159768620087e+23)
   x
   (if (<= y 1.8902435904584662e+30) (- 1.0 (/ (* y (- 1.0 x)) (+ y 1.0))) x)))
double code(double x, double y) {
	return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
double code(double x, double y) {
	double tmp;
	if (y <= -3.599159768620087e+23) {
		tmp = x;
	} else if (y <= 1.8902435904584662e+30) {
		tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0));
	} else {
		tmp = x;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original22.2
Target0.2
Herbie7.8
\[\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 < -3.59915976862008701e23 or 1.89024359045846623e30 < y

    1. Initial program 46.7

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
    2. Taylor expanded around inf 15.3

      \[\leadsto \color{blue}{x}\]

    if -3.59915976862008701e23 < y < 1.89024359045846623e30

    1. Initial program 1.6

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification7.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.599159768620087 \cdot 10^{+23}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.8902435904584662 \cdot 10^{+30}:\\ \;\;\;\;1 - \frac{y \cdot \left(1 - x\right)}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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