Migdal et al, Equation (51)

Percentage Accurate: 99.5% → 99.2%
Time: 13.3s
Alternatives: 12
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \end{array} \]
(FPCore (k n)
 :precision binary64
 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
	return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
	return (1.0 / Math.sqrt(k)) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n):
	return (1.0 / math.sqrt(k)) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n)
	return Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0)))
end
function tmp = code(k, n)
	tmp = (1.0 / sqrt(k)) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0));
end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\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 12 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.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \end{array} \]
(FPCore (k n)
 :precision binary64
 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
	return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
	return (1.0 / Math.sqrt(k)) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n):
	return (1.0 / math.sqrt(k)) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n)
	return Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0)))
end
function tmp = code(k, n)
	tmp = (1.0 / sqrt(k)) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0));
end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}

Alternative 1: 99.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 3 \cdot 10^{-44}:\\ \;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 3e-44)
   (* (sqrt (* 2.0 n)) (sqrt (/ PI k)))
   (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k))))
double code(double k, double n) {
	double tmp;
	if (k <= 3e-44) {
		tmp = sqrt((2.0 * n)) * sqrt((((double) M_PI) / k));
	} else {
		tmp = sqrt((pow((2.0 * (((double) M_PI) * n)), (1.0 - k)) / k));
	}
	return tmp;
}
public static double code(double k, double n) {
	double tmp;
	if (k <= 3e-44) {
		tmp = Math.sqrt((2.0 * n)) * Math.sqrt((Math.PI / k));
	} else {
		tmp = Math.sqrt((Math.pow((2.0 * (Math.PI * n)), (1.0 - k)) / k));
	}
	return tmp;
}
def code(k, n):
	tmp = 0
	if k <= 3e-44:
		tmp = math.sqrt((2.0 * n)) * math.sqrt((math.pi / k))
	else:
		tmp = math.sqrt((math.pow((2.0 * (math.pi * n)), (1.0 - k)) / k))
	return tmp
function code(k, n)
	tmp = 0.0
	if (k <= 3e-44)
		tmp = Float64(sqrt(Float64(2.0 * n)) * sqrt(Float64(pi / k)));
	else
		tmp = sqrt(Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(1.0 - k)) / k));
	end
	return tmp
end
function tmp_2 = code(k, n)
	tmp = 0.0;
	if (k <= 3e-44)
		tmp = sqrt((2.0 * n)) * sqrt((pi / k));
	else
		tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k));
	end
	tmp_2 = tmp;
end
code[k_, n_] := If[LessEqual[k, 3e-44], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 3 \cdot 10^{-44}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if k < 3.0000000000000002e-44

    1. Initial program 98.5%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 77.1%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative77.1%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*77.1%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified77.1%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod76.4%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr76.4%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*76.4%

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}}} \]
      2. sqrt-prod99.5%

        \[\leadsto \color{blue}{\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}} \]
    9. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}} \]
    10. Step-by-step derivation
      1. *-commutative99.5%

        \[\leadsto \sqrt{\color{blue}{n \cdot 2}} \cdot \sqrt{\frac{\pi}{k}} \]
    11. Simplified99.5%

      \[\leadsto \color{blue}{\sqrt{n \cdot 2} \cdot \sqrt{\frac{\pi}{k}}} \]

    if 3.0000000000000002e-44 < k

    1. Initial program 99.6%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Applied egg-rr99.7%

      \[\leadsto \color{blue}{\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(2 \cdot \left(0.5 + k \cdot -0.5\right)\right)}}{k}}} \]
    4. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto \sqrt{\frac{{\left(2 \cdot \color{blue}{\left(n \cdot \pi\right)}\right)}^{\left(2 \cdot \left(0.5 + k \cdot -0.5\right)\right)}}{k}} \]
      2. distribute-lft-in99.7%

        \[\leadsto \sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\color{blue}{\left(2 \cdot 0.5 + 2 \cdot \left(k \cdot -0.5\right)\right)}}}{k}} \]
      3. metadata-eval99.7%

        \[\leadsto \sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(\color{blue}{1} + 2 \cdot \left(k \cdot -0.5\right)\right)}}{k}} \]
      4. *-commutative99.7%

        \[\leadsto \sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(1 + 2 \cdot \color{blue}{\left(-0.5 \cdot k\right)}\right)}}{k}} \]
      5. associate-*r*99.7%

        \[\leadsto \sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(1 + \color{blue}{\left(2 \cdot -0.5\right) \cdot k}\right)}}{k}} \]
      6. metadata-eval99.7%

        \[\leadsto \sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(1 + \color{blue}{-1} \cdot k\right)}}{k}} \]
      7. neg-mul-199.7%

        \[\leadsto \sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(1 + \color{blue}{\left(-k\right)}\right)}}{k}} \]
      8. sub-neg99.7%

        \[\leadsto \sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\color{blue}{\left(1 - k\right)}}}{k}} \]
    5. Simplified99.7%

      \[\leadsto \color{blue}{\sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 3 \cdot 10^{-44}:\\ \;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 \cdot \left(\pi \cdot n\right)\\ \frac{{k}^{-0.5} \cdot \sqrt{t\_0}}{{t\_0}^{\left(k \cdot 0.5\right)}} \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (let* ((t_0 (* 2.0 (* PI n))))
   (/ (* (pow k -0.5) (sqrt t_0)) (pow t_0 (* k 0.5)))))
double code(double k, double n) {
	double t_0 = 2.0 * (((double) M_PI) * n);
	return (pow(k, -0.5) * sqrt(t_0)) / pow(t_0, (k * 0.5));
}
public static double code(double k, double n) {
	double t_0 = 2.0 * (Math.PI * n);
	return (Math.pow(k, -0.5) * Math.sqrt(t_0)) / Math.pow(t_0, (k * 0.5));
}
def code(k, n):
	t_0 = 2.0 * (math.pi * n)
	return (math.pow(k, -0.5) * math.sqrt(t_0)) / math.pow(t_0, (k * 0.5))
function code(k, n)
	t_0 = Float64(2.0 * Float64(pi * n))
	return Float64(Float64((k ^ -0.5) * sqrt(t_0)) / (t_0 ^ Float64(k * 0.5)))
end
function tmp = code(k, n)
	t_0 = 2.0 * (pi * n);
	tmp = ((k ^ -0.5) * sqrt(t_0)) / (t_0 ^ (k * 0.5));
end
code[k_, n_] := Block[{t$95$0 = N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Power[k, -0.5], $MachinePrecision] * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] / N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 \cdot \left(\pi \cdot n\right)\\
\frac{{k}^{-0.5} \cdot \sqrt{t\_0}}{{t\_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.1%

    \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. associate-*r*99.1%

      \[\leadsto \frac{1}{\sqrt{k}} \cdot {\color{blue}{\left(2 \cdot \left(\pi \cdot n\right)\right)}}^{\left(\frac{1 - k}{2}\right)} \]
    2. div-sub99.1%

      \[\leadsto \frac{1}{\sqrt{k}} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\color{blue}{\left(\frac{1}{2} - \frac{k}{2}\right)}} \]
    3. metadata-eval99.1%

      \[\leadsto \frac{1}{\sqrt{k}} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\color{blue}{0.5} - \frac{k}{2}\right)} \]
    4. pow-div99.3%

      \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{0.5}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}}} \]
    5. pow1/299.3%

      \[\leadsto \frac{1}{\sqrt{k}} \cdot \frac{\color{blue}{\sqrt{2 \cdot \left(\pi \cdot n\right)}}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
    6. associate-*r/99.3%

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{k}} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}}} \]
    7. pow1/299.3%

      \[\leadsto \frac{\frac{1}{\color{blue}{{k}^{0.5}}} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
    8. pow-flip99.3%

      \[\leadsto \frac{\color{blue}{{k}^{\left(-0.5\right)}} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
    9. metadata-eval99.3%

      \[\leadsto \frac{{k}^{\color{blue}{-0.5}} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
    10. div-inv99.3%

      \[\leadsto \frac{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\color{blue}{\left(k \cdot \frac{1}{2}\right)}}} \]
    11. metadata-eval99.3%

      \[\leadsto \frac{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot \color{blue}{0.5}\right)}} \]
  4. Applied egg-rr99.3%

    \[\leadsto \color{blue}{\frac{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}} \]
  5. Add Preprocessing

Alternative 3: 99.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \pi \cdot \left(2 \cdot n\right)\\ \frac{\sqrt{t\_0}}{\sqrt{k} \cdot {t\_0}^{\left(k \cdot 0.5\right)}} \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (let* ((t_0 (* PI (* 2.0 n))))
   (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
	double t_0 = ((double) M_PI) * (2.0 * n);
	return sqrt(t_0) / (sqrt(k) * pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
	double t_0 = Math.PI * (2.0 * n);
	return Math.sqrt(t_0) / (Math.sqrt(k) * Math.pow(t_0, (k * 0.5)));
}
def code(k, n):
	t_0 = math.pi * (2.0 * n)
	return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n)
	t_0 = Float64(pi * Float64(2.0 * n))
	return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5))))
