Average Error: 22.0 → 0.2
Time: 14.2s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -116113257.18599545955657958984375 \lor \neg \left(y \le 111711424.78256571292877197265625\right):\\ \;\;\;\;\left(\frac{1}{y} + x\right) - 1 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - 1}{y \cdot y - 1 \cdot 1} \cdot \left(\left(y - 1\right) \cdot y\right) + 1\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -116113257.18599545955657958984375 \lor \neg \left(y \le 111711424.78256571292877197265625\right):\\
\;\;\;\;\left(\frac{1}{y} + x\right) - 1 \cdot \frac{x}{y}\\

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

\end{array}
double f(double x, double y) {
        double r360504 = 1.0;
        double r360505 = x;
        double r360506 = r360504 - r360505;
        double r360507 = y;
        double r360508 = r360506 * r360507;
        double r360509 = r360507 + r360504;
        double r360510 = r360508 / r360509;
        double r360511 = r360504 - r360510;
        return r360511;
}

double f(double x, double y) {
        double r360512 = y;
        double r360513 = -116113257.18599546;
        bool r360514 = r360512 <= r360513;
        double r360515 = 111711424.78256571;
        bool r360516 = r360512 <= r360515;
        double r360517 = !r360516;
        bool r360518 = r360514 || r360517;
        double r360519 = 1.0;
        double r360520 = r360519 / r360512;
        double r360521 = x;
        double r360522 = r360520 + r360521;
        double r360523 = r360521 / r360512;
        double r360524 = r360519 * r360523;
        double r360525 = r360522 - r360524;
        double r360526 = r360521 - r360519;
        double r360527 = r360512 * r360512;
        double r360528 = r360519 * r360519;
        double r360529 = r360527 - r360528;
        double r360530 = r360526 / r360529;
        double r360531 = r360512 - r360519;
        double r360532 = r360531 * r360512;
        double r360533 = r360530 * r360532;
        double r360534 = r360533 + r360519;
        double r360535 = r360518 ? r360525 : r360534;
        return r360535;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original22.0
Target0.3
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 < -116113257.18599546 or 111711424.78256571 < y

    1. Initial program 45.3

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

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

      \[\leadsto \color{blue}{\frac{x - 1}{y + 1} \cdot y + 1}\]
    5. Using strategy rm
    6. Applied flip-+45.9

      \[\leadsto \frac{x - 1}{\color{blue}{\frac{y \cdot y - 1 \cdot 1}{y - 1}}} \cdot y + 1\]
    7. Applied associate-/r/45.9

      \[\leadsto \color{blue}{\left(\frac{x - 1}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right)\right)} \cdot y + 1\]
    8. Applied associate-*l*47.0

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

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

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

    if -116113257.18599546 < y < 111711424.78256571

    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. Using strategy rm
    4. Applied fma-udef0.2

      \[\leadsto \color{blue}{\frac{x - 1}{y + 1} \cdot y + 1}\]
    5. Using strategy rm
    6. Applied flip-+0.2

      \[\leadsto \frac{x - 1}{\color{blue}{\frac{y \cdot y - 1 \cdot 1}{y - 1}}} \cdot y + 1\]
    7. Applied associate-/r/0.2

      \[\leadsto \color{blue}{\left(\frac{x - 1}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right)\right)} \cdot y + 1\]
    8. Applied associate-*l*0.2

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

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

Reproduce

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