Linear.Quaternion:$c/ from linear-1.19.1.3, E

Percentage Accurate: 99.9% → 99.9%
Time: 10.7s
Alternatives: 7
Speedup: 1.7×

Specification

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

\\
\left(\left(x \cdot x + y \cdot y\right) + y \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 7 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(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))
double code(double x, double y) {
	return (((x * x) + (y * y)) + (y * y)) + (y * y);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (((x * x) + (y * y)) + (y * y)) + (y * y)
end function
public static double code(double x, double y) {
	return (((x * x) + (y * y)) + (y * y)) + (y * y);
}
def code(x, y):
	return (((x * x) + (y * y)) + (y * y)) + (y * y)
function code(x, y)
	return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(y * y)) + Float64(y * y))
end
function tmp = code(x, y)
	tmp = (((x * x) + (y * y)) + (y * y)) + (y * y);
end
code[x_, y_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.9% accurate, 0.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
    10. metadata-eval99.9%

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

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

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

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

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

      \[\leadsto \mathsf{fma.f64}\left(\mathsf{*.f64}\left(y, y\right), 3, \left(x \cdot x\right)\right) \]
    5. *-lowering-*.f6499.9%

      \[\leadsto \mathsf{fma.f64}\left(\mathsf{*.f64}\left(y, y\right), 3, \mathsf{*.f64}\left(x, x\right)\right) \]
  6. Applied egg-rr99.9%

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

Alternative 2: 82.0% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2.8 \cdot 10^{+22}:\\ \;\;\;\;\frac{y \cdot -9}{\frac{-3}{y}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (* x x) 2.8e+22) (/ (* y -9.0) (/ -3.0 y)) (* x x)))
double code(double x, double y) {
	double tmp;
	if ((x * x) <= 2.8e+22) {
		tmp = (y * -9.0) / (-3.0 / 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 * x) <= 2.8d+22) then
        tmp = (y * (-9.0d0)) / ((-3.0d0) / y)
    else
        tmp = x * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x * x) <= 2.8e+22) {
		tmp = (y * -9.0) / (-3.0 / y);
	} else {
		tmp = x * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x * x) <= 2.8e+22:
		tmp = (y * -9.0) / (-3.0 / y)
	else:
		tmp = x * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (Float64(x * x) <= 2.8e+22)
		tmp = Float64(Float64(y * -9.0) / Float64(-3.0 / y));
	else
		tmp = Float64(x * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x * x) <= 2.8e+22)
		tmp = (y * -9.0) / (-3.0 / y);
	else
		tmp = x * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.8e+22], N[(N[(y * -9.0), $MachinePrecision] / N[(-3.0 / y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2.8 \cdot 10^{+22}:\\
\;\;\;\;\frac{y \cdot -9}{\frac{-3}{y}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 2.8e22

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(\left(y \cdot y\right) \cdot 3\right) \cdot \left(\left(y \cdot y\right) \cdot 3\right)}{\mathsf{fma}\left(x, x, \mathsf{neg}\left(3 \cdot \left(y \cdot y\right)\right)\right)} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(\left(y \cdot y\right) \cdot 3\right) \cdot \left(\left(y \cdot y\right) \cdot 3\right)\right), \color{blue}{\left(\mathsf{fma}\left(x, x, \mathsf{neg}\left(3 \cdot \left(y \cdot y\right)\right)\right)\right)}\right) \]
    6. Applied egg-rr39.6%

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, y\right)\right)\right), -9\right)\right), \mathsf{*.f64}\left(y, \left(y \cdot \color{blue}{-3}\right)\right)\right) \]
      6. *-lowering-*.f6433.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, y\right)\right)\right), -9\right)\right), \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, \color{blue}{-3}\right)\right)\right) \]
    9. Simplified33.8%

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(-9 \cdot {y}^{4}\right)}, \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, -3\right)\right)\right) \]
    11. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(-9, \left({y}^{4}\right)\right), \mathsf{*.f64}\left(\color{blue}{y}, \mathsf{*.f64}\left(y, -3\right)\right)\right) \]
      2. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(-9, \left({y}^{\left(2 \cdot 2\right)}\right)\right), \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, -3\right)\right)\right) \]
      3. pow-sqrN/A

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(-9, \mathsf{*.f64}\left(\left({y}^{2}\right), \left({y}^{2}\right)\right)\right), \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, -3\right)\right)\right) \]
      5. unpow2N/A

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(-9, \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left({y}^{2}\right)\right)\right), \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, -3\right)\right)\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(-9, \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left(y \cdot y\right)\right)\right), \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, -3\right)\right)\right) \]
      8. *-lowering-*.f6433.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(-9, \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \mathsf{*.f64}\left(y, y\right)\right)\right), \mathsf{*.f64}\left(y, \mathsf{*.f64}\left(y, -3\right)\right)\right) \]
    12. Simplified33.8%

      \[\leadsto \frac{\color{blue}{-9 \cdot \left(\left(y \cdot y\right) \cdot \left(y \cdot y\right)\right)}}{y \cdot \left(y \cdot -3\right)} \]
    13. Step-by-step derivation
      1. clear-numN/A

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

        \[\leadsto \frac{1}{\frac{\left(y \cdot y\right) \cdot -3}{\color{blue}{-9} \cdot \left(\left(y \cdot y\right) \cdot \left(y \cdot y\right)\right)}} \]
      3. associate-*r*N/A

        \[\leadsto \frac{1}{\frac{\left(y \cdot y\right) \cdot -3}{-9 \cdot \left(\left(\left(y \cdot y\right) \cdot y\right) \cdot \color{blue}{y}\right)}} \]
      4. associate-*r*N/A

        \[\leadsto \frac{1}{\frac{\left(y \cdot y\right) \cdot -3}{-9 \cdot \left(\left(y \cdot \left(y \cdot y\right)\right) \cdot y\right)}} \]
      5. associate-*r*N/A

        \[\leadsto \frac{1}{\frac{\left(y \cdot y\right) \cdot -3}{\left(-9 \cdot \left(y \cdot \left(y \cdot y\right)\right)\right) \cdot \color{blue}{y}}} \]
      6. times-fracN/A

        \[\leadsto \frac{1}{\frac{y \cdot y}{-9 \cdot \left(y \cdot \left(y \cdot y\right)\right)} \cdot \color{blue}{\frac{-3}{y}}} \]
      7. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{\frac{y \cdot y}{-9 \cdot \left(y \cdot \left(y \cdot y\right)\right)}}}{\color{blue}{\frac{-3}{y}}} \]
      8. clear-numN/A

        \[\leadsto \frac{\frac{-9 \cdot \left(y \cdot \left(y \cdot y\right)\right)}{y \cdot y}}{\frac{\color{blue}{-3}}{y}} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-9 \cdot \frac{y \cdot \left(y \cdot y\right)}{y \cdot y}}{\frac{\color{blue}{-3}}{y}} \]
      10. cube-unmultN/A

        \[\leadsto \frac{-9 \cdot \frac{{y}^{3}}{y \cdot y}}{\frac{-3}{y}} \]
      11. pow2N/A

        \[\leadsto \frac{-9 \cdot \frac{{y}^{3}}{{y}^{2}}}{\frac{-3}{y}} \]
      12. pow-divN/A

        \[\leadsto \frac{-9 \cdot {y}^{\left(3 - 2\right)}}{\frac{-3}{y}} \]
      13. metadata-evalN/A

        \[\leadsto \frac{-9 \cdot {y}^{1}}{\frac{-3}{y}} \]
      14. unpow1N/A

        \[\leadsto \frac{-9 \cdot y}{\frac{-3}{y}} \]
      15. /-lowering-/.f64N/A

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(-9, y\right), \left(\frac{\color{blue}{-3}}{y}\right)\right) \]
      17. /-lowering-/.f6483.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(-9, y\right), \mathsf{/.f64}\left(-3, \color{blue}{y}\right)\right) \]
    14. Applied egg-rr83.4%

      \[\leadsto \color{blue}{\frac{-9 \cdot y}{\frac{-3}{y}}} \]

    if 2.8e22 < (*.f64 x x)

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y\right) \cdot 3} \]
    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-*.f6484.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2.8 \cdot 10^{+22}:\\ \;\;\;\;\frac{y \cdot -9}{\frac{-3}{y}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 5.5 \cdot 10^{+21}:\\ \;\;\;\;y \cdot \left(y \cdot 3\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (* x x) 5.5e+21) (* y (* y 3.0)) (* x x)))
