Average Error: 21.8 → 7.4
Time: 12.0s
Precision: 64
\[1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}\]
\[\begin{array}{l} \mathbf{if}\;y \le -120684821833.98685:\\ \;\;\;\;\left(x + \frac{\frac{x}{y} \cdot 1.0}{y}\right) - \frac{x}{y} \cdot 1.0\\ \mathbf{elif}\;y \le 4.471669177154523 \cdot 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(y, \left(1.0 \cdot 1.0 + \left(y \cdot y - 1.0 \cdot y\right)\right) \cdot \frac{x - 1.0}{\mathsf{fma}\left(y, y \cdot y, \left(1.0 \cdot 1.0\right) \cdot 1.0\right)}, 1.0\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + \frac{\frac{x}{y} \cdot 1.0}{y}\right) - \frac{x}{y} \cdot 1.0\\ \end{array}\]
1.0 - \frac{\left(1.0 - x\right) \cdot y}{y + 1.0}
\begin{array}{l}
\mathbf{if}\;y \le -120684821833.98685:\\
\;\;\;\;\left(x + \frac{\frac{x}{y} \cdot 1.0}{y}\right) - \frac{x}{y} \cdot 1.0\\

\mathbf{elif}\;y \le 4.471669177154523 \cdot 10^{+32}:\\
\;\;\;\;\mathsf{fma}\left(y, \left(1.0 \cdot 1.0 + \left(y \cdot y - 1.0 \cdot y\right)\right) \cdot \frac{x - 1.0}{\mathsf{fma}\left(y, y \cdot y, \left(1.0 \cdot 1.0\right) \cdot 1.0\right)}, 1.0\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x + \frac{\frac{x}{y} \cdot 1.0}{y}\right) - \frac{x}{y} \cdot 1.0\\

\end{array}
double f(double x, double y) {
        double r11853432 = 1.0;
        double r11853433 = x;
        double r11853434 = r11853432 - r11853433;
        double r11853435 = y;
        double r11853436 = r11853434 * r11853435;
        double r11853437 = r11853435 + r11853432;
        double r11853438 = r11853436 / r11853437;
        double r11853439 = r11853432 - r11853438;
        return r11853439;
}

double f(double x, double y) {
        double r11853440 = y;
        double r11853441 = -120684821833.98685;
        bool r11853442 = r11853440 <= r11853441;
        double r11853443 = x;
        double r11853444 = r11853443 / r11853440;
        double r11853445 = 1.0;
        double r11853446 = r11853444 * r11853445;
        double r11853447 = r11853446 / r11853440;
        double r11853448 = r11853443 + r11853447;
        double r11853449 = r11853448 - r11853446;
        double r11853450 = 4.471669177154523e+32;
        bool r11853451 = r11853440 <= r11853450;
        double r11853452 = r11853445 * r11853445;
        double r11853453 = r11853440 * r11853440;
        double r11853454 = r11853445 * r11853440;
        double r11853455 = r11853453 - r11853454;
        double r11853456 = r11853452 + r11853455;
        double r11853457 = r11853443 - r11853445;
        double r11853458 = r11853452 * r11853445;
        double r11853459 = fma(r11853440, r11853453, r11853458);
        double r11853460 = r11853457 / r11853459;
        double r11853461 = r11853456 * r11853460;
        double r11853462 = fma(r11853440, r11853461, r11853445);
        double r11853463 = r11853451 ? r11853462 : r11853449;
        double r11853464 = r11853442 ? r11853449 : r11853463;
        return r11853464;
}

Error

Bits error versus x

Bits error versus y

Target

Original21.8
Target0.2
Herbie7.4
\[\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 < -120684821833.98685 or 4.471669177154523e+32 < y

    1. Initial program 45.9

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

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

      \[\leadsto \mathsf{fma}\left(y, \frac{x - 1.0}{\color{blue}{\left(\sqrt[3]{1.0 + y} \cdot \sqrt[3]{1.0 + y}\right) \cdot \sqrt[3]{1.0 + y}}}, 1.0\right)\]
    5. Applied associate-/r*30.8

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\frac{\frac{x - 1.0}{\sqrt[3]{1.0 + y} \cdot \sqrt[3]{1.0 + y}}}{\sqrt[3]{1.0 + y}}}, 1.0\right)\]
    6. Using strategy rm
    7. Applied fma-udef30.7

      \[\leadsto \color{blue}{y \cdot \frac{\frac{x - 1.0}{\sqrt[3]{1.0 + y} \cdot \sqrt[3]{1.0 + y}}}{\sqrt[3]{1.0 + y}} + 1.0}\]
    8. Simplified30.0

      \[\leadsto \color{blue}{y \cdot \frac{x - 1.0}{y + 1.0}} + 1.0\]
    9. Using strategy rm
    10. Applied add-cube-cbrt30.8

      \[\leadsto y \cdot \color{blue}{\left(\left(\sqrt[3]{\frac{x - 1.0}{y + 1.0}} \cdot \sqrt[3]{\frac{x - 1.0}{y + 1.0}}\right) \cdot \sqrt[3]{\frac{x - 1.0}{y + 1.0}}\right)} + 1.0\]
    11. Applied associate-*r*30.8

      \[\leadsto \color{blue}{\left(y \cdot \left(\sqrt[3]{\frac{x - 1.0}{y + 1.0}} \cdot \sqrt[3]{\frac{x - 1.0}{y + 1.0}}\right)\right) \cdot \sqrt[3]{\frac{x - 1.0}{y + 1.0}}} + 1.0\]
    12. Taylor expanded around inf 14.6

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

      \[\leadsto \color{blue}{\left(\frac{\frac{x}{y} \cdot 1.0}{y} + x\right) - \frac{x}{y} \cdot 1.0}\]

    if -120684821833.98685 < y < 4.471669177154523e+32

    1. Initial program 1.2

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

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

      \[\leadsto \mathsf{fma}\left(y, \frac{x - 1.0}{\color{blue}{\frac{{1.0}^{3} + {y}^{3}}{1.0 \cdot 1.0 + \left(y \cdot y - 1.0 \cdot y\right)}}}, 1.0\right)\]
    5. Applied associate-/r/1.2

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\frac{x - 1.0}{{1.0}^{3} + {y}^{3}} \cdot \left(1.0 \cdot 1.0 + \left(y \cdot y - 1.0 \cdot y\right)\right)}, 1.0\right)\]
    6. Simplified1.2

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

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

Reproduce

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