14

I recently found the following function, that returns $1$ if its argument is a prime number, and $0$ otherwise. Let $\chi_{\mathbb{P}}: \mathbb{Z}\rightarrow\{0,1\}$ for $n>4$ be defined as follows: $$ \chi_{\mathbb{P}}(n)=\frac{(-1)^{\frac{2}{n}\Gamma(n)}-1}{(-1)^{-\frac{2}{n}}-1}. $$ Then $\chi_{\mathbb{P}}$ is the characteristic function of the primes. Note that here $\Gamma$ denotes the usual gamma function.

The first few values, starting from $n=5$ are the following:

1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, ...

For convenience I include the relevant Mathematica code here:

 Table[((-1)^(2 Gamma[n]/n) - 1)/((-1)^(-2/n) - 1), {n, 5, 20}]

Is this already known? I have not found references to it in literature.

TheSimpliFire
  • 28,628
  • 10
  • 66
  • 140
Klangen
  • 5,540
  • 6
    Characteristic function of primes is $A010051$ in the OEIS.

    There, it is given: ("For n > 4, a(n) = (n-2)! mod n. - Thomas Ordowski, Jul 24 2016")

    $$\space n\gt 4,\space a(n) = \Gamma(n-1)\pmod n$$

    Which is the closest expression to your expressions that is listed there. Both this expression and yours, are a consequence of Wilson's theorem.

    – Vepir Oct 12 '19 at 13:25
  • 2
    As for the title, there is of course just one characteristic function of the prime numbers. You are really asking if the expression for it is new. – Marc van Leeuwen Oct 13 '19 at 11:28
  • 2
    "Let $\chi_{\mathbb{P}}: \mathbb{Z}\rightarrow{0,1}$ for $n>4$ be defined" makes no sense. If you only define anything for integers exceeding $4$, then you have not defined a function with $\Bbb Z$ as domain. – Marc van Leeuwen Oct 13 '19 at 11:30
  • Why does not it work for 4? – Anixx Jun 14 '24 at 15:41

2 Answers2

18

Update: This characteristic function was known since 1895. The formula$$\chi(n)=\frac{e^{2\pi i(n-1)!/n}-1}{e^{-2\pi i/n}-1}$$ appears in Formulas for Primes by Dudley (1983) which is equivalent to your formulation.


As $n\in\Bbb Z^+$, if $\chi_{\Bbb P}(n)=1$ then $$\chi_{\mathbb{P}}(n)=\frac{(-1)^{2\Gamma(n)/n}-1}{(-1)^{-2/n}-1}=\frac{(-1)^{2(n-1)!/n}-1}{(-1)^{-2/n}-1}=1\implies (-1)^{2(n-1)!/n}=(-1)^{-2/n}$$ which is equivalent to $$\frac{2(n-1)!}n\equiv-\frac2n\pmod2\implies2\cdot\left(\frac{(n-1)!+1}{n}\right)\equiv0\pmod2$$ which is true if the term in brackets is an integer; that is, if $n\mid (n-1)!+1$, which in turn is equivalent to Wilson's Theorem.

Note that on the other hand, $$\chi_{\Bbb P}(n)=0\implies\frac{2(n-1)!}n\equiv0\pmod2\implies n\mid(n-1)!$$ so $n$ cannot be prime.

TheSimpliFire
  • 28,628
  • 10
  • 66
  • 140
  • When $n=8$ what is the meaning of $(-1)^{-2/n}$? Is it $\frac{1}{\sqrt{\sqrt{-1}}}$? Or $\frac{-1}{\sqrt{\sqrt{-1}}}$? Is this formula supposed to give imaginary numbers? For $n=7$ what is the meaning of $(-1)^{-2/7}$? Its value seems ambiguous. – Michael Oct 13 '19 at 03:58
  • @Michael When $n$ is even, it does not matter what value (real or complex) the (non-zero) denominator takes, as the numerator is zero from the definition of $\chi_{\Bbb P}$. When $n$ is odd, the ambiguity of the powers can be avoided as long as the $(-1)^\bullet$ terms on the numerator and on the denominator are consistently defined. – TheSimpliFire Oct 13 '19 at 07:51
  • "Consistently defined" is unclear. Perhaps it means some weird thing like $$(-1)^{2x/n} = ((-1)^2)^{x/n} = 1^{x/n} = 1 \quad \forall n \in {1, 2, 3, ...}$$ I don't think a formula with an unclear numerator and denominator is math. If the formula can only be evaluated by assuming it is the same as "$(n-1)! + 1$ is divisible by $n$," then, it is better to just state this latter condition. – Michael Oct 13 '19 at 13:19
  • @Michael A choice needs to be made to evaluate each term separately. Most common would probably be $-1 = e^{i\pi}$, but every other choice yields the same end result. It is therefore unambigous and perfectly fine to write it as such. – Klaus Oct 15 '19 at 14:14
  • @Klaus : Thanks. If you write $e^{i \pi x}$ I know what you are talking about, if you write $(-1)^x$ I do not, so, I don't see much value in writing $(-1)^x$. – Michael Oct 16 '19 at 00:31
  • @Michael Yes, I agree, $e^{i\pi x}$ is better to avoid confusion. – Klaus Oct 16 '19 at 10:12
9

Yes, this is a variant of Wilson's theorem.

Klaus
  • 11,316