?

Average Accuracy: 100.0% → 100.0%
Time: 4.3s
Precision: binary64
Cost: 13248

?

\[\left(x + y\right) \cdot \left(x + y\right) \]
\[\mathsf{fma}\left(x, \mathsf{fma}\left(y, 2, x\right), y \cdot y\right) \]
(FPCore (x y) :precision binary64 (* (+ x y) (+ x y)))
(FPCore (x y) :precision binary64 (fma x (fma y 2.0 x) (* y y)))
double code(double x, double y) {
	return (x + y) * (x + y);
}
double code(double x, double y) {
	return fma(x, fma(y, 2.0, x), (y * y));
}
function code(x, y)
	return Float64(Float64(x + y) * Float64(x + y))
end
function code(x, y)
	return fma(x, fma(y, 2.0, x), Float64(y * y))
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(x * N[(y * 2.0 + x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\left(x + y\right) \cdot \left(x + y\right)
\mathsf{fma}\left(x, \mathsf{fma}\left(y, 2, x\right), y \cdot y\right)

Error?

Target

Original100.0%
Target100.0%
Herbie100.0%
\[x \cdot x + \left(y \cdot y + 2 \cdot \left(y \cdot x\right)\right) \]

Derivation?

  1. Initial program 100.0%

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

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

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

    [Start]100.0

    \[ 2 \cdot \left(y \cdot x\right) + \left({y}^{2} + {x}^{2}\right) \]

    +-commutative [=>]100.0

    \[ 2 \cdot \left(y \cdot x\right) + \color{blue}{\left({x}^{2} + {y}^{2}\right)} \]

    unpow2 [=>]100.0

    \[ 2 \cdot \left(y \cdot x\right) + \left(\color{blue}{x \cdot x} + {y}^{2}\right) \]

    unpow2 [=>]100.0

    \[ 2 \cdot \left(y \cdot x\right) + \left(x \cdot x + \color{blue}{y \cdot y}\right) \]

    associate-+r+ [=>]100.0

    \[ \color{blue}{\left(2 \cdot \left(y \cdot x\right) + x \cdot x\right) + y \cdot y} \]

    +-commutative [=>]100.0

    \[ \color{blue}{\left(x \cdot x + 2 \cdot \left(y \cdot x\right)\right)} + y \cdot y \]

    associate-*r* [=>]100.0

    \[ \left(x \cdot x + \color{blue}{\left(2 \cdot y\right) \cdot x}\right) + y \cdot y \]

    distribute-rgt-out [=>]100.0

    \[ \color{blue}{x \cdot \left(x + 2 \cdot y\right)} + y \cdot y \]

    fma-def [=>]100.0

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

    +-commutative [=>]100.0

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

    *-commutative [=>]100.0

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

    fma-def [=>]100.0

    \[ \mathsf{fma}\left(x, \color{blue}{\mathsf{fma}\left(y, 2, x\right)}, y \cdot y\right) \]
  4. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy66.8%
Cost845
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{-50} \lor \neg \left(x \leq -2.85 \cdot 10^{-70}\right) \land x \leq -2.6 \cdot 10^{-133}:\\ \;\;\;\;x \cdot \left(x + y \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 2
Accuracy100.0%
Cost704
\[y \cdot y + x \cdot \left(x + y \cdot 2\right) \]
Alternative 3
Accuracy100.0%
Cost448
\[\left(x + y\right) \cdot \left(x + y\right) \]
Alternative 4
Accuracy68.2%
Cost324
\[\begin{array}{l} \mathbf{if}\;y \leq 7 \cdot 10^{-98}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 5
Accuracy56.7%
Cost192
\[x \cdot x \]

Error

Reproduce?

herbie shell --seed 2023137 
(FPCore (x y)
  :name "Examples.Basics.BasicTests:f3 from sbv-4.4"
  :precision binary64

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

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