Migdal et al, Equation (51)

Percentage Accurate: 99.4% → 99.4%
Time: 17.6s
Alternatives: 9
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 9 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.4% 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.4% 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.6%

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

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

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

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

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

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

    \[\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 2: 98.7% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 99.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 72.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
      2. *-commutative72.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{\pi \cdot \frac{n}{k}} \cdot \sqrt{2}} \]
      3. div-inv72.2%

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

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

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

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

        \[\leadsto \sqrt{n \cdot \color{blue}{\frac{\pi}{k}}} \cdot \sqrt{2} \]
      8. *-commutative72.2%

        \[\leadsto \sqrt{\color{blue}{\frac{\pi}{k} \cdot n}} \cdot \sqrt{2} \]
      9. sqrt-unprod99.1%

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

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

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

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

    if 3.2e-77 < k

    1. Initial program 99.7%

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

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

      \[\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}}} \]
    5. Step-by-step derivation
      1. distribute-lft-in99.2%

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 59.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 1.85 \cdot 10^{+87}:\\ \;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \mathsf{fma}\left(\pi, \frac{2 \cdot n}{k}, -1\right)}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 1.85e+87)
   (* (sqrt (/ PI k)) (sqrt (* 2.0 n)))
   (sqrt (+ 1.0 (fma PI (/ (* 2.0 n) k) -1.0)))))
double code(double k, double n) {
	double tmp;
	if (k <= 1.85e+87) {
		tmp = sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
	} else {
		tmp = sqrt((1.0 + fma(((double) M_PI), ((2.0 * n) / k), -1.0)));
	}
	return tmp;
}
function code(k, n)
	tmp = 0.0
	if (k <= 1.85e+87)
		tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n)));
	else
		tmp = sqrt(Float64(1.0 + fma(pi, Float64(Float64(2.0 * n) / k), -1.0)));
	end
	return tmp
end
code[k_, n_] := If[LessEqual[k, 1.85e+87], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(1.0 + N[(Pi * N[(N[(2.0 * n), $MachinePrecision] / k), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.85 \cdot 10^{+87}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\

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


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

    1. Initial program 99.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 56.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
      2. *-commutative56.6%

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

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

        \[\leadsto \sqrt{\color{blue}{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}} \]
    9. Simplified56.7%

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

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

        \[\leadsto \color{blue}{\sqrt{\pi \cdot \frac{n}{k}} \cdot \sqrt{2}} \]
      3. div-inv56.6%

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

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

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

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

        \[\leadsto \sqrt{n \cdot \color{blue}{\frac{\pi}{k}}} \cdot \sqrt{2} \]
      8. *-commutative56.5%

        \[\leadsto \sqrt{\color{blue}{\frac{\pi}{k} \cdot n}} \cdot \sqrt{2} \]
      9. sqrt-unprod72.3%

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

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

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

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

    if 1.85000000000000001e87 < 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.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
      2. *-commutative2.8%

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

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

        \[\leadsto \sqrt{\color{blue}{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}} \]
    9. Simplified2.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(\color{blue}{2 \cdot \left(\frac{n}{k} \cdot \pi\right)}\right)} - 1} \]
      7. associate-/r/42.4%

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

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

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

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(\left(n \cdot \color{blue}{\frac{\pi}{k}}\right) \cdot 2\right)} - 1} \]
      11. associate-*l*42.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{1 + \mathsf{fma}\left(\pi, \frac{n \cdot 2}{k}, -1\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.7%

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

Alternative 4: 59.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 1.85 \cdot 10^{+87}:\\ \;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-1 + \mathsf{fma}\left(n, 2 \cdot \frac{\pi}{k}, 1\right)}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 1.85e+87)
   (* (sqrt (/ PI k)) (sqrt (* 2.0 n)))
   (sqrt (+ -1.0 (fma n (* 2.0 (/ PI k)) 1.0)))))
