Examples.Basics.ProofTests:f4 from sbv-4.4

Percentage Accurate: 93.8% → 99.9%
Time: 8.0s
Alternatives: 8
Speedup: 0.8×

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 8 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: 93.8% 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: 99.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot x + y \cdot \left(x \cdot 2\right)\right) + y \cdot y\\ \mathbf{if}\;t\_0 \leq 2 \cdot 10^{+306}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ (+ (* x x) (* y (* x 2.0))) (* y y))))
   (if (<= t_0 2e+306) t_0 (* y (+ y (* x (+ 2.0 (/ x y))))))))
double code(double x, double y) {
	double t_0 = ((x * x) + (y * (x * 2.0))) + (y * y);
	double tmp;
	if (t_0 <= 2e+306) {
		tmp = t_0;
	} else {
		tmp = y * (y + (x * (2.0 + (x / y))));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((x * x) + (y * (x * 2.0d0))) + (y * y)
    if (t_0 <= 2d+306) then
        tmp = t_0
    else
        tmp = y * (y + (x * (2.0d0 + (x / y))))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = ((x * x) + (y * (x * 2.0))) + (y * y);
	double tmp;
	if (t_0 <= 2e+306) {
		tmp = t_0;
	} else {
		tmp = y * (y + (x * (2.0 + (x / y))));
	}
	return tmp;
}
def code(x, y):
	t_0 = ((x * x) + (y * (x * 2.0))) + (y * y)
	tmp = 0
	if t_0 <= 2e+306:
		tmp = t_0
	else:
		tmp = y * (y + (x * (2.0 + (x / y))))
	return tmp
function code(x, y)
	t_0 = Float64(Float64(Float64(x * x) + Float64(y * Float64(x * 2.0))) + Float64(y * y))
	tmp = 0.0
	if (t_0 <= 2e+306)
		tmp = t_0;
	else
		tmp = Float64(y * Float64(y + Float64(x * Float64(2.0 + Float64(x / y)))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = ((x * x) + (y * (x * 2.0))) + (y * y);
	tmp = 0.0;
	if (t_0 <= 2e+306)
		tmp = t_0;
	else
		tmp = y * (y + (x * (2.0 + (x / y))));
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e+306], t$95$0, N[(y * N[(y + N[(x * N[(2.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x \cdot x + y \cdot \left(x \cdot 2\right)\right) + y \cdot y\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+306}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) (*.f64 y y)) < 2.00000000000000003e306

    1. Initial program 100.0%

      \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \]
    2. Add Preprocessing

    if 2.00000000000000003e306 < (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) (*.f64 y y))

    1. Initial program 92.9%

      \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{x \cdot x - \left(x \cdot 2\right) \cdot y}\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
      2. fmm-defN/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \mathsf{*.f64}\left(y, y\right)\right) \]
      3. div-subN/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)} - \frac{\left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \left(\frac{\left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right)\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
    4. Applied egg-rr5.1%

      \[\leadsto \color{blue}{\left(\frac{x \cdot \left(x \cdot \left(x \cdot x\right)\right)}{x \cdot \left(x - y \cdot 2\right)} - \frac{y \cdot y}{x} \cdot \frac{\left(x \cdot x\right) \cdot 4}{x - y \cdot 2}\right)} + y \cdot y \]
    5. Taylor expanded in y around inf

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(y \cdot \left(\frac{{x}^{2}}{y} - -2 \cdot x\right)\right)}, \mathsf{*.f64}\left(y, y\right)\right) \]
    6. Simplified96.9%

      \[\leadsto \color{blue}{y \cdot \left(x \cdot 2 + \frac{x \cdot x}{y}\right)} + y \cdot y \]
    7. Step-by-step derivation
      1. distribute-lft-outN/A

        \[\leadsto y \cdot \color{blue}{\left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right)} \]
      2. *-commutativeN/A

        \[\leadsto \left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right) \cdot \color{blue}{y} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right), \color{blue}{y}\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\left(y + \left(x \cdot 2 + \frac{x \cdot x}{y}\right)\right), y\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot 2 + \frac{x \cdot x}{y}\right)\right), y\right) \]
      6. associate-/l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot 2 + x \cdot \frac{x}{y}\right)\right), y\right) \]
      7. distribute-lft-outN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot \left(2 + \frac{x}{y}\right)\right)\right), y\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \left(2 + \frac{x}{y}\right)\right)\right), y\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(2, \left(\frac{x}{y}\right)\right)\right)\right), y\right) \]
      10. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(2, \mathsf{/.f64}\left(x, y\right)\right)\right)\right), y\right) \]
    8. Applied egg-rr100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot x + y \cdot \left(x \cdot 2\right)\right) + y \cdot y \leq 2 \cdot 10^{+306}:\\ \;\;\;\;\left(x \cdot x + y \cdot \left(x \cdot 2\right)\right) + y \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.7% accurate, 0.1× speedup?

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

