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

\mathbf{else}:\\
\;\;\;\;\frac{x - 1}{y + 1} \cdot y + 1\\

\end{array}
double f(double x, double y) {
        double r439309 = 1.0;
        double r439310 = x;
        double r439311 = r439309 - r439310;
        double r439312 = y;
        double r439313 = r439311 * r439312;
        double r439314 = r439312 + r439309;
        double r439315 = r439313 / r439314;
        double r439316 = r439309 - r439315;
        return r439316;
}

double f(double x, double y) {
        double r439317 = y;
        double r439318 = -1979426812970.8699;
        bool r439319 = r439317 <= r439318;
        double r439320 = 216523043.9852226;
        bool r439321 = r439317 <= r439320;
        double r439322 = !r439321;
        bool r439323 = r439319 || r439322;
        double r439324 = 1.0;
        double r439325 = 1.0;
        double r439326 = r439325 / r439317;
        double r439327 = x;
        double r439328 = r439327 / r439317;
        double r439329 = r439326 - r439328;
        double r439330 = fma(r439324, r439329, r439327);
        double r439331 = r439327 - r439324;
        double r439332 = r439317 + r439324;
        double r439333 = r439331 / r439332;
        double r439334 = r439333 * r439317;
        double r439335 = r439334 + r439324;
        double r439336 = r439323 ? r439330 : r439335;
        return r439336;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.4
Target0.2
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 < -1979426812970.8699 or 216523043.9852226 < y

    1. Initial program 46.2

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

      \[\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 -1979426812970.8699 < y < 216523043.9852226

    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 fma-udef0.2

      \[\leadsto \color{blue}{\frac{x - 1}{y + 1} \cdot y + 1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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