double code(double x, double y) {
	double tmp;
	if ((x * x) <= 5.5e+21) {
		tmp = y * (y * 3.0);
	} 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 * x) <= 5.5d+21) then
        tmp = y * (y * 3.0d0)
    else
        tmp = x * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x * x) <= 5.5e+21) {
		tmp = y * (y * 3.0);
	} else {
		tmp = x * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x * x) <= 5.5e+21:
		tmp = y * (y * 3.0)
	else:
		tmp = x * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (Float64(x * x) <= 5.5e+21)
		tmp = Float64(y * Float64(y * 3.0));
	else
		tmp = Float64(x * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x * x) <= 5.5e+21)
		tmp = y * (y * 3.0);
	else
		tmp = x * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 5.5e+21], N[(y * N[(y * 3.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5.5 \cdot 10^{+21}:\\
\;\;\;\;y \cdot \left(y \cdot 3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 5.5e21

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{3 \cdot {y}^{2}} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(3, \color{blue}{\left({y}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(3, \left(y \cdot \color{blue}{y}\right)\right) \]
      3. *-lowering-*.f6483.3%

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

      \[\leadsto \color{blue}{3 \cdot \left(y \cdot y\right)} \]
    8. Step-by-step derivation
      1. associate-*r*N/A

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

        \[\leadsto \left(y \cdot 3\right) \cdot y \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(y \cdot 3\right), \color{blue}{y}\right) \]
      4. *-lowering-*.f6483.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, 3\right), y\right) \]
    9. Applied egg-rr83.3%

      \[\leadsto \color{blue}{\left(y \cdot 3\right) \cdot y} \]

    if 5.5e21 < (*.f64 x x)

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y\right) \cdot 3} \]
    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-*.f6484.5%

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

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

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