end
function tmp = code(k, n)
	t_0 = pi * (2.0 * n);
	tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5)));
end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[(N[Sqrt[k], $MachinePrecision] * N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \pi \cdot \left(2 \cdot n\right)\\
\frac{\sqrt{t\_0}}{\sqrt{k} \cdot {t\_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.1%

    \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. associate-*l/99.2%

      \[\leadsto \color{blue}{\frac{1 \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}} \]
    2. *-un-lft-identity99.2%

      \[\leadsto \frac{\color{blue}{{\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}}}{\sqrt{k}} \]
    3. associate-*r*99.2%

      \[\leadsto \frac{{\color{blue}{\left(2 \cdot \left(\pi \cdot n\right)\right)}}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}} \]
    4. div-sub99.2%

      \[\leadsto \frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\color{blue}{\left(\frac{1}{2} - \frac{k}{2}\right)}}}{\sqrt{k}} \]
    5. metadata-eval99.2%

      \[\leadsto \frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\color{blue}{0.5} - \frac{k}{2}\right)}}{\sqrt{k}} \]
    6. pow-div99.3%

      \[\leadsto \frac{\color{blue}{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{0.5}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}}}}{\sqrt{k}} \]
    7. pow1/299.3%

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{2 \cdot \left(\pi \cdot n\right)}}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}}}{\sqrt{k}} \]
    8. associate-/l/99.3%

      \[\leadsto \color{blue}{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{\sqrt{k} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}}} \]
    9. div-inv99.3%

      \[\leadsto \frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{\sqrt{k} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\color{blue}{\left(k \cdot \frac{1}{2}\right)}}} \]
    10. metadata-eval99.3%

      \[\leadsto \frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{\sqrt{k} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot \color{blue}{0.5}\right)}} \]
  4. Applied egg-rr99.3%

    \[\leadsto \color{blue}{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{\sqrt{k} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}} \]
  5. Step-by-step derivation
    1. associate-/l/99.3%

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\sqrt{k}}} \]
    2. unpow1/299.3%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\color{blue}{{k}^{0.5}}} \]
    3. metadata-eval99.3%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{{k}^{\color{blue}{\left(2 \cdot 0.25\right)}}} \]
    4. pow-sqr99.1%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\color{blue}{{k}^{0.25} \cdot {k}^{0.25}}} \]
    5. fabs-sqr99.1%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\color{blue}{\left|{k}^{0.25} \cdot {k}^{0.25}\right|}} \]
    6. pow-sqr99.3%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|\color{blue}{{k}^{\left(2 \cdot 0.25\right)}}\right|} \]
    7. metadata-eval99.3%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|{k}^{\color{blue}{0.5}}\right|} \]
    8. unpow1/299.3%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|\color{blue}{\sqrt{k}}\right|} \]
    9. fabs-neg99.3%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\color{blue}{\left|-\sqrt{k}\right|}} \]
    10. neg-mul-199.3%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|\color{blue}{-1 \cdot \sqrt{k}}\right|} \]
    11. rem-square-sqrt0.0%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{k}\right|} \]
    12. unpow1/20.0%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|\left(\sqrt{-1} \cdot \sqrt{-1}\right) \cdot \color{blue}{{k}^{0.5}}\right|} \]
    13. metadata-eval0.0%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|\left(\sqrt{-1} \cdot \sqrt{-1}\right) \cdot {k}^{\color{blue}{\left(2 \cdot 0.25\right)}}\right|} \]
    14. pow-sqr0.0%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|\left(\sqrt{-1} \cdot \sqrt{-1}\right) \cdot \color{blue}{\left({k}^{0.25} \cdot {k}^{0.25}\right)}\right|} \]
    15. unswap-sqr0.0%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\left|\color{blue}{\left(\sqrt{-1} \cdot {k}^{0.25}\right) \cdot \left(\sqrt{-1} \cdot {k}^{0.25}\right)}\right|} \]
    16. fabs-sqr0.0%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\color{blue}{\left(\sqrt{-1} \cdot {k}^{0.25}\right) \cdot \left(\sqrt{-1} \cdot {k}^{0.25}\right)}} \]
    17. unswap-sqr0.0%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right) \cdot \left({k}^{0.25} \cdot {k}^{0.25}\right)}} \]
    18. rem-square-sqrt27.9%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\color{blue}{-1} \cdot \left({k}^{0.25} \cdot {k}^{0.25}\right)} \]
    19. pow-sqr27.9%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{-1 \cdot \color{blue}{{k}^{\left(2 \cdot 0.25\right)}}} \]
    20. metadata-eval27.9%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{-1 \cdot {k}^{\color{blue}{0.5}}} \]
    21. unpow1/227.9%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{-1 \cdot \color{blue}{\sqrt{k}}} \]
    22. neg-mul-127.9%

      \[\leadsto \frac{\frac{\sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}}{\color{blue}{-\sqrt{k}}} \]
  6. Simplified99.3%

    \[\leadsto \color{blue}{\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k} \cdot {\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}} \]
  7. Add Preprocessing

