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

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

\end{array}
double f(double x, double y) {
        double r818204 = 1.0;
        double r818205 = x;
        double r818206 = r818204 - r818205;
        double r818207 = y;
        double r818208 = r818206 * r818207;
        double r818209 = r818207 + r818204;
        double r818210 = r818208 / r818209;
        double r818211 = r818204 - r818210;
        return r818211;
}

double f(double x, double y) {
        double r818212 = y;
        double r818213 = -213552842032.68936;
        bool r818214 = r818212 <= r818213;
        double r818215 = 117884680.70271897;
        bool r818216 = r818212 <= r818215;
        double r818217 = !r818216;
        bool r818218 = r818214 || r818217;
        double r818219 = 1.0;
        double r818220 = 1.0;
        double r818221 = r818220 / r818212;
        double r818222 = x;
        double r818223 = r818222 / r818212;
        double r818224 = r818221 - r818223;
        double r818225 = fma(r818219, r818224, r818222);
        double r818226 = r818222 - r818219;
        double r818227 = r818212 + r818219;
        double r818228 = r818226 / r818227;
        double r818229 = fma(r818228, r818212, r818219);
        double r818230 = r818218 ? r818225 : r818229;
        return r818230;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.7
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 < -213552842032.68936 or 117884680.70271897 < y

    1. Initial program 45.8

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

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

      \[\leadsto \mathsf{fma}\left(\frac{y}{\color{blue}{1 \cdot \left(y + 1\right)}}, x - 1, 1\right)\]
    5. Applied add-cube-cbrt30.1

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}}{1 \cdot \left(y + 1\right)}, x - 1, 1\right)\]
    6. Applied times-frac30.1

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{1} \cdot \frac{\sqrt[3]{y}}{y + 1}}, x - 1, 1\right)\]
    7. Simplified30.1

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right)} \cdot \frac{\sqrt[3]{y}}{y + 1}, x - 1, 1\right)\]
    8. Using strategy rm
    9. Applied fma-udef30.1

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \frac{\sqrt[3]{y}}{y + 1}\right) \cdot \left(x - 1\right) + 1}\]
    10. Simplified29.3

      \[\leadsto \color{blue}{\frac{x - 1}{\frac{y + 1}{y}}} + 1\]
    11. Taylor expanded around inf 0.1

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

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

    if -213552842032.68936 < y < 117884680.70271897

    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{y}{y + 1}, x - 1, 1\right)}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity0.2

      \[\leadsto \mathsf{fma}\left(\frac{y}{\color{blue}{1 \cdot \left(y + 1\right)}}, x - 1, 1\right)\]
    5. Applied add-cube-cbrt0.6

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}}{1 \cdot \left(y + 1\right)}, x - 1, 1\right)\]
    6. Applied times-frac0.6

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{1} \cdot \frac{\sqrt[3]{y}}{y + 1}}, x - 1, 1\right)\]
    7. Simplified0.6

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right)} \cdot \frac{\sqrt[3]{y}}{y + 1}, x - 1, 1\right)\]
    8. Using strategy rm
    9. Applied fma-udef0.6

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

      \[\leadsto \color{blue}{\frac{x - 1}{\frac{y + 1}{y}}} + 1\]
    11. Using strategy rm
    12. Applied associate-/r/0.2

      \[\leadsto \color{blue}{\frac{x - 1}{y + 1} \cdot y} + 1\]
    13. Applied fma-def0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x - 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 -213552842032.689361572265625 \lor \neg \left(y \le 117884680.7027189731597900390625\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{y} - \frac{x}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x - 1}{y + 1}, y, 1\right)\\ \end{array}\]

Reproduce

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