Alternative 4: 82.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 6.5 \cdot 10^{+21}:\\ \;\;\;\;\left(y \cdot y\right) \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (* x x) 6.5e+21) (* (* y y) 3.0) (* x x)))
double code(double x, double y) {
	double tmp;
	if ((x * x) <= 6.5e+21) {
		tmp = (y * y) * 3.0;
	} 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 * x) <= 6.5d+21) then
        tmp = (y * y) * 3.0d0
    else
        tmp = x * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x * x) <= 6.5e+21) {
		tmp = (y * y) * 3.0;
	} else {
		tmp = x * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x * x) <= 6.5e+21:
		tmp = (y * y) * 3.0
	else:
		tmp = x * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (Float64(x * x) <= 6.5e+21)
		tmp = Float64(Float64(y * y) * 3.0);
	else
		tmp = Float64(x * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x * x) <= 6.5e+21)
		tmp = (y * y) * 3.0;
	else
		tmp = x * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 6.5e+21], N[(N[(y * y), $MachinePrecision] * 3.0), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 6.5 \cdot 10^{+21}:\\
\;\;\;\;\left(y \cdot y\right) \cdot 3\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 6.5e21

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{3 \cdot {y}^{2}} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(3, \color{blue}{\left({y}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(3, \left(y \cdot \color{blue}{y}\right)\right) \]
      3. *-lowering-*.f6483.3%

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

      \[\leadsto \color{blue}{3 \cdot \left(y \cdot y\right)} \]

    if 6.5e21 < (*.f64 x x)

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y\right) \cdot 3} \]
    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-*.f6484.5%

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

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

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

Alternative 5: 99.9% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
    10. metadata-eval99.9%

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

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

Alternative 6: 99.9% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
    10. metadata-eval99.9%

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

    \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y\right) \cdot 3} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. associate-*l*N/A

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, 3\right), y\right)\right) \]
  6. Applied egg-rr99.9%

    \[\leadsto x \cdot x + \color{blue}{\left(y \cdot 3\right) \cdot y} \]
  7. Final simplification99.9%

    \[\leadsto x \cdot x + y \cdot \left(y \cdot 3\right) \]
  8. Add Preprocessing

Alternative 7: 57.7% accurate, 5.0× 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 99.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(y, y\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
    10. metadata-eval99.9%

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

    \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y\right) \cdot 3} \]
  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.4%

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

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

Developer Target 1: 99.9% accurate, 1.4× speedup?

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

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

Reproduce

?
herbie shell --seed 2024163 
(FPCore (x y)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, E"
  :precision binary64

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

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