Average Error: 6.9 → 2.1
Time: 3.0s
Precision: 64
\[x + \frac{\left(y - x\right) \cdot z}{t}\]
\[\mathsf{fma}\left(\frac{z}{t}, y - x, x\right)\]
x + \frac{\left(y - x\right) \cdot z}{t}
\mathsf{fma}\left(\frac{z}{t}, y - x, x\right)
double f(double x, double y, double z, double t) {
        double r494921 = x;
        double r494922 = y;
        double r494923 = r494922 - r494921;
        double r494924 = z;
        double r494925 = r494923 * r494924;
        double r494926 = t;
        double r494927 = r494925 / r494926;
        double r494928 = r494921 + r494927;
        return r494928;
}

double f(double x, double y, double z, double t) {
        double r494929 = z;
        double r494930 = t;
        double r494931 = r494929 / r494930;
        double r494932 = y;
        double r494933 = x;
        double r494934 = r494932 - r494933;
        double r494935 = fma(r494931, r494934, r494933);
        return r494935;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.9
Target2.0
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. Initial program 6.9

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

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

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

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

    \[\leadsto \color{blue}{\frac{z}{\frac{t}{y - x}}} + x\]
  8. Using strategy rm
  9. Applied associate-/r/2.1

    \[\leadsto \color{blue}{\frac{z}{t} \cdot \left(y - x\right)} + x\]
  10. Applied fma-def2.1

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

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

Reproduce

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