Average Error: 0.0 → 0.0
Time: 4.5s
Precision: 64
\[\left(x + y\right) \cdot \left(x + y\right)\]
\[\mathsf{fma}\left(y, y, \mathsf{fma}\left(2, y, x\right) \cdot x\right)\]
\left(x + y\right) \cdot \left(x + y\right)
\mathsf{fma}\left(y, y, \mathsf{fma}\left(2, y, x\right) \cdot x\right)
double f(double x, double y) {
        double r28034968 = x;
        double r28034969 = y;
        double r28034970 = r28034968 + r28034969;
        double r28034971 = r28034970 * r28034970;
        return r28034971;
}

double f(double x, double y) {
        double r28034972 = y;
        double r28034973 = 2.0;
        double r28034974 = x;
        double r28034975 = fma(r28034973, r28034972, r28034974);
        double r28034976 = r28034975 * r28034974;
        double r28034977 = fma(r28034972, r28034972, r28034976);
        return r28034977;
}

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}{{y}^{2} + \left({x}^{2} + 2 \cdot \left(x \cdot y\right)\right)}\]
  3. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(2, x \cdot y, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}\]
  4. Taylor expanded around 0 0.0

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

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

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

Reproduce

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

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

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