Average Error: 0.1 → 0.1
Time: 2.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 r493740 = x;
        double r493741 = y;
        double r493742 = r493740 * r493741;
        double r493743 = z;
        double r493744 = r493743 * r493743;
        double r493745 = r493742 + r493744;
        double r493746 = r493745 + r493744;
        double r493747 = r493746 + r493744;
        return r493747;
}

double f(double x, double y, double z) {
        double r493748 = 3.0;
        double r493749 = z;
        double r493750 = r493749 * r493749;
        double r493751 = x;
        double r493752 = y;
        double r493753 = r493751 * r493752;
        double r493754 = fma(r493748, r493750, r493753);
        return r493754;
}

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