Average Error: 0.0 → 0.0
Time: 4.7s
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 r277195 = d1;
        double r277196 = d2;
        double r277197 = r277195 * r277196;
        double r277198 = d3;
        double r277199 = r277195 * r277198;
        double r277200 = r277197 - r277199;
        double r277201 = d4;
        double r277202 = r277201 * r277195;
        double r277203 = r277200 + r277202;
        double r277204 = r277195 * r277195;
        double r277205 = r277203 - r277204;
        return r277205;
}

double f(double d1, double d2, double d3, double d4) {
        double r277206 = d2;
        double r277207 = d3;
        double r277208 = r277206 - r277207;
        double r277209 = d1;
        double r277210 = d4;
        double r277211 = r277209 * r277210;
        double r277212 = -r277209;
        double r277213 = r277212 * r277209;
        double r277214 = r277211 + r277213;
        double r277215 = fma(r277208, r277209, r277214);
        return r277215;
}

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