Plotting $g(n,r)-$ the distinct values of a two-dimensional prime counting function

150 Views Asked by At

$\pi(k)$ is the prime counting function.

$$g(n,r) = \# \{ \pi(k)\pi(n-k)\pi(j)\pi(r-j) : 0 \leqslant k \leqslant n,~ 0 \leqslant j \leqslant r\}\,.$$

I would like to see a plot of $g(n,r).$

Here's a plot of $\pi(k)\pi(j)\pi(7-k)\pi(7-j)$ which implies $g(7,7)=3$ because there are $3$ distinct levels in the plot:

enter image description here

I've been able to plot $g(n)=\# \{ \pi(k)\pi(n-k): 0 \leqslant k \leqslant n\}$ but am having trouble going up a dimension. I have an idea of what the plot in 3 dimensions should look like but would like to see what it looks like exactly to make sure I have the right idea.

Some context: Does anyone know why this plot forms bands?

1

There are 1 best solutions below

0
On BEST ANSWER

If you know a bit of Python magic (or any other programming language) I have a fix to see the plot that you desire. There's probably a clever-er way to do this, but this is the simplest one I can think of.

Basically, all you need to do is go to the Online Encyclopedia of Integer Sequences and find the sequence of corresponding to the prime counting function. Here you can find the values of $\pi(n)$ for $n\le 78$. Using this list (which you can just copy and paste into Python) you can simply compute all the products $\pi(k)\pi(n-k)\pi(r-j)$ by looping over all $0\le k \le n, 0\le j \le r$, and put them into a 'set' S.

By 'set' I mean a set class in Python, which is crucial for it will take care of repeated elements more efficiently than checking wether they're on a list or not. Then you can ask Python to return $size(S)$, the number of elements in the set $S$, and there you have it, the value of $g(n,r)$. You can store these on a $78 \times 78$ matrix, and then plot the height map using Matplotlib or any other of your favourite plotting tool on Python.

This will give you the graph of $g(n,r)$ in the square $[1,78]\times [1,78]$.

If you wanna get a larger square, say $k \times k$, then you can compute $\pi(n)$ for $n\le k$ by yourself by implementing Erastothenes sieve.

EDIT: If you code up what I mention this is what you get. A plot of $g(n,r)$ for $(n,r) \in [1,78]\times [1,78]$ , where $n$ is in the $x$-axis and $r$ in the $y$-axis. I don't know if it is appropriate to post code in Math StackExchange, so, if you if you're interested in seeing my code feel free to get in touch.

Plot of <span class=$g(n,r)$ for $(n,r) \in [1,78]\times [1,78]$">