Average Error: 0.0 → 0.0
Time: 16.9s
Precision: 64
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\]
\[d1 \cdot d2 + \mathsf{fma}\left(d1, d4 - d1, -d1 \cdot d3\right)\]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
d1 \cdot d2 + \mathsf{fma}\left(d1, d4 - d1, -d1 \cdot d3\right)
double f(double d1, double d2, double d3, double d4) {
        double r144451 = d1;
        double r144452 = d2;
        double r144453 = r144451 * r144452;
        double r144454 = d3;
        double r144455 = r144451 * r144454;
        double r144456 = r144453 - r144455;
        double r144457 = d4;
        double r144458 = r144457 * r144451;
        double r144459 = r144456 + r144458;
        double r144460 = r144451 * r144451;
        double r144461 = r144459 - r144460;
        return r144461;
}

double f(double d1, double d2, double d3, double d4) {
        double r144462 = d1;
        double r144463 = d2;
        double r144464 = r144462 * r144463;
        double r144465 = d4;
        double r144466 = r144465 - r144462;
        double r144467 = d3;
        double r144468 = r144462 * r144467;
        double r144469 = -r144468;
        double r144470 = fma(r144462, r144466, r144469);
        double r144471 = r144464 + r144470;
        return r144471;
}

Error

Bits error versus d1

Bits error versus d2

Bits error versus d3

Bits error versus d4

Target

Original0.0
Target0.0
Herbie0.0
\[d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right)\]

Derivation

  1. Initial program 0.0

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\]
  2. Using strategy rm
  3. Applied associate--l+0.0

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

    \[\leadsto \left(d1 \cdot d2 - d1 \cdot d3\right) + \color{blue}{d1 \cdot \left(d4 - d1\right)}\]
  5. Using strategy rm
  6. Applied sub-neg0.0

    \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(-d1 \cdot d3\right)\right)} + d1 \cdot \left(d4 - d1\right)\]
  7. Applied associate-+l+0.0

    \[\leadsto \color{blue}{d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d1 \cdot \left(d4 - d1\right)\right)}\]
  8. Simplified0.0

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

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

Reproduce

herbie shell --seed 2019235 +o rules:numerics
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

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

  (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))