Average Error: 6.4 → 1.1
Time: 1.2m
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;x + \frac{\left(y - x\right) \cdot z}{t} = -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t} - \frac{x}{t}, z, x\right)\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot z}{t} \le -2.715106235456037737959438890335298524578 \cdot 10^{-132}:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x - \frac{x}{\frac{t}{z}}\right)\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;x + \frac{\left(y - x\right) \cdot z}{t} = -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t} - \frac{x}{t}, z, x\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r20750325 = x;
        double r20750326 = y;
        double r20750327 = r20750326 - r20750325;
        double r20750328 = z;
        double r20750329 = r20750327 * r20750328;
        double r20750330 = t;
        double r20750331 = r20750329 / r20750330;
        double r20750332 = r20750325 + r20750331;
        return r20750332;
}

double f(double x, double y, double z, double t) {
        double r20750333 = x;
        double r20750334 = y;
        double r20750335 = r20750334 - r20750333;
        double r20750336 = z;
        double r20750337 = r20750335 * r20750336;
        double r20750338 = t;
        double r20750339 = r20750337 / r20750338;
        double r20750340 = r20750333 + r20750339;
        double r20750341 = -inf.0;
        bool r20750342 = r20750340 <= r20750341;
        double r20750343 = r20750334 / r20750338;
        double r20750344 = r20750333 / r20750338;
        double r20750345 = r20750343 - r20750344;
        double r20750346 = fma(r20750345, r20750336, r20750333);
        double r20750347 = -2.7151062354560377e-132;
        bool r20750348 = r20750340 <= r20750347;
        double r20750349 = r20750336 / r20750338;
        double r20750350 = r20750338 / r20750336;
        double r20750351 = r20750333 / r20750350;
        double r20750352 = r20750333 - r20750351;
        double r20750353 = fma(r20750349, r20750334, r20750352);
        double r20750354 = r20750348 ? r20750340 : r20750353;
        double r20750355 = r20750342 ? r20750346 : r20750354;
        return r20750355;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.4
Target2.1
Herbie1.1
\[\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 3 regimes
  2. if (+ x (/ (* (- y x) z) t)) < -inf.0

    1. Initial program 64.0

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

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

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

    if -inf.0 < (+ x (/ (* (- y x) z) t)) < -2.7151062354560377e-132

    1. Initial program 0.2

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

    if -2.7151062354560377e-132 < (+ x (/ (* (- y x) z) t))

    1. Initial program 6.4

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

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

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

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

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

Reproduce

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