Average Error: 22.9 → 0.5
Time: 28.1s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -7385014489371156615186612224 \lor \neg \left(y \le 303708.4300355311133898794651031494140625\right):\\ \;\;\;\;\mathsf{fma}\left(1, \left(\frac{1}{y} + \frac{x}{{y}^{2}}\right) - \left(\frac{1}{{y}^{2}} + \frac{x}{y}\right), 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 -7385014489371156615186612224 \lor \neg \left(y \le 303708.4300355311133898794651031494140625\right):\\
\;\;\;\;\mathsf{fma}\left(1, \left(\frac{1}{y} + \frac{x}{{y}^{2}}\right) - \left(\frac{1}{{y}^{2}} + \frac{x}{y}\right), x\right)\\

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

\end{array}
double f(double x, double y) {
        double r510264 = 1.0;
        double r510265 = x;
        double r510266 = r510264 - r510265;
        double r510267 = y;
        double r510268 = r510266 * r510267;
        double r510269 = r510267 + r510264;
        double r510270 = r510268 / r510269;
        double r510271 = r510264 - r510270;
        return r510271;
}

double f(double x, double y) {
        double r510272 = y;
        double r510273 = -7.385014489371157e+27;
        bool r510274 = r510272 <= r510273;
        double r510275 = 303708.4300355311;
        bool r510276 = r510272 <= r510275;
        double r510277 = !r510276;
        bool r510278 = r510274 || r510277;
        double r510279 = 1.0;
        double r510280 = 1.0;
        double r510281 = r510280 / r510272;
        double r510282 = x;
        double r510283 = 2.0;
        double r510284 = pow(r510272, r510283);
        double r510285 = r510282 / r510284;
        double r510286 = r510281 + r510285;
        double r510287 = r510280 / r510284;
        double r510288 = r510282 / r510272;
        double r510289 = r510287 + r510288;
        double r510290 = r510286 - r510289;
        double r510291 = fma(r510279, r510290, r510282);
        double r510292 = r510282 - r510279;
        double r510293 = r510272 + r510279;
        double r510294 = r510292 / r510293;
        double r510295 = fma(r510294, r510272, r510279);
        double r510296 = r510278 ? r510291 : r510295;
        return r510296;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.9
Target0.2
Herbie0.5
\[\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 < -7.385014489371157e+27 or 303708.4300355311 < y

    1. Initial program 46.8

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

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

      \[\leadsto \color{blue}{\log \left(e^{\mathsf{fma}\left(\frac{x - 1}{y + 1}, y, 1\right)}\right)}\]
    5. Using strategy rm
    6. Applied expm1-log1p-u60.9

      \[\leadsto \log \color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\mathsf{fma}\left(\frac{x - 1}{y + 1}, y, 1\right)}\right)\right)\right)}\]
    7. Taylor expanded around inf 0.0

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

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

    if -7.385014489371157e+27 < y < 303708.4300355311

    1. Initial program 0.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -7385014489371156615186612224 \lor \neg \left(y \le 303708.4300355311133898794651031494140625\right):\\ \;\;\;\;\mathsf{fma}\left(1, \left(\frac{1}{y} + \frac{x}{{y}^{2}}\right) - \left(\frac{1}{{y}^{2}} + \frac{x}{y}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x - 1}{y + 1}, y, 1\right)\\ \end{array}\]

Reproduce

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