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 r478116 = x;
        double r478117 = r478116 * r478116;
        double r478118 = y;
        double r478119 = r478118 * r478118;
        double r478120 = r478117 + r478119;
        double r478121 = r478120 + r478119;
        double r478122 = r478121 + r478119;
        return r478122;
}

double f(double x, double y) {
        double r478123 = x;
        double r478124 = y;
        double r478125 = r478124 * r478124;
        double r478126 = fma(r478124, r478124, r478125);
        double r478127 = fma(r478123, r478123, r478126);
        double r478128 = r478127 + r478125;
        return r478128;
}

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