Migdal et al, Equation (51)

Percentage Accurate: 99.5% → 99.4%
Time: 19.9s
Alternatives: 5
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 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.4% accurate, 0.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

Alternative 3: 88.1% accurate, 1.0× speedup?

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

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

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

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

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

      \[\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-u97.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-udef88.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-rr82.4%

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

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

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

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

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

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

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

Alternative 4: 38.4% accurate, 1.5× speedup?

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

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

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

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

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

      \[\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-u97.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-udef88.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-rr82.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{{\left(e^{1.5 \cdot \left(-1 \cdot \log k + \log \left(2 \cdot \left(n \cdot \pi\right)\right)\right)}\right)}^{0.3333333333333333}} \]
  13. Step-by-step derivation
    1. Simplified35.9%

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

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

    Alternative 5: 38.4% accurate, 1.5× speedup?

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

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

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

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

        \[\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-u97.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-udef88.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-rr82.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Reproduce

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