Average Error: 21.7 → 0.2
Time: 27.0s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -118947643.39979676902294158935546875 \lor \neg \left(y \le 119396997.72706203162670135498046875\right):\\ \;\;\;\;x + \frac{1}{y} \cdot \left(1 - 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 -118947643.39979676902294158935546875 \lor \neg \left(y \le 119396997.72706203162670135498046875\right):\\
\;\;\;\;x + \frac{1}{y} \cdot \left(1 - x\right)\\

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

\end{array}
double f(double x, double y) {
        double r449653 = 1.0;
        double r449654 = x;
        double r449655 = r449653 - r449654;
        double r449656 = y;
        double r449657 = r449655 * r449656;
        double r449658 = r449656 + r449653;
        double r449659 = r449657 / r449658;
        double r449660 = r449653 - r449659;
        return r449660;
}

double f(double x, double y) {
        double r449661 = y;
        double r449662 = -118947643.39979677;
        bool r449663 = r449661 <= r449662;
        double r449664 = 119396997.72706203;
        bool r449665 = r449661 <= r449664;
        double r449666 = !r449665;
        bool r449667 = r449663 || r449666;
        double r449668 = x;
        double r449669 = 1.0;
        double r449670 = r449669 / r449661;
        double r449671 = 1.0;
        double r449672 = r449671 - r449668;
        double r449673 = r449670 * r449672;
        double r449674 = r449668 + r449673;
        double r449675 = r449668 - r449669;
        double r449676 = r449661 + r449669;
        double r449677 = r449675 / r449676;
        double r449678 = fma(r449677, r449661, r449669);
        double r449679 = r449667 ? r449674 : r449678;
        return r449679;
}

Error

Bits error versus x

Bits error versus y

Target

Original21.7
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 < -118947643.39979677 or 119396997.72706203 < y

    1. Initial program 44.6

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

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

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

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

    if -118947643.39979677 < y < 119396997.72706203

    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 -118947643.39979676902294158935546875 \lor \neg \left(y \le 119396997.72706203162670135498046875\right):\\ \;\;\;\;x + \frac{1}{y} \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x - 1}{y + 1}, y, 1\right)\\ \end{array}\]

Reproduce

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