Average Error: 22.9 → 0.5
Time: 30.5s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -7385014489371156615186612224 \lor \neg \left(y \le 303708.4300355311133898794651031494140625\right):\\ \;\;\;\;\mathsf{fma}\left(1, \left(\frac{1}{y} + \frac{x}{{y}^{2}}\right) - \left(\frac{1}{{y}^{2}} + \frac{x}{y}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x - 1}{y + 1}, y, 1\right)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -7385014489371156615186612224 \lor \neg \left(y \le 303708.4300355311133898794651031494140625\right):\\
\;\;\;\;\mathsf{fma}\left(1, \left(\frac{1}{y} + \frac{x}{{y}^{2}}\right) - \left(\frac{1}{{y}^{2}} + \frac{x}{y}\right), x\right)\\

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

\end{array}
double f(double x, double y) {
        double r384323 = 1.0;
        double r384324 = x;
        double r384325 = r384323 - r384324;
        double r384326 = y;
        double r384327 = r384325 * r384326;
        double r384328 = r384326 + r384323;
        double r384329 = r384327 / r384328;
        double r384330 = r384323 - r384329;
        return r384330;
}

double f(double x, double y) {
        double r384331 = y;
        double r384332 = -7.385014489371157e+27;
        bool r384333 = r384331 <= r384332;
        double r384334 = 303708.4300355311;
        bool r384335 = r384331 <= r384334;
        double r384336 = !r384335;
        bool r384337 = r384333 || r384336;
        double r384338 = 1.0;
        double r384339 = 1.0;
        double r384340 = r384339 / r384331;
        double r384341 = x;
        double r384342 = 2.0;
        double r384343 = pow(r384331, r384342);
        double r384344 = r384341 / r384343;
        double r384345 = r384340 + r384344;
        double r384346 = r384339 / r384343;
        double r384347 = r384341 / r384331;
        double r384348 = r384346 + r384347;
        double r384349 = r384345 - r384348;
        double r384350 = fma(r384338, r384349, r384341);
        double r384351 = r384341 - r384338;
        double r384352 = r384331 + r384338;
        double r384353 = r384351 / r384352;
        double r384354 = fma(r384353, r384331, r384338);
        double r384355 = r384337 ? r384350 : r384354;
        return r384355;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.9
Target0.2
Herbie0.5
\[\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 < -7.385014489371157e+27 or 303708.4300355311 < y

    1. Initial program 46.8

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

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

      \[\leadsto \color{blue}{\log \left(e^{\mathsf{fma}\left(\frac{x - 1}{y + 1}, y, 1\right)}\right)}\]
    5. Using strategy rm
    6. Applied expm1-log1p-u60.9

      \[\leadsto \log \color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\mathsf{fma}\left(\frac{x - 1}{y + 1}, y, 1\right)}\right)\right)\right)}\]
    7. Taylor expanded around inf 0.0

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

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

    if -7.385014489371157e+27 < y < 303708.4300355311

    1. Initial program 0.9

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

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

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

Reproduce

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