Looking through some old notebooks I found this monster of a formula:

For any integer $r>1$, we have

$$\pi=(-1)^{\left\lfloor\frac{r}{2}\right\rfloor-\left\lfloor\frac{2r-1}{4}\right\rfloor}\sum_{n=1}^\infty \frac{(2r-1)((2r-1)(n-1))!}{(n(2r-1)-1)!}\left(\sum_{k=1}^{\left\lfloor\frac{2r-1}{2}\right\rfloor} (-1)^{f(k,r)}\frac{\cot\left(\frac{\pi kr}{2r-1}\right)}{(2r-3)!} {2r-3\choose g(k,r)}\right)^{-1},$$

where we have $$f(k,r)=k+1+\frac{1}{2} \left(\left\lfloor \frac{2r-1}{4}\right\rfloor -\left\lfloor \frac{r}{2}\right\rfloor+k-1\right) \left(\left\lfloor \frac{2r-1}{4}\right\rfloor -\left\lfloor \frac{r}{2}\right\rfloor+k\right)$$ and $$g(k,r)=k \left\lfloor \frac{2r-1}{2}\right\rfloor -1\ \% \ 2 r-1,$$ with $\%$ denoting the modulo operation. It's kind of messy but I can't seem to simplify it much more. A number of years have passed since I found it and I don't even remember how I derived it (also, I haven't done any mathematics for over five years so I'm kind of rusty). I'm pretty sure it has something to do with rising or falling factorials though. It seems to converge pretty quickly. To get the first one thousand decimals of $\pi$ with, say $r=300$, we don't really need the series to go to infinity, $17$ will suffice.

So, my question is if anyone knows anything about this formula. Is it well-known? Are there any other, similar formulas? What's going on with the cotangents? I have a hard time "visualizing" what's going on (and I really wish I kept better, more detailed notes).


Edit:

If anyone is interested, here is more compact (and hopefully more legible) version which holds true if and only if $r\equiv 3\pmod{4}$:

$$\pi=\sum_{n=1}^\infty \frac{r(r(n-1))!}{(nr-1)!}\left(\sum_{k=1}^{\frac{r-1}{2}} i^{k (k-1)-2}\frac{\cot\left(\frac{\pi k(r+1)}{2r}\right)}{(r-2)!} {r-2\choose \frac{k (r+1)-2}{2}\ \% \ r}\right)^{-1}.$$


Edit 2 (some background):

Just to give some context: I think this formula grew out of the study of series such as

$$\sum_{n=1}^{\infty} (rn)_{1-r}=\sum_{n=1}^{\infty}\left(\prod_{i=1}^{r-1}(rn-i)\right)^{-1}=\sum_{n=1}^{\infty}\frac{1}{(rn-1)(rn-2)\cdots (rn-r+1)},$$

where $(n)_r$ is the Pochhammer symbol. The basic idea is that

$$\sum_{\substack{\gcd(r,a_i)=1 \\ a_i<r}}^{\infty}\frac{A}{(rn-1)(rn-a_1)\cdots (rn-a_s)}=\pi,$$

for some (increasingly unruly and complicated) factor $A$. For example:

$$\sum_{n=1}^{\infty}\frac{8}{(4n-1)(4n-3)}$$ $$\sum_{n=1}^{\infty}\frac{\frac{150}{\sqrt{250-110\sqrt{5}}}}{(5n-1)(5n-2)(5n-3)(5n-4)}$$ $$\sum_{n=1}^{\infty}\frac{8\sqrt{3}}{(6n-1)(6n-5)}$$

and for $r=7$ the factor looks something like this:

$$-\frac{5040 (-1)^{4/7} \left(2 \sqrt[7]{-1}-2 (-1)^{5/7}+(-1)^{6/7}-1\right) \sqrt[3]{26767+44439 i \sqrt{3}}}{56 i \sqrt[3]{26767+44439 i \sqrt{3}}+\sqrt[3]{14} \left(\sqrt[3]{2} \left(26767+44439 i \sqrt{3}\right)^{2/3} \left(\sqrt{3}-i\right)-1238 \sqrt[3]{7} \left(\sqrt{3}+i\right)\right)}.$$

Moving around some terms here and there I guess we end up with the infinite series of factorials to the left and $A$ being the inverted sum on the right. What would be cool to know is if there's any way of simplifying the whole binomial-mod-thing. Any thoughts are welcome!


Note the following identity: \begin{equation} \frac{1}{1-x^r}= \frac{1}{r} \sum\limits_{p=0}^{r-1} \frac{-1}{x-e^{\frac{2 \imath \pi p}{r}}} \cdot (-1)^{\frac{2 p}{r}} \quad (i) \end{equation} where $r$ is a positive integer.

Now, let us assume that $r\ge 3$ is a prime number. We define the following quantity: \begin{equation} {\mathfrak S}(r):= \sum\limits_{n=1}^\infty \frac{1}{\prod\limits_{p=1}^{r-1} (r n-p)} \end{equation} Then we have: \begin{eqnarray} {\mathfrak S}(r)&=& \int\limits_{[0,1]^{r-1}} \frac{\prod\limits_{\xi=1}^{r-1}t_\xi^{r-1-\xi}}{\left(1-\prod\limits_{\xi=1}^{r-1} t_\xi^r\right)} \cdot \prod\limits_{\xi=1}^{r-1} dt_\xi \\ &=&\frac{\pi}{r (r-2)!} \sum\limits_{q=0}^{r-2} \binom{r-2}{q} (-1)^q \cot[\frac{\pi(1+q)}{r}] + \frac{\pi \imath^{3 r+1}}{r(r-2)!} \sum\limits_{q=0}^{r-1} (-1)^q \left( 2 \sin[\frac{\pi q}{r}]\right)^{r-2} \frac{q}{r} \end{eqnarray} where we obtained the expression on the very bottom by using $(i)$ and successively integrating over $t_\xi$ starting from $\xi=r-1$ all the way down to $\xi=1$.

In[13]:= r = Prime[RandomInteger[{2, 10}]]; M = 5000;
N[Take[Accumulate[
    Table[1/Product[r n - p, {p, 1, r - 1}], {n, 1, M}]], -5], 
  100] // MatrixForm
N[1/r (I \[Pi])/(r - 2)! Sum[
    Binomial[r - 2, q] (-1)^q (-1)^((2 (q + 1) p )/r)
      If[p == 0, 1, (2 p)/r - 1], {p, 0, r - 1}, {q, 0, r - 2}] + 
  1/r (I \[Pi])/(r - 2)! Sum[ (1 - E^((2 I p \[Pi])/r))^(r - 2)  p/
     r (-1)^(1 + 2 p/r), {p, 0, r - 1}], 100]
N[1/r  \[Pi]/(r - 2)! Sum[
    Binomial[r - 2, q] (-1)^q ( Cot[(\[Pi] (1 + q))/r]), {q, 0, 
     r - 2}] + 
  1/r ( I^(3 r + 1) \[Pi])/(r - 2)! Sum[ (-1)^
     q (2 Sin[(  q \[Pi])/r])^(r - 2)  q/r, {q, 0, r - 1}], 100]

enter image description here