Average Error: 0.2 → 0.0
Time: 8.2s
Precision: 64
\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
\[\mathsf{fma}\left(30, d1, d1 \cdot d2\right)\]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20
\mathsf{fma}\left(30, d1, d1 \cdot d2\right)
double f(double d1, double d2) {
        double r161077 = d1;
        double r161078 = 10.0;
        double r161079 = r161077 * r161078;
        double r161080 = d2;
        double r161081 = r161077 * r161080;
        double r161082 = r161079 + r161081;
        double r161083 = 20.0;
        double r161084 = r161077 * r161083;
        double r161085 = r161082 + r161084;
        return r161085;
}

double f(double d1, double d2) {
        double r161086 = 30.0;
        double r161087 = d1;
        double r161088 = d2;
        double r161089 = r161087 * r161088;
        double r161090 = fma(r161086, r161087, r161089);
        return r161090;
}

Error

Bits error versus d1

Bits error versus d2

Target

Original0.2
Target0.0
Herbie0.0
\[d1 \cdot \left(30 + d2\right)\]

Derivation

  1. Initial program 0.2

    \[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
  2. Simplified0.0

    \[\leadsto \color{blue}{d1 \cdot \left(20 + \left(10 + d2\right)\right)}\]
  3. Using strategy rm
  4. Applied add-exp-log15.4

    \[\leadsto d1 \cdot \color{blue}{e^{\log \left(20 + \left(10 + d2\right)\right)}}\]
  5. Taylor expanded around 0 0.0

    \[\leadsto \color{blue}{30 \cdot d1 + d1 \cdot d2}\]
  6. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(30, d1, d1 \cdot d2\right)}\]
  7. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(30, d1, d1 \cdot d2\right)\]

Reproduce

herbie shell --seed 2019198 +o rules:numerics
(FPCore (d1 d2)
  :name "FastMath test2"

  :herbie-target
  (* d1 (+ 30.0 d2))

  (+ (+ (* d1 10.0) (* d1 d2)) (* d1 20.0)))