Average Error: 21.9 → 0.2
Time: 10.0s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -153989642.26731661 \lor \neg \left(y \le 96213748.28506726\right):\\ \;\;\;\;\left(\frac{1}{y} + x\right) - 1 \cdot \frac{x}{y}\\ \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 -153989642.26731661 \lor \neg \left(y \le 96213748.28506726\right):\\
\;\;\;\;\left(\frac{1}{y} + x\right) - 1 \cdot \frac{x}{y}\\

\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 r731146 = 1.0;
        double r731147 = x;
        double r731148 = r731146 - r731147;
        double r731149 = y;
        double r731150 = r731148 * r731149;
        double r731151 = r731149 + r731146;
        double r731152 = r731150 / r731151;
        double r731153 = r731146 - r731152;
        return r731153;
}

double f(double x, double y) {
        double r731154 = y;
        double r731155 = -153989642.2673166;
        bool r731156 = r731154 <= r731155;
        double r731157 = 96213748.28506726;
        bool r731158 = r731154 <= r731157;
        double r731159 = !r731158;
        bool r731160 = r731156 || r731159;
        double r731161 = 1.0;
        double r731162 = r731161 / r731154;
        double r731163 = x;
        double r731164 = r731162 + r731163;
        double r731165 = r731163 / r731154;
        double r731166 = r731161 * r731165;
        double r731167 = r731164 - r731166;
        double r731168 = r731163 - r731161;
        double r731169 = r731154 * r731154;
        double r731170 = r731161 * r731161;
        double r731171 = r731169 - r731170;
        double r731172 = r731168 / r731171;
        double r731173 = r731154 - r731161;
        double r731174 = r731172 * r731173;
        double r731175 = fma(r731174, r731154, r731161);
        double r731176 = r731160 ? r731167 : r731175;
        return r731176;
}

Error

Bits error versus x

Bits error versus y

Target

Original21.9
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 < -153989642.2673166 or 96213748.28506726 < y

    1. Initial program 45.0

      \[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. Using strategy rm
    4. Applied flip-+45.3

      \[\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.4

      \[\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}{\left(\frac{1}{y} + x\right) - 1 \cdot \frac{x}{y}}\]

    if -153989642.2673166 < y < 96213748.28506726

    1. Initial program 0.1

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

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

      \[\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.1

      \[\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 -153989642.26731661 \lor \neg \left(y \le 96213748.28506726\right):\\ \;\;\;\;\left(\frac{1}{y} + x\right) - 1 \cdot \frac{x}{y}\\ \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 2020046 +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))))