Average Error: 0.1 → 0.0
Time: 5.7s
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 r288040 = d1;
        double r288041 = 3.0;
        double r288042 = r288040 * r288041;
        double r288043 = d2;
        double r288044 = r288040 * r288043;
        double r288045 = r288042 + r288044;
        double r288046 = d3;
        double r288047 = r288040 * r288046;
        double r288048 = r288045 + r288047;
        return r288048;
}

double f(double d1, double d2, double d3) {
        double r288049 = d1;
        double r288050 = 3.0;
        double r288051 = d2;
        double r288052 = r288049 * r288051;
        double r288053 = fma(r288049, r288050, r288052);
        double r288054 = d3;
        double r288055 = r288049 * r288054;
        double r288056 = r288053 + r288055;
        return r288056;
}

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