Average Error: 0.2 → 0.0
Time: 1.0s
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 r153076 = d1;
        double r153077 = 10.0;
        double r153078 = r153076 * r153077;
        double r153079 = d2;
        double r153080 = r153076 * r153079;
        double r153081 = r153078 + r153080;
        double r153082 = 20.0;
        double r153083 = r153076 * r153082;
        double r153084 = r153081 + r153083;
        return r153084;
}

double f(double d1, double d2) {
        double r153085 = 30.0;
        double r153086 = d1;
        double r153087 = d2;
        double r153088 = r153086 * r153087;
        double r153089 = fma(r153085, r153086, r153088);
        return r153089;
}

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(d1, 10 + d2, d1 \cdot 20\right)}\]
  3. Taylor expanded around 0 0.0

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

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

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

Reproduce

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

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

  (+ (+ (* d1 10) (* d1 d2)) (* d1 20)))