Average Error: 22.0 → 0.2
Time: 20.9s
Precision: 64
\[1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}\]
\[\begin{array}{l} \mathbf{if}\;y \le -142333186.8719295:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{elif}\;y \le 129170539.97446656:\\ \;\;\;\;y \cdot \frac{x - 1.0}{1.0 + y} + 1.0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \end{array}\]
1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}
\begin{array}{l}
\mathbf{if}\;y \le -142333186.8719295:\\
\;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\

\mathbf{elif}\;y \le 129170539.97446656:\\
\;\;\;\;y \cdot \frac{x - 1.0}{1.0 + y} + 1.0\\

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

\end{array}
double f(double x, double y) {
        double r21215096 = 1.0;
        double r21215097 = x;
        double r21215098 = r21215096 - r21215097;
        double r21215099 = y;
        double r21215100 = r21215098 * r21215099;
        double r21215101 = r21215099 + r21215096;
        double r21215102 = r21215100 / r21215101;
        double r21215103 = r21215096 - r21215102;
        return r21215103;
}

double f(double x, double y) {
        double r21215104 = y;
        double r21215105 = -142333186.8719295;
        bool r21215106 = r21215104 <= r21215105;
        double r21215107 = 1.0;
        double r21215108 = 1.0;
        double r21215109 = r21215108 / r21215104;
        double r21215110 = x;
        double r21215111 = r21215110 / r21215104;
        double r21215112 = r21215109 - r21215111;
        double r21215113 = fma(r21215107, r21215112, r21215110);
        double r21215114 = 129170539.97446656;
        bool r21215115 = r21215104 <= r21215114;
        double r21215116 = r21215110 - r21215107;
        double r21215117 = r21215107 + r21215104;
        double r21215118 = r21215116 / r21215117;
        double r21215119 = r21215104 * r21215118;
        double r21215120 = r21215119 + r21215107;
        double r21215121 = r21215115 ? r21215120 : r21215113;
        double r21215122 = r21215106 ? r21215113 : r21215121;
        return r21215122;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.0
Target0.2
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;y \lt -3693.8482788297247:\\ \;\;\;\;\frac{1.0}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y \lt 6799310503.41891:\\ \;\;\;\;1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1.0}{y} - \left(\frac{x}{y} - x\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -142333186.8719295 or 129170539.97446656 < y

    1. Initial program 44.5

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

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

      \[\leadsto \color{blue}{\frac{x - 1.0}{1.0 + y} \cdot y + 1.0}\]
    5. Taylor expanded around inf 0.2

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

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

    if -142333186.8719295 < y < 129170539.97446656

    1. Initial program 0.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -142333186.8719295:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{elif}\;y \le 129170539.97446656:\\ \;\;\;\;y \cdot \frac{x - 1.0}{1.0 + y} + 1.0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, D"

  :herbie-target
  (if (< y -3693.8482788297247) (- (/ 1.0 y) (- (/ x y) x)) (if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) (- (/ 1.0 y) (- (/ x y) x))))

  (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))