Average Error: 0.1 → 0.0
Time: 7.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 r366700 = d1;
        double r366701 = 3.0;
        double r366702 = r366700 * r366701;
        double r366703 = d2;
        double r366704 = r366700 * r366703;
        double r366705 = r366702 + r366704;
        double r366706 = d3;
        double r366707 = r366700 * r366706;
        double r366708 = r366705 + r366707;
        return r366708;
}

double f(double d1, double d2, double d3) {
        double r366709 = d1;
        double r366710 = 3.0;
        double r366711 = d2;
        double r366712 = r366709 * r366711;
        double r366713 = fma(r366709, r366710, r366712);
        double r366714 = d3;
        double r366715 = r366709 * r366714;
        double r366716 = r366713 + r366715;
        return r366716;
}

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 2019350 +o rules:numerics
(FPCore (d1 d2 d3)
  :name "FastMath test3"
  :precision binary64

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

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