Numeric.Log:$clog1p from log-domain-0.10.2.1, A

Percentage Accurate: 99.9% → 99.9%
Time: 5.4s
Alternatives: 8
Speedup: 1.2×

Specification

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

\\
\left(x \cdot 2 + x \cdot x\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: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 1.0× speedup?

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

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

    \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
  2. Add Preprocessing
  3. Final simplification100.0%

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

Alternative 2: 83.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \cdot y \leq 1.1 \cdot 10^{-54}:\\ \;\;\;\;x \cdot x + x \cdot 2\\ \mathbf{elif}\;y \cdot y \leq 3.9 \cdot 10^{-28} \lor \neg \left(y \cdot y \leq 2.6 \cdot 10^{+156}\right):\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (* y y) 1.1e-54)
   (+ (* x x) (* x 2.0))
   (if (or (<= (* y y) 3.9e-28) (not (<= (* y y) 2.6e+156))) (* y y) (* x x))))
double code(double x, double y) {
	double tmp;
	if ((y * y) <= 1.1e-54) {
		tmp = (x * x) + (x * 2.0);
	} else if (((y * y) <= 3.9e-28) || !((y * y) <= 2.6e+156)) {
		tmp = y * y;
	} else {
		tmp = x * x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y * y) <= 1.1d-54) then
        tmp = (x * x) + (x * 2.0d0)
    else if (((y * y) <= 3.9d-28) .or. (.not. ((y * y) <= 2.6d+156))) then
        tmp = y * y
    else
        tmp = x * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y * y) <= 1.1e-54) {
		tmp = (x * x) + (x * 2.0);
	} else if (((y * y) <= 3.9e-28) || !((y * y) <= 2.6e+156)) {
		tmp = y * y;
	} else {
		tmp = x * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y * y) <= 1.1e-54:
		tmp = (x * x) + (x * 2.0)
	elif ((y * y) <= 3.9e-28) or not ((y * y) <= 2.6e+156):
		tmp = y * y
	else:
		tmp = x * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (Float64(y * y) <= 1.1e-54)
		tmp = Float64(Float64(x * x) + Float64(x * 2.0));
	elseif ((Float64(y * y) <= 3.9e-28) || !(Float64(y * y) <= 2.6e+156))
		tmp = Float64(y * y);
	else
		tmp = Float64(x * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y * y) <= 1.1e-54)
		tmp = (x * x) + (x * 2.0);
	elseif (((y * y) <= 3.9e-28) || ~(((y * y) <= 2.6e+156)))
		tmp = y * y;
	else
		tmp = x * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 1.1e-54], N[(N[(x * x), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(y * y), $MachinePrecision], 3.9e-28], N[Not[LessEqual[N[(y * y), $MachinePrecision], 2.6e+156]], $MachinePrecision]], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 1.1 \cdot 10^{-54}:\\
\;\;\;\;x \cdot x + x \cdot 2\\

\mathbf{elif}\;y \cdot y \leq 3.9 \cdot 10^{-28} \lor \neg \left(y \cdot y \leq 2.6 \cdot 10^{+156}\right):\\
\;\;\;\;y \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 y y) < 1.1e-54

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 73.1%

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
    4. Step-by-step derivation
      1. unpow273.1%

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in61.3%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity61.3%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*74.1%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out74.1%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/74.1%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval74.1%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{\color{blue}{2}}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      8. unpow274.1%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \frac{\color{blue}{y \cdot y}}{{x}^{2}}\right)\right) \]
      9. unpow274.1%

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

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
    5. Simplified74.3%

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

      \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
    7. Step-by-step derivation
      1. distribute-lft-in95.3%

        \[\leadsto \color{blue}{x \cdot x + x \cdot 2} \]
    8. Applied egg-rr95.3%

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

    if 1.1e-54 < (*.f64 y y) < 3.89999999999999999e-28 or 2.60000000000000019e156 < (*.f64 y y)

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 90.5%

      \[\leadsto \color{blue}{{y}^{2}} \]
    4. Step-by-step derivation
      1. unpow290.5%

        \[\leadsto \color{blue}{y \cdot y} \]
    5. Simplified90.5%

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

    if 3.89999999999999999e-28 < (*.f64 y y) < 2.60000000000000019e156

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 84.8%

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

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in58.8%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity58.8%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*85.3%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out85.3%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/85.3%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval85.3%

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

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

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

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
    5. Simplified85.2%

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

      \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
    7. Taylor expanded in x around inf 62.8%

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

        \[\leadsto \color{blue}{x \cdot x} \]
    9. Simplified62.8%

      \[\leadsto \color{blue}{x \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification87.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot y \leq 1.1 \cdot 10^{-54}:\\ \;\;\;\;x \cdot x + x \cdot 2\\ \mathbf{elif}\;y \cdot y \leq 3.9 \cdot 10^{-28} \lor \neg \left(y \cdot y \leq 2.6 \cdot 10^{+156}\right):\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 83.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \cdot y \leq 10^{-54}:\\ \;\;\;\;x \cdot \left(x + 2\right)\\ \mathbf{elif}\;y \cdot y \leq 5.4 \cdot 10^{-32} \lor \neg \left(y \cdot y \leq 2.6 \cdot 10^{+156}\right):\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (* y y) 1e-54)
   (* x (+ x 2.0))
   (if (or (<= (* y y) 5.4e-32) (not (<= (* y y) 2.6e+156))) (* y y) (* x x))))
double code(double x, double y) {
	double tmp;
	if ((y * y) <= 1e-54) {
		tmp = x * (x + 2.0);
	} else if (((y * y) <= 5.4e-32) || !((y * y) <= 2.6e+156)) {
		tmp = y * y;
	} else {
		tmp = x * x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y * y) <= 1d-54) then
        tmp = x * (x + 2.0d0)
    else if (((y * y) <= 5.4d-32) .or. (.not. ((y * y) <= 2.6d+156))) then
        tmp = y * y
    else
        tmp = x * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y * y) <= 1e-54) {
		tmp = x * (x + 2.0);
	} else if (((y * y) <= 5.4e-32) || !((y * y) <= 2.6e+156)) {
		tmp = y * y;
	} else {
		tmp = x * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y * y) <= 1e-54:
		tmp = x * (x + 2.0)
	elif ((y * y) <= 5.4e-32) or not ((y * y) <= 2.6e+156):
		tmp = y * y
	else:
		tmp = x * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (Float64(y * y) <= 1e-54)
		tmp = Float64(x * Float64(x + 2.0));
	elseif ((Float64(y * y) <= 5.4e-32) || !(Float64(y * y) <= 2.6e+156))
		tmp = Float64(y * y);
	else
		tmp = Float64(x * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y * y) <= 1e-54)
		tmp = x * (x + 2.0);
	elseif (((y * y) <= 5.4e-32) || ~(((y * y) <= 2.6e+156)))
		tmp = y * y;
	else
		tmp = x * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 1e-54], N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(y * y), $MachinePrecision], 5.4e-32], N[Not[LessEqual[N[(y * y), $MachinePrecision], 2.6e+156]], $MachinePrecision]], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;y \cdot y \leq 5.4 \cdot 10^{-32} \lor \neg \left(y \cdot y \leq 2.6 \cdot 10^{+156}\right):\\
\;\;\;\;y \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 y y) < 1e-54

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 73.1%

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
    4. Step-by-step derivation
      1. unpow273.1%

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in61.3%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity61.3%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*74.1%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out74.1%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/74.1%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval74.1%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{\color{blue}{2}}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      8. unpow274.1%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \frac{\color{blue}{y \cdot y}}{{x}^{2}}\right)\right) \]
      9. unpow274.1%

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

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
    5. Simplified74.3%

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

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

    if 1e-54 < (*.f64 y y) < 5.39999999999999962e-32 or 2.60000000000000019e156 < (*.f64 y y)

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 90.5%

      \[\leadsto \color{blue}{{y}^{2}} \]
    4. Step-by-step derivation
      1. unpow290.5%

        \[\leadsto \color{blue}{y \cdot y} \]
    5. Simplified90.5%

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

    if 5.39999999999999962e-32 < (*.f64 y y) < 2.60000000000000019e156

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 84.8%

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

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in58.8%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity58.8%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*85.3%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out85.3%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/85.3%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval85.3%

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

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

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

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
    5. Simplified85.2%

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

      \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
    7. Taylor expanded in x around inf 62.8%

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

        \[\leadsto \color{blue}{x \cdot x} \]
    9. Simplified62.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot y \leq 10^{-54}:\\ \;\;\;\;x \cdot \left(x + 2\right)\\ \mathbf{elif}\;y \cdot y \leq 5.4 \cdot 10^{-32} \lor \neg \left(y \cdot y \leq 2.6 \cdot 10^{+156}\right):\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 71.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+35}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-117}:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-197}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 18000000000000:\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -1.45e+35)
   (* x x)
   (if (<= x -2.4e-117)
     (* y y)
     (if (<= x -2.7e-197)
       (* x 2.0)
       (if (<= x 18000000000000.0) (* y y) (* x x))))))
