Average Error: 0.1 → 0.1
Time: 15.2s
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 r22077086 = x;
        double r22077087 = y;
        double r22077088 = r22077086 * r22077087;
        double r22077089 = z;
        double r22077090 = r22077089 * r22077089;
        double r22077091 = r22077088 + r22077090;
        double r22077092 = r22077091 + r22077090;
        double r22077093 = r22077092 + r22077090;
        return r22077093;
}

double f(double x, double y, double z) {
        double r22077094 = 3.0;
        double r22077095 = z;
        double r22077096 = r22077095 * r22077095;
        double r22077097 = x;
        double r22077098 = y;
        double r22077099 = r22077097 * r22077098;
        double r22077100 = fma(r22077094, r22077096, r22077099);
        return r22077100;
}

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