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

Percentage Accurate: 99.9% → 99.9%
Time: 9.2s
Alternatives: 7
Speedup: 1.0×

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

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

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

      \[\leadsto \color{blue}{\left(y \cdot y + \left(x \cdot x + y \cdot y\right)\right)} + y \cdot y \]
    2. sqr-neg99.8%

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

      \[\leadsto \color{blue}{\left(\left(x \cdot x + \left(-y\right) \cdot \left(-y\right)\right) + y \cdot y\right)} + y \cdot y \]
    4. sqr-neg99.8%

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

      \[\leadsto \color{blue}{y \cdot y + \left(\left(x \cdot x + \left(-y\right) \cdot \left(-y\right)\right) + \left(-y\right) \cdot \left(-y\right)\right)} \]
    6. fma-define99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, y, \left(x \cdot x + \left(-y\right) \cdot \left(-y\right)\right) + \left(-y\right) \cdot \left(-y\right)\right)} \]
    7. sqr-neg99.9%

      \[\leadsto \mathsf{fma}\left(y, y, \left(x \cdot x + \left(-y\right) \cdot \left(-y\right)\right) + \color{blue}{y \cdot y}\right) \]
    8. sqr-neg99.9%

      \[\leadsto \mathsf{fma}\left(y, y, \left(x \cdot x + \color{blue}{y \cdot y}\right) + y \cdot y\right) \]
    9. associate-+l+99.9%

      \[\leadsto \mathsf{fma}\left(y, y, \color{blue}{x \cdot x + \left(y \cdot y + y \cdot y\right)}\right) \]
    10. fma-define99.9%

      \[\leadsto \mathsf{fma}\left(y, y, \color{blue}{\mathsf{fma}\left(x, x, y \cdot y + y \cdot y\right)}\right) \]
    11. count-299.9%

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

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

Alternative 2: 99.9% accurate, 0.1× speedup?

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

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

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

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

      \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y + \left(y \cdot y + y \cdot y\right)\right)} \]
    3. fma-define99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot y + \left(y \cdot y + y \cdot y\right)\right)} \]
    4. count-299.9%

      \[\leadsto \mathsf{fma}\left(x, x, y \cdot y + \color{blue}{2 \cdot \left(y \cdot y\right)}\right) \]
    5. distribute-rgt1-in99.9%

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

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

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(2 + -1 \cdot -1\right)}\right) \]
    8. associate-*l*99.8%

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

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

      \[\leadsto \mathsf{fma}\left(x, x, y \cdot \left(y \cdot \color{blue}{3}\right)\right) \]
  3. Simplified99.8%

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

