Average Error: 22.6 → 0.2
Time: 37.6s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -160840129.4508117735385894775390625:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{elif}\;y \le 149371639.0268229544162750244140625:\\ \;\;\;\;\mathsf{fma}\left(-\left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right), \frac{y \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}}, \left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right) \cdot \frac{y \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}}\right) + \mathsf{fma}\left(1, 1, \frac{\left(-y\right) \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}} \cdot \left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -160840129.4508117735385894775390625:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\

\mathbf{elif}\;y \le 149371639.0268229544162750244140625:\\
\;\;\;\;\mathsf{fma}\left(-\left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right), \frac{y \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}}, \left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right) \cdot \frac{y \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}}\right) + \mathsf{fma}\left(1, 1, \frac{\left(-y\right) \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}} \cdot \left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\

\end{array}
double f(double x, double y) {
        double r26961566 = 1.0;
        double r26961567 = x;
        double r26961568 = r26961566 - r26961567;
        double r26961569 = y;
        double r26961570 = r26961568 * r26961569;
        double r26961571 = r26961569 + r26961566;
        double r26961572 = r26961570 / r26961571;
        double r26961573 = r26961566 - r26961572;
        return r26961573;
}

double f(double x, double y) {
        double r26961574 = y;
        double r26961575 = -160840129.45081177;
        bool r26961576 = r26961574 <= r26961575;
        double r26961577 = 1.0;
        double r26961578 = 1.0;
        double r26961579 = r26961578 / r26961574;
        double r26961580 = x;
        double r26961581 = r26961580 / r26961574;
        double r26961582 = r26961579 - r26961581;
        double r26961583 = fma(r26961577, r26961582, r26961580);
        double r26961584 = 149371639.02682295;
        bool r26961585 = r26961574 <= r26961584;
        double r26961586 = r26961577 * r26961577;
        double r26961587 = r26961577 * r26961574;
        double r26961588 = r26961586 - r26961587;
        double r26961589 = r26961574 * r26961574;
        double r26961590 = r26961588 + r26961589;
        double r26961591 = -r26961590;
        double r26961592 = r26961577 - r26961580;
        double r26961593 = r26961574 * r26961592;
        double r26961594 = 3.0;
        double r26961595 = pow(r26961574, r26961594);
        double r26961596 = pow(r26961577, r26961594);
        double r26961597 = r26961595 + r26961596;
        double r26961598 = r26961593 / r26961597;
        double r26961599 = r26961590 * r26961598;
        double r26961600 = fma(r26961591, r26961598, r26961599);
        double r26961601 = -r26961574;
        double r26961602 = r26961601 * r26961592;
        double r26961603 = r26961602 / r26961597;
        double r26961604 = r26961603 * r26961590;
        double r26961605 = fma(r26961578, r26961577, r26961604);
        double r26961606 = r26961600 + r26961605;
        double r26961607 = r26961585 ? r26961606 : r26961583;
        double r26961608 = r26961576 ? r26961583 : r26961607;
        return r26961608;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.6
Target0.2
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;y \lt -3693.848278829724677052581682801246643066:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y \lt 6799310503.41891002655029296875:\\ \;\;\;\;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 < -160840129.45081177 or 149371639.02682295 < y

    1. Initial program 45.7

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)}\]

    if -160840129.45081177 < y < 149371639.02682295

    1. Initial program 0.2

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

      \[\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/0.2

      \[\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. Applied *-un-lft-identity0.2

      \[\leadsto \color{blue}{1 \cdot 1} - \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)\]
    6. Applied prod-diff0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -160840129.4508117735385894775390625:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{elif}\;y \le 149371639.0268229544162750244140625:\\ \;\;\;\;\mathsf{fma}\left(-\left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right), \frac{y \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}}, \left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right) \cdot \frac{y \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}}\right) + \mathsf{fma}\left(1, 1, \frac{\left(-y\right) \cdot \left(1 - x\right)}{{y}^{3} + {1}^{3}} \cdot \left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, D"

  :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))))