Average Error: 0.1 → 0.1
Time: 3.2s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left({y}^{2}, 3, {x}^{2}\right)\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left({y}^{2}, 3, {x}^{2}\right)
double f(double x, double y) {
        double r518047 = x;
        double r518048 = r518047 * r518047;
        double r518049 = y;
        double r518050 = r518049 * r518049;
        double r518051 = r518048 + r518050;
        double r518052 = r518051 + r518050;
        double r518053 = r518052 + r518050;
        return r518053;
}

double f(double x, double y) {
        double r518054 = y;
        double r518055 = 2.0;
        double r518056 = pow(r518054, r518055);
        double r518057 = 3.0;
        double r518058 = x;
        double r518059 = pow(r518058, r518055);
        double r518060 = fma(r518056, r518057, r518059);
        return r518060;
}

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. Using strategy rm
  3. Applied add-sqr-sqrt0.2

    \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}} + y \cdot y\]
  4. Applied fma-def0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, y \cdot y\right)}\]
  5. Taylor expanded around 0 0.4

    \[\leadsto \color{blue}{{x}^{2} + \left({y}^{2} + {\left(\sqrt{2}\right)}^{2} \cdot {y}^{2}\right)}\]
  6. Simplified0.1

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

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

Reproduce

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