Average Error: 6.5 → 2.8
Time: 2.3s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.65847709437532703 \cdot 10^{-177}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\frac{t}{y - x}}, z, x\right)\\ \mathbf{elif}\;z \le 3.83756883089101483 \cdot 10^{-81}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x - \frac{x \cdot z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;z \le -2.65847709437532703 \cdot 10^{-177}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\frac{t}{y - x}}, z, x\right)\\

\mathbf{elif}\;z \le 3.83756883089101483 \cdot 10^{-81}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x - \frac{x \cdot z}{t}\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r456449 = x;
        double r456450 = y;
        double r456451 = r456450 - r456449;
        double r456452 = z;
        double r456453 = r456451 * r456452;
        double r456454 = t;
        double r456455 = r456453 / r456454;
        double r456456 = r456449 + r456455;
        return r456456;
}

double f(double x, double y, double z, double t) {
        double r456457 = z;
        double r456458 = -2.658477094375327e-177;
        bool r456459 = r456457 <= r456458;
        double r456460 = 1.0;
        double r456461 = t;
        double r456462 = y;
        double r456463 = x;
        double r456464 = r456462 - r456463;
        double r456465 = r456461 / r456464;
        double r456466 = r456460 / r456465;
        double r456467 = fma(r456466, r456457, r456463);
        double r456468 = 3.837568830891015e-81;
        bool r456469 = r456457 <= r456468;
        double r456470 = r456457 / r456461;
        double r456471 = r456463 * r456457;
        double r456472 = r456471 / r456461;
        double r456473 = r456463 - r456472;
        double r456474 = fma(r456470, r456462, r456473);
        double r456475 = r456464 / r456461;
        double r456476 = fma(r456475, r456457, r456463);
        double r456477 = r456469 ? r456474 : r456476;
        double r456478 = r456459 ? r456467 : r456477;
        return r456478;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.5
Target2.0
Herbie2.8
\[\begin{array}{l} \mathbf{if}\;x \lt -9.0255111955330046 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x \lt 4.2750321637007147 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -2.658477094375327e-177

    1. Initial program 8.1

      \[x + \frac{\left(y - x\right) \cdot z}{t}\]
    2. Simplified4.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)}\]
    3. Using strategy rm
    4. Applied clear-num4.1

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

    if -2.658477094375327e-177 < z < 3.837568830891015e-81

    1. Initial program 1.6

      \[x + \frac{\left(y - x\right) \cdot z}{t}\]
    2. Simplified11.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)}\]
    3. Using strategy rm
    4. Applied div-inv11.8

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(y - x\right) \cdot \frac{1}{t}}, z, x\right)\]
    5. Taylor expanded around 0 1.6

      \[\leadsto \color{blue}{\left(\frac{z \cdot y}{t} + x\right) - \frac{x \cdot z}{t}}\]
    6. Simplified1.8

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

    if 3.837568830891015e-81 < z

    1. Initial program 11.2

      \[x + \frac{\left(y - x\right) \cdot z}{t}\]
    2. Simplified2.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)}\]
    3. Using strategy rm
    4. Applied clear-num2.6

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{\frac{t}{y - x}}}, z, x\right)\]
    5. Taylor expanded around inf 11.2

      \[\leadsto \color{blue}{\left(\frac{z \cdot y}{t} + x\right) - \frac{x \cdot z}{t}}\]
    6. Simplified2.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.65847709437532703 \cdot 10^{-177}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\frac{t}{y - x}}, z, x\right)\\ \mathbf{elif}\;z \le 3.83756883089101483 \cdot 10^{-81}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x - \frac{x \cdot z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020062 +o rules:numerics
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

  (+ x (/ (* (- y x) z) t)))