Average Error: 0.0 → 0.0
Time: 1.8s
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 r231427 = d1;
        double r231428 = d2;
        double r231429 = r231427 * r231428;
        double r231430 = d3;
        double r231431 = r231427 * r231430;
        double r231432 = r231429 - r231431;
        double r231433 = d4;
        double r231434 = r231433 * r231427;
        double r231435 = r231432 + r231434;
        double r231436 = r231427 * r231427;
        double r231437 = r231435 - r231436;
        return r231437;
}

double f(double d1, double d2, double d3, double d4) {
        double r231438 = d2;
        double r231439 = d3;
        double r231440 = r231438 - r231439;
        double r231441 = d1;
        double r231442 = d4;
        double r231443 = r231441 * r231442;
        double r231444 = -r231441;
        double r231445 = r231444 * r231441;
        double r231446 = r231443 + r231445;
        double r231447 = fma(r231440, r231441, r231446);
        return r231447;
}

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