4

Let $p_n$ denote the $n$th prime number. Let $p_n \lt a \lt b \lt p_{n+1}^2$ be any such integers. Their oddness or divisibility does not matter as in my previous posts, which makes this formula particularly nice.

An inclusion-exclusion based & modular-arithmetical counting formula for the twin primes is:

$$f(a,b) = b - a + \sum_{1 \ \neq \ d \ \mid \ p_n\#} (-1)^{\omega(d)}\sum_{2 \ \nmid \ c \ \mid \ d}\left( \left\lfloor\dfrac{b - x_{c,d}}{d}\right\rfloor + \left\lfloor\dfrac{x_{c,d} - a}{d}\right\rfloor \right)$$

where $x = x_{c,d} =$ any solution in $\Bbb{Z}$ to the simultaneous & CRT system:

$$ x = 1 \pmod c \\ x = -1 \pmod {d/c} $$

Note that the purpose of this formula is purely theoretical and is in no way optimal for counting up the twin primes in an interval.

Questions.

How can we relate this to the inclusion-exclusion formula for $\pi(x)$?

Found here: "Algorithms evaluating $\pi(x)$". It's very close because the alternating sum over divisors of $p_n\#$ does the same thing as that sum, except our sum is missing $d = 1$ and inside of our sum is another sum, and not just a floor of a fraction.

Many other MSE users including mathlove, BillyJoe, and JyrkiLahtonen have been helpful in developing this formula.


Attempt.

We know that $\sum_{d \mid p_n\#} (-1)^{\omega(d)} \lfloor\dfrac{z}{d} \rfloor = x + \sum_{1 \neq d \mid p_n\#} (-1)^{\omega(d)} \lfloor \dfrac{z}{d}\rfloor = \pi(z) - \pi(\sqrt{z}) + 1$ by the given link.

Thus $\sum_{1 \neq d \mid p_n\#} (-1)^{\omega(d)}\lfloor\dfrac{ z}{d} \rfloor =\pi(x) - x - \pi(\sqrt{x}) + 1$ if we can get the double sum into a sum of sums of this form.


The double summation naturally has the form of:

$$ -\sum_{1\ \neq\ cd \ \mid\ p_n\# \\ 2 \ \nmid\ c} (-1)^{\omega(d)} \left(\lfloor \dfrac{b - x_{c,d}}{cd}\rfloor + \lfloor \dfrac{x_{c,d} - a}{cd}\rfloor \right) $$

where $x = x_{c,d} \in \Bbb{Z}$ is any solution to the simultaneous CRT system:

$$ x = 1 \pmod {c} \\ x = -1 \pmod {d} $$


Here's what an example computation looks like, with the equivalent ceil's in place of floor around $a$'s expression:

$$ f(a,b) = - a + b - \left\lceil{\frac{a}{6} - \frac{5}{6}}\right\rceil - \left\lceil{\frac{a}{6} - \frac{1}{6}}\right\rceil + \left\lceil{\frac{a}{3} - \frac{1}{3}}\right\rceil + \left\lceil{\frac{a}{3} + \frac{1}{3}}\right\rceil + \left\lceil{\frac{a}{2} - \frac{1}{2}}\right\rceil + \left\lfloor{\frac{b}{6} - \frac{5}{6}}\right\rfloor + \left\lfloor{\frac{b}{6} - \frac{1}{6}}\right\rfloor - \left\lfloor{\frac{b}{3} - \frac{1}{3}}\right\rfloor - \left\lfloor{\frac{b}{3} + \frac{1}{3}}\right\rfloor - \left\lfloor{\frac{b}{2} - \frac{1}{2}}\right\rfloor \\ = f(5,23) = 3 $$

There are precisely $3$ twin prime averages in the range $[5, 23]$. See verification code link for larger examples.

Here is actually the next example (as $n$ grows):

$$ f(a,b) = - a + b + \left\lceil{\frac{a}{30} - \frac{29}{30}}\right\rceil + \left\lceil{\frac{a}{30} - \frac{1}{30}}\right\rceil + \left\lceil{\frac{a}{30} + \frac{11}{30}}\right\rceil + \left\lceil{\frac{a}{30} + \frac{19}{30}}\right\rceil - \left\lceil{\frac{a}{15} - \frac{11}{15}}\right\rceil - \left\lceil{\frac{a}{15} - \frac{1}{15}}\right\rceil - \left\lceil{\frac{a}{15} + \frac{1}{15}}\right\rceil - \left\lceil{\frac{a}{15} + \frac{11}{15}}\right\rceil - \left\lceil{\frac{a}{10} - \frac{9}{10}}\right\rceil - \left\lceil{\frac{a}{10} - \frac{1}{10}}\right\rceil - \left\lceil{\frac{a}{6} - \frac{5}{6}}\right\rceil - \left\lceil{\frac{a}{6} - \frac{1}{6}}\right\rceil + \left\lceil{\frac{a}{5} - \frac{1}{5}}\right\rceil + \left\lceil{\frac{a}{5} + \frac{1}{5}}\right\rceil + \left\lceil{\frac{a}{3} - \frac{1}{3}}\right\rceil + \left\lceil{\frac{a}{3} + \frac{1}{3}}\right\rceil + \left\lceil{\frac{a}{2} - \frac{1}{2}}\right\rceil - \left\lfloor{\frac{b}{30} - \frac{29}{30}}\right\rfloor - \left\lfloor{\frac{b}{30} - \frac{1}{30}}\right\rfloor - \left\lfloor{\frac{b}{30} + \frac{11}{30}}\right\rfloor - \left\lfloor{\frac{b}{30} + \frac{19}{30}}\right\rfloor + \left\lfloor{\frac{b}{15} - \frac{11}{15}}\right\rfloor + \left\lfloor{\frac{b}{15} - \frac{1}{15}}\right\rfloor + \left\lfloor{\frac{b}{15} + \frac{1}{15}}\right\rfloor + \left\lfloor{\frac{b}{15} + \frac{11}{15}}\right\rfloor + \left\lfloor{\frac{b}{10} - \frac{9}{10}}\right\rfloor + \left\lfloor{\frac{b}{10} - \frac{1}{10}}\right\rfloor + \left\lfloor{\frac{b}{6} - \frac{5}{6}}\right\rfloor + \left\lfloor{\frac{b}{6} - \frac{1}{6}}\right\rfloor - \left\lfloor{\frac{b}{5} - \frac{1}{5}}\right\rfloor - \left\lfloor{\frac{b}{5} + \frac{1}{5}}\right\rfloor - \left\lfloor{\frac{b}{3} - \frac{1}{3}}\right\rfloor - \left\lfloor{\frac{b}{3} + \frac{1}{3}}\right\rfloor - \left\lfloor{\frac{b}{2} - \frac{1}{2}}\right\rfloor \\ = f(7,47) = 4 $$

As you can see, the number of terms we directly consider in the double summation seems to grow exponentially. This doesn't matter, however. The twin prime conjecture doesn't care.


The floor-free formula can be derived as follows. Clearly $\lfloor \dfrac{z}{d}\rfloor = \dfrac{z - z_{(d)}}{d},$ for all $z \in \Bbb{Z}$ and $d \in \Bbb{Z}, d \neq 0$.

$$ f(a,b) = b - a - \\ \sum_{1 \neq cd \mid p_n\# \\ 2 \nmid c} (-1)^{\omega(d)}\left(\dfrac{b - x_{c,d} - (b - x_{c,d})_{(cd)}}{cd} + \dfrac{x_{c,d} - a - (x_{c,d} - a)_{(cd)}}{cd} \right) = \\ -\sum_{1 \neq cd \mid p_n\# \\ 2 \nmid c} \left((-1)^{\omega(d)}\dfrac{ (b - x_{c,d})_{(cd)} + (x_{c,d} - a)_{(cd)}}{cd}\right) $$

But for minimal residues $z_{(e)},z'_{(e)} \in \Bbb{Z}$ we clearly have that $(z + z')_{(e)} \leq z_{(e)} + z_{(e)}'$, and thus we have a lower bounding mechanism (perhaps?).


Here is proof of the formula.

1 Answers1

2

Too long to insert in a comment. I don't think the formula can have any practical use.

Also, for large values ​​of n it does not give an exact result.

Yet this exact formula which has a similar complexity but which has no practical use:

$\pi_{\text{twin}} (n) = 1 + \\ \sum \limits_{k=1}^{\left\lfloor{\frac{n-1}{6}}\right\rfloor} {\left\lfloor \left( \displaystyle 1 + \displaystyle\sum_{a=1}^{\left\lfloor\frac{1+\sqrt{-1+6\cdot k}}{6}\right\rfloor} {\left( \left\lfloor\frac{-1+6\cdot k}{-1+6\cdot a}\right\rfloor - \left\lfloor\frac{-2+6\cdot k}{-1+6\cdot a}\right\rfloor \right)} + \displaystyle\sum_{a=1}^{\left\lfloor\frac{-1+\sqrt{-1+6\cdot k}}{6}\right\rfloor} {\left( \left\lfloor\frac{-1+6\cdot k}{1+6\cdot a}\right\rfloor - \left\lfloor\frac{-2+6\cdot k}{1+6\cdot a}\right\rfloor \right)} \\ + \displaystyle\sum_{a=1}^{\left\lfloor\frac{1+\sqrt{1+6\cdot k}}{6}\right\rfloor} {\left( \left\lfloor\frac{1+6\cdot k}{-1+6\cdot a}\right\rfloor - \left\lfloor\frac{6\cdot k}{-1+6\cdot a}\right\rfloor \right)} + \displaystyle\sum_{a=1}^{\left\lfloor\frac{-1+\sqrt{1+6\cdot k}}{6}\right\rfloor} {\left( \left\lfloor\frac{1+6\cdot k}{1+6\cdot a}\right\rfloor - \left\lfloor\frac{6\cdot k}{1+6\cdot a}\right\rfloor \right)} \right)^{-1}\right\rfloor}$

user140242
  • 702
  • 3
  • 13
  • See proof in this MO post: https://mathoverflow.net/questions/407984/the-number-of-twin-prime-averages-in-the-interval-a-b-has-a-nice-formula-wh

    Not only is the formula exact, but I have proven it to be so.

    – EffingLoveMath Nov 08 '21 at 20:10
  • 1
    that link is not working, it is removed ? @DanielDonnelly – mick Nov 26 '23 at 21:05
  • @mick it shows for me, but I guess is hidden for you, let me teach you the formula, we can't really make posts that teach unless you ask me a specific question then send me link to your post to answer it – EffingLoveMath Nov 27 '23 at 03:34
  • 1
    I remember seeing the proof that Daniels formula works before it was removed and the proof was valid. I assume a proof of this formula is the similar.

    I suggest to you guys posting the proofs as a good addition. Daniel probably has it in his MO under deleted or some copy ?

    Even if these formula are not so practical, i find them very instructive, in particular with their proofs.

    In fact, I bet they will be useful some day. Related to a proof of twin prime conjectures probably.

    @DanielDonnelly

    – mick May 08 '24 at 22:11
  • @mick Please join me in chat and we can discuss – EffingLoveMath May 09 '24 at 08:55
  • 1
    @mick Made this a while back: https://enjoysmath.blogspot.com/2022/09/elementary-counting-formula-for-number.html

    Ping me in chat if you want help making your way through it. My latest formula though just has the inner sum over all $r^2 = 1 \pmod d$ (the standard residues) but with a certain added in ceiling/floor term in the inner sum, you can let $r$ be any residue in $\Bbb{Z}$ i.e. any element of $r + d\Bbb{Z}$. Would be happy to teach you how to derive my latest formula. It's actually just solving a linear inequality and reasoning with floor / modular arithmetic.

    – EffingLoveMath Jun 08 '24 at 07:33
  • @mick just search my profile with the [twin-primes] tag to see all the related posts on this. I am no longer certain that we can crack the problem at our level of the game. It's like the math does not submit no matter what attack we make on the problem. – EffingLoveMath Jun 08 '24 at 07:36
  • 1
    @HighAsAKiteOnMath are you Daniel Donnelly ? name change or other profile ? Confused – mick Jun 22 '24 at 22:17
  • 1
    @mick yeah dat's me >:| – EffingLoveMath Jun 22 '24 at 22:59
  • @mick I don't want to dissuade you from studying this topic. But I failed, and so did all the other mathematicians of the past at solving it. So perhaps some new math (possibly elementary starting out, but which dives deep quick), or some super heavy-duty power tools will be needed to efficiently & elegantly crack these NT problems. That is why I recommend stopping your study on the topic, taking a break from it to study more and more of the mathematical giants' tools. Then one day your expertise at elementary approaches + your knowledge of advanced math, may be able crack this! – EffingLoveMath Jun 22 '24 at 23:02
  • @mick It's so strange that we cannot reason about these repeating sequences (referring to my other posts on that), as fundamental as they are and simple to describe. Basically, modulo $5$ the sequence is $\overline{2,1,2} = 2,1,2,2,1,2,2,1,2,\dots$ meaning, you start at $0$ modulo $5$, have to jump 2 to skip one, can add 1 to get to 3, then must jump 2 to skip -1 (modulo $5$, $-1 = 4$). Then repeat. But you must combine it with a certain operation with the corresponding repeating sequences for all other primes in $p_1, \dots, p_n$. We cannot seem to prove bounds on the 1st entry in result – EffingLoveMath Jun 22 '24 at 23:07
  • @mick [...] reason you skip $\pm 1 \pmod {p_i}$ is that $x = \pm 1 \pmod {p_i}$ indicates that $x$ cannot be a twin prime average in the range $p_{n} + 2, \dots, p_{n+1}^2-2$ (Sieve of Eratosthenes bounds). Then you can write $x = \pm 1 \pmod {p_i} \iff x^2 = 1 \pmod {p_i}$ and hence the familiar $x^2 - 1$ polynomial. See my recent posts on combining these sequences. Prove that first entry in the combined repeating sequence (operation result) is $\leq p_{n+1}^2 - 2$ and you've proven twin primes. So that is what I mean, so strange that we cannot prove this easily! – EffingLoveMath Jun 22 '24 at 23:09
  • 1
    @HighAsAKiteOnMath now I am confused. Plz clarify. – mick Jun 22 '24 at 23:28
  • https://math.stackexchange.com/questions/4884001/an-exotic-operation-on-repeating-sequences-of-natural-numbers-such-as-overline

    The operation psuedo code therein is not right, but I did code it up (and deleted it), but it's fairly straightforward to code the operation in Python, where you represent a repeating sequence as a tuple type like (2,1,2). The operation is associative. I can teach you more about it in chat. Basically this is one step more fundamental than the counting formulas we have. Perhaps we could come up with some lemmas for estimating the first entry in the operation.

    – EffingLoveMath Jun 22 '24 at 23:32