Examples.Basics.ProofTests:f4 from sbv-4.4

Percentage Accurate: 94.0% → 100.0%
Time: 3.3s
Alternatives: 5
Speedup: 1.9×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
double code(double x, double y) {
	return ((x * x) + ((x * 2.0) * y)) + (y * 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
public static double code(double x, double y) {
	return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
def code(x, y):
	return ((x * x) + ((x * 2.0) * y)) + (y * y)
function code(x, y)
	return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y))
end
function tmp = code(x, y)
	tmp = ((x * x) + ((x * 2.0) * y)) + (y * 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]
\begin{array}{l}

\\
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 94.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
double code(double x, double y) {
	return ((x * x) + ((x * 2.0) * y)) + (y * 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
public static double code(double x, double y) {
	return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
def code(x, y):
	return ((x * x) + ((x * 2.0) * y)) + (y * y)
function code(x, y)
	return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y))
end
function tmp = code(x, y)
	tmp = ((x * x) + ((x * 2.0) * y)) + (y * 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]
\begin{array}{l}

\\
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
\end{array}

Alternative 1: 100.0% accurate, 0.1× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 4 \cdot 10^{+276}:\\ \;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(x \cdot 2 + y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + y \cdot y\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= (+ (+ (* x x) (* (* x 2.0) y)) (* y y)) 4e+276)
   (fma x x (* y (+ (* x 2.0) y)))
   (+ (* x x) (* y y))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276) {
		tmp = fma(x, x, (y * ((x * 2.0) + y)));
	} else {
		tmp = (x * x) + (y * y);
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) <= 4e+276)
		tmp = fma(x, x, Float64(y * Float64(Float64(x * 2.0) + y)));
	else
		tmp = Float64(Float64(x * x) + Float64(y * y));
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], 4e+276], N[(x * x + N[(y * N[(N[(x * 2.0), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 4 \cdot 10^{+276}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(x \cdot 2 + y\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot x + y \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) < 4.0000000000000002e276

    1. Initial program 99.9%

      \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \]
    2. Step-by-step derivation
      1. associate-+l+99.9%

        \[\leadsto \color{blue}{x \cdot x + \left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      3. distribute-rgt-out100.0%

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

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

    if 4.0000000000000002e276 < (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y))

    1. Initial program 83.9%

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

      \[\leadsto \color{blue}{{x}^{2}} + y \cdot y \]
    3. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
    4. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
  3. Recombined 2 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 4 \cdot 10^{+276}:\\ \;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(x \cdot 2 + y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + y \cdot y\\ \end{array} \]

Alternative 2: 100.0% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 4 \cdot 10^{+276}:\\ \;\;\;\;y \cdot y + x \cdot \left(x + 2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + y \cdot y\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= (+ (+ (* x x) (* (* x 2.0) y)) (* y y)) 4e+276)
   (+ (* y y) (* x (+ x (* 2.0 y))))
   (+ (* x x) (* y y))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276) {
		tmp = (y * y) + (x * (x + (2.0 * y)));
	} else {
		tmp = (x * x) + (y * y);
	}
	return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((((x * x) + ((x * 2.0d0) * y)) + (y * y)) <= 4d+276) then
        tmp = (y * y) + (x * (x + (2.0d0 * y)))
    else
        tmp = (x * x) + (y * y)
    end if
    code = tmp
end function
assert x < y;
public static double code(double x, double y) {
	double tmp;
	if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276) {
		tmp = (y * y) + (x * (x + (2.0 * y)));
	} else {
		tmp = (x * x) + (y * y);
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if (((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276:
		tmp = (y * y) + (x * (x + (2.0 * y)))
	else:
		tmp = (x * x) + (y * y)
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) <= 4e+276)
		tmp = Float64(Float64(y * y) + Float64(x * Float64(x + Float64(2.0 * y))));
	else
		tmp = Float64(Float64(x * x) + Float64(y * y));
	end
	return tmp
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276)
		tmp = (y * y) + (x * (x + (2.0 * y)));
	else
		tmp = (x * x) + (y * y);
	end
	tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], 4e+276], N[(N[(y * y), $MachinePrecision] + N[(x * N[(x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 4 \cdot 10^{+276}:\\
\;\;\;\;y \cdot y + x \cdot \left(x + 2 \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot x + y \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) < 4.0000000000000002e276

    1. Initial program 99.9%

      \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \]
    2. Step-by-step derivation
      1. associate-+l+99.9%

        \[\leadsto \color{blue}{x \cdot x + \left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      3. distribute-rgt-out100.0%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot \left(x \cdot 2 + y\right)\right)} \]
    4. Step-by-step derivation
      1. fma-udef99.9%

        \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
      2. distribute-rgt-in99.9%

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      3. associate-+l+99.9%

        \[\leadsto \color{blue}{\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y} \]
      4. +-commutative99.9%

        \[\leadsto \color{blue}{y \cdot y + \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right)} \]
      5. associate-*l*99.9%

        \[\leadsto y \cdot y + \left(x \cdot x + \color{blue}{x \cdot \left(2 \cdot y\right)}\right) \]
      6. distribute-lft-out100.0%

        \[\leadsto y \cdot y + \color{blue}{x \cdot \left(x + 2 \cdot y\right)} \]
    5. Applied egg-rr100.0%

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

    if 4.0000000000000002e276 < (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y))

    1. Initial program 83.9%

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

      \[\leadsto \color{blue}{{x}^{2}} + y \cdot y \]
    3. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
    4. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
  3. Recombined 2 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 4 \cdot 10^{+276}:\\ \;\;\;\;y \cdot y + x \cdot \left(x + 2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + y \cdot y\\ \end{array} \]

Alternative 3: 98.9% accurate, 1.9× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ x \cdot x + y \cdot y \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (+ (* x x) (* y y)))
assert(x < y);
double code(double x, double y) {
	return (x * x) + (y * y);
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * x) + (y * y)
end function
assert x < y;
public static double code(double x, double y) {
	return (x * x) + (y * y);
}
[x, y] = sort([x, y])
def code(x, y):
	return (x * x) + (y * y)
x, y = sort([x, y])
function code(x, y)
	return Float64(Float64(x * x) + Float64(y * y))
end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
	tmp = (x * x) + (y * y);
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot x + y \cdot y
\end{array}
Derivation
  1. Initial program 92.1%

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

    \[\leadsto \color{blue}{{x}^{2}} + y \cdot y \]
  3. Step-by-step derivation
    1. unpow297.8%

      \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
  4. Simplified97.8%

    \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
  5. Final simplification97.8%

    \[\leadsto x \cdot x + y \cdot y \]

Alternative 4: 87.3% accurate, 2.6× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-132}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (if (<= x -4e-132) (* x x) (* y y)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (x <= -4e-132) {
		tmp = x * x;
	} else {
		tmp = y * y;
	}
	return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-4d-132)) then
        tmp = x * x
    else
        tmp = y * y
    end if
    code = tmp
end function
assert x < y;
public static double code(double x, double y) {
	double tmp;
	if (x <= -4e-132) {
		tmp = x * x;
	} else {
		tmp = y * y;
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if x <= -4e-132:
		tmp = x * x
	else:
		tmp = y * y
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (x <= -4e-132)
		tmp = Float64(x * x);
	else
		tmp = Float64(y * y);
	end
	return tmp
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -4e-132)
		tmp = x * x;
	else
		tmp = y * y;
	end
	tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[x, -4e-132], N[(x * x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-132}:\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;y \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.9999999999999999e-132

    1. Initial program 91.5%

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

      \[\leadsto \color{blue}{{x}^{2}} + y \cdot y \]
    3. Step-by-step derivation
      1. unpow295.8%

        \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
    4. Simplified95.8%

      \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
    5. Taylor expanded in x around inf 69.6%

      \[\leadsto \color{blue}{{x}^{2}} \]
    6. Step-by-step derivation
      1. unpow269.6%

        \[\leadsto \color{blue}{x \cdot x} \]
    7. Simplified69.6%

      \[\leadsto \color{blue}{x \cdot x} \]

    if -3.9999999999999999e-132 < x

    1. Initial program 92.6%

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

      \[\leadsto \color{blue}{{y}^{2}} \]
    3. Step-by-step derivation
      1. unpow269.8%

        \[\leadsto \color{blue}{y \cdot y} \]
    4. Simplified69.8%

      \[\leadsto \color{blue}{y \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification69.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-132}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]

Alternative 5: 56.9% accurate, 4.3× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ x \cdot x \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (* x x))
assert(x < y);
double code(double x, double y) {
	return x * x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x * x
end function
assert x < y;
public static double code(double x, double y) {
	return x * x;
}
[x, y] = sort([x, y])
def code(x, y):
	return x * x
x, y = sort([x, y])
function code(x, y)
	return Float64(x * x)
end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
	tmp = x * x;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot x
\end{array}
Derivation
  1. Initial program 92.1%

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

    \[\leadsto \color{blue}{{x}^{2}} + y \cdot y \]
  3. Step-by-step derivation
    1. unpow297.8%

      \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
  4. Simplified97.8%

    \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
  5. Taylor expanded in x around inf 56.7%

    \[\leadsto \color{blue}{{x}^{2}} \]
  6. Step-by-step derivation
    1. unpow256.7%

      \[\leadsto \color{blue}{x \cdot x} \]
  7. Simplified56.7%

    \[\leadsto \color{blue}{x \cdot x} \]
  8. Final simplification56.7%

    \[\leadsto x \cdot x \]

Developer target: 94.0% accurate, 1.0× speedup?

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

\\
x \cdot x + \left(y \cdot y + \left(x \cdot y\right) \cdot 2\right)
\end{array}

Reproduce

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