\\
\mathsf{fma}\left(y, y, x \cdot \left(x + y \cdot 2\right)\right)
\end{array}
Derivation
  1. Initial program 97.2%

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

      \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
    4. distribute-rgt-outN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
    7. *-lowering-*.f6499.2%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
  3. Simplified99.2%

    \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. distribute-rgt-inN/A

      \[\leadsto x \cdot x + \left(\left(x \cdot 2\right) \cdot y + \color{blue}{y \cdot y}\right) \]
    2. associate-+l+N/A

      \[\leadsto \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + \color{blue}{y \cdot y} \]
    3. +-commutativeN/A

      \[\leadsto y \cdot y + \color{blue}{\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right)} \]
    4. fma-defineN/A

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{y}, x \cdot x + \left(x \cdot 2\right) \cdot y\right) \]
    5. fma-lowering-fma.f64N/A

      \[\leadsto \mathsf{fma.f64}\left(y, \color{blue}{y}, \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right)\right) \]
    6. associate-*l*N/A

      \[\leadsto \mathsf{fma.f64}\left(y, y, \left(x \cdot x + x \cdot \left(2 \cdot y\right)\right)\right) \]
    7. distribute-lft-outN/A

      \[\leadsto \mathsf{fma.f64}\left(y, y, \left(x \cdot \left(x + 2 \cdot y\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma.f64}\left(y, y, \mathsf{*.f64}\left(x, \left(x + 2 \cdot y\right)\right)\right) \]
    9. +-lowering-+.f64N/A

      \[\leadsto \mathsf{fma.f64}\left(y, y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \left(2 \cdot y\right)\right)\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \mathsf{fma.f64}\left(y, y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \left(y \cdot 2\right)\right)\right)\right) \]
    11. *-lowering-*.f6498.0%

      \[\leadsto \mathsf{fma.f64}\left(y, y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \mathsf{*.f64}\left(y, 2\right)\right)\right)\right) \]
  6. Applied egg-rr98.0%

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

Alternative 3: 98.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 8500:\\ \;\;\;\;x \cdot x + y \cdot \left(y + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 8500.0)
   (+ (* x x) (* y (+ y (* x 2.0))))
   (* y (+ y (* x (+ 2.0 (/ x y)))))))