Alternative 3: 77.3% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.8 \cdot 10^{-93}:\\
\;\;\;\;y \cdot \left(y \cdot 3\right)\\

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


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

    1. Initial program 99.8%

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

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

        \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y + \left(y \cdot y + y \cdot y\right)\right)} \]
      3. fma-define99.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot y + \left(y \cdot y + y \cdot y\right)\right)} \]
      4. count-299.8%

        \[\leadsto \mathsf{fma}\left(x, x, y \cdot y + \color{blue}{2 \cdot \left(y \cdot y\right)}\right) \]
      5. distribute-rgt1-in99.8%

        \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(2 + 1\right) \cdot \left(y \cdot y\right)}\right) \]
      6. metadata-eval99.8%

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

        \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(2 + -1 \cdot -1\right)}\right) \]
      8. associate-*l*99.8%

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

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

        \[\leadsto \mathsf{fma}\left(x, x, y \cdot \left(y \cdot \color{blue}{3}\right)\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-sqr-sqrt99.6%

        \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)}} \]
      2. fma-undefine99.6%

        \[\leadsto \sqrt{\color{blue}{x \cdot x + y \cdot \left(y \cdot 3\right)}} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      3. add-sqr-sqrt99.6%

        \[\leadsto \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot \left(y \cdot 3\right)} \cdot \sqrt{y \cdot \left(y \cdot 3\right)}}} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      4. hypot-define99.6%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 3\right)}\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      5. associate-*r*99.7%

        \[\leadsto \mathsf{hypot}\left(x, \sqrt{\color{blue}{\left(y \cdot y\right) \cdot 3}}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      6. sqrt-prod99.6%

        \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y} \cdot \sqrt{3}}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      7. sqrt-prod45.6%

        \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{3}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      8. add-sqr-sqrt99.7%

        \[\leadsto \mathsf{hypot}\left(x, \color{blue}{y} \cdot \sqrt{3}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      9. fma-undefine99.7%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \sqrt{\color{blue}{x \cdot x + y \cdot \left(y \cdot 3\right)}} \]
      10. add-sqr-sqrt99.7%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot \left(y \cdot 3\right)} \cdot \sqrt{y \cdot \left(y \cdot 3\right)}}} \]
      11. hypot-define99.7%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 3\right)}\right)} \]
      12. associate-*r*99.7%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \sqrt{\color{blue}{\left(y \cdot y\right) \cdot 3}}\right) \]
      13. sqrt-prod99.5%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y} \cdot \sqrt{3}}\right) \]
      14. sqrt-prod45.5%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{3}\right) \]
      15. add-sqr-sqrt99.5%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{y} \cdot \sqrt{3}\right) \]
    6. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right)} \]
    7. Simplified99.5%

      \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left(x, y \cdot \sqrt{3}\right)\right)}^{2}} \]
    8. Taylor expanded in x around 0 65.8%

      \[\leadsto {\color{blue}{\left(y \cdot \sqrt{3}\right)}}^{2} \]
    9. Step-by-step derivation
      1. unpow-prod-down65.8%

        \[\leadsto \color{blue}{{y}^{2} \cdot {\left(\sqrt{3}\right)}^{2}} \]
      2. pow265.8%

        \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot {\left(\sqrt{3}\right)}^{2} \]
      3. pow265.8%

        \[\leadsto \left(y \cdot y\right) \cdot \color{blue}{\left(\sqrt{3} \cdot \sqrt{3}\right)} \]
      4. rem-square-sqrt66.1%

        \[\leadsto \left(y \cdot y\right) \cdot \color{blue}{3} \]
      5. associate-*l*66.1%

        \[\leadsto \color{blue}{y \cdot \left(y \cdot 3\right)} \]
    10. Applied egg-rr66.1%

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

    if 8.79999999999999983e-93 < x

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto {x}^{2} \cdot \left(1 + \color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right)} \cdot 3\right) \]
    6. Applied egg-rr96.3%

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

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot 3\right) \]
    8. Applied egg-rr96.3%

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot 3\right) \]
    9. Step-by-step derivation
      1. associate-*r/96.3%

        \[\leadsto \left(x \cdot x\right) \cdot \left(1 + \color{blue}{\frac{\frac{y}{x} \cdot y}{x}} \cdot 3\right) \]
    10. Applied egg-rr96.3%

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

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

