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

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

\end{array}
double f(double x, double y) {
        double r433206 = 1.0;
        double r433207 = x;
        double r433208 = r433206 - r433207;
        double r433209 = y;
        double r433210 = r433208 * r433209;
        double r433211 = r433209 + r433206;
        double r433212 = r433210 / r433211;
        double r433213 = r433206 - r433212;
        return r433213;
}

double f(double x, double y) {
        double r433214 = y;
        double r433215 = -197475236.47678238;
        bool r433216 = r433214 <= r433215;
        double r433217 = 107669609.3560517;
        bool r433218 = r433214 <= r433217;
        double r433219 = !r433218;
        bool r433220 = r433216 || r433219;
        double r433221 = 1.0;
        double r433222 = 1.0;
        double r433223 = r433222 / r433214;
        double r433224 = x;
        double r433225 = r433224 / r433214;
        double r433226 = r433223 - r433225;
        double r433227 = fma(r433221, r433226, r433224);
        double r433228 = r433224 - r433221;
        double r433229 = r433214 * r433214;
        double r433230 = r433221 * r433221;
        double r433231 = r433229 - r433230;
        double r433232 = r433228 / r433231;
        double r433233 = r433214 - r433221;
        double r433234 = r433232 * r433233;
        double r433235 = fma(r433234, r433214, r433221);
        double r433236 = r433220 ? r433227 : r433235;
        return r433236;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.3
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 < -197475236.47678238 or 107669609.3560517 < y

    1. Initial program 45.7

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

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

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

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

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

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

    if -197475236.47678238 < y < 107669609.3560517

    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 flip-+0.2

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

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

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

Reproduce

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