Average Error: 0.1 → 0.1
Time: 3.0s
Precision: 64
\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z\]
\[\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, z \cdot z\right)\right) + z \cdot z\]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, z \cdot z\right)\right) + z \cdot z
double f(double x, double y, double z) {
        double r446190 = x;
        double r446191 = y;
        double r446192 = r446190 * r446191;
        double r446193 = z;
        double r446194 = r446193 * r446193;
        double r446195 = r446192 + r446194;
        double r446196 = r446195 + r446194;
        double r446197 = r446196 + r446194;
        return r446197;
}

double f(double x, double y, double z) {
        double r446198 = z;
        double r446199 = x;
        double r446200 = y;
        double r446201 = r446198 * r446198;
        double r446202 = fma(r446199, r446200, r446201);
        double r446203 = fma(r446198, r446198, r446202);
        double r446204 = r446203 + r446201;
        return r446204;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original0.1
Target0.1
Herbie0.1
\[\left(3 \cdot z\right) \cdot z + y \cdot x\]

Derivation

  1. Initial program 0.1

    \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z\]
  2. Using strategy rm
  3. Applied associate-+l+0.1

    \[\leadsto \color{blue}{\left(x \cdot y + z \cdot z\right) + \left(z \cdot z + z \cdot z\right)}\]
  4. Simplified0.1

    \[\leadsto \left(x \cdot y + z \cdot z\right) + \color{blue}{\mathsf{fma}\left(z, z, z \cdot z\right)}\]
  5. Using strategy rm
  6. Applied fma-def0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, z \cdot z\right)} + \mathsf{fma}\left(z, z, z \cdot z\right)\]
  7. Using strategy rm
  8. Applied fma-udef0.1

    \[\leadsto \mathsf{fma}\left(x, y, z \cdot z\right) + \color{blue}{\left(z \cdot z + z \cdot z\right)}\]
  9. Applied associate-+r+0.1

    \[\leadsto \color{blue}{\left(\mathsf{fma}\left(x, y, z \cdot z\right) + z \cdot z\right) + z \cdot z}\]
  10. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, z \cdot z\right)\right)} + z \cdot z\]
  11. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, z \cdot z\right)\right) + z \cdot z\]

Reproduce

herbie shell --seed 2020065 +o rules:numerics
(FPCore (x y z)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
  :precision binary64

  :herbie-target
  (+ (* (* 3 z) z) (* y x))

  (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))