Average Error: 0.1 → 0.1
Time: 3.1s
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 r492016 = x;
        double r492017 = r492016 * r492016;
        double r492018 = y;
        double r492019 = r492018 * r492018;
        double r492020 = r492017 + r492019;
        double r492021 = r492020 + r492019;
        double r492022 = r492021 + r492019;
        return r492022;
}

double f(double x, double y) {
        double r492023 = 3.0;
        double r492024 = y;
        double r492025 = r492024 * r492024;
        double r492026 = x;
        double r492027 = r492026 * r492026;
        double r492028 = fma(r492023, r492025, r492027);
        return r492028;
}

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(3, y \cdot y, x \cdot x\right)}\]
  3. Final simplification0.1

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

Reproduce

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