Average Error: 0.1 → 0.2
Time: 3.2s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\mathsf{hypot}\left(x, \sqrt{2} \cdot y\right) \cdot \mathsf{hypot}\left(x, \sqrt{2} \cdot y\right)}, y \cdot y\right)\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\mathsf{hypot}\left(x, \sqrt{2} \cdot y\right) \cdot \mathsf{hypot}\left(x, \sqrt{2} \cdot y\right)}, y \cdot y\right)
double f(double x, double y) {
        double r439457 = x;
        double r439458 = r439457 * r439457;
        double r439459 = y;
        double r439460 = r439459 * r439459;
        double r439461 = r439458 + r439460;
        double r439462 = r439461 + r439460;
        double r439463 = r439462 + r439460;
        return r439463;
}

double f(double x, double y) {
        double r439464 = x;
        double r439465 = r439464 * r439464;
        double r439466 = y;
        double r439467 = r439466 * r439466;
        double r439468 = r439465 + r439467;
        double r439469 = r439468 + r439467;
        double r439470 = sqrt(r439469);
        double r439471 = 2.0;
        double r439472 = sqrt(r439471);
        double r439473 = r439472 * r439466;
        double r439474 = hypot(r439464, r439473);
        double r439475 = r439474 * r439474;
        double r439476 = sqrt(r439475);
        double r439477 = fma(r439470, r439476, r439467);
        return r439477;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.1
Target0.1
Herbie0.2
\[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 add-sqr-sqrt0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\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\right)\]
  7. Simplified0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\color{blue}{\mathsf{hypot}\left(x, \sqrt{2} \cdot y\right)} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}}, y \cdot y\right)\]
  8. Simplified0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\mathsf{hypot}\left(x, \sqrt{2} \cdot y\right) \cdot \color{blue}{\mathsf{hypot}\left(x, \sqrt{2} \cdot y\right)}}, y \cdot y\right)\]
  9. Final simplification0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\mathsf{hypot}\left(x, \sqrt{2} \cdot y\right) \cdot \mathsf{hypot}\left(x, \sqrt{2} \cdot y\right)}, y \cdot y\right)\]

Reproduce

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