Average Error: 0.1 → 0.1
Time: 13.3s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(y \cdot y, 3, x \cdot x\right)\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(y \cdot y, 3, x \cdot x\right)
double f(double x, double y) {
        double r18963803 = x;
        double r18963804 = r18963803 * r18963803;
        double r18963805 = y;
        double r18963806 = r18963805 * r18963805;
        double r18963807 = r18963804 + r18963806;
        double r18963808 = r18963807 + r18963806;
        double r18963809 = r18963808 + r18963806;
        return r18963809;
}

double f(double x, double y) {
        double r18963810 = y;
        double r18963811 = r18963810 * r18963810;
        double r18963812 = 3.0;
        double r18963813 = x;
        double r18963814 = r18963813 * r18963813;
        double r18963815 = fma(r18963811, r18963812, r18963814);
        return r18963815;
}

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

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

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

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

Reproduce

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