Average Error: 6.1 → 1.9
Time: 18.6s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\mathsf{fma}\left(\frac{z}{t}, y, x - x \cdot \frac{z}{t}\right)\]
x + \frac{\left(y - x\right) \cdot z}{t}
\mathsf{fma}\left(\frac{z}{t}, y, x - x \cdot \frac{z}{t}\right)
double f(double x, double y, double z, double t) {
        double r19678162 = x;
        double r19678163 = y;
        double r19678164 = r19678163 - r19678162;
        double r19678165 = z;
        double r19678166 = r19678164 * r19678165;
        double r19678167 = t;
        double r19678168 = r19678166 / r19678167;
        double r19678169 = r19678162 + r19678168;
        return r19678169;
}

double f(double x, double y, double z, double t) {
        double r19678170 = z;
        double r19678171 = t;
        double r19678172 = r19678170 / r19678171;
        double r19678173 = y;
        double r19678174 = x;
        double r19678175 = r19678174 * r19678172;
        double r19678176 = r19678174 - r19678175;
        double r19678177 = fma(r19678172, r19678173, r19678176);
        return r19678177;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.1
Target1.7
Herbie1.9
\[\begin{array}{l} \mathbf{if}\;x \lt -9.025511195533005 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x \lt 4.275032163700715 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array}\]

Derivation

  1. Initial program 6.1

    \[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.1

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

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

    \[\leadsto \mathsf{fma}\left(\frac{z}{t}, y, x - \color{blue}{\left(x \cdot \frac{1}{t}\right)} \cdot z\right)\]
  7. Applied associate-*l*1.9

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

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

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

Reproduce

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