Average Error: 22.1 → 0.2
Time: 30.5s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -31112195187751.66796875 \lor \neg \left(y \le 165630154.1629503071308135986328125\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x - 1}{y + 1} \cdot y + 1\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -31112195187751.66796875 \lor \neg \left(y \le 165630154.1629503071308135986328125\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x - 1}{y + 1} \cdot y + 1\\

\end{array}
double f(double x, double y) {
        double r575352 = 1.0;
        double r575353 = x;
        double r575354 = r575352 - r575353;
        double r575355 = y;
        double r575356 = r575354 * r575355;
        double r575357 = r575355 + r575352;
        double r575358 = r575356 / r575357;
        double r575359 = r575352 - r575358;
        return r575359;
}

double f(double x, double y) {
        double r575360 = y;
        double r575361 = -31112195187751.668;
        bool r575362 = r575360 <= r575361;
        double r575363 = 165630154.1629503;
        bool r575364 = r575360 <= r575363;
        double r575365 = !r575364;
        bool r575366 = r575362 || r575365;
        double r575367 = 1.0;
        double r575368 = 1.0;
        double r575369 = r575368 / r575360;
        double r575370 = x;
        double r575371 = r575370 / r575360;
        double r575372 = r575369 - r575371;
        double r575373 = fma(r575367, r575372, r575370);
        double r575374 = r575370 - r575367;
        double r575375 = r575360 + r575367;
        double r575376 = r575374 / r575375;
        double r575377 = r575376 * r575360;
        double r575378 = r575377 + r575367;
        double r575379 = r575366 ? r575373 : r575378;
        return r575379;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.1
Target0.2
Herbie0.2
\[\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 < -31112195187751.668 or 165630154.1629503 < y

    1. Initial program 45.4

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

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

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

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

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

    if -31112195187751.668 < y < 165630154.1629503

    1. Initial program 0.4

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

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

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

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

Reproduce

herbie shell --seed 2019306 +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.84827882972468) (- (/ 1 y) (- (/ x y) x)) (if (< y 6799310503.41891003) (- 1 (/ (* (- 1 x) y) (+ y 1))) (- (/ 1 y) (- (/ x y) x))))

  (- 1 (/ (* (- 1 x) y) (+ y 1))))