Average Error: 0.1 → 0.1
Time: 16.7s
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 r302670 = x;
        double r302671 = y;
        double r302672 = r302670 * r302671;
        double r302673 = z;
        double r302674 = r302673 * r302673;
        double r302675 = r302672 + r302674;
        double r302676 = r302675 + r302674;
        double r302677 = r302676 + r302674;
        return r302677;
}

double f(double x, double y, double z) {
        double r302678 = 3.0;
        double r302679 = z;
        double r302680 = r302679 * r302679;
        double r302681 = x;
        double r302682 = y;
        double r302683 = r302681 * r302682;
        double r302684 = fma(r302678, r302680, r302683);
        return r302684;
}

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. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{3 \cdot {z}^{2} + x \cdot y}\]
  3. Simplified0.1

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

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

Reproduce

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