Average Error: 0.2 → 0.0
Time: 15.1s
Precision: 64
\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
\[\mathsf{fma}\left(d1, 30, d1 \cdot d2\right)\]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20
\mathsf{fma}\left(d1, 30, d1 \cdot d2\right)
double f(double d1, double d2) {
        double r6633082 = d1;
        double r6633083 = 10.0;
        double r6633084 = r6633082 * r6633083;
        double r6633085 = d2;
        double r6633086 = r6633082 * r6633085;
        double r6633087 = r6633084 + r6633086;
        double r6633088 = 20.0;
        double r6633089 = r6633082 * r6633088;
        double r6633090 = r6633087 + r6633089;
        return r6633090;
}

double f(double d1, double d2) {
        double r6633091 = d1;
        double r6633092 = 30.0;
        double r6633093 = d2;
        double r6633094 = r6633091 * r6633093;
        double r6633095 = fma(r6633091, r6633092, r6633094);
        return r6633095;
}

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(\left(d2 + 10\right) + 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(d1, 30, d1 \cdot d2\right)}\]
  5. Final simplification0.0

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

Reproduce

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

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

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