Average Error: 22.0 → 0.2
Time: 20.2s
Precision: 64
\[1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}\]
\[\begin{array}{l} \mathbf{if}\;y \le -160840129.45081177:\\ \;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{elif}\;y \le 149371639.02682295:\\ \;\;\;\;\mathsf{fma}\left(-\left(\left(1.0 \cdot 1.0 - 1.0 \cdot y\right) + y \cdot y\right), \frac{y \cdot \left(1.0 - x\right)}{{y}^{3} + {1.0}^{3}}, \left(\left(1.0 \cdot 1.0 - 1.0 \cdot y\right) + y \cdot y\right) \cdot \frac{y \cdot \left(1.0 - x\right)}{{y}^{3} + {1.0}^{3}}\right) + \mathsf{fma}\left(1, 1.0, \frac{\left(-y\right) \cdot \left(1.0 - x\right)}{{y}^{3} + {1.0}^{3}} \cdot \left(\left(1.0 \cdot 1.0 - 1.0 \cdot y\right) + y \cdot y\right)\right)\\ \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 -160840129.45081177:\\
\;\;\;\;\mathsf{fma}\left(1.0, \frac{1}{y} - \frac{x}{y}, x\right)\\

\mathbf{elif}\;y \le 149371639.02682295:\\
\;\;\;\;\mathsf{fma}\left(-\left(\left(1.0 \cdot 1.0 - 1.0 \cdot y\right) + y \cdot y\right), \frac{y \cdot \left(1.0 - x\right)}{{y}^{3} + {1.0}^{3}}, \left(\left(1.0 \cdot 1.0 - 1.0 \cdot y\right) + y \cdot y\right) \cdot \frac{y \cdot \left(1.0 - x\right)}{{y}^{3} + {1.0}^{3}}\right) + \mathsf{fma}\left(1, 1.0, \frac{\left(-y\right) \cdot \left(1.0 - x\right)}{{y}^{3} + {1.0}^{3}} \cdot \left(\left(1.0 \cdot 1.0 - 1.0 \cdot y\right) + y \cdot y\right)\right)\\

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

\end{array}
double f(double x, double y) {
        double r35950233 = 1.0;
        double r35950234 = x;
        double r35950235 = r35950233 - r35950234;
        double r35950236 = y;
        double r35950237 = r35950235 * r35950236;
        double r35950238 = r35950236 + r35950233;
        double r35950239 = r35950237 / r35950238;
        double r35950240 = r35950233 - r35950239;
        return r35950240;
}

double f(double x, double y) {
        double r35950241 = y;
        double r35950242 = -160840129.45081177;
        bool r35950243 = r35950241 <= r35950242;
        double r35950244 = 1.0;
        double r35950245 = 1.0;
        double r35950246 = r35950245 / r35950241;
        double r35950247 = x;
        double r35950248 = r35950247 / r35950241;
        double r35950249 = r35950246 - r35950248;
        double r35950250 = fma(r35950244, r35950249, r35950247);
        double r35950251 = 149371639.02682295;
        bool r35950252 = r35950241 <= r35950251;
        double r35950253 = r35950244 * r35950244;
        double r35950254 = r35950244 * r35950241;
        double r35950255 = r35950253 - r35950254;
        double r35950256 = r35950241 * r35950241;
        double r35950257 = r35950255 + r35950256;
        double r35950258 = -r35950257;
        double r35950259 = r35950244 - r35950247;
        double r35950260 = r35950241 * r35950259;
        double r35950261 = 3.0;
        double r35950262 = pow(r35950241, r35950261);
        double r35950263 = pow(r35950244, r35950261);
        double r35950264 = r35950262 + r35950263;
        double r35950265 = r35950260 / r35950264;
        double r35950266 = r35950257 * r35950265;
        double r35950267 = fma(r35950258, r35950265, r35950266);
        double r35950268 = -r35950241;
        double r35950269 = r35950268 * r35950259;
        double r35950270 = r35950269 / r35950264;
        double r35950271 = r35950270 * r35950257;
        double r35950272 = fma(r35950245, r35950244, r35950271);
        double r35950273 = r35950267 + r35950272;
        double r35950274 = r35950252 ? r35950273 : r35950250;
        double r35950275 = r35950243 ? r35950250 : r35950274;
        return r35950275;
}

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 < -160840129.45081177 or 149371639.02682295 < y

    1. Initial program 44.7

      \[1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}\]
    2. Taylor expanded around inf 0.2

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

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

    if -160840129.45081177 < y < 149371639.02682295

    1. Initial program 0.2

      \[1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}\]
    2. Using strategy rm
    3. Applied flip3-+0.2

      \[\leadsto 1.0 - \frac{\left(1.0 - x\right) \cdot y}{\color{blue}{\frac{{y}^{3} + {1.0}^{3}}{y \cdot y + \left(1.0 \cdot 1.0 - y \cdot 1.0\right)}}}\]
    4. Applied associate-/r/0.2

      \[\leadsto 1.0 - \color{blue}{\frac{\left(1.0 - x\right) \cdot y}{{y}^{3} + {1.0}^{3}} \cdot \left(y \cdot y + \left(1.0 \cdot 1.0 - y \cdot 1.0\right)\right)}\]
    5. Applied *-un-lft-identity0.2

      \[\leadsto \color{blue}{1 \cdot 1.0} - \frac{\left(1.0 - x\right) \cdot y}{{y}^{3} + {1.0}^{3}} \cdot \left(y \cdot y + \left(1.0 \cdot 1.0 - y \cdot 1.0\right)\right)\]
    6. Applied prod-diff0.2

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

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

Reproduce

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