Average Error: 0.1 → 0.0
Time: 7.6s
Precision: 64
\[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3\]
\[\mathsf{fma}\left(d1, \left(3 + d2\right), \left(d3 \cdot d1\right)\right)\]
\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3
\mathsf{fma}\left(d1, \left(3 + d2\right), \left(d3 \cdot d1\right)\right)
double f(double d1, double d2, double d3) {
        double r31921468 = d1;
        double r31921469 = 3.0;
        double r31921470 = r31921468 * r31921469;
        double r31921471 = d2;
        double r31921472 = r31921468 * r31921471;
        double r31921473 = r31921470 + r31921472;
        double r31921474 = d3;
        double r31921475 = r31921468 * r31921474;
        double r31921476 = r31921473 + r31921475;
        return r31921476;
}

double f(double d1, double d2, double d3) {
        double r31921477 = d1;
        double r31921478 = 3.0;
        double r31921479 = d2;
        double r31921480 = r31921478 + r31921479;
        double r31921481 = d3;
        double r31921482 = r31921481 * r31921477;
        double r31921483 = fma(r31921477, r31921480, r31921482);
        return r31921483;
}

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. Using strategy rm
  3. Applied distribute-lft-out0.1

    \[\leadsto \color{blue}{d1 \cdot \left(3 + d2\right)} + d1 \cdot d3\]
  4. Applied fma-def0.0

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

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

Reproduce

herbie shell --seed 2019124 +o rules:numerics
(FPCore (d1 d2 d3)
  :name "FastMath test3"

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

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