Average Error: 0.0 → 0.0
Time: 3.5s
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 r257090 = d1;
        double r257091 = d2;
        double r257092 = r257090 * r257091;
        double r257093 = d3;
        double r257094 = r257090 * r257093;
        double r257095 = r257092 - r257094;
        double r257096 = d4;
        double r257097 = r257096 * r257090;
        double r257098 = r257095 + r257097;
        double r257099 = r257090 * r257090;
        double r257100 = r257098 - r257099;
        return r257100;
}

double f(double d1, double d2, double d3, double d4) {
        double r257101 = d1;
        double r257102 = d2;
        double r257103 = r257101 * r257102;
        double r257104 = d4;
        double r257105 = d3;
        double r257106 = r257105 * r257101;
        double r257107 = -r257106;
        double r257108 = fma(r257101, r257104, r257107);
        double r257109 = r257103 + r257108;
        double r257110 = r257101 * r257101;
        double r257111 = r257109 - r257110;
        return r257111;
}

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