Average Error: 22.4 → 7.7
Time: 3.7s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -18236680180944340 \lor \neg \left(y \le 29987682850388436\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right), x - 1, 1\right)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -18236680180944340 \lor \neg \left(y \le 29987682850388436\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\

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

\end{array}
double f(double x, double y) {
        double r238759 = 1.0;
        double r238760 = x;
        double r238761 = r238759 - r238760;
        double r238762 = y;
        double r238763 = r238761 * r238762;
        double r238764 = r238762 + r238759;
        double r238765 = r238763 / r238764;
        double r238766 = r238759 - r238765;
        return r238766;
}

double f(double x, double y) {
        double r238767 = y;
        double r238768 = -1.823668018094434e+16;
        bool r238769 = r238767 <= r238768;
        double r238770 = 29987682850388436.0;
        bool r238771 = r238767 <= r238770;
        double r238772 = !r238771;
        bool r238773 = r238769 || r238772;
        double r238774 = x;
        double r238775 = r238774 / r238767;
        double r238776 = 1.0;
        double r238777 = r238776 / r238767;
        double r238778 = r238777 - r238776;
        double r238779 = fma(r238775, r238778, r238774);
        double r238780 = r238767 * r238767;
        double r238781 = r238776 * r238776;
        double r238782 = r238780 - r238781;
        double r238783 = r238767 / r238782;
        double r238784 = r238767 - r238776;
        double r238785 = r238783 * r238784;
        double r238786 = r238774 - r238776;
        double r238787 = fma(r238785, r238786, r238776);
        double r238788 = r238773 ? r238779 : r238787;
        return r238788;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.4
Target0.2
Herbie7.7
\[\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 < -1.823668018094434e+16 or 29987682850388436.0 < y

    1. Initial program 46.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{y + 1}, x - 1, 1\right)}\]
    3. Taylor expanded around inf 15.7

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

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

    if -1.823668018094434e+16 < y < 29987682850388436.0

    1. Initial program 0.7

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

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

      \[\leadsto \mathsf{fma}\left(\frac{y}{\color{blue}{\frac{y \cdot y - 1 \cdot 1}{y - 1}}}, x - 1, 1\right)\]
    5. Applied associate-/r/0.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -18236680180944340 \lor \neg \left(y \le 29987682850388436\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{1}{y} - 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{y \cdot y - 1 \cdot 1} \cdot \left(y - 1\right), x - 1, 1\right)\\ \end{array}\]

Reproduce

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