Average Error: 0.0 → 0.0
Time: 5.8s
Precision: 64
\[\left(x + y\right) \cdot \left(x + y\right)\]
\[\mathsf{fma}\left(x, x, 2 \cdot \left(x \cdot y\right) + y \cdot y\right)\]
\left(x + y\right) \cdot \left(x + y\right)
\mathsf{fma}\left(x, x, 2 \cdot \left(x \cdot y\right) + y \cdot y\right)
double f(double x, double y) {
        double r341825 = x;
        double r341826 = y;
        double r341827 = r341825 + r341826;
        double r341828 = r341827 * r341827;
        return r341828;
}

double f(double x, double y) {
        double r341829 = x;
        double r341830 = 2.0;
        double r341831 = y;
        double r341832 = r341829 * r341831;
        double r341833 = r341830 * r341832;
        double r341834 = r341831 * r341831;
        double r341835 = r341833 + r341834;
        double r341836 = fma(r341829, r341829, r341835);
        return r341836;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.0
Target0.0
Herbie0.0
\[x \cdot x + \left(y \cdot y + 2 \cdot \left(y \cdot x\right)\right)\]

Derivation

  1. Initial program 0.0

    \[\left(x + y\right) \cdot \left(x + y\right)\]
  2. Taylor expanded around 0 0.0

    \[\leadsto \color{blue}{{x}^{2} + \left({y}^{2} + 2 \cdot \left(x \cdot y\right)\right)}\]
  3. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot \mathsf{fma}\left(x, 2, y\right)\right)}\]
  4. Using strategy rm
  5. Applied fma-udef0.0

    \[\leadsto \mathsf{fma}\left(x, x, y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\]
  6. Applied distribute-lft-in0.0

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

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

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

Reproduce

herbie shell --seed 2019212 +o rules:numerics
(FPCore (x y)
  :name "Examples.Basics.BasicTests:f3 from sbv-4.4"
  :precision binary64

  :herbie-target
  (+ (* x x) (+ (* y y) (* 2 (* y x))))

  (* (+ x y) (+ x y)))