Average Error: 0.0 → 0.0
Time: 2.6s
Precision: 64
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\]
\[\mathsf{fma}\left(d1, d2 - \left(d3 - d4\right), -d1 \cdot d1\right)\]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\mathsf{fma}\left(d1, d2 - \left(d3 - d4\right), -d1 \cdot d1\right)
double f(double d1, double d2, double d3, double d4) {
        double r281514 = d1;
        double r281515 = d2;
        double r281516 = r281514 * r281515;
        double r281517 = d3;
        double r281518 = r281514 * r281517;
        double r281519 = r281516 - r281518;
        double r281520 = d4;
        double r281521 = r281520 * r281514;
        double r281522 = r281519 + r281521;
        double r281523 = r281514 * r281514;
        double r281524 = r281522 - r281523;
        return r281524;
}

double f(double d1, double d2, double d3, double d4) {
        double r281525 = d1;
        double r281526 = d2;
        double r281527 = d3;
        double r281528 = d4;
        double r281529 = r281527 - r281528;
        double r281530 = r281526 - r281529;
        double r281531 = r281525 * r281525;
        double r281532 = -r281531;
        double r281533 = fma(r281525, r281530, r281532);
        return r281533;
}

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 - \left(d1 \cdot d3 - d4 \cdot d1\right)\right)} - d1 \cdot d1\]
  4. Simplified0.0

    \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot \left(d3 - d4\right)}\right) - d1 \cdot d1\]
  5. Using strategy rm
  6. Applied distribute-lft-out--0.0

    \[\leadsto \color{blue}{d1 \cdot \left(d2 - \left(d3 - d4\right)\right)} - d1 \cdot d1\]
  7. Applied fma-neg0.0

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

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

Reproduce

herbie shell --seed 2020049 +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)))