I recently noticed a pattern in twin primes. My questions are: does this pattern continue to hold indefinitely, and how would I prove it? Here's the pattern:

For the $n$th prime, there exists exactly $n-2$ twin prime pairs that can be created as follows:

$p_n$ is the $n$th prime,


$(p_nP_p-4, p_nP_p-2)$

Here's what I've worked up to:

$n=3$ $(p_n=5)$ has $3-2=1$ twin prime pairs $P_p=3$ gives $(15-4,15-2)=(11,13)$

$n=4$ has 2 $P_p=3$ gives $(17,19)$ $P_p=3\cdot 5$ gives $(101,103)$

$n=5$ has 3 (29,31), (227,229), (1151,1153)

$n=6$ has 4 (191,193), (269,271), (2141,2143), (2999,3001)

$n=7$ has 5 (659,661), (2801,2803), (4637,4639), (23201,23203), (255251,255253)

Again, my questions are: does this pattern continue to hold indefinitely, and how would I prove it?

P.S. How about a pic of a brute force Mathematica script up to like 20?

  • 1
    $\begingroup$ A proof that the pattern holds on forever would prove the twin-prime-conjecture. +1 for the discovery of the nice pattern. $\endgroup$
    – Peter
    Feb 17, 2016 at 19:01
  • $\begingroup$ I'll polish this up later. Posted this on a cell phone during lunch break! $\endgroup$ Feb 17, 2016 at 19:01
  • $\begingroup$ @Peter Shhhh, lol. But yes, that's my ultimate goal. That would be SO awesome for someone with only an undergrad degree teaching 4th grade math! $\endgroup$ Feb 17, 2016 at 19:04
  • $\begingroup$ This definitely deserves a bounty eventually, but I'm a poor man with little reputation. $\endgroup$ Feb 17, 2016 at 19:05

3 Answers 3


This is an answer to your last demand:

 q = Prime[n] Times@@@Rest[Subsets[Table[Prime[k], {k, 2, n - 1}]]];
 twin = Intersection[Select[q - 4, PrimeQ] + 2, Select[q - 2, PrimeQ]];
 Print["n = ", n, " - ", twin, " - ", Length[twin]],
 {n, 3, 20}]

The pattern breaks at $n=9$, since there are $8$ and not $7$ pairs of twin primes. For $n=20$ there are $2674$ pairs.

I have included the possibility of $m=2$, since you use it (although in the question you say $2<m<n$.)

  • $\begingroup$ Awesome! Thanks! Too bad it doesn't continue exactly the same. Still, it's producing more rather than less. Also, $m=2$ would give an even number even after subtracting 2 or 4. $\endgroup$ Feb 17, 2016 at 19:25
  • 1
    $\begingroup$ @user3363795 Actually that would be $m=1$ since $p_2 = 3$ :). $\endgroup$
    – Erick Wong
    Feb 17, 2016 at 19:28
  • $\begingroup$ Oops, you're definitely right! Meant 2 itself not the 2nd prime. Editing now. $\endgroup$ Feb 17, 2016 at 19:30
  • 1
    $\begingroup$ In PARI/GP (free software), this function gives your pairs: f(n) = li=List();for(subset=1,1<<(n-2)-1,v=vecextract([2..n-1],subset);pp=prod(m=1,#v,prime(v[m]));a=prime(n)*pp-4;ispseudoprime(a)&&ispseudoprime(a+2)&&listput(li,[a,a+2]));Vec(li) The sequence giving number of pairs as a function of $n$, goes $1, 2, 3, 4, 5, 6, 8, 11, 27, 39, 53, 92, 179, 271, 492, 854, 1451, 2674, 4619, 8428, 14946, 27265, 49585, \ldots$. It is not in OEIS. $\endgroup$ Feb 17, 2016 at 22:29
  • $\begingroup$ @Jeppe Cool! Any way for me to submit it? $\endgroup$ Feb 18, 2016 at 15:10

Julián Aguirre's answer is the definitive one, but I also want to give some insight on why this conjecture is kind of unreasonable (i.e. that one should expect it to become false by just doing a little computation).

Caveat: none of the following is proven — for instance, it hasn't been proven that there are infinitely many twin primes, so the probability of a number being part of a twin prime could in fact be $0$. But it is based on what number theorists call a heuristic argument based on the idea that primes are a reasonably good source of randomness and don't contain hidden correlations except for those that are easily explained (e.g. very few even numbers are prime). Heuristic arguments are frequently used to guess at what conjectures are plausible and which are implausible, and surprisingly they can be made quite precise.

There is a huge amount of flexibility in choosing $P_p$ (exponentially many choices), so one might expect that the failure of this conjecture will be that there are too many twin primes than predicted (and indeed this is what Julián discovered). How would we begin to analyze this?

Given a random large number $N$, the chances that $(N,N+2)$ is a twin prime are a little bit higher than $1/(\log N)^2$. In your case these numbers are not entirely random but they are specifically chosen to be indivisible by certain small primes ($2$ as well as the primes composing $P_p$), so we should really think of $1/(\log N)^2$ as a lower bound.

For a given $P_p = \prod_{p \in S_p} p$, the size of $1/(\log N)^2$ will depend on the specific set of primes $S_p$ that go into it: $\log N$ itself will be almost exactly equal to $\log p_n + \sum_{p \in S_p} \log p$. Since we're going for a lower bound, instead of summing up all the possibilities let's just take the worst case of all primes from $p_2$ to $p_n$. This gives (after some computation) $\log N \approx p_n$ so $1/(\log N)^2 \approx 1/p_n^2$.

But there are $2^{n-2}$ choices for $P_p$. Each of them has at least a $1/p_n^2$ chance of being part of a twin prime, so heuristically we would expect to find $2^{n-2}/p_n^2$ twin primes this way. Since $p_n$ only grows as fast as $n \log n$, the expected number of twin primes approaches infinity very quickly, so we should easily expect it to outstrip $n-2$ itself.

On the other hand, given that it has no reason to be true in general, it's nice that the pattern does hold up for $n=3, \ldots, 8$.


Starting from a prime $p_n$, the first candidate for a twin prime that the pattern generates is $3p_n-4$. If this formula does indeed produce prime numbers, then by iterating it, we have a simple way to generate arbitrarily large primes. That would be a big deal all by itself, as no such generator is known today. So we should be skeptical that the formula works...

Well, let's try it!

$5 \times 3 - 4 = 11$
$11 \times 3 - 4 = 29$
$29 \times 3 - 4 = 83$
$83 \times 3 - 4 = 245$

but $245$ is not prime.

  • $\begingroup$ Perhaps I am misinterpreting your answer, but I don't think the OP meant that all subsets of primes between $p_2$ and $p_n$ are guaranteed to produce a prime, so why would you infer that $3p_n-4$ is prime? $\endgroup$
    – Erick Wong
    Feb 17, 2016 at 19:27
  • $\begingroup$ Yes, not everything it generates is prime, or a twin prime. However, if each prime generates at least one unique twin, then twins are infinite as primes are infinite. $\endgroup$ Feb 17, 2016 at 19:28
  • 1
    $\begingroup$ @ErickWong Ah, I though $P_p$ was meant to be one of the $n-2$ products of consecutive primes starting from $3$ up to a maximum $<p_n$. $\endgroup$ Feb 17, 2016 at 21:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .