Average Error: 6.8 → 1.9
Time: 12.2s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.867509036970048745891178036710973818173 \cdot 10^{-290}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;x \le 9.954863872437945886830732175117733893802 \cdot 10^{-260}:\\ \;\;\;\;\frac{y - x}{t} \cdot z + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \end{array}\]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;x \le -3.867509036970048745891178036710973818173 \cdot 10^{-290}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r401297 = x;
        double r401298 = y;
        double r401299 = r401298 - r401297;
        double r401300 = z;
        double r401301 = r401299 * r401300;
        double r401302 = t;
        double r401303 = r401301 / r401302;
        double r401304 = r401297 + r401303;
        return r401304;
}

double f(double x, double y, double z, double t) {
        double r401305 = x;
        double r401306 = -3.867509036970049e-290;
        bool r401307 = r401305 <= r401306;
        double r401308 = y;
        double r401309 = r401308 - r401305;
        double r401310 = t;
        double r401311 = z;
        double r401312 = r401310 / r401311;
        double r401313 = r401309 / r401312;
        double r401314 = r401305 + r401313;
        double r401315 = 9.954863872437946e-260;
        bool r401316 = r401305 <= r401315;
        double r401317 = r401309 / r401310;
        double r401318 = r401317 * r401311;
        double r401319 = r401318 + r401305;
        double r401320 = r401311 / r401310;
        double r401321 = fma(r401309, r401320, r401305);
        double r401322 = r401316 ? r401319 : r401321;
        double r401323 = r401307 ? r401314 : r401322;
        return r401323;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.8
Target2.0
Herbie1.9
\[\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 < -3.867509036970049e-290

    1. Initial program 7.0

      \[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)}\]
    3. Using strategy rm
    4. Applied fma-udef1.9

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

      \[\leadsto \color{blue}{z \cdot \frac{y - x}{t}} + x\]
    6. Using strategy rm
    7. Applied associate-*r/7.0

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

      \[\leadsto \frac{\color{blue}{\left(y - x\right) \cdot z}}{t} + x\]
    9. Using strategy rm
    10. Applied associate-/l*1.9

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

    if -3.867509036970049e-290 < x < 9.954863872437946e-260

    1. Initial program 5.5

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

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

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

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

    if 9.954863872437946e-260 < x

    1. Initial program 6.7

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

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

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

Reproduce

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