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

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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. Applied egg-rr0.0

    \[\leadsto \color{blue}{y \cdot \left(x + y\right) + x \cdot \left(x + y\right)} \]
  3. Taylor expanded in y around 0 0.0

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

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

    [Start]0.0

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

    +-commutative [=>]0.0

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

    unpow2 [=>]0.0

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

    unpow2 [=>]0.0

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

    associate-+r+ [=>]0.0

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

    associate-*r* [=>]0.0

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

    distribute-rgt-out [=>]0.0

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

    *-commutative [=>]0.0

    \[ x \cdot \left(\color{blue}{y \cdot 2} + x\right) + y \cdot y \]
  5. Final simplification0.0

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

Alternatives

Alternative 1
Error8.2
Cost845
\[\begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{-42} \lor \neg \left(x \leq -1.45 \cdot 10^{-59}\right) \land x \leq -6.5 \cdot 10^{-150}:\\ \;\;\;\;x \cdot \left(x + y \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 2
Error8.3
Cost844
\[\begin{array}{l} t_0 := x \cdot \left(x + y \cdot 2\right)\\ \mathbf{if}\;x \leq -2.4 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-60}:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;x \leq -4.7 \cdot 10^{-150}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot 2\right)\\ \end{array} \]
Alternative 3
Error0.0
Cost448
\[\left(x + y\right) \cdot \left(x + y\right) \]
Alternative 4
Error7.8
Cost324
\[\begin{array}{l} \mathbf{if}\;y \leq 1.08 \cdot 10^{-157}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 5
Error28.0
Cost192
\[x \cdot x \]

Error

Reproduce

herbie shell --seed 2023016 
(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)))