Average Error: 6.4 → 2.1
Time: 2.9s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.7932208206939209 \cdot 10^{-119} \lor \neg \left(x \le 1.849643447572145 \cdot 10^{-145}\right):\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{t}{y - x}} + x\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;x \le -2.7932208206939209 \cdot 10^{-119} \lor \neg \left(x \le 1.849643447572145 \cdot 10^{-145}\right):\\
\;\;\;\;1 \cdot \mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r435166 = x;
        double r435167 = y;
        double r435168 = r435167 - r435166;
        double r435169 = z;
        double r435170 = r435168 * r435169;
        double r435171 = t;
        double r435172 = r435170 / r435171;
        double r435173 = r435166 + r435172;
        return r435173;
}

double f(double x, double y, double z, double t) {
        double r435174 = x;
        double r435175 = -2.793220820693921e-119;
        bool r435176 = r435174 <= r435175;
        double r435177 = 1.849643447572145e-145;
        bool r435178 = r435174 <= r435177;
        double r435179 = !r435178;
        bool r435180 = r435176 || r435179;
        double r435181 = 1.0;
        double r435182 = z;
        double r435183 = t;
        double r435184 = r435182 / r435183;
        double r435185 = y;
        double r435186 = r435185 - r435174;
        double r435187 = fma(r435184, r435186, r435174);
        double r435188 = r435181 * r435187;
        double r435189 = r435183 / r435186;
        double r435190 = r435182 / r435189;
        double r435191 = r435190 + r435174;
        double r435192 = r435180 ? r435188 : r435191;
        return r435192;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.4
Target2.1
Herbie2.1
\[\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 2 regimes
  2. if x < -2.793220820693921e-119 or 1.849643447572145e-145 < x

    1. Initial program 6.8

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

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

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

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

      \[\leadsto \color{blue}{\frac{z}{\frac{t}{y - x}}} + x\]
    8. Using strategy rm
    9. Applied *-un-lft-identity6.8

      \[\leadsto \frac{z}{\frac{t}{y - x}} + \color{blue}{1 \cdot x}\]
    10. Applied *-un-lft-identity6.8

      \[\leadsto \color{blue}{1 \cdot \frac{z}{\frac{t}{y - x}}} + 1 \cdot x\]
    11. Applied distribute-lft-out6.8

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

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

    if -2.793220820693921e-119 < x < 1.849643447572145e-145

    1. Initial program 5.5

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.7932208206939209 \cdot 10^{-119} \lor \neg \left(x \le 1.849643447572145 \cdot 10^{-145}\right):\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{t}{y - x}} + x\\ \end{array}\]

Reproduce

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