Average Error: 0.2 → 0.4
Time: 8.3s
Precision: 64
\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
\[d1 \cdot \mathsf{fma}\left(\sqrt{20}, \sqrt{20}, 10 + d2\right)\]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20
d1 \cdot \mathsf{fma}\left(\sqrt{20}, \sqrt{20}, 10 + d2\right)
double f(double d1, double d2) {
        double r242574 = d1;
        double r242575 = 10.0;
        double r242576 = r242574 * r242575;
        double r242577 = d2;
        double r242578 = r242574 * r242577;
        double r242579 = r242576 + r242578;
        double r242580 = 20.0;
        double r242581 = r242574 * r242580;
        double r242582 = r242579 + r242581;
        return r242582;
}

double f(double d1, double d2) {
        double r242583 = d1;
        double r242584 = 20.0;
        double r242585 = sqrt(r242584);
        double r242586 = 10.0;
        double r242587 = d2;
        double r242588 = r242586 + r242587;
        double r242589 = fma(r242585, r242585, r242588);
        double r242590 = r242583 * r242589;
        return r242590;
}

Error

Bits error versus d1

Bits error versus d2

Target

Original0.2
Target0.0
Herbie0.4
\[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 add-sqr-sqrt0.4

    \[\leadsto d1 \cdot \left(\color{blue}{\sqrt{20} \cdot \sqrt{20}} + \left(10 + d2\right)\right)\]
  5. Applied fma-def0.4

    \[\leadsto d1 \cdot \color{blue}{\mathsf{fma}\left(\sqrt{20}, \sqrt{20}, 10 + d2\right)}\]
  6. Final simplification0.4

    \[\leadsto d1 \cdot \mathsf{fma}\left(\sqrt{20}, \sqrt{20}, 10 + d2\right)\]

Reproduce

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

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

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