double code(double x, double y) {
	double tmp;
	if (x <= -1.45e+35) {
		tmp = x * x;
	} else if (x <= -2.4e-117) {
		tmp = y * y;
	} else if (x <= -2.7e-197) {
		tmp = x * 2.0;
	} else if (x <= 18000000000000.0) {
		tmp = y * y;
	} else {
		tmp = x * x;
	}
	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+35)) then
        tmp = x * x
    else if (x <= (-2.4d-117)) then
        tmp = y * y
    else if (x <= (-2.7d-197)) then
        tmp = x * 2.0d0
    else if (x <= 18000000000000.0d0) then
        tmp = y * y
    else
        tmp = x * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.45e+35) {
		tmp = x * x;
	} else if (x <= -2.4e-117) {
		tmp = y * y;
	} else if (x <= -2.7e-197) {
		tmp = x * 2.0;
	} else if (x <= 18000000000000.0) {
		tmp = y * y;
	} else {
		tmp = x * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.45e+35:
		tmp = x * x
	elif x <= -2.4e-117:
		tmp = y * y
	elif x <= -2.7e-197:
		tmp = x * 2.0
	elif x <= 18000000000000.0:
		tmp = y * y
	else:
		tmp = x * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.45e+35)
		tmp = Float64(x * x);
	elseif (x <= -2.4e-117)
		tmp = Float64(y * y);
	elseif (x <= -2.7e-197)
		tmp = Float64(x * 2.0);
	elseif (x <= 18000000000000.0)
		tmp = Float64(y * y);
	else
		tmp = Float64(x * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.45e+35)
		tmp = x * x;
	elseif (x <= -2.4e-117)
		tmp = y * y;
	elseif (x <= -2.7e-197)
		tmp = x * 2.0;
	elseif (x <= 18000000000000.0)
		tmp = y * y;
	else
		tmp = x * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.45e+35], N[(x * x), $MachinePrecision], If[LessEqual[x, -2.4e-117], N[(y * y), $MachinePrecision], If[LessEqual[x, -2.7e-197], N[(x * 2.0), $MachinePrecision], If[LessEqual[x, 18000000000000.0], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -2.4 \cdot 10^{-117}:\\
\;\;\;\;y \cdot y\\

\mathbf{elif}\;x \leq -2.7 \cdot 10^{-197}:\\
\;\;\;\;x \cdot 2\\

\mathbf{elif}\;x \leq 18000000000000:\\
\;\;\;\;y \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.44999999999999997e35 or 1.8e13 < x

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 86.7%

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
    4. Step-by-step derivation
      1. unpow286.7%

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in60.1%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity60.1%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*86.7%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out86.7%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/86.7%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval86.7%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{\color{blue}{2}}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      8. unpow286.7%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \frac{\color{blue}{y \cdot y}}{{x}^{2}}\right)\right) \]
      9. unpow286.7%

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

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

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

      \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
    7. Taylor expanded in x around inf 89.5%

      \[\leadsto \color{blue}{{x}^{2}} \]
    8. Step-by-step derivation
      1. unpow289.5%

        \[\leadsto \color{blue}{x \cdot x} \]
    9. Simplified89.5%

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

    if -1.44999999999999997e35 < x < -2.40000000000000014e-117 or -2.70000000000000017e-197 < x < 1.8e13

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 60.8%

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

        \[\leadsto \color{blue}{y \cdot y} \]
    5. Simplified60.8%

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

    if -2.40000000000000014e-117 < x < -2.70000000000000017e-197

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 41.7%

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
    4. Step-by-step derivation
      1. unpow241.7%

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in41.7%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity41.7%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*64.0%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out64.0%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/64.0%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval64.0%

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

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

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

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
    5. Simplified64.2%

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

      \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
    7. Taylor expanded in x around 0 68.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+35}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-117}:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-197}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 18000000000000:\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 96.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{-141}:\\
\;\;\;\;x \cdot x + x \cdot 2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y y) < 4.9999999999999999e-141

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 72.8%

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

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in60.2%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity60.2%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*73.9%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out73.9%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/73.9%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval73.9%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{\color{blue}{2}}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      8. unpow273.9%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \frac{\color{blue}{y \cdot y}}{{x}^{2}}\right)\right) \]
      9. unpow273.9%

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

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
    5. Simplified74.1%

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

      \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
    7. Step-by-step derivation
      1. distribute-lft-in98.8%

        \[\leadsto \color{blue}{x \cdot x + x \cdot 2} \]
    8. Applied egg-rr98.8%

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

    if 4.9999999999999999e-141 < (*.f64 y y)

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 98.0%

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

        \[\leadsto \color{blue}{x \cdot x} + y \cdot y \]
    5. Simplified98.0%

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

