?

Average Accuracy: 100.0% → 100.0%
Time: 3.4s
Precision: binary64
Cost: 704

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \]
\[y \cdot y + x \cdot \left(x + 2 \cdot y\right) \]
(FPCore (x y) :precision binary64 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
(FPCore (x y) :precision binary64 (+ (* y y) (* x (+ x (* 2.0 y)))))
double code(double x, double y) {
	return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
double code(double x, double y) {
	return (y * y) + (x * (x + (2.0 * y)));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (y * y) + (x * (x + (2.0d0 * y)))
end function
public static double code(double x, double y) {
	return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
public static double code(double x, double y) {
	return (y * y) + (x * (x + (2.0 * y)));
}
def code(x, y):
	return ((x * x) + ((x * 2.0) * y)) + (y * y)
def code(x, y):
	return (y * y) + (x * (x + (2.0 * y)))
function code(x, y)
	return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y))
end
function code(x, y)
	return Float64(Float64(y * y) + Float64(x * Float64(x + Float64(2.0 * y))))
end
function tmp = code(x, y)
	tmp = ((x * x) + ((x * 2.0) * y)) + (y * y);
end
function tmp = code(x, y)
	tmp = (y * y) + (x * (x + (2.0 * y)));
end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(N[(y * y), $MachinePrecision] + N[(x * N[(x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
y \cdot y + x \cdot \left(x + 2 \cdot y\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Initial program 100.0%

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

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

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

    [Start]100.0

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

    associate-*r* [=>]100.0

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

    unpow2 [=>]100.0

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

    distribute-rgt-in [<=]100.0

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

    +-commutative [<=]100.0

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

    \[\leadsto y \cdot y + x \cdot \left(x + 2 \cdot y\right) \]

Alternatives

Alternative 1
Accuracy86.6%
Cost845
\[\begin{array}{l} \mathbf{if}\;y \leq 8.8 \cdot 10^{-119}:\\ \;\;\;\;x \cdot \left(x + 2 \cdot y\right)\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{-54} \lor \neg \left(y \leq 1.26 \cdot 10^{-36}\right):\\ \;\;\;\;y \cdot \left(y + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 2
Accuracy86.7%
Cost844
\[\begin{array}{l} \mathbf{if}\;y \leq 3.85 \cdot 10^{-119}:\\ \;\;\;\;x \cdot \left(x + 2 \cdot y\right)\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-54}:\\ \;\;\;\;y \cdot y + 2 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-37}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot 2\right)\\ \end{array} \]
Alternative 3
Accuracy87.1%
Cost324
\[\begin{array}{l} \mathbf{if}\;x \leq -6.6 \cdot 10^{-99}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 4
Accuracy55.3%
Cost192
\[x \cdot x \]

Error

Reproduce?

herbie shell --seed 2023133 
(FPCore (x y)
  :name "Examples.Basics.ProofTests:f4 from sbv-4.4"
  :precision binary64

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

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