Average Error: 6.1 → 1.9
Time: 18.0s
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 r20887112 = x;
        double r20887113 = y;
        double r20887114 = r20887113 - r20887112;
        double r20887115 = z;
        double r20887116 = r20887114 * r20887115;
        double r20887117 = t;
        double r20887118 = r20887116 / r20887117;
        double r20887119 = r20887112 + r20887118;
        return r20887119;
}

double f(double x, double y, double z, double t) {
        double r20887120 = z;
        double r20887121 = t;
        double r20887122 = r20887120 / r20887121;
        double r20887123 = y;
        double r20887124 = x;
        double r20887125 = r20887124 * r20887122;
        double r20887126 = r20887124 - r20887125;
        double r20887127 = fma(r20887122, r20887123, r20887126);
        return r20887127;
}

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