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

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

\end{array}
double f(double x, double y) {
        double r504150 = 1.0;
        double r504151 = x;
        double r504152 = r504150 - r504151;
        double r504153 = y;
        double r504154 = r504152 * r504153;
        double r504155 = r504153 + r504150;
        double r504156 = r504154 / r504155;
        double r504157 = r504150 - r504156;
        return r504157;
}

double f(double x, double y) {
        double r504158 = y;
        double r504159 = -319655046.4933925;
        bool r504160 = r504158 <= r504159;
        double r504161 = 191468540.1676344;
        bool r504162 = r504158 <= r504161;
        double r504163 = !r504162;
        bool r504164 = r504160 || r504163;
        double r504165 = x;
        double r504166 = 1.0;
        double r504167 = r504166 / r504158;
        double r504168 = 1.0;
        double r504169 = r504168 - r504165;
        double r504170 = r504167 * r504169;
        double r504171 = r504165 + r504170;
        double r504172 = r504165 - r504166;
        double r504173 = r504158 + r504166;
        double r504174 = r504172 / r504173;
        double r504175 = fma(r504174, r504158, r504166);
        double r504176 = r504164 ? r504171 : r504175;
        return r504176;
}

Error

Bits error versus x

Bits error versus y

Target

Original22.5
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 < -319655046.4933925 or 191468540.1676344 < y

    1. Initial program 46.1

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

    if -319655046.4933925 < y < 191468540.1676344

    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. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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