Average Error: 0.0 → 0.0
Time: 12.4s
Precision: 64
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\]
\[\mathsf{fma}\left(d1, d4 - d1, d1 \cdot \left(d2 - d3\right)\right) + d1 \cdot \left(\left(-d1\right) + d1\right)\]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\mathsf{fma}\left(d1, d4 - d1, d1 \cdot \left(d2 - d3\right)\right) + d1 \cdot \left(\left(-d1\right) + d1\right)
double f(double d1, double d2, double d3, double d4) {
        double r218984 = d1;
        double r218985 = d2;
        double r218986 = r218984 * r218985;
        double r218987 = d3;
        double r218988 = r218984 * r218987;
        double r218989 = r218986 - r218988;
        double r218990 = d4;
        double r218991 = r218990 * r218984;
        double r218992 = r218989 + r218991;
        double r218993 = r218984 * r218984;
        double r218994 = r218992 - r218993;
        return r218994;
}

double f(double d1, double d2, double d3, double d4) {
        double r218995 = d1;
        double r218996 = d4;
        double r218997 = r218996 - r218995;
        double r218998 = d2;
        double r218999 = d3;
        double r219000 = r218998 - r218999;
        double r219001 = r218995 * r219000;
        double r219002 = fma(r218995, r218997, r219001);
        double r219003 = -r218995;
        double r219004 = r219003 + r218995;
        double r219005 = r218995 * r219004;
        double r219006 = r219002 + r219005;
        return r219006;
}

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 add-sqr-sqrt31.8

    \[\leadsto \color{blue}{\sqrt{\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1} \cdot \sqrt{\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1}} - d1 \cdot d1\]
  4. Applied prod-diff31.8

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

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

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

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

Reproduce

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