Average Error: 0.0 → 0.0
Time: 12.0s
Precision: 64
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\]
\[\left(d4 + \mathsf{fma}\left(d3, -1, d3 - d1\right)\right) \cdot d1 + \mathsf{fma}\left(1, d2, -d3\right) \cdot d1\]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\left(d4 + \mathsf{fma}\left(d3, -1, d3 - d1\right)\right) \cdot d1 + \mathsf{fma}\left(1, d2, -d3\right) \cdot d1
double f(double d1, double d2, double d3, double d4) {
        double r388257 = d1;
        double r388258 = d2;
        double r388259 = r388257 * r388258;
        double r388260 = d3;
        double r388261 = r388257 * r388260;
        double r388262 = r388259 - r388261;
        double r388263 = d4;
        double r388264 = r388263 * r388257;
        double r388265 = r388262 + r388264;
        double r388266 = r388257 * r388257;
        double r388267 = r388265 - r388266;
        return r388267;
}

double f(double d1, double d2, double d3, double d4) {
        double r388268 = d4;
        double r388269 = d3;
        double r388270 = -1.0;
        double r388271 = d1;
        double r388272 = r388269 - r388271;
        double r388273 = fma(r388269, r388270, r388272);
        double r388274 = r388268 + r388273;
        double r388275 = r388274 * r388271;
        double r388276 = 1.0;
        double r388277 = d2;
        double r388278 = -r388269;
        double r388279 = fma(r388276, r388277, r388278);
        double r388280 = r388279 * r388271;
        double r388281 = r388275 + r388280;
        return r388281;
}

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}{d1 \cdot \left(\left(\left(d2 - d3\right) - d1\right) + d4\right)}\]
  3. Using strategy rm
  4. Applied distribute-lft-in0.0

    \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right) + d1 \cdot d4}\]
  5. Using strategy rm
  6. Applied *-un-lft-identity0.0

    \[\leadsto d1 \cdot \left(\left(d2 - \color{blue}{1 \cdot d3}\right) - d1\right) + d1 \cdot d4\]
  7. Applied *-un-lft-identity0.0

    \[\leadsto d1 \cdot \left(\left(\color{blue}{1 \cdot d2} - 1 \cdot d3\right) - d1\right) + d1 \cdot d4\]
  8. Applied prod-diff0.0

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"

  :herbie-target
  (* d1 (- (+ (- d2 d3) d4) d1))

  (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))