Average Error: 0.1 → 0.1
Time: 17.0s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(x, x, \left(3 \cdot y\right) \cdot y\right)\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(x, x, \left(3 \cdot y\right) \cdot y\right)
double f(double x, double y) {
        double r674902 = x;
        double r674903 = r674902 * r674902;
        double r674904 = y;
        double r674905 = r674904 * r674904;
        double r674906 = r674903 + r674905;
        double r674907 = r674906 + r674905;
        double r674908 = r674907 + r674905;
        return r674908;
}

double f(double x, double y) {
        double r674909 = x;
        double r674910 = 3.0;
        double r674911 = y;
        double r674912 = r674910 * r674911;
        double r674913 = r674912 * r674911;
        double r674914 = fma(r674909, r674909, r674913);
        return r674914;
}

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

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

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

Reproduce

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

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

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