Average Error: 0.1 → 0.0
Time: 5.0s
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 r339577 = d1;
        double r339578 = 3.0;
        double r339579 = r339577 * r339578;
        double r339580 = d2;
        double r339581 = r339577 * r339580;
        double r339582 = r339579 + r339581;
        double r339583 = d3;
        double r339584 = r339577 * r339583;
        double r339585 = r339582 + r339584;
        return r339585;
}

double f(double d1, double d2, double d3) {
        double r339586 = d1;
        double r339587 = 3.0;
        double r339588 = d2;
        double r339589 = r339586 * r339588;
        double r339590 = fma(r339586, r339587, r339589);
        double r339591 = d3;
        double r339592 = r339586 * r339591;
        double r339593 = r339590 + r339592;
        return r339593;
}

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

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

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