Average Error: 0.1 → 0.1
Time: 9.3s
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 r22103459 = x;
        double r22103460 = y;
        double r22103461 = r22103459 * r22103460;
        double r22103462 = z;
        double r22103463 = r22103462 * r22103462;
        double r22103464 = r22103461 + r22103463;
        double r22103465 = r22103464 + r22103463;
        double r22103466 = r22103465 + r22103463;
        return r22103466;
}

double f(double x, double y, double z) {
        double r22103467 = y;
        double r22103468 = x;
        double r22103469 = z;
        double r22103470 = 3.0;
        double r22103471 = r22103469 * r22103470;
        double r22103472 = r22103471 * r22103469;
        double r22103473 = fma(r22103467, r22103468, r22103472);
        return r22103473;
}

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