Average Error: 0.2 → 0.0
Time: 23.9s
Precision: 64
\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
\[\mathsf{fma}\left(1, d2 \cdot d1, 30 \cdot d1\right)\]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20
\mathsf{fma}\left(1, d2 \cdot d1, 30 \cdot d1\right)
double f(double d1, double d2) {
        double r18147967 = d1;
        double r18147968 = 10.0;
        double r18147969 = r18147967 * r18147968;
        double r18147970 = d2;
        double r18147971 = r18147967 * r18147970;
        double r18147972 = r18147969 + r18147971;
        double r18147973 = 20.0;
        double r18147974 = r18147967 * r18147973;
        double r18147975 = r18147972 + r18147974;
        return r18147975;
}

double f(double d1, double d2) {
        double r18147976 = 1.0;
        double r18147977 = d2;
        double r18147978 = d1;
        double r18147979 = r18147977 * r18147978;
        double r18147980 = 30.0;
        double r18147981 = r18147980 * r18147978;
        double r18147982 = fma(r18147976, r18147979, r18147981);
        return r18147982;
}

Error

Bits error versus d1

Bits error versus d2

Target

Original0.2
Target0.0
Herbie0.0
\[d1 \cdot \left(30 + d2\right)\]

Derivation

  1. Initial program 0.2

    \[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
  2. Simplified0.0

    \[\leadsto \color{blue}{d1 \cdot \left(20 + \left(10 + d2\right)\right)}\]
  3. Using strategy rm
  4. Applied flip-+11.3

    \[\leadsto d1 \cdot \color{blue}{\frac{20 \cdot 20 - \left(10 + d2\right) \cdot \left(10 + d2\right)}{20 - \left(10 + d2\right)}}\]
  5. Applied associate-*r/13.7

    \[\leadsto \color{blue}{\frac{d1 \cdot \left(20 \cdot 20 - \left(10 + d2\right) \cdot \left(10 + d2\right)\right)}{20 - \left(10 + d2\right)}}\]
  6. Taylor expanded around 0 0.0

    \[\leadsto \color{blue}{1 \cdot \left(d2 \cdot d1\right) + 30 \cdot d1}\]
  7. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(1, d2 \cdot d1, 30 \cdot d1\right)}\]
  8. Final simplification0.0

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

Reproduce

herbie shell --seed 2019173 +o rules:numerics
(FPCore (d1 d2)
  :name "FastMath test2"

  :herbie-target
  (* d1 (+ 30.0 d2))

  (+ (+ (* d1 10.0) (* d1 d2)) (* d1 20.0)))