double code(double x, double y) {
	double tmp;
	if (y <= 8500.0) {
		tmp = (x * x) + (y * (y + (x * 2.0)));
	} else {
		tmp = y * (y + (x * (2.0 + (x / y))));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 8500.0d0) then
        tmp = (x * x) + (y * (y + (x * 2.0d0)))
    else
        tmp = y * (y + (x * (2.0d0 + (x / y))))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= 8500.0) {
		tmp = (x * x) + (y * (y + (x * 2.0)));
	} else {
		tmp = y * (y + (x * (2.0 + (x / y))));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 8500.0:
		tmp = (x * x) + (y * (y + (x * 2.0)))
	else:
		tmp = y * (y + (x * (2.0 + (x / y))))
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 8500.0)
		tmp = Float64(Float64(x * x) + Float64(y * Float64(y + Float64(x * 2.0))));
	else
		tmp = Float64(y * Float64(y + Float64(x * Float64(2.0 + Float64(x / y)))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 8500.0)
		tmp = (x * x) + (y * (y + (x * 2.0)));
	else
		tmp = y * (y + (x * (2.0 + (x / y))));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 8500.0], N[(N[(x * x), $MachinePrecision] + N[(y * N[(y + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(y + N[(x * N[(2.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 8500:\\
\;\;\;\;x \cdot x + y \cdot \left(y + x \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 8500

    1. Initial program 98.4%

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

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
      4. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
      7. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
    3. Simplified100.0%

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

    if 8500 < y

    1. Initial program 93.6%

      \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{x \cdot x - \left(x \cdot 2\right) \cdot y}\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
      2. fmm-defN/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \mathsf{*.f64}\left(y, y\right)\right) \]
      3. div-subN/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)} - \frac{\left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \left(\frac{\left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right)\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
    4. Applied egg-rr26.1%

      \[\leadsto \color{blue}{\left(\frac{x \cdot \left(x \cdot \left(x \cdot x\right)\right)}{x \cdot \left(x - y \cdot 2\right)} - \frac{y \cdot y}{x} \cdot \frac{\left(x \cdot x\right) \cdot 4}{x - y \cdot 2}\right)} + y \cdot y \]
    5. Taylor expanded in y around inf

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(y \cdot \left(\frac{{x}^{2}}{y} - -2 \cdot x\right)\right)}, \mathsf{*.f64}\left(y, y\right)\right) \]
    6. Simplified98.4%

      \[\leadsto \color{blue}{y \cdot \left(x \cdot 2 + \frac{x \cdot x}{y}\right)} + y \cdot y \]
    7. Step-by-step derivation
      1. distribute-lft-outN/A

        \[\leadsto y \cdot \color{blue}{\left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right)} \]
      2. *-commutativeN/A

        \[\leadsto \left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right) \cdot \color{blue}{y} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right), \color{blue}{y}\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\left(y + \left(x \cdot 2 + \frac{x \cdot x}{y}\right)\right), y\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot 2 + \frac{x \cdot x}{y}\right)\right), y\right) \]
      6. associate-/l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot 2 + x \cdot \frac{x}{y}\right)\right), y\right) \]
      7. distribute-lft-outN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot \left(2 + \frac{x}{y}\right)\right)\right), y\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \left(2 + \frac{x}{y}\right)\right)\right), y\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(2, \left(\frac{x}{y}\right)\right)\right)\right), y\right) \]
      10. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(2, \mathsf{/.f64}\left(x, y\right)\right)\right)\right), y\right) \]
    8. Applied egg-rr100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 8500:\\ \;\;\;\;x \cdot x + y \cdot \left(y + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 5 \cdot 10^{-173}:\\ \;\;\;\;x \cdot \left(x + y \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 5e-173) (* x (+ x (* y 2.0))) (* y (+ y (* x (+ 2.0 (/ x y)))))))
