Migdal et al, Equation (51)

Percentage Accurate: 99.4% → 99.5%
Time: 12.0s
Alternatives: 8
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 8 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.5% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

Alternative 2: 99.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \pi \cdot \left(2 \cdot n\right)\\
\mathbf{if}\;k \leq 2.6 \cdot 10^{-48}:\\
\;\;\;\;\frac{\sqrt{t_0}}{\sqrt{k}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{t_0}^{\left(1 - k\right)}}{k}}\\


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

    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. Step-by-step derivation
      1. *-commutative99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.59999999999999987e-48 < k

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 2.6 \cdot 10^{-48}:\\ \;\;\;\;\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\ \end{array} \]

Alternative 3: 51.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.18 \cdot 10^{+219}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}\\

\mathbf{else}:\\
\;\;\;\;{\left({\left(\pi \cdot \frac{n}{k}\right)}^{2} \cdot 4\right)}^{0.25}\\


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

    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. *-commutative99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.18e219 < 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. Step-by-step derivation
      1. *-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\frac{\color{blue}{2 \cdot \left(\pi \cdot n\right)}}{k}} \]
    9. Taylor expanded in n around 0 2.7%

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

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

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

      \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\frac{n}{k} \cdot \pi\right)}} \]
    12. Step-by-step derivation
      1. pow1/22.7%

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

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

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

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

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

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

        \[\leadsto {\left(\frac{2 \cdot \left(\pi \cdot n\right)}{k}\right)}^{\color{blue}{\left(0.25 + 0.25\right)}} \]
      8. pow-prod-up2.7%

        \[\leadsto \color{blue}{{\left(\frac{2 \cdot \left(\pi \cdot n\right)}{k}\right)}^{0.25} \cdot {\left(\frac{2 \cdot \left(\pi \cdot n\right)}{k}\right)}^{0.25}} \]
      9. pow-prod-down24.8%

        \[\leadsto \color{blue}{{\left(\frac{2 \cdot \left(\pi \cdot n\right)}{k} \cdot \frac{2 \cdot \left(\pi \cdot n\right)}{k}\right)}^{0.25}} \]
    13. Applied egg-rr24.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;k \leq 1.18 \cdot 10^{+219}:\\ \;\;\;\;\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}\\ \mathbf{else}:\\ \;\;\;\;{\left({\left(\pi \cdot \frac{n}{k}\right)}^{2} \cdot 4\right)}^{0.25}\\ \end{array} \]

Alternative 4: 49.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 38.8% accurate, 1.5× speedup?

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

\\
\frac{1}{\sqrt{0.5 \cdot \frac{k}{\pi \cdot n}}}
\end{array}
Derivation
  1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt{\frac{\color{blue}{2 \cdot \left(\pi \cdot n\right)}}{k}} \]
  9. Taylor expanded in n around 0 45.3%

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

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

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

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

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

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

      \[\leadsto \sqrt{\frac{2}{1} \cdot \frac{\color{blue}{\pi \cdot n}}{k}} \]
    4. times-frac45.3%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{\frac{1}{2} \cdot \frac{k}{\pi \cdot n}}}} \]
    11. metadata-eval45.8%

      \[\leadsto \frac{1}{\sqrt{\color{blue}{0.5} \cdot \frac{k}{\pi \cdot n}}} \]
    12. *-commutative45.8%

      \[\leadsto \frac{1}{\sqrt{0.5 \cdot \frac{k}{\color{blue}{n \cdot \pi}}}} \]
  13. Applied egg-rr45.8%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{0.5 \cdot \frac{k}{n \cdot \pi}}}} \]
  14. Final simplification45.8%

    \[\leadsto \frac{1}{\sqrt{0.5 \cdot \frac{k}{\pi \cdot n}}} \]

Alternative 6: 38.8% accurate, 1.5× speedup?

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

\\
\frac{1}{\sqrt{0.5 \cdot \frac{\frac{k}{n}}{\pi}}}
\end{array}
Derivation
  1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt{\frac{\color{blue}{2 \cdot \left(\pi \cdot n\right)}}{k}} \]
  9. Taylor expanded in n around 0 45.3%

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

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

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

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

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

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

      \[\leadsto \sqrt{\frac{2}{1} \cdot \frac{\color{blue}{\pi \cdot n}}{k}} \]
    4. times-frac45.3%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{\frac{1}{2} \cdot \frac{k}{\pi \cdot n}}}} \]
    11. metadata-eval45.8%

      \[\leadsto \frac{1}{\sqrt{\color{blue}{0.5} \cdot \frac{k}{\pi \cdot n}}} \]
    12. *-commutative45.8%

      \[\leadsto \frac{1}{\sqrt{0.5 \cdot \frac{k}{\color{blue}{n \cdot \pi}}}} \]
  13. Applied egg-rr45.8%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{0.5 \cdot \frac{k}{n \cdot \pi}}}} \]
  14. Step-by-step derivation
    1. associate-/r*45.8%

      \[\leadsto \frac{1}{\sqrt{0.5 \cdot \color{blue}{\frac{\frac{k}{n}}{\pi}}}} \]
  15. Simplified45.8%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{0.5 \cdot \frac{\frac{k}{n}}{\pi}}}} \]
  16. Final simplification45.8%

    \[\leadsto \frac{1}{\sqrt{0.5 \cdot \frac{\frac{k}{n}}{\pi}}} \]

Alternative 7: 38.1% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt{\frac{\color{blue}{2 \cdot \left(\pi \cdot n\right)}}{k}} \]
  9. Taylor expanded in n around 0 45.3%

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

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

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

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

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

Alternative 8: 38.1% accurate, 1.5× speedup?

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

\\
\sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}
\end{array}
Derivation
  1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt{\frac{\color{blue}{2 \cdot \left(\pi \cdot n\right)}}{k}} \]
  9. Taylor expanded in n around 0 45.3%

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

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

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

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

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

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

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

    \[\leadsto \sqrt{2 \cdot \color{blue}{\frac{\pi}{\frac{k}{n}}}} \]
  14. Final simplification45.4%

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

Reproduce

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