Average Error: 0.1 → 0.1
Time: 15.1s
Precision: 64
\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z\]
\[\mathsf{fma}\left(3, z \cdot z, x \cdot y\right)\]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(3, z \cdot z, x \cdot y\right)
double f(double x, double y, double z) {
        double r21149391 = x;
        double r21149392 = y;
        double r21149393 = r21149391 * r21149392;
        double r21149394 = z;
        double r21149395 = r21149394 * r21149394;
        double r21149396 = r21149393 + r21149395;
        double r21149397 = r21149396 + r21149395;
        double r21149398 = r21149397 + r21149395;
        return r21149398;
}

double f(double x, double y, double z) {
        double r21149399 = 3.0;
        double r21149400 = z;
        double r21149401 = r21149400 * r21149400;
        double r21149402 = x;
        double r21149403 = y;
        double r21149404 = r21149402 * r21149403;
        double r21149405 = fma(r21149399, r21149401, r21149404);
        return r21149405;
}

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. Simplified0.1

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

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

Reproduce

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

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

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