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

Percentage Accurate: 99.9% → 99.9%
Time: 5.7s
Alternatives: 4
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 4 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.9%

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

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

      \[\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.9%

      \[\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.9%

      \[\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.9%

      \[\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.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+99.9%

      \[\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. *-lft-identity99.9%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x, x, \sqrt{\left(\color{blue}{{y}^{2}} \cdot \left(y \cdot y\right)\right) \cdot \left(3 \cdot 3\right)}\right) \]
    5. pow289.4%

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

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

      \[\leadsto \mathsf{fma}\left(x, x, \sqrt{{y}^{\color{blue}{4}} \cdot \left(3 \cdot 3\right)}\right) \]
    8. metadata-eval89.5%

      \[\leadsto \mathsf{fma}\left(x, x, \sqrt{{y}^{4} \cdot \color{blue}{9}}\right) \]
  6. Applied egg-rr89.5%

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

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\sqrt{{y}^{4}} \cdot \sqrt{9}}\right) \]
    2. sqrt-pow199.9%

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{{y}^{\left(\frac{4}{2}\right)}} \cdot \sqrt{9}\right) \]
    3. metadata-eval99.9%

      \[\leadsto \mathsf{fma}\left(x, x, {y}^{\color{blue}{2}} \cdot \sqrt{9}\right) \]
    4. pow299.9%

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

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

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

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

Alternative 3: 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.9%

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

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

Alternative 4: 57.4% 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.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+99.9%

      \[\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. *-lft-identity99.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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, \left(y \cdot y\right) \cdot 3\right)} \]
    7. add-sqr-sqrt99.8%

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

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

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

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

      \[\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) \]
    12. sqrt-prod47.9%

      \[\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) \]
    13. add-sqr-sqrt99.7%

      \[\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.7%

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

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

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

      \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot {\left(\sqrt{3}\right)}^{2} \]
    2. associate-*r*52.9%

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

      \[\leadsto y \cdot \left(y \cdot \color{blue}{{3}^{\left(\frac{2}{2}\right)}}\right) \]
    4. metadata-eval53.1%

      \[\leadsto y \cdot \left(y \cdot {3}^{\color{blue}{1}}\right) \]
    5. metadata-eval53.1%

      \[\leadsto y \cdot \left(y \cdot \color{blue}{3}\right) \]
    6. add-sqr-sqrt52.9%

      \[\leadsto \color{blue}{\sqrt{y \cdot \left(y \cdot 3\right)} \cdot \sqrt{y \cdot \left(y \cdot 3\right)}} \]
    7. sqrt-unprod44.7%

      \[\leadsto \color{blue}{\sqrt{\left(y \cdot \left(y \cdot 3\right)\right) \cdot \left(y \cdot \left(y \cdot 3\right)\right)}} \]
    8. metadata-eval44.7%

      \[\leadsto \sqrt{\left(y \cdot \left(y \cdot \color{blue}{{3}^{1}}\right)\right) \cdot \left(y \cdot \left(y \cdot 3\right)\right)} \]
    9. metadata-eval44.7%

      \[\leadsto \sqrt{\left(y \cdot \left(y \cdot {3}^{\color{blue}{\left(\frac{2}{2}\right)}}\right)\right) \cdot \left(y \cdot \left(y \cdot 3\right)\right)} \]
    10. sqrt-pow244.7%

      \[\leadsto \sqrt{\left(y \cdot \left(y \cdot \color{blue}{{\left(\sqrt{3}\right)}^{2}}\right)\right) \cdot \left(y \cdot \left(y \cdot 3\right)\right)} \]
    11. associate-*r*44.7%

      \[\leadsto \sqrt{\color{blue}{\left(\left(y \cdot y\right) \cdot {\left(\sqrt{3}\right)}^{2}\right)} \cdot \left(y \cdot \left(y \cdot 3\right)\right)} \]
    12. metadata-eval44.7%

      \[\leadsto \sqrt{\left(\left(y \cdot y\right) \cdot {\left(\sqrt{3}\right)}^{2}\right) \cdot \left(y \cdot \left(y \cdot \color{blue}{{3}^{1}}\right)\right)} \]
    13. metadata-eval44.7%

      \[\leadsto \sqrt{\left(\left(y \cdot y\right) \cdot {\left(\sqrt{3}\right)}^{2}\right) \cdot \left(y \cdot \left(y \cdot {3}^{\color{blue}{\left(\frac{2}{2}\right)}}\right)\right)} \]
    14. sqrt-pow244.6%

      \[\leadsto \sqrt{\left(\left(y \cdot y\right) \cdot {\left(\sqrt{3}\right)}^{2}\right) \cdot \left(y \cdot \left(y \cdot \color{blue}{{\left(\sqrt{3}\right)}^{2}}\right)\right)} \]
    15. associate-*r*44.6%

      \[\leadsto \sqrt{\left(\left(y \cdot y\right) \cdot {\left(\sqrt{3}\right)}^{2}\right) \cdot \color{blue}{\left(\left(y \cdot y\right) \cdot {\left(\sqrt{3}\right)}^{2}\right)}} \]
    16. swap-sqr44.7%

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

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

      \[\leadsto \sqrt{\left({y}^{2} \cdot \color{blue}{{y}^{2}}\right) \cdot \left({\left(\sqrt{3}\right)}^{2} \cdot {\left(\sqrt{3}\right)}^{2}\right)} \]
    19. pow-prod-up44.7%

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

      \[\leadsto \sqrt{{y}^{\color{blue}{4}} \cdot \left({\left(\sqrt{3}\right)}^{2} \cdot {\left(\sqrt{3}\right)}^{2}\right)} \]
  10. Applied egg-rr44.8%

    \[\leadsto \color{blue}{\sqrt{{y}^{4} \cdot 9}} \]
  11. Step-by-step derivation
    1. sqrt-prod89.4%

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\sqrt{{y}^{4}} \cdot \sqrt{9}}\right) \]
    2. sqrt-pow199.9%

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{{y}^{\left(\frac{4}{2}\right)}} \cdot \sqrt{9}\right) \]
    3. metadata-eval99.9%

      \[\leadsto \mathsf{fma}\left(x, x, {y}^{\color{blue}{2}} \cdot \sqrt{9}\right) \]
    4. pow299.9%

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

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

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 3\right)}\right) \]
  12. Applied egg-rr53.1%

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