Average Error: 0.1 → 0.1
Time: 20.3s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(3, y \cdot y, x \cdot x\right)\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(3, y \cdot y, x \cdot x\right)
double f(double x, double y) {
        double r20243437 = x;
        double r20243438 = r20243437 * r20243437;
        double r20243439 = y;
        double r20243440 = r20243439 * r20243439;
        double r20243441 = r20243438 + r20243440;
        double r20243442 = r20243441 + r20243440;
        double r20243443 = r20243442 + r20243440;
        return r20243443;
}

double f(double x, double y) {
        double r20243444 = 3.0;
        double r20243445 = y;
        double r20243446 = r20243445 * r20243445;
        double r20243447 = x;
        double r20243448 = r20243447 * r20243447;
        double r20243449 = fma(r20243444, r20243446, r20243448);
        return r20243449;
}

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. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{3 \cdot {y}^{2} + {x}^{2}}\]
  3. Simplified0.1

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

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

Reproduce

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