Average Error: 22.0 → 0.2
Time: 19.7s
Precision: 64
\[1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}\]
\[\begin{array}{l} \mathbf{if}\;y \le -142333186.8719295:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{elif}\;y \le 129170539.97446656:\\ \;\;\;\;y \cdot \frac{x - 1.0}{1.0 + y} + 1.0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \end{array}\]
1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}
\begin{array}{l}
\mathbf{if}\;y \le -142333186.8719295:\\
\;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\

\mathbf{elif}\;y \le 129170539.97446656:\\
\;\;\;\;y \cdot \frac{x - 1.0}{1.0 + y} + 1.0\\

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

\end{array}
double f(double x, double y) {
        double r31958269 = 1.0;
        double r31958270 = x;
        double r31958271 = r31958269 - r31958270;
        double r31958272 = y;
        double r31958273 = r31958271 * r31958272;
        double r31958274 = r31958272 + r31958269;
        double r31958275 = r31958273 / r31958274;
        double r31958276 = r31958269 - r31958275;
        return r31958276;
}

double f(double x, double y) {
        double r31958277 = y;
        double r31958278 = -142333186.8719295;
        bool r31958279 = r31958277 <= r31958278;
        double r31958280 = 1.0;
        double r31958281 = 1.0;
        double r31958282 = r31958281 / r31958277;
        double r31958283 = x;
        double r31958284 = r31958283 / r31958277;
        double r31958285 = r31958282 - r31958284;
        double r31958286 = fma(r31958280, r31958285, r31958283);
        double r31958287 = 129170539.97446656;
        bool r31958288 = r31958277 <= r31958287;
        double r31958289 = r31958283 - r31958280;
        double r31958290 = r31958280 + r31958277;
        double r31958291 = r31958289 / r31958290;
        double r31958292 = r31958277 * r31958291;
        double r31958293 = r31958292 + r31958280;
        double r31958294 = r31958288 ? r31958293 : r31958286;
        double r31958295 = r31958279 ? r31958286 : r31958294;
        return r31958295;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.0
Target0.2
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;y \lt -3693.8482788297247:\\ \;\;\;\;\frac{1.0}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y \lt 6799310503.41891:\\ \;\;\;\;1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1.0}{y} - \left(\frac{x}{y} - x\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -142333186.8719295 or 129170539.97446656 < y

    1. Initial program 44.5

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

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

      \[\leadsto \color{blue}{\frac{x - 1.0}{1.0 + y} \cdot y + 1.0}\]
    5. Taylor expanded around inf 0.2

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

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

    if -142333186.8719295 < y < 129170539.97446656

    1. Initial program 0.1

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

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

      \[\leadsto \color{blue}{\frac{x - 1.0}{1.0 + y} \cdot y + 1.0}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -142333186.8719295:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{elif}\;y \le 129170539.97446656:\\ \;\;\;\;y \cdot \frac{x - 1.0}{1.0 + y} + 1.0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \end{array}\]

Reproduce

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