Average Error: 22.0 → 0.7
Time: 3.5s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} \mathbf{if}\;\begin{array}{l} t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\ t_0 \leq 5.6689047161900774 \cdot 10^{-14} \lor \neg \left(t_0 \leq 1.0000000000000002\right) \end{array}:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{y}{1 + y}\\ \left(1 - t_1\right) + x \cdot t_1 \end{array}\\ \mathbf{else}:\\ \;\;\;\;\left(x + \left(\frac{x}{{y}^{2}} + \frac{1}{y}\right)\right) - \left(\frac{x}{y} + \frac{1}{{y}^{2}}\right)\\ \end{array} \]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;\begin{array}{l}
t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
t_0 \leq 5.6689047161900774 \cdot 10^{-14} \lor \neg \left(t_0 \leq 1.0000000000000002\right)
\end{array}:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{y}{1 + y}\\
\left(1 - t_1\right) + x \cdot t_1
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\left(x + \left(\frac{x}{{y}^{2}} + \frac{1}{y}\right)\right) - \left(\frac{x}{y} + \frac{1}{{y}^{2}}\right)\\


\end{array}
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (if (let* ((t_0 (/ (* (- 1.0 x) y) (+ 1.0 y))))
       (or (<= t_0 5.6689047161900774e-14) (not (<= t_0 1.0000000000000002))))
   (let* ((t_1 (/ y (+ 1.0 y)))) (+ (- 1.0 t_1) (* x t_1)))
   (- (+ x (+ (/ x (pow y 2.0)) (/ 1.0 y))) (+ (/ x y) (/ 1.0 (pow y 2.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 = ((1.0 - x) * y) / (1.0 + y);
	double tmp;
	if ((t_0 <= 5.6689047161900774e-14) || !(t_0 <= 1.0000000000000002)) {
		double t_1_1 = y / (1.0 + y);
		tmp = (1.0 - t_1_1) + (x * t_1_1);
	} else {
		tmp = (x + ((x / pow(y, 2.0)) + (1.0 / y))) - ((x / y) + (1.0 / pow(y, 2.0)));
	}
	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.7
\[\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 (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 5.6689047161900774e-14 or 1.00000000000000022 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1))

    1. Initial program 10.5

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

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

      \[\leadsto 1 - \color{blue}{\frac{y}{y + 1} \cdot \left(1 - x\right)} \]
    4. Using strategy rm
    5. Applied sub-neg_binary640.4

      \[\leadsto 1 - \frac{y}{y + 1} \cdot \color{blue}{\left(1 + \left(-x\right)\right)} \]
    6. Applied distribute-lft-in_binary640.4

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

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

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

    if 5.6689047161900774e-14 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 1.00000000000000022

    1. Initial program 57.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 5.6689047161900774 \cdot 10^{-14} \lor \neg \left(\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 1.0000000000000002\right):\\ \;\;\;\;\left(1 - \frac{y}{1 + y}\right) + x \cdot \frac{y}{1 + y}\\ \mathbf{else}:\\ \;\;\;\;\left(x + \left(\frac{x}{{y}^{2}} + \frac{1}{y}\right)\right) - \left(\frac{x}{y} + \frac{1}{{y}^{2}}\right)\\ \end{array} \]

Reproduce

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