Average Error: 0.1 → 0.1
Time: 3.3s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, y \cdot y\right)\right) + y \cdot y\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, y \cdot y\right)\right) + y \cdot y
double f(double x, double y) {
        double r445861 = x;
        double r445862 = r445861 * r445861;
        double r445863 = y;
        double r445864 = r445863 * r445863;
        double r445865 = r445862 + r445864;
        double r445866 = r445865 + r445864;
        double r445867 = r445866 + r445864;
        return r445867;
}

double f(double x, double y) {
        double r445868 = x;
        double r445869 = y;
        double r445870 = r445869 * r445869;
        double r445871 = fma(r445869, r445869, r445870);
        double r445872 = fma(r445868, r445868, r445871);
        double r445873 = r445872 + r445870;
        return r445873;
}

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 fma-udef0.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}\]
  7. Simplified0.1

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

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

Reproduce

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