Average Error: 0.0 → 0.0
Time: 5.1s
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 r288800 = d1;
        double r288801 = d2;
        double r288802 = r288800 * r288801;
        double r288803 = d3;
        double r288804 = r288800 * r288803;
        double r288805 = r288802 - r288804;
        double r288806 = d4;
        double r288807 = r288806 * r288800;
        double r288808 = r288805 + r288807;
        double r288809 = r288800 * r288800;
        double r288810 = r288808 - r288809;
        return r288810;
}

double f(double d1, double d2, double d3, double d4) {
        double r288811 = d2;
        double r288812 = d3;
        double r288813 = r288811 - r288812;
        double r288814 = d1;
        double r288815 = d4;
        double r288816 = r288814 * r288815;
        double r288817 = -r288814;
        double r288818 = r288817 * r288814;
        double r288819 = r288816 + r288818;
        double r288820 = fma(r288813, r288814, r288819);
        return r288820;
}

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