Alternative 4: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{{k}^{-0.5}}{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(k \cdot 0.5 - 0.5\right)}} \end{array} \]
(FPCore (k n)
 :precision binary64
 (/ (pow k -0.5) (pow (* PI (* 2.0 n)) (- (* k 0.5) 0.5))))
double code(double k, double n) {
	return pow(k, -0.5) / pow((((double) M_PI) * (2.0 * n)), ((k * 0.5) - 0.5));
}
public static double code(double k, double n) {
	return Math.pow(k, -0.5) / Math.pow((Math.PI * (2.0 * n)), ((k * 0.5) - 0.5));
}
def code(k, n):
	return math.pow(k, -0.5) / math.pow((math.pi * (2.0 * n)), ((k * 0.5) - 0.5))
function code(k, n)
	return Float64((k ^ -0.5) / (Float64(pi * Float64(2.0 * n)) ^ Float64(Float64(k * 0.5) - 0.5)))
end
function tmp = code(k, n)
	tmp = (k ^ -0.5) / ((pi * (2.0 * n)) ^ ((k * 0.5) - 0.5));
end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] / N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(N[(k * 0.5), $MachinePrecision] - 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{{k}^{-0.5}}{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(k \cdot 0.5 - 0.5\right)}}
\end{array}
Derivation
  1. Initial program 99.1%

    \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in k around 0 99.2%

    \[\leadsto \color{blue}{\sqrt{\frac{1}{k}}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.2%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot {\color{blue}{\left(2 \cdot \left(\pi \cdot n\right)\right)}}^{\left(\frac{1 - k}{2}\right)} \]
    2. div-sub99.2%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\color{blue}{\left(\frac{1}{2} - \frac{k}{2}\right)}} \]
    3. metadata-eval99.2%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\color{blue}{0.5} - \frac{k}{2}\right)} \]
    4. pow-sub99.3%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot \color{blue}{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{0.5}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}}} \]
    5. *-commutative99.3%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot \frac{{\left(2 \cdot \color{blue}{\left(n \cdot \pi\right)}\right)}^{0.5}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
    6. pow1/299.3%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot \frac{\color{blue}{\sqrt{2 \cdot \left(n \cdot \pi\right)}}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
    7. *-commutative99.3%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot \frac{\sqrt{2 \cdot \left(n \cdot \pi\right)}}{{\left(2 \cdot \color{blue}{\left(n \cdot \pi\right)}\right)}^{\left(\frac{k}{2}\right)}} \]
    8. div-inv99.3%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot \frac{\sqrt{2 \cdot \left(n \cdot \pi\right)}}{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\color{blue}{\left(k \cdot \frac{1}{2}\right)}}} \]
    9. metadata-eval99.3%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot \frac{\sqrt{2 \cdot \left(n \cdot \pi\right)}}{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(k \cdot \color{blue}{0.5}\right)}} \]
    10. clear-num99.2%

      \[\leadsto \sqrt{\frac{1}{k}} \cdot \color{blue}{\frac{1}{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(k \cdot 0.5\right)}}{\sqrt{2 \cdot \left(n \cdot \pi\right)}}}} \]
    11. un-div-inv99.3%

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{k}}}{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(k \cdot 0.5\right)}}{\sqrt{2 \cdot \left(n \cdot \pi\right)}}}} \]
    12. inv-pow99.3%

      \[\leadsto \frac{\sqrt{\color{blue}{{k}^{-1}}}}{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(k \cdot 0.5\right)}}{\sqrt{2 \cdot \left(n \cdot \pi\right)}}} \]
    13. sqrt-pow199.3%

      \[\leadsto \frac{\color{blue}{{k}^{\left(\frac{-1}{2}\right)}}}{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(k \cdot 0.5\right)}}{\sqrt{2 \cdot \left(n \cdot \pi\right)}}} \]
    14. metadata-eval99.3%

      \[\leadsto \frac{{k}^{\color{blue}{-0.5}}}{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(k \cdot 0.5\right)}}{\sqrt{2 \cdot \left(n \cdot \pi\right)}}} \]
  5. Applied egg-rr99.2%

    \[\leadsto \color{blue}{\frac{{k}^{-0.5}}{{\left(\left(n \cdot 2\right) \cdot \pi\right)}^{\left(k \cdot 0.5 - 0.5\right)}}} \]
  6. Final simplification99.2%

    \[\leadsto \frac{{k}^{-0.5}}{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(k \cdot 0.5 - 0.5\right)}} \]
  7. Add Preprocessing

Alternative 5: 74.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 3.1:\\ \;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 3.1) (* (sqrt (* 2.0 n)) (sqrt (/ PI k))) (sqrt 0.0)))
double code(double k, double n) {
	double tmp;
	if (k <= 3.1) {
		tmp = sqrt((2.0 * n)) * sqrt((((double) M_PI) / k));
	} else {
		tmp = sqrt(0.0);
	}
	return tmp;
}
public static double code(double k, double n) {
	double tmp;
	if (k <= 3.1) {
		tmp = Math.sqrt((2.0 * n)) * Math.sqrt((Math.PI / k));
	} else {
		tmp = Math.sqrt(0.0);
	}
	return tmp;
}
def code(k, n):
	tmp = 0
	if k <= 3.1:
		tmp = math.sqrt((2.0 * n)) * math.sqrt((math.pi / k))
	else:
		tmp = math.sqrt(0.0)
	return tmp
function code(k, n)
	tmp = 0.0
	if (k <= 3.1)
		tmp = Float64(sqrt(Float64(2.0 * n)) * sqrt(Float64(pi / k)));
	else
		tmp = sqrt(0.0);
	end
	return tmp
end
function tmp_2 = code(k, n)
	tmp = 0.0;
	if (k <= 3.1)
		tmp = sqrt((2.0 * n)) * sqrt((pi / k));
	else
		tmp = sqrt(0.0);
	end
	tmp_2 = tmp;
