Average Error: 22.0 → 7.3
Time: 15.5s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.724271217506247524333158481631304690353 \cdot 10^{48} \lor \neg \left(y \le 91869831345953177600\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -1.724271217506247524333158481631304690353 \cdot 10^{48} \lor \neg \left(y \le 91869831345953177600\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\

\mathbf{else}:\\
\;\;\;\;\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)\\

\end{array}
double f(double x, double y) {
        double r507217 = 1.0;
        double r507218 = x;
        double r507219 = r507217 - r507218;
        double r507220 = y;
        double r507221 = r507219 * r507220;
        double r507222 = r507220 + r507217;
        double r507223 = r507221 / r507222;
        double r507224 = r507217 - r507223;
        return r507224;
}

double f(double x, double y) {
        double r507225 = y;
        double r507226 = -1.7242712175062475e+48;
        bool r507227 = r507225 <= r507226;
        double r507228 = 9.186983134595318e+19;
        bool r507229 = r507225 <= r507228;
        double r507230 = !r507229;
        bool r507231 = r507227 || r507230;
        double r507232 = x;
        double r507233 = r507232 / r507225;
        double r507234 = 1.0;
        double r507235 = r507234 / r507225;
        double r507236 = r507235 - r507234;
        double r507237 = fma(r507233, r507236, r507232);
        double r507238 = 1.0;
        double r507239 = r507234 + r507225;
        double r507240 = r507238 / r507239;
        double r507241 = cbrt(r507240);
        double r507242 = r507241 * r507241;
        double r507243 = r507242 * r507241;
        double r507244 = r507225 * r507243;
        double r507245 = r507232 - r507234;
        double r507246 = fma(r507244, r507245, r507234);
        double r507247 = r507231 ? r507237 : r507246;
        return r507247;
}

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. Simplified28.8

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

      \[\leadsto \mathsf{fma}\left(y \cdot \color{blue}{\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)\]
    8. Simplified29.6

      \[\leadsto \mathsf{fma}\left(y \cdot \left(\color{blue}{\left(\sqrt[3]{\frac{1}{y + 1}} \cdot \sqrt[3]{\frac{1}{y + 1}}\right)} \cdot \sqrt[3]{\frac{1}{1 + y}}\right), x - 1, 1\right)\]
    9. Simplified29.6

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

      \[\leadsto \color{blue}{\left(1 \cdot \frac{x}{{y}^{2}} + x\right) - 1 \cdot \frac{x}{y}}\]
    11. 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. Simplified2.2

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

      \[\leadsto \mathsf{fma}\left(y \cdot \color{blue}{\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)\]
    8. Simplified2.3

      \[\leadsto \mathsf{fma}\left(y \cdot \left(\color{blue}{\left(\sqrt[3]{\frac{1}{y + 1}} \cdot \sqrt[3]{\frac{1}{y + 1}}\right)} \cdot \sqrt[3]{\frac{1}{1 + y}}\right), x - 1, 1\right)\]
    9. Simplified2.3

      \[\leadsto \mathsf{fma}\left(y \cdot \left(\left(\sqrt[3]{\frac{1}{y + 1}} \cdot \sqrt[3]{\frac{1}{y + 1}}\right) \cdot \color{blue}{\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} \lor \neg \left(y \le 91869831345953177600\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \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))))