Average Error: 0.1 → 0.1
Time: 10.5s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(3 \cdot y, 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 \cdot y, y, x \cdot x\right)
double f(double x, double y) {
        double r555369 = x;
        double r555370 = r555369 * r555369;
        double r555371 = y;
        double r555372 = r555371 * r555371;
        double r555373 = r555370 + r555372;
        double r555374 = r555373 + r555372;
        double r555375 = r555374 + r555372;
        return r555375;
}

double f(double x, double y) {
        double r555376 = 3.0;
        double r555377 = y;
        double r555378 = r555376 * r555377;
        double r555379 = x;
        double r555380 = r555379 * r555379;
        double r555381 = fma(r555378, r555377, r555380);
        return r555381;
}

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. Using strategy rm
  6. Applied *-un-lft-identity0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{\color{blue}{1 \cdot \left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right)}}, \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, y \cdot y\right)\]
  7. Applied sqrt-prod0.2

    \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{1} \cdot \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)\]
  8. Simplified0.2

    \[\leadsto \mathsf{fma}\left(\color{blue}{1} \cdot \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)\]
  9. Simplified0.2

    \[\leadsto \mathsf{fma}\left(1 \cdot \color{blue}{\mathsf{hypot}\left(\sqrt{2} \cdot y, x\right)}, \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, y \cdot y\right)\]
  10. Taylor expanded around 0 0.2

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

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

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

Reproduce

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