Average Error: 22.7 → 0.1
Time: 4.4s
Precision: binary64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\ t_1 := \frac{y}{1 + y}\\ \mathbf{if}\;t_0 \leq 0.8836801561647109:\\ \;\;\;\;1 + t_1 \cdot \left(x + -1\right)\\ \mathbf{elif}\;t_0 \leq 1.0000000994880573:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\left(x + \frac{x}{y \cdot y}\right) + \left(\frac{1 - x}{{y}^{3}} - \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot t_1 + \left(1 - t_1\right)\\ \end{array} \]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
t_1 := \frac{y}{1 + y}\\
\mathbf{if}\;t_0 \leq 0.8836801561647109:\\
\;\;\;\;1 + t_1 \cdot \left(x + -1\right)\\

\mathbf{elif}\;t_0 \leq 1.0000000994880573:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\left(x + \frac{x}{y \cdot y}\right) + \left(\frac{1 - x}{{y}^{3}} - \left(\frac{1}{y \cdot y} + \frac{x + -1}{y}\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot t_1 + \left(1 - t_1\right)\\


\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 x) y) (+ 1.0 y))) (t_1 (/ y (+ 1.0 y))))
   (if (<= t_0 0.8836801561647109)
     (+ 1.0 (* t_1 (+ x -1.0)))
     (if (<= t_0 1.0000000994880573)
       (log1p
        (expm1
         (+
          (+ x (/ x (* y y)))
          (- (/ (- 1.0 x) (pow y 3.0)) (+ (/ 1.0 (* y y)) (/ (+ x -1.0) y))))))
       (+ (* x t_1) (- 1.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 - x) * y) / (1.0 + y);
	double t_1 = y / (1.0 + y);
	double tmp;
	if (t_0 <= 0.8836801561647109) {
		tmp = 1.0 + (t_1 * (x + -1.0));
	} else if (t_0 <= 1.0000000994880573) {
		tmp = log1p(expm1((x + (x / (y * y))) + (((1.0 - x) / pow(y, 3.0)) - ((1.0 / (y * y)) + ((x + -1.0) / y)))));
	} else {
		tmp = (x * t_1) + (1.0 - t_1);
	}
	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.7
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 (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 0.88368015616471085

    1. Initial program 7.3

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

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

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

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

    if 0.88368015616471085 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 1.0000000994880573

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{x + -1}{1 + y}, 1\right)} \]
    3. Taylor expanded in y around inf 0.2

      \[\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.2

      \[\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. Applied log1p-expm1-u_binary640.2

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\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)\right)\right)} \]
    6. Simplified0.2

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

    if 1.0000000994880573 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1))

    1. Initial program 20.8

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

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

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

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

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

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

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

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

Reproduce

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