Average Error: 0.1 → 0.1
Time: 38.4s
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 \cdot x\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 \cdot x\right)
double f(double x, double y) {
        double r18661217 = x;
        double r18661218 = r18661217 * r18661217;
        double r18661219 = y;
        double r18661220 = r18661219 * r18661219;
        double r18661221 = r18661218 + r18661220;
        double r18661222 = r18661221 + r18661220;
        double r18661223 = r18661222 + r18661220;
        return r18661223;
}

double f(double x, double y) {
        double r18661224 = 3.0;
        double r18661225 = y;
        double r18661226 = r18661225 * r18661225;
        double r18661227 = x;
        double r18661228 = r18661227 * r18661227;
        double r18661229 = fma(r18661224, r18661226, r18661228);
        return r18661229;
}

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 inf 0.1

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

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

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

Reproduce

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