Average Error: 6.5 → 2.8
Time: 2.5s
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 r381715 = x;
        double r381716 = y;
        double r381717 = r381716 - r381715;
        double r381718 = z;
        double r381719 = r381717 * r381718;
        double r381720 = t;
        double r381721 = r381719 / r381720;
        double r381722 = r381715 + r381721;
        return r381722;
}

double f(double x, double y, double z, double t) {
        double r381723 = z;
        double r381724 = -2.658477094375327e-177;
        bool r381725 = r381723 <= r381724;
        double r381726 = 1.0;
        double r381727 = t;
        double r381728 = y;
        double r381729 = x;
        double r381730 = r381728 - r381729;
        double r381731 = r381727 / r381730;
        double r381732 = r381726 / r381731;
        double r381733 = fma(r381732, r381723, r381729);
        double r381734 = 3.837568830891015e-81;
        bool r381735 = r381723 <= r381734;
        double r381736 = r381723 / r381727;
        double r381737 = r381729 * r381723;
        double r381738 = r381737 / r381727;
        double r381739 = r381729 - r381738;
        double r381740 = fma(r381736, r381728, r381739);
        double r381741 = r381730 / r381727;
        double r381742 = fma(r381741, r381723, r381729);
        double r381743 = r381735 ? r381740 : r381742;
        double r381744 = r381725 ? r381733 : r381743;
        return r381744;
}

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)))