Average Error: 22.6 → 0.2
Time: 16.8s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -127831090.96717210114002227783203125 \lor \neg \left(y \le 457167308.285513937473297119140625\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left(x - 1\right) \cdot \frac{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 -127831090.96717210114002227783203125 \lor \neg \left(y \le 457167308.285513937473297119140625\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\

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

\end{array}
double f(double x, double y) {
        double r531225 = 1.0;
        double r531226 = x;
        double r531227 = r531225 - r531226;
        double r531228 = y;
        double r531229 = r531227 * r531228;
        double r531230 = r531228 + r531225;
        double r531231 = r531229 / r531230;
        double r531232 = r531225 - r531231;
        return r531232;
}

double f(double x, double y) {
        double r531233 = y;
        double r531234 = -127831090.9671721;
        bool r531235 = r531233 <= r531234;
        double r531236 = 457167308.28551394;
        bool r531237 = r531233 <= r531236;
        double r531238 = !r531237;
        bool r531239 = r531235 || r531238;
        double r531240 = 1.0;
        double r531241 = 1.0;
        double r531242 = r531241 / r531233;
        double r531243 = x;
        double r531244 = r531243 / r531233;
        double r531245 = r531242 - r531244;
        double r531246 = fma(r531240, r531245, r531243);
        double r531247 = r531243 - r531240;
        double r531248 = r531233 + r531240;
        double r531249 = r531241 / r531248;
        double r531250 = r531247 * r531249;
        double r531251 = fma(r531250, r531233, r531240);
        double r531252 = r531239 ? r531246 : r531251;
        return r531252;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.6
Target0.3
Herbie0.2
\[\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 < -127831090.9671721 or 457167308.28551394 < y

    1. Initial program 45.7

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

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

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

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

    if -127831090.9671721 < y < 457167308.28551394

    1. Initial program 0.2

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

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

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

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

Reproduce

herbie shell --seed 2019209 +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.84827882972468) (- (/ 1 y) (- (/ x y) x)) (if (< y 6799310503.41891003) (- 1 (/ (* (- 1 x) y) (+ y 1))) (- (/ 1 y) (- (/ x y) x))))

  (- 1 (/ (* (- 1 x) y) (+ y 1))))