end
code[k_, n_] := If[LessEqual[k, 3.1], N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[0.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 3.1:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if k < 3.10000000000000009

    1. Initial program 98.3%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 76.2%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative76.2%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*76.2%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified76.2%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod75.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr75.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*75.6%

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}}} \]
      2. sqrt-prod95.4%

        \[\leadsto \color{blue}{\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}} \]
    9. Applied egg-rr95.4%

      \[\leadsto \color{blue}{\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}} \]
    10. Step-by-step derivation
      1. *-commutative95.4%

        \[\leadsto \sqrt{\color{blue}{n \cdot 2}} \cdot \sqrt{\frac{\pi}{k}} \]
    11. Simplified95.4%

      \[\leadsto \color{blue}{\sqrt{n \cdot 2} \cdot \sqrt{\frac{\pi}{k}}} \]

    if 3.10000000000000009 < k

    1. Initial program 100.0%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 2.6%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative2.6%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*2.6%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified2.6%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod2.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr2.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u2.6%

        \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)\right)}} \]
      2. expm1-undefine24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    9. Applied egg-rr24.1%

      \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    10. Step-by-step derivation
      1. sub-neg24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \left(-1\right)}} \]
      2. metadata-eval24.1%

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \color{blue}{-1}} \]
      3. +-commutative24.1%

        \[\leadsto \sqrt{\color{blue}{-1 + e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      4. log1p-undefine24.1%

        \[\leadsto \sqrt{-1 + e^{\color{blue}{\log \left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      5. rem-exp-log24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}} \]
      6. +-commutative24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right) + 1\right)}} \]
      7. associate-*r*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}} + 1\right)} \]
      8. associate-*r/24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\frac{\left(2 \cdot n\right) \cdot \pi}{k}} + 1\right)} \]
      9. *-commutative24.1%

        \[\leadsto \sqrt{-1 + \left(\frac{\color{blue}{\pi \cdot \left(2 \cdot n\right)}}{k} + 1\right)} \]
      10. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\pi \cdot \frac{2 \cdot n}{k}} + 1\right)} \]
      11. fma-define24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\mathsf{fma}\left(\pi, \frac{2 \cdot n}{k}, 1\right)}} \]
      12. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \mathsf{fma}\left(\pi, \color{blue}{2 \cdot \frac{n}{k}}, 1\right)} \]
    11. Simplified24.1%

      \[\leadsto \sqrt{\color{blue}{-1 + \mathsf{fma}\left(\pi, 2 \cdot \frac{n}{k}, 1\right)}} \]
    12. Taylor expanded in n around 0 55.0%

      \[\leadsto \sqrt{-1 + \color{blue}{1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 3.1:\\ \;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\pi}{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 62.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 2.6:\\ \;\;\;\;\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 2.6) (* (sqrt 2.0) (sqrt (* n (/ PI k)))) (sqrt 0.0)))
double code(double k, double n) {
	double tmp;
	if (k <= 2.6) {
		tmp = sqrt(2.0) * sqrt((n * (((double) M_PI) / k)));
	} else {
		tmp = sqrt(0.0);
	}
	return tmp;
}
public static double code(double k, double n) {
	double tmp;
	if (k <= 2.6) {
		tmp = Math.sqrt(2.0) * Math.sqrt((n * (Math.PI / k)));
	} else {
		tmp = Math.sqrt(0.0);
	}
	return tmp;
}
def code(k, n):
	tmp = 0
	if k <= 2.6:
		tmp = math.sqrt(2.0) * math.sqrt((n * (math.pi / k)))
	else:
		tmp = math.sqrt(0.0)
	return tmp
function code(k, n)
	tmp = 0.0
	if (k <= 2.6)
		tmp = Float64(sqrt(2.0) * sqrt(Float64(n * Float64(pi / k))));
	else
		tmp = sqrt(0.0);
	end
	return tmp
end
function tmp_2 = code(k, n)
	tmp = 0.0;
	if (k <= 2.6)
		tmp = sqrt(2.0) * sqrt((n * (pi / k)));
	else
		tmp = sqrt(0.0);
	end
	tmp_2 = tmp;
end
code[k_, n_] := If[LessEqual[k, 2.6], N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[0.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.6:\\
\;\;\;\;\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if k < 2.60000000000000009

    1. Initial program 98.3%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 76.2%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative76.2%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*76.2%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified76.2%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]

    if 2.60000000000000009 < k

    1. Initial program 100.0%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 2.6%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative2.6%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*2.6%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified2.6%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod2.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr2.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u2.6%

        \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)\right)}} \]
      2. expm1-undefine24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    9. Applied egg-rr24.1%

      \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    10. Step-by-step derivation
      1. sub-neg24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \left(-1\right)}} \]
      2. metadata-eval24.1%

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \color{blue}{-1}} \]
      3. +-commutative24.1%

        \[\leadsto \sqrt{\color{blue}{-1 + e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      4. log1p-undefine24.1%

        \[\leadsto \sqrt{-1 + e^{\color{blue}{\log \left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      5. rem-exp-log24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}} \]
      6. +-commutative24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right) + 1\right)}} \]
      7. associate-*r*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}} + 1\right)} \]
      8. associate-*r/24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\frac{\left(2 \cdot n\right) \cdot \pi}{k}} + 1\right)} \]
      9. *-commutative24.1%

        \[\leadsto \sqrt{-1 + \left(\frac{\color{blue}{\pi \cdot \left(2 \cdot n\right)}}{k} + 1\right)} \]
      10. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\pi \cdot \frac{2 \cdot n}{k}} + 1\right)} \]
      11. fma-define24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\mathsf{fma}\left(\pi, \frac{2 \cdot n}{k}, 1\right)}} \]
      12. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \mathsf{fma}\left(\pi, \color{blue}{2 \cdot \frac{n}{k}}, 1\right)} \]
    11. Simplified24.1%

      \[\leadsto \sqrt{\color{blue}{-1 + \mathsf{fma}\left(\pi, 2 \cdot \frac{n}{k}, 1\right)}} \]
    12. Taylor expanded in n around 0 55.0%

      \[\leadsto \sqrt{-1 + \color{blue}{1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 2.6:\\ \;\;\;\;\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}} \end{array} \]