Alternative 4: 77.3% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.15 \cdot 10^{-93}:\\
\;\;\;\;y \cdot \left(y \cdot 3\right)\\

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


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

    1. Initial program 99.8%

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

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

        \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y + \left(y \cdot y + y \cdot y\right)\right)} \]
      3. fma-define99.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot y + \left(y \cdot y + y \cdot y\right)\right)} \]
      4. count-299.8%

        \[\leadsto \mathsf{fma}\left(x, x, y \cdot y + \color{blue}{2 \cdot \left(y \cdot y\right)}\right) \]
      5. distribute-rgt1-in99.8%

        \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(2 + 1\right) \cdot \left(y \cdot y\right)}\right) \]
      6. metadata-eval99.8%

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

        \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(2 + -1 \cdot -1\right)}\right) \]
      8. associate-*l*99.8%

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

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

        \[\leadsto \mathsf{fma}\left(x, x, y \cdot \left(y \cdot \color{blue}{3}\right)\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-sqr-sqrt99.6%

        \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)}} \]
      2. fma-undefine99.6%

        \[\leadsto \sqrt{\color{blue}{x \cdot x + y \cdot \left(y \cdot 3\right)}} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      3. add-sqr-sqrt99.6%

        \[\leadsto \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot \left(y \cdot 3\right)} \cdot \sqrt{y \cdot \left(y \cdot 3\right)}}} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      4. hypot-define99.6%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 3\right)}\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      5. associate-*r*99.7%

        \[\leadsto \mathsf{hypot}\left(x, \sqrt{\color{blue}{\left(y \cdot y\right) \cdot 3}}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      6. sqrt-prod99.6%

        \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y} \cdot \sqrt{3}}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      7. sqrt-prod45.6%

        \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{3}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      8. add-sqr-sqrt99.7%

        \[\leadsto \mathsf{hypot}\left(x, \color{blue}{y} \cdot \sqrt{3}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
      9. fma-undefine99.7%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \sqrt{\color{blue}{x \cdot x + y \cdot \left(y \cdot 3\right)}} \]
      10. add-sqr-sqrt99.7%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot \left(y \cdot 3\right)} \cdot \sqrt{y \cdot \left(y \cdot 3\right)}}} \]
      11. hypot-define99.7%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 3\right)}\right)} \]
      12. associate-*r*99.7%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \sqrt{\color{blue}{\left(y \cdot y\right) \cdot 3}}\right) \]
      13. sqrt-prod99.5%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y} \cdot \sqrt{3}}\right) \]
      14. sqrt-prod45.5%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{3}\right) \]
      15. add-sqr-sqrt99.5%

        \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{y} \cdot \sqrt{3}\right) \]
    6. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right)} \]
    7. Simplified99.5%

      \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left(x, y \cdot \sqrt{3}\right)\right)}^{2}} \]
    8. Taylor expanded in x around 0 65.8%

      \[\leadsto {\color{blue}{\left(y \cdot \sqrt{3}\right)}}^{2} \]
    9. Step-by-step derivation
      1. unpow-prod-down65.8%

        \[\leadsto \color{blue}{{y}^{2} \cdot {\left(\sqrt{3}\right)}^{2}} \]
      2. pow265.8%

        \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot {\left(\sqrt{3}\right)}^{2} \]
      3. pow265.8%

        \[\leadsto \left(y \cdot y\right) \cdot \color{blue}{\left(\sqrt{3} \cdot \sqrt{3}\right)} \]
      4. rem-square-sqrt66.1%

        \[\leadsto \left(y \cdot y\right) \cdot \color{blue}{3} \]
      5. associate-*l*66.1%

        \[\leadsto \color{blue}{y \cdot \left(y \cdot 3\right)} \]
    10. Applied egg-rr66.1%

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

    if 1.1499999999999999e-93 < x

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto {x}^{2} \cdot \left(1 + \color{blue}{\left(\frac{y}{x} \cdot \frac{y}{x}\right)} \cdot 3\right) \]
    6. Applied egg-rr96.3%

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

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot 3\right) \]
    8. Applied egg-rr96.3%

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

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

Alternative 5: 99.9% accurate, 1.0× speedup?

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

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

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

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

Alternative 6: 58.0% accurate, 1.7× speedup?

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

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

    \[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt99.7%

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}} + y \cdot y \]
    2. pow299.7%

      \[\leadsto \color{blue}{{\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}\right)}^{2}} + y \cdot y \]
    3. +-commutative99.7%

      \[\leadsto {\left(\sqrt{\color{blue}{y \cdot y + \left(x \cdot x + y \cdot y\right)}}\right)}^{2} + y \cdot y \]
    4. add-sqr-sqrt99.7%

      \[\leadsto {\left(\sqrt{y \cdot y + \color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\right)}^{2} + y \cdot y \]
    5. hypot-define99.8%

      \[\leadsto {\color{blue}{\left(\mathsf{hypot}\left(y, \sqrt{x \cdot x + y \cdot y}\right)\right)}}^{2} + y \cdot y \]
    6. hypot-define99.7%

      \[\leadsto {\left(\mathsf{hypot}\left(y, \color{blue}{\mathsf{hypot}\left(x, y\right)}\right)\right)}^{2} + y \cdot y \]
  4. Applied egg-rr99.7%

    \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left(y, \mathsf{hypot}\left(x, y\right)\right)\right)}^{2}} + y \cdot y \]
  5. Taylor expanded in x around 0 56.5%

    \[\leadsto {\left(\mathsf{hypot}\left(y, \color{blue}{y}\right)\right)}^{2} + y \cdot y \]
  6. Step-by-step derivation
    1. unpow256.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(y, y\right) \cdot \mathsf{hypot}\left(y, y\right)} + y \cdot y \]
    2. hypot-undefine56.5%

      \[\leadsto \color{blue}{\sqrt{y \cdot y + y \cdot y}} \cdot \mathsf{hypot}\left(y, y\right) + y \cdot y \]
    3. hypot-undefine56.5%

      \[\leadsto \sqrt{y \cdot y + y \cdot y} \cdot \color{blue}{\sqrt{y \cdot y + y \cdot y}} + y \cdot y \]
    4. add-sqr-sqrt56.6%

      \[\leadsto \color{blue}{\left(y \cdot y + y \cdot y\right)} + y \cdot y \]
    5. distribute-lft-out56.6%

      \[\leadsto \color{blue}{y \cdot \left(y + y\right)} + y \cdot y \]
  7. Applied egg-rr56.6%

    \[\leadsto \color{blue}{y \cdot \left(y + y\right)} + y \cdot y \]
  8. Final simplification56.6%

    \[\leadsto y \cdot y + y \cdot \left(y + y\right) \]
  9. Add Preprocessing

