Average Error: 22.3 → 7.6
Time: 4.2s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -3.46847315426235216 \cdot 10^{42} \lor \neg \left(y \le 2.53588463642297086 \cdot 10^{46}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1 \cdot \left(\frac{y}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right)\right), x - 1, 1\right)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -3.46847315426235216 \cdot 10^{42} \lor \neg \left(y \le 2.53588463642297086 \cdot 10^{46}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\

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

\end{array}
double f(double x, double y) {
        double r644004 = 1.0;
        double r644005 = x;
        double r644006 = r644004 - r644005;
        double r644007 = y;
        double r644008 = r644006 * r644007;
        double r644009 = r644007 + r644004;
        double r644010 = r644008 / r644009;
        double r644011 = r644004 - r644010;
        return r644011;
}

double f(double x, double y) {
        double r644012 = y;
        double r644013 = -3.468473154262352e+42;
        bool r644014 = r644012 <= r644013;
        double r644015 = 2.535884636422971e+46;
        bool r644016 = r644012 <= r644015;
        double r644017 = !r644016;
        bool r644018 = r644014 || r644017;
        double r644019 = x;
        double r644020 = r644019 / r644012;
        double r644021 = 1.0;
        double r644022 = r644021 / r644012;
        double r644023 = r644022 - r644021;
        double r644024 = fma(r644020, r644023, r644019);
        double r644025 = 1.0;
        double r644026 = r644012 * r644012;
        double r644027 = r644021 * r644021;
        double r644028 = r644026 - r644027;
        double r644029 = r644012 / r644028;
        double r644030 = r644012 - r644021;
        double r644031 = r644029 * r644030;
        double r644032 = r644025 * r644031;
        double r644033 = r644019 - r644021;
        double r644034 = fma(r644032, r644033, r644021);
        double r644035 = r644018 ? r644024 : r644034;
        return r644035;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.3
Target0.2
Herbie7.6
\[\begin{array}{l} \mathbf{if}\;y \lt -3693.84827882972468:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y \lt 6799310503.41891003:\\ \;\;\;\;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 < -3.468473154262352e+42 or 2.535884636422971e+46 < y

    1. Initial program 47.9

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

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

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

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

    if -3.468473154262352e+42 < y < 2.535884636422971e+46

    1. Initial program 3.2

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

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

      \[\leadsto \mathsf{fma}\left(\frac{y}{\color{blue}{1 \cdot \left(y + 1\right)}}, x - 1, 1\right)\]
    5. Applied *-un-lft-identity3.0

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{1 \cdot y}}{1 \cdot \left(y + 1\right)}, x - 1, 1\right)\]
    6. Applied times-frac3.0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{1} \cdot \frac{y}{y + 1}}, x - 1, 1\right)\]
    7. Simplified3.0

      \[\leadsto \mathsf{fma}\left(\color{blue}{1} \cdot \frac{y}{y + 1}, x - 1, 1\right)\]
    8. Using strategy rm
    9. Applied flip-+3.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.46847315426235216 \cdot 10^{42} \lor \neg \left(y \le 2.53588463642297086 \cdot 10^{46}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1 \cdot \left(\frac{y}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right)\right), x - 1, 1\right)\\ \end{array}\]

Reproduce

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