Average Error: 0.0 → 0.0
Time: 3.0s
Precision: 64
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\]
\[\left(d1 \cdot d2 + \mathsf{fma}\left(d1, d4, -d3 \cdot d1\right)\right) - d1 \cdot d1\]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\left(d1 \cdot d2 + \mathsf{fma}\left(d1, d4, -d3 \cdot d1\right)\right) - d1 \cdot d1
double f(double d1, double d2, double d3, double d4) {
        double r157229 = d1;
        double r157230 = d2;
        double r157231 = r157229 * r157230;
        double r157232 = d3;
        double r157233 = r157229 * r157232;
        double r157234 = r157231 - r157233;
        double r157235 = d4;
        double r157236 = r157235 * r157229;
        double r157237 = r157234 + r157236;
        double r157238 = r157229 * r157229;
        double r157239 = r157237 - r157238;
        return r157239;
}

double f(double d1, double d2, double d3, double d4) {
        double r157240 = d1;
        double r157241 = d2;
        double r157242 = r157240 * r157241;
        double r157243 = d4;
        double r157244 = d3;
        double r157245 = r157244 * r157240;
        double r157246 = -r157245;
        double r157247 = fma(r157240, r157243, r157246);
        double r157248 = r157242 + r157247;
        double r157249 = r157240 * r157240;
        double r157250 = r157248 - r157249;
        return r157250;
}

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 sub-neg0.0

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

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

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

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

Reproduce

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