Average Error: 0.1 → 0.0
Time: 2.8s
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 r270879 = d1;
        double r270880 = 3.0;
        double r270881 = r270879 * r270880;
        double r270882 = d2;
        double r270883 = r270879 * r270882;
        double r270884 = r270881 + r270883;
        double r270885 = d3;
        double r270886 = r270879 * r270885;
        double r270887 = r270884 + r270886;
        return r270887;
}

double f(double d1, double d2, double d3) {
        double r270888 = 3.0;
        double r270889 = d1;
        double r270890 = d3;
        double r270891 = d2;
        double r270892 = r270889 * r270891;
        double r270893 = fma(r270889, r270890, r270892);
        double r270894 = fma(r270888, r270889, r270893);
        return r270894;
}

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

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

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