Average Error: 0.1 → 0.1
Time: 2.7s
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 r498986 = x;
        double r498987 = r498986 * r498986;
        double r498988 = y;
        double r498989 = r498988 * r498988;
        double r498990 = r498987 + r498989;
        double r498991 = r498990 + r498989;
        double r498992 = r498991 + r498989;
        return r498992;
}

double f(double x, double y) {
        double r498993 = y;
        double r498994 = 2.0;
        double r498995 = pow(r498993, r498994);
        double r498996 = 3.0;
        double r498997 = x;
        double r498998 = pow(r498997, r498994);
        double r498999 = fma(r498995, r498996, r498998);
        return r498999;
}

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)))