(FPCore (k n)
 :precision binary64
 (/ (pow (* 2.0 (* PI n)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
	return pow((2.0 * (((double) M_PI) * n)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
	return Math.pow((2.0 * (Math.PI * n)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n):
	return math.pow((2.0 * (math.pi * n)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n)
	return Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k))
end
function tmp = code(k, n)
	tmp = ((2.0 * (pi * n)) ^ (0.5 - (k / 2.0))) / sqrt(k);
end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Derivation
  1. Initial program 99.1%

    \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
  2. Step-by-step derivation
    1. associate-*l/99.2%

      \[\leadsto \color{blue}{\frac{1 \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}} \]
    2. *-lft-identity99.2%

      \[\leadsto \frac{\color{blue}{{\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}}}{\sqrt{k}} \]
    3. associate-*l*99.2%

      \[\leadsto \frac{{\color{blue}{\left(2 \cdot \left(\pi \cdot n\right)\right)}}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}} \]
    4. div-sub99.2%

      \[\leadsto \frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\color{blue}{\left(\frac{1}{2} - \frac{k}{2}\right)}}}{\sqrt{k}} \]
    5. metadata-eval99.2%

      \[\leadsto \frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\color{blue}{0.5} - \frac{k}{2}\right)}}{\sqrt{k}} \]
  3. Simplified99.2%

    \[\leadsto \color{blue}{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 8: 62.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 4:\\ \;\;\;\;\sqrt{\left(\pi \cdot \left(2 \cdot n\right)\right) \cdot \frac{1}{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 4.0) (sqrt (* (* PI (* 2.0 n)) (/ 1.0 k))) (sqrt 0.0)))
double code(double k, double n) {
	double tmp;
	if (k <= 4.0) {
		tmp = sqrt(((((double) M_PI) * (2.0 * n)) * (1.0 / k)));
	} else {
		tmp = sqrt(0.0);
	}
	return tmp;
}
public static double code(double k, double n) {
	double tmp;
	if (k <= 4.0) {
		tmp = Math.sqrt(((Math.PI * (2.0 * n)) * (1.0 / k)));
	} else {
		tmp = Math.sqrt(0.0);
	}
	return tmp;
}
def code(k, n):
	tmp = 0
	if k <= 4.0:
		tmp = math.sqrt(((math.pi * (2.0 * n)) * (1.0 / k)))
	else:
		tmp = math.sqrt(0.0)
	return tmp
function code(k, n)
	tmp = 0.0
	if (k <= 4.0)
		tmp = sqrt(Float64(Float64(pi * Float64(2.0 * n)) * Float64(1.0 / k)));
	else
		tmp = sqrt(0.0);
	end
	return tmp
end
function tmp_2 = code(k, n)
	tmp = 0.0;
	if (k <= 4.0)
		tmp = sqrt(((pi * (2.0 * n)) * (1.0 / k)));
	else
		tmp = sqrt(0.0);
	end
	tmp_2 = tmp;
end
code[k_, n_] := If[LessEqual[k, 4.0], N[Sqrt[N[(N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision] * N[(1.0 / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 4:\\
\;\;\;\;\sqrt{\left(\pi \cdot \left(2 \cdot n\right)\right) \cdot \frac{1}{k}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if k < 4

    1. Initial program 98.3%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*r*98.3%

        \[\leadsto \frac{1}{\sqrt{k}} \cdot {\color{blue}{\left(2 \cdot \left(\pi \cdot n\right)\right)}}^{\left(\frac{1 - k}{2}\right)} \]
      2. div-sub98.3%

        \[\leadsto \frac{1}{\sqrt{k}} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\color{blue}{\left(\frac{1}{2} - \frac{k}{2}\right)}} \]
      3. metadata-eval98.3%

        \[\leadsto \frac{1}{\sqrt{k}} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\color{blue}{0.5} - \frac{k}{2}\right)} \]
      4. pow-div98.5%

        \[\leadsto \frac{1}{\sqrt{k}} \cdot \color{blue}{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{0.5}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}}} \]
      5. pow1/298.5%

        \[\leadsto \frac{1}{\sqrt{k}} \cdot \frac{\color{blue}{\sqrt{2 \cdot \left(\pi \cdot n\right)}}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
      6. associate-*r/98.5%

        \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{k}} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}}} \]
      7. pow1/298.5%

        \[\leadsto \frac{\frac{1}{\color{blue}{{k}^{0.5}}} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
      8. pow-flip98.6%

        \[\leadsto \frac{\color{blue}{{k}^{\left(-0.5\right)}} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
      9. metadata-eval98.6%

        \[\leadsto \frac{{k}^{\color{blue}{-0.5}} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(\frac{k}{2}\right)}} \]
      10. div-inv98.6%

        \[\leadsto \frac{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\color{blue}{\left(k \cdot \frac{1}{2}\right)}}} \]
      11. metadata-eval98.6%

        \[\leadsto \frac{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot \color{blue}{0.5}\right)}} \]
    4. Applied egg-rr98.6%

      \[\leadsto \color{blue}{\frac{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}} \]
    5. Taylor expanded in k around 0 94.6%

      \[\leadsto \frac{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}{\color{blue}{1}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt94.3%

        \[\leadsto \frac{\color{blue}{\sqrt{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}} \cdot \sqrt{{k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}}}}{1} \]
      2. sqrt-unprod75.4%

        \[\leadsto \frac{\color{blue}{\sqrt{\left({k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}\right) \cdot \left({k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}\right)}}}{1} \]
      3. *-commutative75.4%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\pi \cdot n\right)} \cdot {k}^{-0.5}\right)} \cdot \left({k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}\right)}}{1} \]
      4. *-commutative75.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \color{blue}{\left(n \cdot \pi\right)}} \cdot {k}^{-0.5}\right) \cdot \left({k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}\right)}}{1} \]
      5. metadata-eval75.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot {k}^{\color{blue}{\left(\frac{-1}{2}\right)}}\right) \cdot \left({k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}\right)}}{1} \]
      6. sqrt-pow175.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \color{blue}{\sqrt{{k}^{-1}}}\right) \cdot \left({k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}\right)}}{1} \]
      7. inv-pow75.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \sqrt{\color{blue}{\frac{1}{k}}}\right) \cdot \left({k}^{-0.5} \cdot \sqrt{2 \cdot \left(\pi \cdot n\right)}\right)}}{1} \]
      8. *-commutative75.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \sqrt{\frac{1}{k}}\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\pi \cdot n\right)} \cdot {k}^{-0.5}\right)}}}{1} \]
      9. *-commutative75.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \sqrt{\frac{1}{k}}\right) \cdot \left(\sqrt{2 \cdot \color{blue}{\left(n \cdot \pi\right)}} \cdot {k}^{-0.5}\right)}}{1} \]
      10. metadata-eval75.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \sqrt{\frac{1}{k}}\right) \cdot \left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot {k}^{\color{blue}{\left(\frac{-1}{2}\right)}}\right)}}{1} \]
      11. sqrt-pow175.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \sqrt{\frac{1}{k}}\right) \cdot \left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \color{blue}{\sqrt{{k}^{-1}}}\right)}}{1} \]
      12. inv-pow75.4%

        \[\leadsto \frac{\sqrt{\left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \sqrt{\frac{1}{k}}\right) \cdot \left(\sqrt{2 \cdot \left(n \cdot \pi\right)} \cdot \sqrt{\color{blue}{\frac{1}{k}}}\right)}}{1} \]
    7. Applied egg-rr75.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\left(\left(n \cdot 2\right) \cdot \pi\right) \cdot \frac{1}{k}}}}{1} \]

    if 4 < k

    1. Initial program 100.0%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 2.6%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative2.6%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*2.6%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified2.6%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod2.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr2.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u2.6%

        \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)\right)}} \]
      2. expm1-undefine24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    9. Applied egg-rr24.1%

      \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    10. Step-by-step derivation
      1. sub-neg24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \left(-1\right)}} \]
      2. metadata-eval24.1%

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \color{blue}{-1}} \]
      3. +-commutative24.1%

        \[\leadsto \sqrt{\color{blue}{-1 + e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      4. log1p-undefine24.1%

        \[\leadsto \sqrt{-1 + e^{\color{blue}{\log \left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      5. rem-exp-log24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}} \]
      6. +-commutative24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right) + 1\right)}} \]
      7. associate-*r*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}} + 1\right)} \]
      8. associate-*r/24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\frac{\left(2 \cdot n\right) \cdot \pi}{k}} + 1\right)} \]
      9. *-commutative24.1%

        \[\leadsto \sqrt{-1 + \left(\frac{\color{blue}{\pi \cdot \left(2 \cdot n\right)}}{k} + 1\right)} \]
      10. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\pi \cdot \frac{2 \cdot n}{k}} + 1\right)} \]
      11. fma-define24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\mathsf{fma}\left(\pi, \frac{2 \cdot n}{k}, 1\right)}} \]
      12. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \mathsf{fma}\left(\pi, \color{blue}{2 \cdot \frac{n}{k}}, 1\right)} \]
    11. Simplified24.1%

      \[\leadsto \sqrt{\color{blue}{-1 + \mathsf{fma}\left(\pi, 2 \cdot \frac{n}{k}, 1\right)}} \]
    12. Taylor expanded in n around 0 55.0%

      \[\leadsto \sqrt{-1 + \color{blue}{1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 4:\\ \;\;\;\;\sqrt{\left(\pi \cdot \left(2 \cdot n\right)\right) \cdot \frac{1}{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 62.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 3:\\ \;\;\;\;\sqrt{\frac{2 \cdot n}{\frac{k}{\pi}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 3.0) (sqrt (/ (* 2.0 n) (/ k PI))) (sqrt 0.0)))
double code(double k, double n) {
	double tmp;
	if (k <= 3.0) {
		tmp = sqrt(((2.0 * n) / (k / ((double) M_PI))));
	} else {
		tmp = sqrt(0.0);
	}
	return tmp;
}
public static double code(double k, double n) {
	double tmp;
	if (k <= 3.0) {
		tmp = Math.sqrt(((2.0 * n) / (k / Math.PI)));
	} else {
		tmp = Math.sqrt(0.0);
	}
	return tmp;
}
def code(k, n):
	tmp = 0
	if k <= 3.0:
		tmp = math.sqrt(((2.0 * n) / (k / math.pi)))
	else:
		tmp = math.sqrt(0.0)
	return tmp
function code(k, n)
	tmp = 0.0
	if (k <= 3.0)
		tmp = sqrt(Float64(Float64(2.0 * n) / Float64(k / pi)));
	else
		tmp = sqrt(0.0);
	end
	return tmp
end
function tmp_2 = code(k, n)
	tmp = 0.0;
	if (k <= 3.0)
		tmp = sqrt(((2.0 * n) / (k / pi)));
	else
		tmp = sqrt(0.0);
	end
	tmp_2 = tmp;
end
code[k_, n_] := If[LessEqual[k, 3.0], N[Sqrt[N[(N[(2.0 * n), $MachinePrecision] / N[(k / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 3:\\
\;\;\;\;\sqrt{\frac{2 \cdot n}{\frac{k}{\pi}}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if k < 3

    1. Initial program 98.3%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 76.2%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative76.2%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*76.2%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified76.2%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod75.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr75.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*75.6%

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}}} \]
      2. clear-num75.6%

        \[\leadsto \sqrt{\left(2 \cdot n\right) \cdot \color{blue}{\frac{1}{\frac{k}{\pi}}}} \]
      3. un-div-inv75.7%

        \[\leadsto \sqrt{\color{blue}{\frac{2 \cdot n}{\frac{k}{\pi}}}} \]
    9. Applied egg-rr75.7%

      \[\leadsto \sqrt{\color{blue}{\frac{2 \cdot n}{\frac{k}{\pi}}}} \]

    if 3 < k

    1. Initial program 100.0%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 2.6%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative2.6%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*2.6%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified2.6%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod2.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr2.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u2.6%

        \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)\right)}} \]
      2. expm1-undefine24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    9. Applied egg-rr24.1%

      \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    10. Step-by-step derivation
      1. sub-neg24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \left(-1\right)}} \]
      2. metadata-eval24.1%

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \color{blue}{-1}} \]
      3. +-commutative24.1%

        \[\leadsto \sqrt{\color{blue}{-1 + e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      4. log1p-undefine24.1%

        \[\leadsto \sqrt{-1 + e^{\color{blue}{\log \left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      5. rem-exp-log24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}} \]
      6. +-commutative24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right) + 1\right)}} \]
      7. associate-*r*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}} + 1\right)} \]
      8. associate-*r/24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\frac{\left(2 \cdot n\right) \cdot \pi}{k}} + 1\right)} \]
      9. *-commutative24.1%

        \[\leadsto \sqrt{-1 + \left(\frac{\color{blue}{\pi \cdot \left(2 \cdot n\right)}}{k} + 1\right)} \]
      10. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\pi \cdot \frac{2 \cdot n}{k}} + 1\right)} \]
      11. fma-define24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\mathsf{fma}\left(\pi, \frac{2 \cdot n}{k}, 1\right)}} \]
      12. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \mathsf{fma}\left(\pi, \color{blue}{2 \cdot \frac{n}{k}}, 1\right)} \]
    11. Simplified24.1%

      \[\leadsto \sqrt{\color{blue}{-1 + \mathsf{fma}\left(\pi, 2 \cdot \frac{n}{k}, 1\right)}} \]
    12. Taylor expanded in n around 0 55.0%

      \[\leadsto \sqrt{-1 + \color{blue}{1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 3:\\ \;\;\;\;\sqrt{\frac{2 \cdot n}{\frac{k}{\pi}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 62.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 3.5:\\ \;\;\;\;\sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 3.5) (sqrt (* 2.0 (/ PI (/ k n)))) (sqrt 0.0)))
double code(double k, double n) {
	double tmp;
	if (k <= 3.5) {
		tmp = sqrt((2.0 * (((double) M_PI) / (k / n))));
	} else {
		tmp = sqrt(0.0);
	}
	return tmp;
}
public static double code(double k, double n) {
	double tmp;
	if (k <= 3.5) {
		tmp = Math.sqrt((2.0 * (Math.PI / (k / n))));
	} else {
		tmp = Math.sqrt(0.0);
	}
	return tmp;
}
def code(k, n):
	tmp = 0
	if k <= 3.5:
		tmp = math.sqrt((2.0 * (math.pi / (k / n))))
	else:
		tmp = math.sqrt(0.0)
	return tmp
function code(k, n)
	tmp = 0.0
	if (k <= 3.5)
		tmp = sqrt(Float64(2.0 * Float64(pi / Float64(k / n))));
	else
		tmp = sqrt(0.0);
	end
	return tmp
end
function tmp_2 = code(k, n)
	tmp = 0.0;
	if (k <= 3.5)
		tmp = sqrt((2.0 * (pi / (k / n))));
	else
		tmp = sqrt(0.0);
	end
	tmp_2 = tmp;
end
code[k_, n_] := If[LessEqual[k, 3.5], N[Sqrt[N[(2.0 * N[(Pi / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 3.5:\\
\;\;\;\;\sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if k < 3.5

    1. Initial program 98.3%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 76.2%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative76.2%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*76.2%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified76.2%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod75.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr75.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. div-inv75.6%

        \[\leadsto \sqrt{2 \cdot \left(n \cdot \color{blue}{\left(\pi \cdot \frac{1}{k}\right)}\right)} \]
    9. Applied egg-rr75.6%

      \[\leadsto \sqrt{2 \cdot \left(n \cdot \color{blue}{\left(\pi \cdot \frac{1}{k}\right)}\right)} \]
    10. Step-by-step derivation
      1. associate-*r*75.7%

        \[\leadsto \sqrt{2 \cdot \color{blue}{\left(\left(n \cdot \pi\right) \cdot \frac{1}{k}\right)}} \]
      2. *-commutative75.7%

        \[\leadsto \sqrt{2 \cdot \left(\color{blue}{\left(\pi \cdot n\right)} \cdot \frac{1}{k}\right)} \]
      3. div-inv75.6%

        \[\leadsto \sqrt{2 \cdot \color{blue}{\frac{\pi \cdot n}{k}}} \]
      4. associate-/l*75.6%

        \[\leadsto \sqrt{2 \cdot \color{blue}{\left(\pi \cdot \frac{n}{k}\right)}} \]
      5. clear-num75.5%

        \[\leadsto \sqrt{2 \cdot \left(\pi \cdot \color{blue}{\frac{1}{\frac{k}{n}}}\right)} \]
      6. un-div-inv75.7%

        \[\leadsto \sqrt{2 \cdot \color{blue}{\frac{\pi}{\frac{k}{n}}}} \]
    11. Applied egg-rr75.7%

      \[\leadsto \sqrt{2 \cdot \color{blue}{\frac{\pi}{\frac{k}{n}}}} \]

    if 3.5 < k

    1. Initial program 100.0%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 2.6%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative2.6%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*2.6%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified2.6%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod2.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr2.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u2.6%

        \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)\right)}} \]
      2. expm1-undefine24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    9. Applied egg-rr24.1%

      \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    10. Step-by-step derivation
      1. sub-neg24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \left(-1\right)}} \]
      2. metadata-eval24.1%

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \color{blue}{-1}} \]
      3. +-commutative24.1%

        \[\leadsto \sqrt{\color{blue}{-1 + e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      4. log1p-undefine24.1%

        \[\leadsto \sqrt{-1 + e^{\color{blue}{\log \left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      5. rem-exp-log24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}} \]
      6. +-commutative24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right) + 1\right)}} \]
      7. associate-*r*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}} + 1\right)} \]
      8. associate-*r/24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\frac{\left(2 \cdot n\right) \cdot \pi}{k}} + 1\right)} \]
      9. *-commutative24.1%

        \[\leadsto \sqrt{-1 + \left(\frac{\color{blue}{\pi \cdot \left(2 \cdot n\right)}}{k} + 1\right)} \]
      10. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\pi \cdot \frac{2 \cdot n}{k}} + 1\right)} \]
      11. fma-define24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\mathsf{fma}\left(\pi, \frac{2 \cdot n}{k}, 1\right)}} \]
      12. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \mathsf{fma}\left(\pi, \color{blue}{2 \cdot \frac{n}{k}}, 1\right)} \]
    11. Simplified24.1%

      \[\leadsto \sqrt{\color{blue}{-1 + \mathsf{fma}\left(\pi, 2 \cdot \frac{n}{k}, 1\right)}} \]
    12. Taylor expanded in n around 0 55.0%

      \[\leadsto \sqrt{-1 + \color{blue}{1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 3.5:\\ \;\;\;\;\sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 62.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 3:\\ \;\;\;\;\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 3.0) (sqrt (* 2.0 (* n (/ PI k)))) (sqrt 0.0)))
