Average Error: 0.0 → 0.0
Time: 9.8s
Precision: 64
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\]
\[\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right) + \left(d1 + \left(-d1\right)\right) \cdot d1\]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right) + \left(d1 + \left(-d1\right)\right) \cdot d1
double f(double d1, double d2, double d3, double d4) {
        double r135094 = d1;
        double r135095 = d2;
        double r135096 = r135094 * r135095;
        double r135097 = d3;
        double r135098 = r135094 * r135097;
        double r135099 = r135096 - r135098;
        double r135100 = d4;
        double r135101 = r135100 * r135094;
        double r135102 = r135099 + r135101;
        double r135103 = r135094 * r135094;
        double r135104 = r135102 - r135103;
        return r135104;
}

double f(double d1, double d2, double d3, double d4) {
        double r135105 = d1;
        double r135106 = d4;
        double r135107 = r135106 - r135105;
        double r135108 = d2;
        double r135109 = d3;
        double r135110 = r135108 - r135109;
        double r135111 = r135110 * r135105;
        double r135112 = fma(r135105, r135107, r135111);
        double r135113 = -r135105;
        double r135114 = r135105 + r135113;
        double r135115 = r135114 * r135105;
        double r135116 = r135112 + r135115;
        return r135116;
}

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 add-sqr-sqrt32.2

    \[\leadsto \color{blue}{\sqrt{\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1} \cdot \sqrt{\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1}} - d1 \cdot d1\]
  4. Applied prod-diff32.2

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

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

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

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

Reproduce

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