double code(double x, double y) {
	double tmp;
	if (y <= 5e-173) {
		tmp = x * (x + (y * 2.0));
	} else {
		tmp = y * (y + (x * (2.0 + (x / y))));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 5d-173) then
        tmp = x * (x + (y * 2.0d0))
    else
        tmp = y * (y + (x * (2.0d0 + (x / y))))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= 5e-173) {
		tmp = x * (x + (y * 2.0));
	} else {
		tmp = y * (y + (x * (2.0 + (x / y))));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 5e-173:
		tmp = x * (x + (y * 2.0))
	else:
		tmp = y * (y + (x * (2.0 + (x / y))))
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 5e-173)
		tmp = Float64(x * Float64(x + Float64(y * 2.0)));
	else
		tmp = Float64(y * Float64(y + Float64(x * Float64(2.0 + Float64(x / y)))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 5e-173)
		tmp = x * (x + (y * 2.0));
	else
		tmp = y * (y + (x * (2.0 + (x / y))));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 5e-173], N[(x * N[(x + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(y + N[(x * N[(2.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{-173}:\\
\;\;\;\;x \cdot \left(x + y \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 5.0000000000000002e-173

    1. Initial program 98.1%

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

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
      4. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
      7. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(1 + 2 \cdot \frac{y}{x}\right)} \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \left(x \cdot x\right) \cdot \left(\color{blue}{1} + 2 \cdot \frac{y}{x}\right) \]
      2. associate-*l*N/A

        \[\leadsto x \cdot \color{blue}{\left(x \cdot \left(1 + 2 \cdot \frac{y}{x}\right)\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(x \cdot \left(1 + 2 \cdot \frac{y}{x}\right)\right)}\right) \]
      4. distribute-rgt-inN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(1 \cdot x + \color{blue}{\left(2 \cdot \frac{y}{x}\right) \cdot x}\right)\right) \]
      5. *-lft-identityN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x + \color{blue}{\left(2 \cdot \frac{y}{x}\right)} \cdot x\right)\right) \]
      6. associate-*r/N/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x + \frac{2 \cdot y}{x} \cdot x\right)\right) \]
      7. associate-*l/N/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x + \frac{\left(2 \cdot y\right) \cdot x}{\color{blue}{x}}\right)\right) \]
      8. associate-/l*N/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x + \left(2 \cdot y\right) \cdot \color{blue}{\frac{x}{x}}\right)\right) \]
      9. *-inversesN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x + \left(2 \cdot y\right) \cdot 1\right)\right) \]
      10. *-rgt-identityN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(x + 2 \cdot \color{blue}{y}\right)\right) \]
      11. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \color{blue}{\left(2 \cdot y\right)}\right)\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \left(y \cdot \color{blue}{2}\right)\right)\right) \]
      13. *-lowering-*.f6464.0%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{2}\right)\right)\right) \]
    7. Simplified64.0%

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

    if 5.0000000000000002e-173 < y

    1. Initial program 96.0%

      \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{x \cdot x - \left(x \cdot 2\right) \cdot y}\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
      2. fmm-defN/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \mathsf{*.f64}\left(y, y\right)\right) \]
      3. div-subN/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)} - \frac{\left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right), \left(\frac{\left(\left(x \cdot 2\right) \cdot y\right) \cdot \left(\left(x \cdot 2\right) \cdot y\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(\left(x \cdot 2\right) \cdot y\right)\right)}\right)\right), \mathsf{*.f64}\left(\color{blue}{y}, y\right)\right) \]
    4. Applied egg-rr32.0%

      \[\leadsto \color{blue}{\left(\frac{x \cdot \left(x \cdot \left(x \cdot x\right)\right)}{x \cdot \left(x - y \cdot 2\right)} - \frac{y \cdot y}{x} \cdot \frac{\left(x \cdot x\right) \cdot 4}{x - y \cdot 2}\right)} + y \cdot y \]
    5. Taylor expanded in y around inf

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(y \cdot \left(\frac{{x}^{2}}{y} - -2 \cdot x\right)\right)}, \mathsf{*.f64}\left(y, y\right)\right) \]
    6. Simplified96.3%

      \[\leadsto \color{blue}{y \cdot \left(x \cdot 2 + \frac{x \cdot x}{y}\right)} + y \cdot y \]
    7. Step-by-step derivation
      1. distribute-lft-outN/A

        \[\leadsto y \cdot \color{blue}{\left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right)} \]
      2. *-commutativeN/A

        \[\leadsto \left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right) \cdot \color{blue}{y} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\left(x \cdot 2 + \frac{x \cdot x}{y}\right) + y\right), \color{blue}{y}\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\left(y + \left(x \cdot 2 + \frac{x \cdot x}{y}\right)\right), y\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot 2 + \frac{x \cdot x}{y}\right)\right), y\right) \]
      6. associate-/l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot 2 + x \cdot \frac{x}{y}\right)\right), y\right) \]
      7. distribute-lft-outN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \left(x \cdot \left(2 + \frac{x}{y}\right)\right)\right), y\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \left(2 + \frac{x}{y}\right)\right)\right), y\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(2, \left(\frac{x}{y}\right)\right)\right)\right), y\right) \]
      10. /-lowering-/.f6497.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(2, \mathsf{/.f64}\left(x, y\right)\right)\right)\right), y\right) \]
    8. Applied egg-rr97.2%

      \[\leadsto \color{blue}{\left(y + x \cdot \left(2 + \frac{x}{y}\right)\right) \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 5 \cdot 10^{-173}:\\ \;\;\;\;x \cdot \left(x + y \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot \left(2 + \frac{x}{y}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 69.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-145}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y \cdot \left(1 + \frac{x \cdot 2}{y}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -1.45e-145) (* x x) (* y (* y (+ 1.0 (/ (* x 2.0) y))))))
double code(double x, double y) {
	double tmp;
	if (x <= -1.45e-145) {
		tmp = x * x;
	} else {
		tmp = y * (y * (1.0 + ((x * 2.0) / y)));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-1.45d-145)) then
        tmp = x * x
    else
        tmp = y * (y * (1.0d0 + ((x * 2.0d0) / y)))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.45e-145) {
		tmp = x * x;
	} else {
		tmp = y * (y * (1.0 + ((x * 2.0) / y)));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.45e-145:
		tmp = x * x
	else:
		tmp = y * (y * (1.0 + ((x * 2.0) / y)))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.45e-145)
		tmp = Float64(x * x);
	else
		tmp = Float64(y * Float64(y * Float64(1.0 + Float64(Float64(x * 2.0) / y))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.45e-145)
		tmp = x * x;
	else
		tmp = y * (y * (1.0 + ((x * 2.0) / y)));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.45e-145], N[(x * x), $MachinePrecision], N[(y * N[(y * N[(1.0 + N[(N[(x * 2.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-145}:\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot \left(1 + \frac{x \cdot 2}{y}\right)\right)\\


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

    1. Initial program 95.7%

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

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
      4. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
      7. *-lowering-*.f6497.8%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
    3. Simplified97.8%

      \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf

      \[\leadsto \color{blue}{{x}^{2}} \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto x \cdot \color{blue}{x} \]
      2. *-lowering-*.f6473.0%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{x}\right) \]
    7. Simplified73.0%

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

    if -1.44999999999999992e-145 < x

    1. Initial program 98.1%

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

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
      4. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
      7. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. distribute-rgt-inN/A

        \[\leadsto x \cdot x + \left(\left(x \cdot 2\right) \cdot y + \color{blue}{y \cdot y}\right) \]
      2. associate-+l+N/A

        \[\leadsto \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + \color{blue}{y \cdot y} \]
      3. +-commutativeN/A

        \[\leadsto y \cdot y + \color{blue}{\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right)} \]
      4. fma-defineN/A

        \[\leadsto \mathsf{fma}\left(y, \color{blue}{y}, x \cdot x + \left(x \cdot 2\right) \cdot y\right) \]
      5. fma-lowering-fma.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(y, \color{blue}{y}, \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{fma.f64}\left(y, y, \left(x \cdot x + x \cdot \left(2 \cdot y\right)\right)\right) \]
      7. distribute-lft-outN/A

        \[\leadsto \mathsf{fma.f64}\left(y, y, \left(x \cdot \left(x + 2 \cdot y\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(y, y, \mathsf{*.f64}\left(x, \left(x + 2 \cdot y\right)\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{fma.f64}\left(y, y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \left(2 \cdot y\right)\right)\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{fma.f64}\left(y, y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \left(y \cdot 2\right)\right)\right)\right) \]
      11. *-lowering-*.f6498.1%

        \[\leadsto \mathsf{fma.f64}\left(y, y, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(x, \mathsf{*.f64}\left(y, 2\right)\right)\right)\right) \]
    6. Applied egg-rr98.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, y, x \cdot \left(x + y \cdot 2\right)\right)} \]
    7. Taylor expanded in y around inf

      \[\leadsto \color{blue}{{y}^{2} \cdot \left(1 + 2 \cdot \frac{x}{y}\right)} \]
    8. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \left(y \cdot y\right) \cdot \left(\color{blue}{1} + 2 \cdot \frac{x}{y}\right) \]
      2. associate-*l*N/A

        \[\leadsto y \cdot \color{blue}{\left(y \cdot \left(1 + 2 \cdot \frac{x}{y}\right)\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(y, \color{blue}{\left(y \cdot \left(1 + 2 \cdot \frac{x}{y}\right)\right)}\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \color{blue}{\left(1 + 2 \cdot \frac{x}{y}\right)}\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(1, \color{blue}{\left(2 \cdot \frac{x}{y}\right)}\right)\right)\right) \]
      6. associate-*r/N/A

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(1, \left(\frac{2 \cdot x}{\color{blue}{y}}\right)\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\left(2 \cdot x\right), \color{blue}{y}\right)\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\left(x \cdot 2\right), y\right)\right)\right)\right) \]
      9. *-lowering-*.f6471.0%

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right)\right) \]
    9. Simplified71.0%

      \[\leadsto \color{blue}{y \cdot \left(y \cdot \left(1 + \frac{x \cdot 2}{y}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 67.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-145}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot 2\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -1.45e-145) (* x x) (* y (+ y (* x 2.0)))))
