Average Error: 0.0 → 0.0
Time: 4.1s
Precision: 64
\[\left(x + y\right) \cdot \left(x + y\right)\]
\[\mathsf{fma}\left(2, y \cdot x, \mathsf{fma}\left(y, y, x \cdot x\right)\right)\]
\left(x + y\right) \cdot \left(x + y\right)
\mathsf{fma}\left(2, y \cdot x, \mathsf{fma}\left(y, y, x \cdot x\right)\right)
double f(double x, double y) {
        double r30753041 = x;
        double r30753042 = y;
        double r30753043 = r30753041 + r30753042;
        double r30753044 = r30753043 * r30753043;
        return r30753044;
}

double f(double x, double y) {
        double r30753045 = 2.0;
        double r30753046 = y;
        double r30753047 = x;
        double r30753048 = r30753046 * r30753047;
        double r30753049 = r30753047 * r30753047;
        double r30753050 = fma(r30753046, r30753046, r30753049);
        double r30753051 = fma(r30753045, r30753048, r30753050);
        return r30753051;
}

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(y, y, x \cdot x\right)\right)}\]
  4. Final simplification0.0

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

Reproduce

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

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

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