Average Error: 21.7 → 0.2
Time: 27.7s
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 r457915 = 1.0;
        double r457916 = x;
        double r457917 = r457915 - r457916;
        double r457918 = y;
        double r457919 = r457917 * r457918;
        double r457920 = r457918 + r457915;
        double r457921 = r457919 / r457920;
        double r457922 = r457915 - r457921;
        return r457922;
}

double f(double x, double y) {
        double r457923 = y;
        double r457924 = -118947643.39979677;
        bool r457925 = r457923 <= r457924;
        double r457926 = 119396997.72706203;
        bool r457927 = r457923 <= r457926;
        double r457928 = !r457927;
        bool r457929 = r457925 || r457928;
        double r457930 = x;
        double r457931 = 1.0;
        double r457932 = r457931 / r457923;
        double r457933 = 1.0;
        double r457934 = r457933 - r457930;
        double r457935 = r457932 * r457934;
        double r457936 = r457930 + r457935;
        double r457937 = r457930 - r457931;
        double r457938 = r457923 + r457931;
        double r457939 = r457937 / r457938;
        double r457940 = fma(r457939, r457923, r457931);
        double r457941 = r457929 ? r457936 : r457940;
        return r457941;
}

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))))