Average Error: 22.0 → 0.2
Time: 10.4s
Precision: binary64
Cost: 8322
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \leq -417680595896.5533:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 89866444.08949669:\\ \;\;\;\;1 - \left(y \cdot y + \left(1 - y\right)\right) \cdot \frac{y \cdot \left(1 - x\right)}{1 + {y}^{3}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1 - x}{y}\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -417680595896.5533:\\
\;\;\;\;x + \frac{1}{y}\\

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

\mathbf{else}:\\
\;\;\;\;x + \frac{1 - x}{y}\\

\end{array}
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (if (<= y -417680595896.5533)
   (+ x (/ 1.0 y))
   (if (<= y 89866444.08949669)
     (- 1.0 (* (+ (* y y) (- 1.0 y)) (/ (* y (- 1.0 x)) (+ 1.0 (pow y 3.0)))))
     (+ x (/ (- 1.0 x) y)))))
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 <= -417680595896.5533) {
		tmp = x + (1.0 / y);
	} else if (y <= 89866444.08949669) {
		tmp = 1.0 - (((y * y) + (1.0 - y)) * ((y * (1.0 - x)) / (1.0 + pow(y, 3.0))));
	} else {
		tmp = x + ((1.0 - x) / y);
	}
	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.0
Target0.2
Herbie0.2
\[\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}\]

Alternatives

Alternative 1
Error0.2
Cost8008
\[\begin{array}{l} \mathbf{if}\;y \leq -117890363.43949382 \lor \neg \left(y \leq 92900470.18977524\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(y \cdot y + \left(1 - y\right)\right) \cdot \frac{y \cdot x - y}{1 + {y}^{3}}\\ \end{array}\]
Alternative 2
Error0.5
Cost1346
\[\begin{array}{l} \mathbf{if}\;y \leq -1.280094041343982 \cdot 10^{+27}:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 263965039.3990486:\\ \;\;\;\;1 - \left(1 - x\right) \cdot \frac{y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1 - x}{y}\\ \end{array}\]
Alternative 3
Error0.8
Cost904
\[\begin{array}{l} \mathbf{if}\;y \leq -3287.1766333942314 \lor \neg \left(y \leq 3623128.183158912\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{y \cdot x}{y + 1}\\ \end{array}\]
Alternative 4
Error1.0
Cost776
\[\begin{array}{l} \mathbf{if}\;y \leq -0.9910596696419218 \lor \neg \left(y \leq 1.0219894613418068\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - y \cdot \left(1 - x\right)\\ \end{array}\]
Alternative 5
Error9.1
Cost776
\[\begin{array}{l} \mathbf{if}\;y \leq -0.9910596696419218 \lor \neg \left(y \leq 1.0219894613418068\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 6
Error9.3
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -0.9910596696419218 \lor \neg \left(y \leq 4.1713392357805543 \cdot 10^{-10}\right):\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 7
Error16.8
Cost706
\[\begin{array}{l} \mathbf{if}\;y \leq -0.9910596696419218:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.1713392357805543 \cdot 10^{-10}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
Alternative 8
Error38.9
Cost64
\[1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if y < -417680595896.553284

    1. Initial program 46.1

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
    2. Using strategy rm
    3. Applied flip-+_binary64_1846650.1

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

      \[\leadsto 1 - \color{blue}{\frac{\left(1 - x\right) \cdot y}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right)}\]
    5. Simplified50.2

      \[\leadsto 1 - \color{blue}{\frac{\left(1 - x\right) \cdot y}{y \cdot y - 1}} \cdot \left(y - 1\right)\]
    6. Taylor expanded around inf 0.0

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

      \[\leadsto \color{blue}{x + \frac{1 - x}{y}}\]
    8. Taylor expanded around 0 0.1

      \[\leadsto x + \color{blue}{\frac{1}{y}}\]
    9. Simplified0.1

      \[\leadsto \color{blue}{x + \frac{1}{y}}\]

    if -417680595896.553284 < y < 89866444.0894966871

    1. Initial program 0.2

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
    2. Using strategy rm
    3. Applied flip3-+_binary64_184950.3

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

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

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

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

    if 89866444.0894966871 < y

    1. Initial program 45.9

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
    2. Using strategy rm
    3. Applied flip-+_binary64_1846650.6

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

      \[\leadsto 1 - \color{blue}{\frac{\left(1 - x\right) \cdot y}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right)}\]
    5. Simplified50.6

      \[\leadsto 1 - \color{blue}{\frac{\left(1 - x\right) \cdot y}{y \cdot y - 1}} \cdot \left(y - 1\right)\]
    6. Taylor expanded around inf 0.1

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

      \[\leadsto \color{blue}{x + \frac{1 - x}{y}}\]
    8. Simplified0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -417680595896.5533:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 89866444.08949669:\\ \;\;\;\;1 - \left(y \cdot y + \left(1 - y\right)\right) \cdot \frac{y \cdot \left(1 - x\right)}{1 + {y}^{3}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1 - x}{y}\\ \end{array}\]

Reproduce

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