Average Error: 0.1 → 0.1
Time: 12.7s
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 r351793 = x;
        double r351794 = r351793 * r351793;
        double r351795 = y;
        double r351796 = r351795 * r351795;
        double r351797 = r351794 + r351796;
        double r351798 = r351797 + r351796;
        double r351799 = r351798 + r351796;
        return r351799;
}

double f(double x, double y) {
        double r351800 = y;
        double r351801 = r351800 * r351800;
        double r351802 = 3.0;
        double r351803 = x;
        double r351804 = r351803 * r351803;
        double r351805 = fma(r351801, r351802, r351804);
        return r351805;
}

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(y \cdot 3\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 2019174 +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)))