Average Error: 0.2 → 0.4
Time: 6.2s
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 r269939 = d1;
        double r269940 = 10.0;
        double r269941 = r269939 * r269940;
        double r269942 = d2;
        double r269943 = r269939 * r269942;
        double r269944 = r269941 + r269943;
        double r269945 = 20.0;
        double r269946 = r269939 * r269945;
        double r269947 = r269944 + r269946;
        return r269947;
}

double f(double d1, double d2) {
        double r269948 = d1;
        double r269949 = 20.0;
        double r269950 = sqrt(r269949);
        double r269951 = 10.0;
        double r269952 = d2;
        double r269953 = r269951 + r269952;
        double r269954 = fma(r269950, r269950, r269953);
        double r269955 = r269948 * r269954;
        return r269955;
}

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)))