Average Error: 0.2 → 0.0
Time: 1.0s
Precision: 64
\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
\[\mathsf{fma}\left(30, d1, d1 \cdot d2\right)\]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20
\mathsf{fma}\left(30, d1, d1 \cdot d2\right)
double f(double d1, double d2) {
        double r133053 = d1;
        double r133054 = 10.0;
        double r133055 = r133053 * r133054;
        double r133056 = d2;
        double r133057 = r133053 * r133056;
        double r133058 = r133055 + r133057;
        double r133059 = 20.0;
        double r133060 = r133053 * r133059;
        double r133061 = r133058 + r133060;
        return r133061;
}

double f(double d1, double d2) {
        double r133062 = 30.0;
        double r133063 = d1;
        double r133064 = d2;
        double r133065 = r133063 * r133064;
        double r133066 = fma(r133062, r133063, r133065);
        return r133066;
}

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.1

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

    \[\leadsto \color{blue}{30 \cdot d1 + d1 \cdot d2}\]
  4. Simplified0.0

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

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

Reproduce

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

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

  (+ (+ (* d1 10) (* d1 d2)) (* d1 20)))