Average Error: 6.5 → 1.6
Time: 2.9s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.4093442608188232 \cdot 10^{-20}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\ \mathbf{elif}\;z \le -9.0264403633635939 \cdot 10^{-299}:\\ \;\;\;\;\left(\frac{z \cdot y}{t} - \frac{x \cdot z}{t}\right) + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;z \le -5.4093442608188232 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\

\mathbf{elif}\;z \le -9.0264403633635939 \cdot 10^{-299}:\\
\;\;\;\;\left(\frac{z \cdot y}{t} - \frac{x \cdot z}{t}\right) + x\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r668215 = x;
        double r668216 = y;
        double r668217 = r668216 - r668215;
        double r668218 = z;
        double r668219 = r668217 * r668218;
        double r668220 = t;
        double r668221 = r668219 / r668220;
        double r668222 = r668215 + r668221;
        return r668222;
}

double f(double x, double y, double z, double t) {
        double r668223 = z;
        double r668224 = -5.409344260818823e-20;
        bool r668225 = r668223 <= r668224;
        double r668226 = y;
        double r668227 = x;
        double r668228 = r668226 - r668227;
        double r668229 = t;
        double r668230 = r668228 / r668229;
        double r668231 = fma(r668230, r668223, r668227);
        double r668232 = -9.026440363363594e-299;
        bool r668233 = r668223 <= r668232;
        double r668234 = r668223 * r668226;
        double r668235 = r668234 / r668229;
        double r668236 = r668227 * r668223;
        double r668237 = r668236 / r668229;
        double r668238 = r668235 - r668237;
        double r668239 = r668238 + r668227;
        double r668240 = r668223 / r668229;
        double r668241 = fma(r668240, r668228, r668227);
        double r668242 = r668233 ? r668239 : r668241;
        double r668243 = r668225 ? r668231 : r668242;
        return r668243;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.5
Target1.9
Herbie1.6
\[\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 < -5.409344260818823e-20

    1. Initial program 13.9

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

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

    if -5.409344260818823e-20 < z < -9.026440363363594e-299

    1. Initial program 1.2

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{\frac{t}{y - x}}}, z, x\right)\]
    5. Using strategy rm
    6. Applied fma-udef9.7

      \[\leadsto \color{blue}{\frac{1}{\frac{t}{y - x}} \cdot z + x}\]
    7. Simplified8.8

      \[\leadsto \color{blue}{\frac{z}{\frac{t}{y - x}}} + x\]
    8. Taylor expanded around 0 1.2

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

    if -9.026440363363594e-299 < z

    1. Initial program 6.2

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{t}{y - x}} \cdot z + x}\]
    7. Simplified6.7

      \[\leadsto \color{blue}{\frac{z}{\frac{t}{y - x}}} + x\]
    8. Using strategy rm
    9. Applied associate-/r/1.8

      \[\leadsto \color{blue}{\frac{z}{t} \cdot \left(y - x\right)} + x\]
    10. Applied fma-def1.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.4093442608188232 \cdot 10^{-20}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y - x}{t}, z, x\right)\\ \mathbf{elif}\;z \le -9.0264403633635939 \cdot 10^{-299}:\\ \;\;\;\;\left(\frac{z \cdot y}{t} - \frac{x \cdot z}{t}\right) + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \end{array}\]

Reproduce

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