# Formula for primes

Willan's Formula is a formula that can find the nth prime number.

$1+\sum _{i=1}^{2^{n}}{\lfloor ({\frac {n}{\sum _{j=1}^{i}{\lfloor (\cos {\pi {\frac {{(j-1)!}+j}{j}}})^{2}\rfloor }}})^{\frac {1}{n}}\rfloor }$ ## Proof

Let's first start with the ${\frac {(j-1)!+1}{j}}$ .

Wilson's theorem says if ${(j-1)!+1}$ is divisible by $j$ , than $j$ is either a prime number or $1$ , meaning when $j$ is prime, ${\frac {(j-1)!+1}{j}}$ is an integer.

It would be much easier if the formula gives a number instead of checking if the number is an integer, and we can do this with the ${\lfloor (\cos {\pi {\frac {{(j-1)!}+j}{j}}})^{2}\rfloor }$ part.

The reason the formula has $\pi$ multiplied by the ${\frac {(j-1)!+1}{j}}$ part is because when ${\frac {(j-1)!+1}{j}}$ is an integer, $\cos({\frac {(j-1)!+1}{j}}\pi )$ will give $1$ or $-1$ .

When squaring the result then $\cos({\frac {(j-1)!+1}{j}}\pi )$ will equal $1$ when ${\frac {(j-1)!+1}{j}}$ is an integer.

By flooring this, the only results are $1$ when ${\frac {(j-1)!+1}{j}}$ is an integer and $0$ when it isn't, leaving${\lfloor (\cos {\pi {\frac {{(j-1)!}+j}{j}}})^{2}\rfloor }$ .

The $\sum _{j=1}^{i}{\lfloor (\cos {\pi {\frac {{(j-1)!}+j}{j}}})^{2}\rfloor }$ will add $1$ s for the primes $1$ - $i$ and and will sum up to the $(\mathbin {\#} {\textrm {primes}}\leq {i})+1$ .

The ${\lfloor ({\frac {n}{\sum _{j=1}^{i}{\lfloor (\cos {\pi {\frac {{(j-1)!}+j}{j}}})^{2}\rfloor }}})^{\frac {1}{n}}\rfloor }$ in short will give $1$ if $n>(\mathbin {\#} {\textrm {primes}}\leq {i})$ and $0$ when $n\geq (\mathbin {\#} {\textrm {primes}}\leq {i})$ .

Take the $p(x)$ of both sides where $p(x)$ is the nth prime number:

$1$ when $nth$ ${\textrm {prime}}>i$ $\Rightarrow {i}<{nth}$ ${\textrm {prime}}$ $0$ when $nth$ ${\textrm {prime}}\leq {i}$ $\Rightarrow {i}\geq {nth}$ ${\textrm {prime}}$ $\sum _{i=1}^{2^{n}}{\lfloor ({\frac {n}{\sum _{j=1}^{i}{\lfloor (\cos {\pi {\frac {{(j-1)!}+j}{j}}})^{2}\rfloor }}})^{\frac {1}{n}}\rfloor }$ gives the number $-1$ , and the $-1$ is because when $i<{nth}$ ${\textrm {prime}}$ reaches $i={nth}$ ${\textrm {prime}}$ , the function doesn't add 1. The formula adds up to $2^{n}$ is because Bertrand's postulate says $2^{n}$ is bigger than the nth prime number.

And finally, $1$ is added because of the $-1$ .