Average Error: 0.1 → 0.0
Time: 2.1s
Precision: 64
\[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3\]
\[\mathsf{fma}\left(3, d1, \mathsf{fma}\left(d1, d3, d1 \cdot d2\right)\right)\]
\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3
\mathsf{fma}\left(3, d1, \mathsf{fma}\left(d1, d3, d1 \cdot d2\right)\right)
double f(double d1, double d2, double d3) {
        double r253975 = d1;
        double r253976 = 3.0;
        double r253977 = r253975 * r253976;
        double r253978 = d2;
        double r253979 = r253975 * r253978;
        double r253980 = r253977 + r253979;
        double r253981 = d3;
        double r253982 = r253975 * r253981;
        double r253983 = r253980 + r253982;
        return r253983;
}

double f(double d1, double d2, double d3) {
        double r253984 = 3.0;
        double r253985 = d1;
        double r253986 = d3;
        double r253987 = d2;
        double r253988 = r253985 * r253987;
        double r253989 = fma(r253985, r253986, r253988);
        double r253990 = fma(r253984, r253985, r253989);
        return r253990;
}

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. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(d1, 3 + d2, d1 \cdot d3\right)}\]
  3. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{3 \cdot d1 + \left(d1 \cdot d3 + d1 \cdot d2\right)}\]
  4. Simplified0.0

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

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

Reproduce

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

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

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