Average Error: 0.2 → 0.0
Time: 7.3s
Precision: 64
\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
\[\mathsf{fma}\left(30, d1, 1 \cdot \left(d1 \cdot d2\right)\right)\]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20
\mathsf{fma}\left(30, d1, 1 \cdot \left(d1 \cdot d2\right)\right)
double f(double d1, double d2) {
        double r178348 = d1;
        double r178349 = 10.0;
        double r178350 = r178348 * r178349;
        double r178351 = d2;
        double r178352 = r178348 * r178351;
        double r178353 = r178350 + r178352;
        double r178354 = 20.0;
        double r178355 = r178348 * r178354;
        double r178356 = r178353 + r178355;
        return r178356;
}

double f(double d1, double d2) {
        double r178357 = 30.0;
        double r178358 = d1;
        double r178359 = 1.0;
        double r178360 = d2;
        double r178361 = r178358 * r178360;
        double r178362 = r178359 * r178361;
        double r178363 = fma(r178357, r178358, r178362);
        return r178363;
}

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

    \[\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/14.4

    \[\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}{30 \cdot d1 + 1 \cdot \left(d1 \cdot d2\right)}\]
  7. Simplified0.0

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

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

Reproduce

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

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

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