Average Error: 0.1 → 0.1
Time: 8.9s
Precision: 64
\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z\]
\[\mathsf{fma}\left(x, y, z \cdot \left(3 \cdot z\right)\right)\]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(x, y, z \cdot \left(3 \cdot z\right)\right)
double f(double x, double y, double z) {
        double r21122267 = x;
        double r21122268 = y;
        double r21122269 = r21122267 * r21122268;
        double r21122270 = z;
        double r21122271 = r21122270 * r21122270;
        double r21122272 = r21122269 + r21122271;
        double r21122273 = r21122272 + r21122271;
        double r21122274 = r21122273 + r21122271;
        return r21122274;
}

double f(double x, double y, double z) {
        double r21122275 = x;
        double r21122276 = y;
        double r21122277 = z;
        double r21122278 = 3.0;
        double r21122279 = r21122278 * r21122277;
        double r21122280 = r21122277 * r21122279;
        double r21122281 = fma(r21122275, r21122276, r21122280);
        return r21122281;
}

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(x, y, 3 \cdot \left(z \cdot z\right)\right)}\]
  4. Using strategy rm
  5. Applied associate-*r*0.1

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

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

Reproduce

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