Average Error: 0.1 → 0.1
Time: 8.9s
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}^{2}\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}^{2}\right)
double f(double x, double y) {
        double r343118 = x;
        double r343119 = r343118 * r343118;
        double r343120 = y;
        double r343121 = r343120 * r343120;
        double r343122 = r343119 + r343121;
        double r343123 = r343122 + r343121;
        double r343124 = r343123 + r343121;
        return r343124;
}

double f(double x, double y) {
        double r343125 = 3.0;
        double r343126 = y;
        double r343127 = r343126 * r343126;
        double r343128 = x;
        double r343129 = 2.0;
        double r343130 = pow(r343128, r343129);
        double r343131 = fma(r343125, r343127, r343130);
        return r343131;
}

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}^{2}\right)}\]
  4. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(3, y \cdot y, {x}^{2}\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)))