Average Error: 22.7 → 0.3
Time: 20.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):\\ \;\;\;\;\left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right) + x\\ \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):\\
\;\;\;\;\left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right) + x\\

\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 r735317 = 1.0;
        double r735318 = x;
        double r735319 = r735317 - r735318;
        double r735320 = y;
        double r735321 = r735319 * r735320;
        double r735322 = r735320 + r735317;
        double r735323 = r735321 / r735322;
        double r735324 = r735317 - r735323;
        return r735324;
}

double f(double x, double y) {
        double r735325 = y;
        double r735326 = -6690123426642433.0;
        bool r735327 = r735325 <= r735326;
        double r735328 = 115382551.39706199;
        bool r735329 = r735325 <= r735328;
        double r735330 = !r735329;
        bool r735331 = r735327 || r735330;
        double r735332 = 1.0;
        double r735333 = r735332 / r735325;
        double r735334 = x;
        double r735335 = r735334 / r735325;
        double r735336 = r735332 * r735335;
        double r735337 = r735333 - r735336;
        double r735338 = r735337 + r735334;
        double r735339 = r735334 - r735332;
        double r735340 = 3.0;
        double r735341 = pow(r735325, r735340);
        double r735342 = pow(r735332, r735340);
        double r735343 = r735341 + r735342;
        double r735344 = r735339 / r735343;
        double r735345 = r735325 * r735325;
        double r735346 = r735332 * r735332;
        double r735347 = r735325 * r735332;
        double r735348 = r735346 - r735347;
        double r735349 = r735345 + r735348;
        double r735350 = r735344 * r735349;
        double r735351 = fma(r735350, r735325, r735332);
        double r735352 = r735331 ? r735338 : r735351;
        return r735352;
}

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 flip3-+53.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/53.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)\]
    6. Taylor expanded around inf 0.1

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

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

    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):\\ \;\;\;\;\left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right) + x\\ \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))))