Average Error: 22.7 → 0.3
Time: 18.9s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -6690123426642433 \lor \neg \left(y \le 115382551.397061989\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x - 1}{{y}^{3} + {1}^{3}} \cdot \left(y \cdot y + \left(1 \cdot 1 - y \cdot 1\right)\right), y, 1\right)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -6690123426642433 \lor \neg \left(y \le 115382551.397061989\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\

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

\end{array}
double f(double x, double y) {
        double r893009 = 1.0;
        double r893010 = x;
        double r893011 = r893009 - r893010;
        double r893012 = y;
        double r893013 = r893011 * r893012;
        double r893014 = r893012 + r893009;
        double r893015 = r893013 / r893014;
        double r893016 = r893009 - r893015;
        return r893016;
}

double f(double x, double y) {
        double r893017 = y;
        double r893018 = -6690123426642433.0;
        bool r893019 = r893017 <= r893018;
        double r893020 = 115382551.39706199;
        bool r893021 = r893017 <= r893020;
        double r893022 = !r893021;
        bool r893023 = r893019 || r893022;
        double r893024 = 1.0;
        double r893025 = 1.0;
        double r893026 = r893025 / r893017;
        double r893027 = x;
        double r893028 = r893027 / r893017;
        double r893029 = r893026 - r893028;
        double r893030 = fma(r893024, r893029, r893027);
        double r893031 = r893027 - r893024;
        double r893032 = 3.0;
        double r893033 = pow(r893017, r893032);
        double r893034 = pow(r893024, r893032);
        double r893035 = r893033 + r893034;
        double r893036 = r893031 / r893035;
        double r893037 = r893017 * r893017;
        double r893038 = r893024 * r893024;
        double r893039 = r893017 * r893024;
        double r893040 = r893038 - r893039;
        double r893041 = r893037 + r893040;
        double r893042 = r893036 * r893041;
        double r893043 = fma(r893042, r893017, r893024);
        double r893044 = r893023 ? r893030 : r893043;
        return r893044;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.7
Target0.2
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;y \lt -3693.84827882972468:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y \lt 6799310503.41891003:\\ \;\;\;\;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 < -6690123426642433.0 or 115382551.39706199 < y

    1. Initial program 46.8

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\sqrt[3]{\frac{x - 1}{y + 1}} \cdot \sqrt[3]{\frac{x - 1}{y + 1}}\right) \cdot \sqrt[3]{\frac{x - 1}{y + 1}}}, y, 1\right)\]
    5. Using strategy rm
    6. Applied fma-udef30.2

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

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

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

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

    if -6690123426642433.0 < y < 115382551.39706199

    1. Initial program 0.4

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

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

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

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

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

Reproduce

herbie shell --seed 2020042 +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))))