Average Error: 0.1 → 0.2
Time: 3.0s
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 r609196 = x;
        double r609197 = r609196 * r609196;
        double r609198 = y;
        double r609199 = r609198 * r609198;
        double r609200 = r609197 + r609199;
        double r609201 = r609200 + r609199;
        double r609202 = r609201 + r609199;
        return r609202;
}

double f(double x, double y) {
        double r609203 = x;
        double r609204 = r609203 * r609203;
        double r609205 = y;
        double r609206 = r609205 * r609205;
        double r609207 = r609204 + r609206;
        double r609208 = r609207 + r609206;
        double r609209 = sqrt(r609208);
        double r609210 = 2.0;
        double r609211 = sqrt(r609210);
        double r609212 = r609211 * r609205;
        double r609213 = hypot(r609203, r609212);
        double r609214 = r609213 * r609213;
        double r609215 = sqrt(r609214);
        double r609216 = fma(r609209, r609215, r609206);
        return r609216;
}

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