Average Error: 22.0 → 7.3
Time: 15.4s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.724271217506247524333158481631304690353 \cdot 10^{48}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\ \mathbf{elif}\;y \le 91869831345953177600:\\ \;\;\;\;\mathsf{fma}\left(y \cdot \left(\left(\sqrt[3]{\frac{1}{1 + y}} \cdot \sqrt[3]{\frac{1}{1 + y}}\right) \cdot \sqrt[3]{\frac{1}{1 + y}}\right), x - 1, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -1.724271217506247524333158481631304690353 \cdot 10^{48}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\

\mathbf{elif}\;y \le 91869831345953177600:\\
\;\;\;\;\mathsf{fma}\left(y \cdot \left(\left(\sqrt[3]{\frac{1}{1 + y}} \cdot \sqrt[3]{\frac{1}{1 + y}}\right) \cdot \sqrt[3]{\frac{1}{1 + y}}\right), x - 1, 1\right)\\

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

\end{array}
double f(double x, double y) {
        double r30724239 = 1.0;
        double r30724240 = x;
        double r30724241 = r30724239 - r30724240;
        double r30724242 = y;
        double r30724243 = r30724241 * r30724242;
        double r30724244 = r30724242 + r30724239;
        double r30724245 = r30724243 / r30724244;
        double r30724246 = r30724239 - r30724245;
        return r30724246;
}

double f(double x, double y) {
        double r30724247 = y;
        double r30724248 = -1.7242712175062475e+48;
        bool r30724249 = r30724247 <= r30724248;
        double r30724250 = x;
        double r30724251 = r30724250 / r30724247;
        double r30724252 = 1.0;
        double r30724253 = r30724252 / r30724247;
        double r30724254 = r30724253 - r30724252;
        double r30724255 = fma(r30724251, r30724254, r30724250);
        double r30724256 = 9.186983134595318e+19;
        bool r30724257 = r30724247 <= r30724256;
        double r30724258 = 1.0;
        double r30724259 = r30724252 + r30724247;
        double r30724260 = r30724258 / r30724259;
        double r30724261 = cbrt(r30724260);
        double r30724262 = r30724261 * r30724261;
        double r30724263 = r30724262 * r30724261;
        double r30724264 = r30724247 * r30724263;
        double r30724265 = r30724250 - r30724252;
        double r30724266 = fma(r30724264, r30724265, r30724252);
        double r30724267 = r30724257 ? r30724266 : r30724255;
        double r30724268 = r30724249 ? r30724255 : r30724267;
        return r30724268;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.0
Target0.2
Herbie7.3
\[\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 < -1.7242712175062475e+48 or 9.186983134595318e+19 < y

    1. Initial program 46.6

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

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

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

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

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

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

    if -1.7242712175062475e+48 < y < 9.186983134595318e+19

    1. Initial program 2.4

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

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

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

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

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

Reproduce

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