Average Error: 0.1 → 0.1
Time: 14.8s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot 3\right)\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot 3\right)
double f(double x, double y) {
        double r20909134 = x;
        double r20909135 = r20909134 * r20909134;
        double r20909136 = y;
        double r20909137 = r20909136 * r20909136;
        double r20909138 = r20909135 + r20909137;
        double r20909139 = r20909138 + r20909137;
        double r20909140 = r20909139 + r20909137;
        return r20909140;
}

double f(double x, double y) {
        double r20909141 = x;
        double r20909142 = y;
        double r20909143 = r20909142 * r20909142;
        double r20909144 = 3.0;
        double r20909145 = r20909143 * r20909144;
        double r20909146 = fma(r20909141, r20909141, r20909145);
        return r20909146;
}

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

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

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

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