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

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

\end{array}
double f(double x, double y) {
        double r609818 = 1.0;
        double r609819 = x;
        double r609820 = r609818 - r609819;
        double r609821 = y;
        double r609822 = r609820 * r609821;
        double r609823 = r609821 + r609818;
        double r609824 = r609822 / r609823;
        double r609825 = r609818 - r609824;
        return r609825;
}

double f(double x, double y) {
        double r609826 = y;
        double r609827 = -15892410532.141876;
        bool r609828 = r609826 <= r609827;
        double r609829 = 132206673.37722518;
        bool r609830 = r609826 <= r609829;
        double r609831 = !r609830;
        bool r609832 = r609828 || r609831;
        double r609833 = 1.0;
        double r609834 = 1.0;
        double r609835 = r609834 / r609826;
        double r609836 = x;
        double r609837 = r609836 / r609826;
        double r609838 = r609835 - r609837;
        double r609839 = fma(r609833, r609838, r609836);
        double r609840 = r609836 - r609833;
        double r609841 = r609826 + r609833;
        double r609842 = r609840 / r609841;
        double r609843 = fma(r609842, r609826, r609833);
        double r609844 = r609834 * r609843;
        double r609845 = r609832 ? r609839 : r609844;
        return r609845;
}

Error

Bits error versus x

Bits error versus y

Target

Original21.8
Target0.2
Herbie0.2
\[\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 < -15892410532.141876 or 132206673.37722518 < y

    1. Initial program 45.7

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

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

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

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

      \[\leadsto \color{blue}{\frac{x - 1}{\frac{y + 1}{y}}} + 1\]
    8. Taylor expanded around inf 0.1

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

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

    if -15892410532.141876 < y < 132206673.37722518

    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{y}{y + 1}, x - 1, 1\right)}\]
    3. Using strategy rm
    4. Applied clear-num0.3

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

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

      \[\leadsto \color{blue}{\frac{x - 1}{\frac{y + 1}{y}}} + 1\]
    8. Using strategy rm
    9. Applied *-un-lft-identity0.3

      \[\leadsto \frac{x - 1}{\frac{y + 1}{y}} + \color{blue}{1 \cdot 1}\]
    10. Applied *-un-lft-identity0.3

      \[\leadsto \color{blue}{1 \cdot \frac{x - 1}{\frac{y + 1}{y}}} + 1 \cdot 1\]
    11. Applied distribute-lft-out0.3

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

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

Reproduce

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