Average Error: 0.0 → 0.0
Time: 13.6s
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 \left(d4 - d1\right)\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 \left(d4 - d1\right)\right)
double f(double d1, double d2, double d3, double d4) {
        double r10106534 = d1;
        double r10106535 = d2;
        double r10106536 = r10106534 * r10106535;
        double r10106537 = d3;
        double r10106538 = r10106534 * r10106537;
        double r10106539 = r10106536 - r10106538;
        double r10106540 = d4;
        double r10106541 = r10106540 * r10106534;
        double r10106542 = r10106539 + r10106541;
        double r10106543 = r10106534 * r10106534;
        double r10106544 = r10106542 - r10106543;
        return r10106544;
}

double f(double d1, double d2, double d3, double d4) {
        double r10106545 = d2;
        double r10106546 = d3;
        double r10106547 = r10106545 - r10106546;
        double r10106548 = d1;
        double r10106549 = d4;
        double r10106550 = r10106549 - r10106548;
        double r10106551 = r10106548 * r10106550;
        double r10106552 = fma(r10106547, r10106548, r10106551);
        return r10106552;
}

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 distribute-lft-out--0.0

    \[\leadsto \left(\color{blue}{d1 \cdot \left(d2 - d3\right)} + d4 \cdot d1\right) - d1 \cdot d1\]
  4. Applied fma-def0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d2 - d3, d4 \cdot d1\right)} - d1 \cdot d1\]
  5. Using strategy rm
  6. Applied add-cube-cbrt1.2

    \[\leadsto \color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(d1, d2 - d3, d4 \cdot d1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(d1, d2 - d3, d4 \cdot d1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(d1, d2 - d3, d4 \cdot d1\right)}} - d1 \cdot d1\]
  7. Applied prod-diff1.2

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

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

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

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

Reproduce

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