Average Error: 0.1 → 0.0
Time: 11.8s
Precision: 64
\[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3\]
\[\mathsf{fma}\left(d3 + 3, d1, d1 \cdot d2\right)\]
\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3
\mathsf{fma}\left(d3 + 3, d1, d1 \cdot d2\right)
double f(double d1, double d2, double d3) {
        double r7299012 = d1;
        double r7299013 = 3.0;
        double r7299014 = r7299012 * r7299013;
        double r7299015 = d2;
        double r7299016 = r7299012 * r7299015;
        double r7299017 = r7299014 + r7299016;
        double r7299018 = d3;
        double r7299019 = r7299012 * r7299018;
        double r7299020 = r7299017 + r7299019;
        return r7299020;
}

double f(double d1, double d2, double d3) {
        double r7299021 = d3;
        double r7299022 = 3.0;
        double r7299023 = r7299021 + r7299022;
        double r7299024 = d1;
        double r7299025 = d2;
        double r7299026 = r7299024 * r7299025;
        double r7299027 = fma(r7299023, r7299024, r7299026);
        return r7299027;
}

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. Simplified0.1

    \[\leadsto \color{blue}{\left(d2 + \left(3 + d3\right)\right) \cdot d1}\]
  3. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{d2 \cdot d1 + \left(d3 \cdot d1 + 3 \cdot d1\right)}\]
  4. Simplified0.1

    \[\leadsto \color{blue}{d1 \cdot \left(\left(3 + d3\right) + d2\right)}\]
  5. Using strategy rm
  6. Applied distribute-rgt-in0.1

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

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

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

Reproduce

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

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

  (+ (+ (* d1 3.0) (* d1 d2)) (* d1 d3)))