Average Error: 6.6 → 2.0
Time: 14.1s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.800389692060424312600133254503662266438 \cdot 10^{-86}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;x \le -3.615258638221127683072678174846267896082 \cdot 10^{-215}:\\ \;\;\;\;z \cdot \frac{y - x}{t} + x\\ \mathbf{elif}\;x \le 1.013053324772574326625267410473662208197 \cdot 10^{-244}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;x \le 9.92450237448606449054040694409844020485 \cdot 10^{-151}:\\ \;\;\;\;x + \frac{1}{t} \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y - x}{\frac{t}{z}} + x\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;x \le -4.800389692060424312600133254503662266438 \cdot 10^{-86}:\\
\;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\

\mathbf{elif}\;x \le -3.615258638221127683072678174846267896082 \cdot 10^{-215}:\\
\;\;\;\;z \cdot \frac{y - x}{t} + x\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{y - x}{\frac{t}{z}} + x\\

\end{array}
double f(double x, double y, double z, double t) {
        double r20819230 = x;
        double r20819231 = y;
        double r20819232 = r20819231 - r20819230;
        double r20819233 = z;
        double r20819234 = r20819232 * r20819233;
        double r20819235 = t;
        double r20819236 = r20819234 / r20819235;
        double r20819237 = r20819230 + r20819236;
        return r20819237;
}

double f(double x, double y, double z, double t) {
        double r20819238 = x;
        double r20819239 = -4.800389692060424e-86;
        bool r20819240 = r20819238 <= r20819239;
        double r20819241 = y;
        double r20819242 = r20819241 - r20819238;
        double r20819243 = z;
        double r20819244 = t;
        double r20819245 = r20819243 / r20819244;
        double r20819246 = fma(r20819242, r20819245, r20819238);
        double r20819247 = -3.6152586382211277e-215;
        bool r20819248 = r20819238 <= r20819247;
        double r20819249 = r20819242 / r20819244;
        double r20819250 = r20819243 * r20819249;
        double r20819251 = r20819250 + r20819238;
        double r20819252 = 1.0130533247725743e-244;
        bool r20819253 = r20819238 <= r20819252;
        double r20819254 = 9.924502374486064e-151;
        bool r20819255 = r20819238 <= r20819254;
        double r20819256 = 1.0;
        double r20819257 = r20819256 / r20819244;
        double r20819258 = r20819242 * r20819243;
        double r20819259 = r20819257 * r20819258;
        double r20819260 = r20819238 + r20819259;
        double r20819261 = r20819244 / r20819243;
        double r20819262 = r20819242 / r20819261;
        double r20819263 = r20819262 + r20819238;
        double r20819264 = r20819255 ? r20819260 : r20819263;
        double r20819265 = r20819253 ? r20819246 : r20819264;
        double r20819266 = r20819248 ? r20819251 : r20819265;
        double r20819267 = r20819240 ? r20819246 : r20819266;
        return r20819267;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.6
Target1.9
Herbie2.0
\[\begin{array}{l} \mathbf{if}\;x \lt -9.025511195533004570453352523209034680317 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x \lt 4.275032163700714748507147332551979944314 \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 4 regimes
  2. if x < -4.800389692060424e-86 or -3.6152586382211277e-215 < x < 1.0130533247725743e-244

    1. Initial program 6.8

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

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

    if -4.800389692060424e-86 < x < -3.6152586382211277e-215

    1. Initial program 4.6

      \[x + \frac{\left(y - x\right) \cdot z}{t}\]
    2. Using strategy rm
    3. Applied associate-/l*3.1

      \[\leadsto x + \color{blue}{\frac{y - x}{\frac{t}{z}}}\]
    4. Using strategy rm
    5. Applied associate-/r/4.4

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

    if 1.0130533247725743e-244 < x < 9.924502374486064e-151

    1. Initial program 4.4

      \[x + \frac{\left(y - x\right) \cdot z}{t}\]
    2. Using strategy rm
    3. Applied div-inv4.5

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

    if 9.924502374486064e-151 < x

    1. Initial program 7.5

      \[x + \frac{\left(y - x\right) \cdot z}{t}\]
    2. Using strategy rm
    3. Applied associate-/l*0.7

      \[\leadsto x + \color{blue}{\frac{y - x}{\frac{t}{z}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification2.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.800389692060424312600133254503662266438 \cdot 10^{-86}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;x \le -3.615258638221127683072678174846267896082 \cdot 10^{-215}:\\ \;\;\;\;z \cdot \frac{y - x}{t} + x\\ \mathbf{elif}\;x \le 1.013053324772574326625267410473662208197 \cdot 10^{-244}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;x \le 9.92450237448606449054040694409844020485 \cdot 10^{-151}:\\ \;\;\;\;x + \frac{1}{t} \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y - x}{\frac{t}{z}} + x\\ \end{array}\]

Reproduce

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

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