Average Error: 21.8 → 0.2
Time: 19.2s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -109215276.02048766613006591796875 \lor \neg \left(y \le 122797968.69595600664615631103515625\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x - 1}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right), y, 1\right)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -109215276.02048766613006591796875 \lor \neg \left(y \le 122797968.69595600664615631103515625\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\

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

\end{array}
double f(double x, double y) {
        double r567584 = 1.0;
        double r567585 = x;
        double r567586 = r567584 - r567585;
        double r567587 = y;
        double r567588 = r567586 * r567587;
        double r567589 = r567587 + r567584;
        double r567590 = r567588 / r567589;
        double r567591 = r567584 - r567590;
        return r567591;
}

double f(double x, double y) {
        double r567592 = y;
        double r567593 = -109215276.02048767;
        bool r567594 = r567592 <= r567593;
        double r567595 = 122797968.695956;
        bool r567596 = r567592 <= r567595;
        double r567597 = !r567596;
        bool r567598 = r567594 || r567597;
        double r567599 = 1.0;
        double r567600 = 1.0;
        double r567601 = r567600 / r567592;
        double r567602 = x;
        double r567603 = r567602 / r567592;
        double r567604 = r567601 - r567603;
        double r567605 = fma(r567599, r567604, r567602);
        double r567606 = r567602 - r567599;
        double r567607 = r567592 * r567592;
        double r567608 = r567599 * r567599;
        double r567609 = r567607 - r567608;
        double r567610 = r567606 / r567609;
        double r567611 = r567592 - r567599;
        double r567612 = r567610 * r567611;
        double r567613 = fma(r567612, r567592, r567599);
        double r567614 = r567598 ? r567605 : r567613;
        return r567614;
}

Error

Bits error versus x

Bits error versus y

Target

Original21.8
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 < -109215276.02048767 or 122797968.695956 < y

    1. Initial program 45.3

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

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

      \[\leadsto \mathsf{fma}\left(\frac{x - 1}{\color{blue}{\frac{y \cdot y - 1 \cdot 1}{y - 1}}}, y, 1\right)\]
    5. Applied associate-/r/45.2

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

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

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

    if -109215276.02048767 < y < 122797968.695956

    1. Initial program 0.1

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

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

      \[\leadsto \mathsf{fma}\left(\frac{x - 1}{\color{blue}{\frac{y \cdot y - 1 \cdot 1}{y - 1}}}, y, 1\right)\]
    5. Applied associate-/r/0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -109215276.02048766613006591796875 \lor \neg \left(y \le 122797968.69595600664615631103515625\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x - 1}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right), y, 1\right)\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< y -3693.8482788297247) (- (/ 1 y) (- (/ x y) x)) (if (< y 6799310503.41891) (- 1 (/ (* (- 1 x) y) (+ y 1))) (- (/ 1 y) (- (/ x y) x))))

  (- 1 (/ (* (- 1 x) y) (+ y 1))))