double code(double k, double n) {
	double tmp;
	if (k <= 1.85e+87) {
		tmp = sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
	} else {
		tmp = sqrt((-1.0 + fma(n, (2.0 * (((double) M_PI) / k)), 1.0)));
	}
	return tmp;
}
function code(k, n)
	tmp = 0.0
	if (k <= 1.85e+87)
		tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n)));
	else
		tmp = sqrt(Float64(-1.0 + fma(n, Float64(2.0 * Float64(pi / k)), 1.0)));
	end
	return tmp
end
code[k_, n_] := If[LessEqual[k, 1.85e+87], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(-1.0 + N[(n * N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.85 \cdot 10^{+87}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\

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


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

    1. Initial program 99.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 56.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
      2. *-commutative56.6%

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

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

        \[\leadsto \sqrt{\color{blue}{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}} \]
    9. Simplified56.7%

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

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

        \[\leadsto \color{blue}{\sqrt{\pi \cdot \frac{n}{k}} \cdot \sqrt{2}} \]
      3. div-inv56.6%

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

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

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

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

        \[\leadsto \sqrt{n \cdot \color{blue}{\frac{\pi}{k}}} \cdot \sqrt{2} \]
      8. *-commutative56.5%

        \[\leadsto \sqrt{\color{blue}{\frac{\pi}{k} \cdot n}} \cdot \sqrt{2} \]
      9. sqrt-unprod72.3%

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

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

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

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

    if 1.85000000000000001e87 < 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.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
      2. *-commutative2.8%

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

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

        \[\leadsto \sqrt{\color{blue}{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}} \]
    9. Simplified2.8%

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

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

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

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

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

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

        \[\leadsto \sqrt{e^{\mathsf{log1p}\left(2 \cdot \left(\color{blue}{\left(n \cdot \frac{1}{k}\right)} \cdot \pi\right)\right)} - 1} \]
      7. associate-*r*42.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{-1 + \mathsf{fma}\left(n, \frac{\pi}{k} \cdot 2, 1\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.7%

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

Alternative 5: 59.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;k \leq 1.85 \cdot 10^{+87}:\\ \;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\pi \cdot \left(-1 + \mathsf{fma}\left(2, \frac{n}{k}, 1\right)\right)}\\ \end{array} \end{array} \]
(FPCore (k n)
 :precision binary64
 (if (<= k 1.85e+87)
   (* (sqrt (/ PI k)) (sqrt (* 2.0 n)))
   (sqrt (* PI (+ -1.0 (fma 2.0 (/ n k) 1.0))))))
double code(double k, double n) {
	double tmp;
	if (k <= 1.85e+87) {
		tmp = sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
	} else {
		tmp = sqrt((((double) M_PI) * (-1.0 + fma(2.0, (n / k), 1.0))));
	}
	return tmp;
}
function code(k, n)
	tmp = 0.0
	if (k <= 1.85e+87)
		tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n)));
	else
		tmp = sqrt(Float64(pi * Float64(-1.0 + fma(2.0, Float64(n / k), 1.0))));
	end
	return tmp
end
code[k_, n_] := If[LessEqual[k, 1.85e+87], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(Pi * N[(-1.0 + N[(2.0 * N[(n / k), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.85 \cdot 10^{+87}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\

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


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

    1. Initial program 99.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 56.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
      2. *-commutative56.6%

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

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

        \[\leadsto \sqrt{\color{blue}{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}} \]
    9. Simplified56.7%

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

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

        \[\leadsto \color{blue}{\sqrt{\pi \cdot \frac{n}{k}} \cdot \sqrt{2}} \]
      3. div-inv56.6%

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

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

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

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

        \[\leadsto \sqrt{n \cdot \color{blue}{\frac{\pi}{k}}} \cdot \sqrt{2} \]
      8. *-commutative56.5%

        \[\leadsto \sqrt{\color{blue}{\frac{\pi}{k} \cdot n}} \cdot \sqrt{2} \]
      9. sqrt-unprod72.3%

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

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

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

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

    if 1.85000000000000001e87 < 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.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
      2. *-commutative2.8%

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

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

        \[\leadsto \sqrt{\color{blue}{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}} \]
    9. Simplified2.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\pi \cdot \color{blue}{\left(-1 + \mathsf{fma}\left(2, \frac{n}{k}, 1\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.7%

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

Alternative 6: 50.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;k \leq 6.5 \cdot 10^{+256}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(\frac{\pi}{k} \cdot \left(2 \cdot n\right)\right)}^{1.5}}\\


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

    1. Initial program 99.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 42.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{\pi \cdot \frac{n}{k}} \cdot \sqrt{2}} \]
      3. div-inv42.5%

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

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

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

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

        \[\leadsto \sqrt{n \cdot \color{blue}{\frac{\pi}{k}}} \cdot \sqrt{2} \]
      8. *-commutative42.5%

        \[\leadsto \sqrt{\color{blue}{\frac{\pi}{k} \cdot n}} \cdot \sqrt{2} \]
      9. sqrt-unprod54.1%

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

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

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

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

    if 6.50000000000000053e256 < 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.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
      2. *-commutative2.9%

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

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

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

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

        \[\leadsto \color{blue}{\sqrt[3]{\left(\sqrt{\pi \cdot \left(\frac{n}{k} \cdot 2\right)} \cdot \sqrt{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}\right) \cdot \sqrt{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}}} \]
      2. pow1/331.1%

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

      \[\leadsto \color{blue}{{\left({\left(2 \cdot \left(n \cdot \frac{\pi}{k}\right)\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    12. Step-by-step derivation
      1. unpow1/331.1%

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

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

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

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

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

Alternative 7: 49.4% accurate, 1.0× speedup?

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

\\
\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}
\end{array}
Derivation
  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. Taylor expanded in k around 0 37.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
    2. *-commutative37.3%

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{\pi \cdot \frac{n}{k}} \cdot \sqrt{2}} \]
    3. div-inv37.2%

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

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

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

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

      \[\leadsto \sqrt{n \cdot \color{blue}{\frac{\pi}{k}}} \cdot \sqrt{2} \]
    8. *-commutative37.2%

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

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

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

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

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

    \[\leadsto \sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n} \]
  13. Add Preprocessing

Alternative 8: 38.1% accurate, 2.0× speedup?

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

\\
\sqrt{\pi \cdot \left(2 \cdot \frac{n}{k}\right)}
\end{array}
Derivation
  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. Taylor expanded in k around 0 37.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
    2. *-commutative37.3%

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

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

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

    \[\leadsto \color{blue}{\sqrt{\pi \cdot \left(\frac{n}{k} \cdot 2\right)}} \]
  10. Final simplification37.3%

    \[\leadsto \sqrt{\pi \cdot \left(2 \cdot \frac{n}{k}\right)} \]
  11. Add Preprocessing

Alternative 9: 38.1% accurate, 2.0× speedup?

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

\\
\sqrt{\pi \cdot \left(n \cdot \frac{2}{k}\right)}
\end{array}
Derivation
  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. Taylor expanded in k around 0 37.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{\pi \cdot n}{k}}} \]
    2. *-commutative37.3%

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

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

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

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

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

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

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

    \[\leadsto \sqrt{\pi \cdot \color{blue}{\frac{2}{\frac{k}{n}}}} \]
  12. Step-by-step derivation
    1. associate-/r/37.3%

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

    \[\leadsto \sqrt{\pi \cdot \color{blue}{\left(\frac{2}{k} \cdot n\right)}} \]
  14. Final simplification37.3%

    \[\leadsto \sqrt{\pi \cdot \left(n \cdot \frac{2}{k}\right)} \]
  15. Add Preprocessing

Reproduce

?
herbie shell --seed 2024113 
(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))))