double code(double k, double n) {
	double tmp;
	if (k <= 3.0) {
		tmp = sqrt((2.0 * (n * (((double) M_PI) / k))));
	} else {
		tmp = sqrt(0.0);
	}
	return tmp;
}
public static double code(double k, double n) {
	double tmp;
	if (k <= 3.0) {
		tmp = Math.sqrt((2.0 * (n * (Math.PI / k))));
	} else {
		tmp = Math.sqrt(0.0);
	}
	return tmp;
}
def code(k, n):
	tmp = 0
	if k <= 3.0:
		tmp = math.sqrt((2.0 * (n * (math.pi / k))))
	else:
		tmp = math.sqrt(0.0)
	return tmp
function code(k, n)
	tmp = 0.0
	if (k <= 3.0)
		tmp = sqrt(Float64(2.0 * Float64(n * Float64(pi / k))));
	else
		tmp = sqrt(0.0);
	end
	return tmp
end
function tmp_2 = code(k, n)
	tmp = 0.0;
	if (k <= 3.0)
		tmp = sqrt((2.0 * (n * (pi / k))));
	else
		tmp = sqrt(0.0);
	end
	tmp_2 = tmp;
end
code[k_, n_] := If[LessEqual[k, 3.0], N[Sqrt[N[(2.0 * N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[0.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 3:\\
\;\;\;\;\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if k < 3

    1. Initial program 98.3%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 76.2%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative76.2%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*76.2%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified76.2%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod75.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr75.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]

    if 3 < k

    1. Initial program 100.0%

      \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in k around 0 2.6%

      \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
    4. Step-by-step derivation
      1. *-commutative2.6%

        \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
      2. associate-/l*2.6%

        \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
    5. Simplified2.6%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
    6. Step-by-step derivation
      1. sqrt-unprod2.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    7. Applied egg-rr2.6%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u2.6%

        \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)\right)}} \]
      2. expm1-undefine24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    9. Applied egg-rr24.1%

      \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
    10. Step-by-step derivation
      1. sub-neg24.1%

        \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \left(-1\right)}} \]
      2. metadata-eval24.1%

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \color{blue}{-1}} \]
      3. +-commutative24.1%

        \[\leadsto \sqrt{\color{blue}{-1 + e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      4. log1p-undefine24.1%

        \[\leadsto \sqrt{-1 + e^{\color{blue}{\log \left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
      5. rem-exp-log24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}} \]
      6. +-commutative24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right) + 1\right)}} \]
      7. associate-*r*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}} + 1\right)} \]
      8. associate-*r/24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\frac{\left(2 \cdot n\right) \cdot \pi}{k}} + 1\right)} \]
      9. *-commutative24.1%

        \[\leadsto \sqrt{-1 + \left(\frac{\color{blue}{\pi \cdot \left(2 \cdot n\right)}}{k} + 1\right)} \]
      10. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \left(\color{blue}{\pi \cdot \frac{2 \cdot n}{k}} + 1\right)} \]
      11. fma-define24.1%

        \[\leadsto \sqrt{-1 + \color{blue}{\mathsf{fma}\left(\pi, \frac{2 \cdot n}{k}, 1\right)}} \]
      12. associate-/l*24.1%

        \[\leadsto \sqrt{-1 + \mathsf{fma}\left(\pi, \color{blue}{2 \cdot \frac{n}{k}}, 1\right)} \]
    11. Simplified24.1%

      \[\leadsto \sqrt{\color{blue}{-1 + \mathsf{fma}\left(\pi, 2 \cdot \frac{n}{k}, 1\right)}} \]
    12. Taylor expanded in n around 0 55.0%

      \[\leadsto \sqrt{-1 + \color{blue}{1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 3:\\ \;\;\;\;\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 27.0% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \sqrt{0} \end{array} \]
(FPCore (k n) :precision binary64 (sqrt 0.0))
double code(double k, double n) {
	return sqrt(0.0);
}
real(8) function code(k, n)
    real(8), intent (in) :: k
    real(8), intent (in) :: n
    code = sqrt(0.0d0)
end function
public static double code(double k, double n) {
	return Math.sqrt(0.0);
}
def code(k, n):
	return math.sqrt(0.0)
function code(k, n)
	return sqrt(0.0)
end
function tmp = code(k, n)
	tmp = sqrt(0.0);
end
code[k_, n_] := N[Sqrt[0.0], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{0}
\end{array}
Derivation
  1. Initial program 99.1%

    \[\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in k around 0 39.1%

    \[\leadsto \color{blue}{\sqrt{\frac{n \cdot \pi}{k}} \cdot \sqrt{2}} \]
  4. Step-by-step derivation
    1. *-commutative39.1%

      \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{\frac{n \cdot \pi}{k}}} \]
    2. associate-/l*39.1%

      \[\leadsto \sqrt{2} \cdot \sqrt{\color{blue}{n \cdot \frac{\pi}{k}}} \]
  5. Simplified39.1%

    \[\leadsto \color{blue}{\sqrt{2} \cdot \sqrt{n \cdot \frac{\pi}{k}}} \]
  6. Step-by-step derivation
    1. sqrt-unprod38.8%

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
  7. Applied egg-rr38.8%

    \[\leadsto \color{blue}{\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}} \]
  8. Step-by-step derivation
    1. expm1-log1p-u37.2%

      \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)\right)}} \]
    2. expm1-undefine36.5%

      \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
  9. Applied egg-rr36.5%

    \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} - 1}} \]
  10. Step-by-step derivation
    1. sub-neg36.5%

      \[\leadsto \sqrt{\color{blue}{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \left(-1\right)}} \]
    2. metadata-eval36.5%

      \[\leadsto \sqrt{e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)} + \color{blue}{-1}} \]
    3. +-commutative36.5%

      \[\leadsto \sqrt{\color{blue}{-1 + e^{\mathsf{log1p}\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
    4. log1p-undefine36.5%

      \[\leadsto \sqrt{-1 + e^{\color{blue}{\log \left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}}} \]
    5. rem-exp-log38.1%

      \[\leadsto \sqrt{-1 + \color{blue}{\left(1 + 2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}} \]
    6. +-commutative38.1%

      \[\leadsto \sqrt{-1 + \color{blue}{\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right) + 1\right)}} \]
    7. associate-*r*38.1%

      \[\leadsto \sqrt{-1 + \left(\color{blue}{\left(2 \cdot n\right) \cdot \frac{\pi}{k}} + 1\right)} \]
    8. associate-*r/38.1%

      \[\leadsto \sqrt{-1 + \left(\color{blue}{\frac{\left(2 \cdot n\right) \cdot \pi}{k}} + 1\right)} \]
    9. *-commutative38.1%

      \[\leadsto \sqrt{-1 + \left(\frac{\color{blue}{\pi \cdot \left(2 \cdot n\right)}}{k} + 1\right)} \]
    10. associate-/l*38.1%

      \[\leadsto \sqrt{-1 + \left(\color{blue}{\pi \cdot \frac{2 \cdot n}{k}} + 1\right)} \]
    11. fma-define38.1%

      \[\leadsto \sqrt{-1 + \color{blue}{\mathsf{fma}\left(\pi, \frac{2 \cdot n}{k}, 1\right)}} \]
    12. associate-/l*38.1%

      \[\leadsto \sqrt{-1 + \mathsf{fma}\left(\pi, \color{blue}{2 \cdot \frac{n}{k}}, 1\right)} \]
  11. Simplified38.1%

    \[\leadsto \sqrt{\color{blue}{-1 + \mathsf{fma}\left(\pi, 2 \cdot \frac{n}{k}, 1\right)}} \]
  12. Taylor expanded in n around 0 29.1%

    \[\leadsto \sqrt{-1 + \color{blue}{1}} \]
  13. Final simplification29.1%

    \[\leadsto \sqrt{0} \]
  14. Add Preprocessing

Reproduce

?
herbie shell --seed 2024139 
(FPCore (k n)
  :name "Migdal et al, Equation (51)"
  :precision binary64
  (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))