double code(double x, double y) {
	double tmp;
	if (x <= -1.45e-145) {
		tmp = x * x;
	} else {
		tmp = y * (y + (x * 2.0));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-1.45d-145)) then
        tmp = x * x
    else
        tmp = y * (y + (x * 2.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.45e-145) {
		tmp = x * x;
	} else {
		tmp = y * (y + (x * 2.0));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.45e-145:
		tmp = x * x
	else:
		tmp = y * (y + (x * 2.0))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.45e-145)
		tmp = Float64(x * x);
	else
		tmp = Float64(y * Float64(y + Float64(x * 2.0)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.45e-145)
		tmp = x * x;
	else
		tmp = y * (y + (x * 2.0));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.45e-145], N[(x * x), $MachinePrecision], N[(y * N[(y + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-145}:\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(y + x \cdot 2\right)\\


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

    1. Initial program 95.7%

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

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
      4. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
      7. *-lowering-*.f6497.8%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
    3. Simplified97.8%

      \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf

      \[\leadsto \color{blue}{{x}^{2}} \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto x \cdot \color{blue}{x} \]
      2. *-lowering-*.f6473.0%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{x}\right) \]
    7. Simplified73.0%

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

    if -1.44999999999999992e-145 < x

    1. Initial program 98.1%

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

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
      4. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
      7. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{2 \cdot \left(x \cdot y\right) + {y}^{2}} \]
    6. Step-by-step derivation
      1. fma-defineN/A

        \[\leadsto \mathsf{fma}\left(2, \color{blue}{x \cdot y}, {y}^{2}\right) \]
      2. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(2, \left(x \cdot 1\right) \cdot y, {y}^{2}\right) \]
      3. *-inversesN/A

        \[\leadsto \mathsf{fma}\left(2, \left(x \cdot \frac{y}{y}\right) \cdot y, {y}^{2}\right) \]
      4. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(2, \frac{x \cdot y}{y} \cdot y, {y}^{2}\right) \]
      5. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(2, \left(\frac{x}{y} \cdot y\right) \cdot y, {y}^{2}\right) \]
      6. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(2, \frac{x}{y} \cdot \color{blue}{\left(y \cdot y\right)}, {y}^{2}\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{fma}\left(2, \frac{x}{y} \cdot {y}^{\color{blue}{2}}, {y}^{2}\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(2, {y}^{2} \cdot \color{blue}{\frac{x}{y}}, {y}^{2}\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(2, \frac{x}{y} \cdot \color{blue}{{y}^{2}}, {y}^{2}\right) \]
      10. fma-defineN/A

        \[\leadsto 2 \cdot \left(\frac{x}{y} \cdot {y}^{2}\right) + \color{blue}{{y}^{2}} \]
      11. associate-*l*N/A

        \[\leadsto \left(2 \cdot \frac{x}{y}\right) \cdot {y}^{2} + {\color{blue}{y}}^{2} \]
      12. *-lft-identityN/A

        \[\leadsto \left(2 \cdot \frac{x}{y}\right) \cdot {y}^{2} + 1 \cdot \color{blue}{{y}^{2}} \]
      13. distribute-rgt-inN/A

        \[\leadsto {y}^{2} \cdot \color{blue}{\left(2 \cdot \frac{x}{y} + 1\right)} \]
      14. unpow2N/A

        \[\leadsto \left(y \cdot y\right) \cdot \left(\color{blue}{2 \cdot \frac{x}{y}} + 1\right) \]
      15. +-commutativeN/A

        \[\leadsto \left(y \cdot y\right) \cdot \left(1 + \color{blue}{2 \cdot \frac{x}{y}}\right) \]
      16. associate-*l*N/A

        \[\leadsto y \cdot \color{blue}{\left(y \cdot \left(1 + 2 \cdot \frac{x}{y}\right)\right)} \]
      17. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(y, \color{blue}{\left(y \cdot \left(1 + 2 \cdot \frac{x}{y}\right)\right)}\right) \]
      18. distribute-lft-inN/A

        \[\leadsto \mathsf{*.f64}\left(y, \left(y \cdot 1 + \color{blue}{y \cdot \left(2 \cdot \frac{x}{y}\right)}\right)\right) \]
      19. *-rgt-identityN/A

        \[\leadsto \mathsf{*.f64}\left(y, \left(y + \color{blue}{y} \cdot \left(2 \cdot \frac{x}{y}\right)\right)\right) \]
      20. associate-*r/N/A

        \[\leadsto \mathsf{*.f64}\left(y, \left(y + y \cdot \frac{2 \cdot x}{\color{blue}{y}}\right)\right) \]
      21. associate-*r/N/A

        \[\leadsto \mathsf{*.f64}\left(y, \left(y + \frac{y \cdot \left(2 \cdot x\right)}{\color{blue}{y}}\right)\right) \]
      22. associate-*l/N/A

        \[\leadsto \mathsf{*.f64}\left(y, \left(y + \frac{y}{y} \cdot \color{blue}{\left(2 \cdot x\right)}\right)\right) \]
      23. *-inversesN/A

        \[\leadsto \mathsf{*.f64}\left(y, \left(y + 1 \cdot \left(\color{blue}{2} \cdot x\right)\right)\right) \]
      24. *-lft-identityN/A

        \[\leadsto \mathsf{*.f64}\left(y, \left(y + 2 \cdot \color{blue}{x}\right)\right) \]
    7. Simplified68.1%

      \[\leadsto \color{blue}{y \cdot \left(y + 2 \cdot x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification69.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-145}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y + x \cdot 2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 66.9% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-145}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= x -1.45e-145) (* x x) (* y y)))
