Average Error: 0.1 → 0.1
Time: 15.5s
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 r24515404 = x;
        double r24515405 = y;
        double r24515406 = r24515404 * r24515405;
        double r24515407 = z;
        double r24515408 = r24515407 * r24515407;
        double r24515409 = r24515406 + r24515408;
        double r24515410 = r24515409 + r24515408;
        double r24515411 = r24515410 + r24515408;
        return r24515411;
}

double f(double x, double y, double z) {
        double r24515412 = 3.0;
        double r24515413 = z;
        double r24515414 = r24515413 * r24515413;
        double r24515415 = x;
        double r24515416 = y;
        double r24515417 = r24515415 * r24515416;
        double r24515418 = fma(r24515412, r24515414, r24515417);
        return r24515418;
}

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 2019163 +o rules:numerics
(FPCore (x y z)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"

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

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