Average Error: 0.1 → 0.1
Time: 8.8s
Precision: 64
\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z\]
\[\mathsf{fma}\left(z \cdot z, 3, y \cdot x\right)\]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(z \cdot z, 3, y \cdot x\right)
double f(double x, double y, double z) {
        double r19621843 = x;
        double r19621844 = y;
        double r19621845 = r19621843 * r19621844;
        double r19621846 = z;
        double r19621847 = r19621846 * r19621846;
        double r19621848 = r19621845 + r19621847;
        double r19621849 = r19621848 + r19621847;
        double r19621850 = r19621849 + r19621847;
        return r19621850;
}

double f(double x, double y, double z) {
        double r19621851 = z;
        double r19621852 = r19621851 * r19621851;
        double r19621853 = 3.0;
        double r19621854 = y;
        double r19621855 = x;
        double r19621856 = r19621854 * r19621855;
        double r19621857 = fma(r19621852, r19621853, r19621856);
        return r19621857;
}

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(y, x, z \cdot \left(z \cdot 3\right)\right)}\]
  4. Taylor expanded around 0 0.1

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

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

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

Reproduce

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

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

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