Average Error: 0.1 → 0.1
Time: 8.2s
Precision: 64
\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z\]
\[\mathsf{fma}\left(y, x, \left(z \cdot 3\right) \cdot z\right)\]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(y, x, \left(z \cdot 3\right) \cdot z\right)
double f(double x, double y, double z) {
        double r21912565 = x;
        double r21912566 = y;
        double r21912567 = r21912565 * r21912566;
        double r21912568 = z;
        double r21912569 = r21912568 * r21912568;
        double r21912570 = r21912567 + r21912569;
        double r21912571 = r21912570 + r21912569;
        double r21912572 = r21912571 + r21912569;
        return r21912572;
}

double f(double x, double y, double z) {
        double r21912573 = y;
        double r21912574 = x;
        double r21912575 = z;
        double r21912576 = 3.0;
        double r21912577 = r21912575 * r21912576;
        double r21912578 = r21912577 * r21912575;
        double r21912579 = fma(r21912573, r21912574, r21912578);
        return r21912579;
}

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. Using strategy rm
  4. Applied fma-udef0.1

    \[\leadsto \color{blue}{3 \cdot \left(z \cdot z\right) + x \cdot y}\]
  5. Taylor expanded around 0 0.1

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

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

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

Reproduce

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