Migdal et al, Equation (51)

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

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

\\
\frac{{k}^{-0.5}}{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\left(-0.5 - k \cdot -0.5\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. 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. Step-by-step derivation
    1. add-sqr-sqrt99.5%

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

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

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

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

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

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

    \[\leadsto \color{blue}{{k}^{-0.5} \cdot {\left({\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(-\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}\right)}^{-1}} \]
  8. Step-by-step derivation
    1. unpow-199.6%

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

      \[\leadsto \color{blue}{\frac{{k}^{-0.5} \cdot 1}{{\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(-\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}} \]
    3. *-rgt-identity99.6%

      \[\leadsto \frac{\color{blue}{{k}^{-0.5}}}{{\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(-\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}} \]
    4. *-commutative99.6%

      \[\leadsto \frac{{k}^{-0.5}}{{\left(\color{blue}{\left(\pi \cdot 2\right)} \cdot n\right)}^{\left(-\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}} \]
    5. associate-*l*99.6%

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

      \[\leadsto \frac{{k}^{-0.5}}{{\left(\pi \cdot \color{blue}{\left(n \cdot 2\right)}\right)}^{\left(-\mathsf{fma}\left(k, -0.5, 0.5\right)\right)}} \]
    7. neg-sub099.6%

      \[\leadsto \frac{{k}^{-0.5}}{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\color{blue}{\left(0 - \mathsf{fma}\left(k, -0.5, 0.5\right)\right)}}} \]
    8. fma-undefine99.6%

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

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

      \[\leadsto \frac{{k}^{-0.5}}{{\left(\pi \cdot \left(n \cdot 2\right)\right)}^{\left(0 - \color{blue}{\left(0.5 + -0.5 \cdot k\right)}\right)}} \]
    11. associate--r+99.6%

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

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

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

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

Alternative 2: 99.3% accurate, 1.0× speedup?

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

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

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


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

    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 68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.49999999999999969e-47 < 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. Applied egg-rr99.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 58.1% accurate, 1.0× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.4500000000000001e42 < 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 1.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{1 + \color{blue}{\mathsf{fma}\left(n, \frac{2}{\frac{k}{\pi}}, -1\right)}} \]
      10. metadata-eval32.3%

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

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

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

Alternative 4: 48.5% accurate, 1.0× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.55e42 < 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 1.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 39.3% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 0.154999999999999999

    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 24.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.154999999999999999 < n

    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. Add Preprocessing
    3. Taylor expanded in k around 0 32.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 99.5% accurate, 1.0× speedup?

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

\\
\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Derivation
  1. Initial program 99.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 7: 38.7% accurate, 1.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 0.154999999999999999

    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 24.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.154999999999999999 < n

    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. Add Preprocessing
    3. Taylor expanded in k around 0 32.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 30.8% accurate, 2.0× speedup?

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

\\
\sqrt{\left(n \cdot 2\right) \cdot \left(\pi \cdot \frac{1}{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 28.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 30.8% accurate, 2.0× 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.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 28.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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