Average Error: 0.1 → 0.1
Time: 11.4s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot 3\right)\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot 3\right)
double f(double x, double y) {
        double r20263089 = x;
        double r20263090 = r20263089 * r20263089;
        double r20263091 = y;
        double r20263092 = r20263091 * r20263091;
        double r20263093 = r20263090 + r20263092;
        double r20263094 = r20263093 + r20263092;
        double r20263095 = r20263094 + r20263092;
        return r20263095;
}

double f(double x, double y) {
        double r20263096 = x;
        double r20263097 = y;
        double r20263098 = r20263097 * r20263097;
        double r20263099 = 3.0;
        double r20263100 = r20263098 * r20263099;
        double r20263101 = fma(r20263096, r20263096, r20263100);
        return r20263101;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.1
Target0.1
Herbie0.1
\[x \cdot x + y \cdot \left(y + \left(y + y\right)\right)\]

Derivation

  1. Initial program 0.1

    \[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
  2. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(3 \cdot y\right) \cdot y\right)}\]
  3. Using strategy rm
  4. Applied associate-*l*0.1

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

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

Reproduce

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

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

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