Average Error: 22.2 → 0.2
Time: 9.6s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -198843285.268944234 \lor \neg \left(y \le 212488777.898407\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -198843285.268944234 \lor \neg \left(y \le 212488777.898407\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\

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

\end{array}
double f(double x, double y) {
        double r706229 = 1.0;
        double r706230 = x;
        double r706231 = r706229 - r706230;
        double r706232 = y;
        double r706233 = r706231 * r706232;
        double r706234 = r706232 + r706229;
        double r706235 = r706233 / r706234;
        double r706236 = r706229 - r706235;
        return r706236;
}

double f(double x, double y) {
        double r706237 = y;
        double r706238 = -198843285.26894423;
        bool r706239 = r706237 <= r706238;
        double r706240 = 212488777.89840698;
        bool r706241 = r706237 <= r706240;
        double r706242 = !r706241;
        bool r706243 = r706239 || r706242;
        double r706244 = 1.0;
        double r706245 = 1.0;
        double r706246 = r706245 / r706237;
        double r706247 = x;
        double r706248 = r706247 / r706237;
        double r706249 = r706246 - r706248;
        double r706250 = fma(r706244, r706249, r706247);
        double r706251 = r706244 - r706247;
        double r706252 = r706251 * r706237;
        double r706253 = r706237 + r706244;
        double r706254 = r706252 / r706253;
        double r706255 = r706244 - r706254;
        double r706256 = r706243 ? r706250 : r706255;
        return r706256;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.2
Target0.2
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;y \lt -3693.84827882972468:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y \lt 6799310503.41891003:\\ \;\;\;\;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 < -198843285.26894423 or 212488777.89840698 < y

    1. Initial program 45.7

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

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

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

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

    if -198843285.26894423 < y < 212488777.89840698

    1. Initial program 0.2

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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