Average Error: 22.9 → 7.7
Time: 15.8s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -4.057680286744787104405461141937759541993 \cdot 10^{78} \lor \neg \left(y \le 13562637422873356\right):\\ \;\;\;\;x + 1 \cdot \left(\frac{x}{y \cdot y} - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{{1}^{3} + {y}^{3}} \cdot \left(\left(1 \cdot 1 - 1 \cdot y\right) + y \cdot 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 -4.057680286744787104405461141937759541993 \cdot 10^{78} \lor \neg \left(y \le 13562637422873356\right):\\
\;\;\;\;x + 1 \cdot \left(\frac{x}{y \cdot y} - \frac{x}{y}\right)\\

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

\end{array}
double f(double x, double y) {
        double r1435330 = 1.0;
        double r1435331 = x;
        double r1435332 = r1435330 - r1435331;
        double r1435333 = y;
        double r1435334 = r1435332 * r1435333;
        double r1435335 = r1435333 + r1435330;
        double r1435336 = r1435334 / r1435335;
        double r1435337 = r1435330 - r1435336;
        return r1435337;
}

double f(double x, double y) {
        double r1435338 = y;
        double r1435339 = -4.057680286744787e+78;
        bool r1435340 = r1435338 <= r1435339;
        double r1435341 = 13562637422873356.0;
        bool r1435342 = r1435338 <= r1435341;
        double r1435343 = !r1435342;
        bool r1435344 = r1435340 || r1435343;
        double r1435345 = x;
        double r1435346 = 1.0;
        double r1435347 = r1435338 * r1435338;
        double r1435348 = r1435345 / r1435347;
        double r1435349 = r1435345 / r1435338;
        double r1435350 = r1435348 - r1435349;
        double r1435351 = r1435346 * r1435350;
        double r1435352 = r1435345 + r1435351;
        double r1435353 = 3.0;
        double r1435354 = pow(r1435346, r1435353);
        double r1435355 = pow(r1435338, r1435353);
        double r1435356 = r1435354 + r1435355;
        double r1435357 = r1435338 / r1435356;
        double r1435358 = r1435346 * r1435346;
        double r1435359 = r1435346 * r1435338;
        double r1435360 = r1435358 - r1435359;
        double r1435361 = r1435360 + r1435347;
        double r1435362 = r1435357 * r1435361;
        double r1435363 = r1435345 - r1435346;
        double r1435364 = fma(r1435362, r1435363, r1435346);
        double r1435365 = r1435344 ? r1435352 : r1435364;
        return r1435365;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.9
Target0.2
Herbie7.7
\[\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 < -4.057680286744787e+78 or 13562637422873356.0 < y

    1. Initial program 48.0

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

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

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

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

    if -4.057680286744787e+78 < y < 13562637422873356.0

    1. Initial program 4.0

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

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

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

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

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

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

Reproduce

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