double code(double x, double y) {
	double tmp;
	if (x <= -1.45e-145) {
		tmp = x * x;
	} else {
		tmp = y * y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-1.45d-145)) then
        tmp = x * x
    else
        tmp = y * y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.45e-145) {
		tmp = x * x;
	} else {
		tmp = y * y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.45e-145:
		tmp = x * x
	else:
		tmp = y * y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.45e-145)
		tmp = Float64(x * x);
	else
		tmp = Float64(y * y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.45e-145)
		tmp = x * x;
	else
		tmp = y * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.45e-145], N[(x * x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-145}:\\
\;\;\;\;x \cdot x\\

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


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

    1. Initial program 95.7%

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

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
      4. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
      7. *-lowering-*.f6497.8%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
    3. Simplified97.8%

      \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf

      \[\leadsto \color{blue}{{x}^{2}} \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto x \cdot \color{blue}{x} \]
      2. *-lowering-*.f6473.0%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{x}\right) \]
    7. Simplified73.0%

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

    if -1.44999999999999992e-145 < x

    1. Initial program 98.1%

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

        \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
      4. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
      7. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{{y}^{2}} \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto y \cdot \color{blue}{y} \]
      2. *-lowering-*.f6466.8%

        \[\leadsto \mathsf{*.f64}\left(y, \color{blue}{y}\right) \]
    7. Simplified66.8%

      \[\leadsto \color{blue}{y \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 58.1% accurate, 4.3× speedup?

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

\\
x \cdot x
\end{array}
Derivation
  1. Initial program 97.2%

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

      \[\leadsto x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)} \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(x \cdot x\right), \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right)\right) \]
    4. distribute-rgt-outN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(y \cdot \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x \cdot 2 + y\right)}\right)\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\left(x \cdot 2\right), \color{blue}{y}\right)\right)\right) \]
    7. *-lowering-*.f6499.2%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, 2\right), y\right)\right)\right) \]
  3. Simplified99.2%

    \[\leadsto \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around inf

    \[\leadsto \color{blue}{{x}^{2}} \]
  6. Step-by-step derivation
    1. unpow2N/A

      \[\leadsto x \cdot \color{blue}{x} \]
    2. *-lowering-*.f6455.1%

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{x}\right) \]
  7. Simplified55.1%

    \[\leadsto \color{blue}{x \cdot x} \]
  8. Add Preprocessing

Developer Target 1: 93.8% 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 2024160 
(FPCore (x y)
  :name "Examples.Basics.ProofTests:f4 from sbv-4.4"
  :precision binary64

  :alt
  (! :herbie-platform default (+ (* x x) (+ (* y y) (* (* x y) 2))))

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