| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 33024 |
\[\begin{array}{l}
t_0 := \left(2 \cdot \pi\right) \cdot n\\
\frac{1}{\sqrt{k}} \cdot \frac{\sqrt{t_0}}{{t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\]

(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (/ (sqrt (* (* 2.0 PI) n)) (pow (expm1 (log1p (* 2.0 (* PI n)))) (* k 0.5)))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
double code(double k, double n) {
return (1.0 / sqrt(k)) * (sqrt(((2.0 * ((double) M_PI)) * n)) / pow(expm1(log1p((2.0 * (((double) M_PI) * n)))), (k * 0.5)));
}
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));
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt(k)) * (Math.sqrt(((2.0 * Math.PI) * n)) / Math.pow(Math.expm1(Math.log1p((2.0 * (Math.PI * n)))), (k * 0.5)));
}
def code(k, 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.sqrt(((2.0 * math.pi) * n)) / math.pow(math.expm1(math.log1p((2.0 * (math.pi * n)))), (k * 0.5)))
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 code(k, n) return Float64(Float64(1.0 / sqrt(k)) * Float64(sqrt(Float64(Float64(2.0 * pi) * n)) / (expm1(log1p(Float64(2.0 * Float64(pi * n)))) ^ Float64(k * 0.5)))) 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]
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision]], $MachinePrecision] / N[Power[N[(Exp[N[Log[1 + N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision], N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot \left(\pi \cdot n\right)\right)\right)\right)}^{\left(k \cdot 0.5\right)}}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 99.5%
Applied egg-rr99.7%
[Start]99.5% | \[ \frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\] |
|---|---|
div-sub [=>]99.5% | \[ \frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\color{blue}{\left(\frac{1}{2} - \frac{k}{2}\right)}}
\] |
metadata-eval [=>]99.5% | \[ \frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\color{blue}{0.5} - \frac{k}{2}\right)}
\] |
pow-sub [=>]99.7% | \[ \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)}}}
\] |
pow1/2 [<=]99.7% | \[ \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)}}
\] |
associate-*l* [=>]99.7% | \[ \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)}}
\] |
associate-*l* [=>]99.7% | \[ \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)}}
\] |
div-inv [=>]99.7% | \[ \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)}}}
\] |
metadata-eval [=>]99.7% | \[ \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)}}
\] |
Simplified99.7%
[Start]99.7% | \[ \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 0.5\right)}}
\] |
|---|---|
associate-*r* [=>]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\color{blue}{\left(2 \cdot \pi\right) \cdot n}}}{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(k \cdot 0.5\right)}}
\] |
associate-*r* [=>]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\color{blue}{\left(\left(2 \cdot \pi\right) \cdot n\right)}}^{\left(k \cdot 0.5\right)}}
\] |
Applied egg-rr99.7%
[Start]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(k \cdot 0.5\right)}}
\] |
|---|---|
*-commutative [=>]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\left(\color{blue}{\left(\pi \cdot 2\right)} \cdot n\right)}^{\left(k \cdot 0.5\right)}}
\] |
associate-*r* [<=]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\color{blue}{\left(\pi \cdot \left(2 \cdot n\right)\right)}}^{\left(k \cdot 0.5\right)}}
\] |
expm1-log1p-u [=>]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\pi \cdot \left(2 \cdot n\right)\right)\right)\right)}}^{\left(k \cdot 0.5\right)}}
\] |
associate-*r* [=>]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(\pi \cdot 2\right) \cdot n}\right)\right)\right)}^{\left(k \cdot 0.5\right)}}
\] |
*-commutative [<=]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\left(2 \cdot \pi\right)} \cdot n\right)\right)\right)}^{\left(k \cdot 0.5\right)}}
\] |
associate-*l* [=>]99.7% | \[ \frac{1}{\sqrt{k}} \cdot \frac{\sqrt{\left(2 \cdot \pi\right) \cdot n}}{{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{2 \cdot \left(\pi \cdot n\right)}\right)\right)\right)}^{\left(k \cdot 0.5\right)}}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 33024 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 26560 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 20036 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 20032 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 19908 |
| Alternative 6 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 19904 |
| Alternative 7 | |
|---|---|
| Accuracy | 50.0% |
| Cost | 19584 |
| Alternative 8 | |
|---|---|
| Accuracy | 38.3% |
| Cost | 13184 |
| Alternative 9 | |
|---|---|
| Accuracy | 38.3% |
| Cost | 13184 |
herbie shell --seed 2023164
(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))))