Alternative 6: 59.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \lor \neg \left(x \leq 2\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -2.0) (not (<= x 2.0))) (* x x) (* x 2.0)))
double code(double x, double y) {
	double tmp;
	if ((x <= -2.0) || !(x <= 2.0)) {
		tmp = x * x;
	} else {
		tmp = 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 <= (-2.0d0)) .or. (.not. (x <= 2.0d0))) then
        tmp = x * x
    else
        tmp = x * 2.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -2.0) || !(x <= 2.0)) {
		tmp = x * x;
	} else {
		tmp = x * 2.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -2.0) or not (x <= 2.0):
		tmp = x * x
	else:
		tmp = x * 2.0
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -2.0) || !(x <= 2.0))
		tmp = Float64(x * x);
	else
		tmp = Float64(x * 2.0);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -2.0) || ~((x <= 2.0)))
		tmp = x * x;
	else
		tmp = x * 2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -2.0], N[Not[LessEqual[x, 2.0]], $MachinePrecision]], N[(x * x), $MachinePrecision], N[(x * 2.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \lor \neg \left(x \leq 2\right):\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;x \cdot 2\\


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

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 87.8%

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

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in63.4%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity63.4%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*87.7%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out87.7%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/87.7%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval87.7%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{\color{blue}{2}}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      8. unpow287.7%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \frac{\color{blue}{y \cdot y}}{{x}^{2}}\right)\right) \]
      9. unpow287.7%

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

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
    5. Simplified99.9%

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

      \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
    7. Taylor expanded in x around inf 83.4%

      \[\leadsto \color{blue}{{x}^{2}} \]
    8. Step-by-step derivation
      1. unpow283.4%

        \[\leadsto \color{blue}{x \cdot x} \]
    9. Simplified83.4%

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

    if -2 < x < 2

    1. Initial program 100.0%

      \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 45.4%

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
    4. Step-by-step derivation
      1. unpow245.4%

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      2. distribute-lft-in45.5%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
      3. *-rgt-identity45.5%

        \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
      4. associate-*l*60.4%

        \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      5. distribute-lft-out60.4%

        \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
      6. associate-*r/60.4%

        \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      7. metadata-eval60.4%

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{\color{blue}{2}}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
      8. unpow260.4%

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

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

        \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
    5. Simplified60.5%

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

      \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
    7. Taylor expanded in x around 0 45.8%

      \[\leadsto \color{blue}{2 \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification63.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2 \lor \neg \left(x \leq 2\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 100.0% accurate, 1.2× speedup?

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

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

    \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-lft-out100.0%

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

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

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

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

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

Alternative 8: 20.5% accurate, 3.7× speedup?

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

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

    \[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf 65.8%

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

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
    2. distribute-lft-in54.1%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 1 + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)} \]
    3. *-rgt-identity54.1%

      \[\leadsto \color{blue}{x \cdot x} + \left(x \cdot x\right) \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right) \]
    4. associate-*l*73.5%

      \[\leadsto x \cdot x + \color{blue}{x \cdot \left(x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
    5. distribute-lft-out73.5%

      \[\leadsto \color{blue}{x \cdot \left(x + x \cdot \left(2 \cdot \frac{1}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right)} \]
    6. associate-*r/73.5%

      \[\leadsto x \cdot \left(x + x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
    7. metadata-eval73.5%

      \[\leadsto x \cdot \left(x + x \cdot \left(\frac{\color{blue}{2}}{x} + \frac{{y}^{2}}{{x}^{2}}\right)\right) \]
    8. unpow273.5%

      \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \frac{\color{blue}{y \cdot y}}{{x}^{2}}\right)\right) \]
    9. unpow273.5%

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

      \[\leadsto x \cdot \left(x + x \cdot \left(\frac{2}{x} + \color{blue}{y \cdot \frac{y}{x \cdot x}}\right)\right) \]
  5. Simplified79.5%

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

    \[\leadsto x \cdot \left(x + \color{blue}{2}\right) \]
  7. Taylor expanded in x around 0 25.4%

    \[\leadsto \color{blue}{2 \cdot x} \]
  8. Final simplification25.4%

    \[\leadsto x \cdot 2 \]
  9. Add Preprocessing

Developer target: 99.9% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024097 
(FPCore (x y)
  :name "Numeric.Log:$clog1p from log-domain-0.10.2.1, A"
  :precision binary64

  :alt
  (+ (* y y) (+ (* 2.0 x) (* x x)))

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