Average Error: 22.3 → 0.2
Time: 30.4s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -197475236.476782381534576416015625 \lor \neg \left(y \le 115806119.112273037433624267578125\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, 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 -197475236.476782381534576416015625 \lor \neg \left(y \le 115806119.112273037433624267578125\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\

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

\end{array}
double f(double x, double y) {
        double r385355 = 1.0;
        double r385356 = x;
        double r385357 = r385355 - r385356;
        double r385358 = y;
        double r385359 = r385357 * r385358;
        double r385360 = r385358 + r385355;
        double r385361 = r385359 / r385360;
        double r385362 = r385355 - r385361;
        return r385362;
}

double f(double x, double y) {
        double r385363 = y;
        double r385364 = -197475236.47678238;
        bool r385365 = r385363 <= r385364;
        double r385366 = 115806119.11227304;
        bool r385367 = r385363 <= r385366;
        double r385368 = !r385367;
        bool r385369 = r385365 || r385368;
        double r385370 = 1.0;
        double r385371 = 1.0;
        double r385372 = r385371 / r385363;
        double r385373 = x;
        double r385374 = r385373 / r385363;
        double r385375 = r385372 - r385374;
        double r385376 = fma(r385370, r385375, r385373);
        double r385377 = r385373 - r385370;
        double r385378 = r385363 + r385370;
        double r385379 = r385377 / r385378;
        double r385380 = fma(r385379, r385363, r385370);
        double r385381 = r385369 ? r385376 : r385380;
        return r385381;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.3
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 < -197475236.47678238 or 115806119.11227304 < y

    1. Initial program 45.7

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

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

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

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

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

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

    if -197475236.47678238 < y < 115806119.11227304

    1. Initial program 0.2

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

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

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

Reproduce

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