Average Error: 0.1 → 0.0
Time: 6.2s
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 r205658 = d1;
        double r205659 = 3.0;
        double r205660 = r205658 * r205659;
        double r205661 = d2;
        double r205662 = r205658 * r205661;
        double r205663 = r205660 + r205662;
        double r205664 = d3;
        double r205665 = r205658 * r205664;
        double r205666 = r205663 + r205665;
        return r205666;
}

double f(double d1, double d2, double d3) {
        double r205667 = d1;
        double r205668 = 3.0;
        double r205669 = d2;
        double r205670 = r205667 * r205669;
        double r205671 = fma(r205667, r205668, r205670);
        double r205672 = d3;
        double r205673 = r205667 * r205672;
        double r205674 = r205671 + r205673;
        return r205674;
}

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)))