Average Error: 0.1 → 0.0
Time: 5.4s
Precision: 64
\[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3\]
\[\mathsf{fma}\left(d1, 3, d1 \cdot d2\right) + d1 \cdot d3\]
\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3
\mathsf{fma}\left(d1, 3, d1 \cdot d2\right) + d1 \cdot d3
double f(double d1, double d2, double d3) {
        double r211302 = d1;
        double r211303 = 3.0;
        double r211304 = r211302 * r211303;
        double r211305 = d2;
        double r211306 = r211302 * r211305;
        double r211307 = r211304 + r211306;
        double r211308 = d3;
        double r211309 = r211302 * r211308;
        double r211310 = r211307 + r211309;
        return r211310;
}

double f(double d1, double d2, double d3) {
        double r211311 = d1;
        double r211312 = 3.0;
        double r211313 = d2;
        double r211314 = r211311 * r211313;
        double r211315 = fma(r211311, r211312, r211314);
        double r211316 = d3;
        double r211317 = r211311 * r211316;
        double r211318 = r211315 + r211317;
        return r211318;
}

Error

Bits error versus d1

Bits error versus d2

Bits error versus d3

Target

Original0.1
Target0.1
Herbie0.0
\[d1 \cdot \left(\left(3 + d2\right) + d3\right)\]

Derivation

  1. Initial program 0.1

    \[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3\]
  2. Using strategy rm
  3. Applied fma-def0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(d1, 3, d1 \cdot d2\right)} + d1 \cdot d3\]
  4. Final simplification0.0

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

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(FPCore (d1 d2 d3)
  :name "FastMath test3"
  :precision binary64

  :herbie-target
  (* d1 (+ (+ 3 d2) d3))

  (+ (+ (* d1 3) (* d1 d2)) (* d1 d3)))