Average Error: 0.0 → 0.0
Time: 3.4s
Precision: 64
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\]
\[\mathsf{fma}\left(d2 - d3, d1, d1 \cdot d4 + \left(-d1\right) \cdot d1\right)\]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\mathsf{fma}\left(d2 - d3, d1, d1 \cdot d4 + \left(-d1\right) \cdot d1\right)
double f(double d1, double d2, double d3, double d4) {
        double r262054 = d1;
        double r262055 = d2;
        double r262056 = r262054 * r262055;
        double r262057 = d3;
        double r262058 = r262054 * r262057;
        double r262059 = r262056 - r262058;
        double r262060 = d4;
        double r262061 = r262060 * r262054;
        double r262062 = r262059 + r262061;
        double r262063 = r262054 * r262054;
        double r262064 = r262062 - r262063;
        return r262064;
}

double f(double d1, double d2, double d3, double d4) {
        double r262065 = d2;
        double r262066 = d3;
        double r262067 = r262065 - r262066;
        double r262068 = d1;
        double r262069 = d4;
        double r262070 = r262068 * r262069;
        double r262071 = -r262068;
        double r262072 = r262071 * r262068;
        double r262073 = r262070 + r262072;
        double r262074 = fma(r262067, r262068, r262073);
        return r262074;
}

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)}\]
  3. Using strategy rm
  4. Applied sub-neg0.0

    \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d1 \cdot \color{blue}{\left(d4 + \left(-d1\right)\right)}\right)\]
  5. Applied distribute-lft-in0.0

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

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

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

Reproduce

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