Alternative 7: 58.0% accurate, 3.0× speedup?

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

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

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

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

      \[\leadsto \color{blue}{x \cdot x + \left(y \cdot y + \left(y \cdot y + y \cdot y\right)\right)} \]
    3. fma-define99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot y + \left(y \cdot y + y \cdot y\right)\right)} \]
    4. count-299.9%

      \[\leadsto \mathsf{fma}\left(x, x, y \cdot y + \color{blue}{2 \cdot \left(y \cdot y\right)}\right) \]
    5. distribute-rgt1-in99.9%

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

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

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(2 + -1 \cdot -1\right)}\right) \]
    8. associate-*l*99.8%

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

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

      \[\leadsto \mathsf{fma}\left(x, x, y \cdot \left(y \cdot \color{blue}{3}\right)\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-sqr-sqrt99.7%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)}} \]
    2. fma-undefine99.7%

      \[\leadsto \sqrt{\color{blue}{x \cdot x + y \cdot \left(y \cdot 3\right)}} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    3. add-sqr-sqrt99.7%

      \[\leadsto \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot \left(y \cdot 3\right)} \cdot \sqrt{y \cdot \left(y \cdot 3\right)}}} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    4. hypot-define99.7%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 3\right)}\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    5. associate-*r*99.7%

      \[\leadsto \mathsf{hypot}\left(x, \sqrt{\color{blue}{\left(y \cdot y\right) \cdot 3}}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    6. sqrt-prod99.7%

      \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y} \cdot \sqrt{3}}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    7. sqrt-prod45.5%

      \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{3}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    8. add-sqr-sqrt99.7%

      \[\leadsto \mathsf{hypot}\left(x, \color{blue}{y} \cdot \sqrt{3}\right) \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 3\right)\right)} \]
    9. fma-undefine99.7%

      \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \sqrt{\color{blue}{x \cdot x + y \cdot \left(y \cdot 3\right)}} \]
    10. add-sqr-sqrt99.7%

      \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot \left(y \cdot 3\right)} \cdot \sqrt{y \cdot \left(y \cdot 3\right)}}} \]
    11. hypot-define99.7%

      \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 3\right)}\right)} \]
    12. associate-*r*99.7%

      \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \sqrt{\color{blue}{\left(y \cdot y\right) \cdot 3}}\right) \]
    13. sqrt-prod99.6%

      \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y} \cdot \sqrt{3}}\right) \]
    14. sqrt-prod45.5%

      \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \sqrt{3}\right) \]
    15. add-sqr-sqrt99.6%

      \[\leadsto \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, \color{blue}{y} \cdot \sqrt{3}\right) \]
  6. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\mathsf{hypot}\left(x, y \cdot \sqrt{3}\right) \cdot \mathsf{hypot}\left(x, y \cdot \sqrt{3}\right)} \]
  7. Simplified99.6%

    \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left(x, y \cdot \sqrt{3}\right)\right)}^{2}} \]
  8. Taylor expanded in x around 0 56.4%

    \[\leadsto {\color{blue}{\left(y \cdot \sqrt{3}\right)}}^{2} \]
  9. Step-by-step derivation
    1. unpow-prod-down56.3%

      \[\leadsto \color{blue}{{y}^{2} \cdot {\left(\sqrt{3}\right)}^{2}} \]
    2. pow256.3%

      \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot {\left(\sqrt{3}\right)}^{2} \]
    3. pow256.3%

      \[\leadsto \left(y \cdot y\right) \cdot \color{blue}{\left(\sqrt{3} \cdot \sqrt{3}\right)} \]
    4. rem-square-sqrt56.6%

      \[\leadsto \left(y \cdot y\right) \cdot \color{blue}{3} \]
    5. associate-*l*56.6%

      \[\leadsto \color{blue}{y \cdot \left(y \cdot 3\right)} \]
  10. Applied egg-rr56.6%

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