Average Error: 0.1 → 0.1
Time: 13.8s
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 r23913770 = x;
        double r23913771 = y;
        double r23913772 = r23913770 * r23913771;
        double r23913773 = z;
        double r23913774 = r23913773 * r23913773;
        double r23913775 = r23913772 + r23913774;
        double r23913776 = r23913775 + r23913774;
        double r23913777 = r23913776 + r23913774;
        return r23913777;
}

double f(double x, double y, double z) {
        double r23913778 = 3.0;
        double r23913779 = z;
        double r23913780 = r23913779 * r23913779;
        double r23913781 = x;
        double r23913782 = y;
        double r23913783 = r23913781 * r23913782;
        double r23913784 = fma(r23913778, r23913780, r23913783);
        return r23913784;
}

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