Idle Musings, Ctd

It’s occurred to me that Idle Musings is probably a poor phrase; better would have been Jumping Jacks For The Mind. I’m just following some odd thoughts percolating through my brain concerning prime numbers; I have no expertise in them nor, for that matter, mathematics in general, and I’ve done no research. I’m just messing around here. I’m stretching the brain in unaccustomed ways, and by all accounts this is good for the brain.

Just to be straight.

Perhaps I should email this off to SCOTUS, given the recent dismaying accounts of their mathphobia.


Last time I introduced the idea of using the underlying indexes in P in the calculation of Pn and suggested that a collection of equations would be necessary; this, in popular jargon, is an algorithm. I’m no theoretician, of course, so I will proceed via inspection to explore the creation of an algorithm.

In case you’re wondering, I’ve thought about this a little but my personal memory scratch space is too small for me to push the ideas out beyond the first seven members of P; I’m writing this down as a substitute for paper, as my handwriting is awful. I shan’t even publish this until a tentative conclusion is reached.

In order to discover and refine the algorithm, the first few known members of the infinite set P will be useful. From the Internet:

P1,2, … = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199 … }

We assume P1 = 2 with no justification. Immediately, we can see

P2 = P1 + 1 = 2 + 1 = 3

so we place

Pn+1 = Pn + n      (Eq. 1)

in our contingent list of equations; it will be withdrawn soon enough. Let’s see how far this takes us:

P3 = P2 + 2 = 3 + 2 = 5    (Eq. 1)   (So far, so good)

P4 = P3 + 3 = 5 + 3 = 8   (Eq. 1)   (wrong!)

which is not only wrong, but also indicative of a longer term problem, which is that whenever n is odd, Eq. 1 will be wrong, because, with the exception of P1, all prime numbers are odd, and adding an odd number n to an odd number Pn will result in an even number. We withdraw Eq. 1 in favor of this:

Pn+1 = Pn + n   when n is even or n = 1  (Eq. 2)

which then leaves us with the question of how to handle odd subscripts. We observe that the wrong answer is an overshoot of 1, so perhaps we can start with that:

Pn+1 = Pn + (n-1)   when n is odd   (Eq. 3)

Continuing to apply our algorithm:

P4 = P3 + (3 – 1) = P3 + 2 = 5 + 2 = 7   (Eq. 3) (that works)

P5 = P4 + 4 = 7 + 4 = 11  (Eq. 2)  (that works)

P6 = P5 + (5 – 1) = 11 + 4 = 15 (Eq. 3) (fails!)

And Eq. 3 fails in two different ways this time.

First, of course, 15 is not a prime number; however, 17 is a prime number. Let’s make the assumption that there is another algorithm for generating the non-prime members of N (the natural numbers greater than 1). Then we can withdraw Eq. 3 in favor of a slightly modified version of same:

Pn+1 = Pn + (n ± 1)   when n is odd   (Eq. 4)

Where the ‘+’ or ‘-‘ is selected on the basis of whether or not Pn + (n – 1) generates an already generated non-prime number; if it does, then we move to the + 1 variant. Perhaps we’ll discern a better rule later.

But more importantly, the failure case cited above refers, at best, to 17; P6 is actually 13! Before discussing how to handle this mistake, let’s get the mechanics out of the way, which is to say, replacing Eq. 2 & 4:

Pn + n => Px  when n is even or n = 1  (Eq. 5, replacing Eq. 2)

Pn + (n ± 1) => Px  when n is odd   (Eq. 6, replacing Eq. 4)

I write Px because we no longer know the value of the subscript, I write => to indicate the loss of connection between n and x.

Back to the precipitating matter, it appears clear that we need a generating function for calculating all prime numbers between Pn and Px. Its behavior should eventually work for P1 … P5, of course. As a very contingent first hack, it’s clear that for n = 5,

Pn+1 = Pn + (n / 2)   (Eq. 7)

where the division results in a whole number, rounded down, should suffice. To be clear, we should have a way to know when to apply it, and we don’t. For the nonce, let us say that we first apply Eq. 5 or Eq. 6, as appropriate, and then test apply Eq. 7, and if 7 generates a number larger than the one previously generated, discard the result from Eq. 7. Applied to n = 5,

P6 = P5 + (5 / 2) = 11 + 2 = 13 (Eq. 3)

Since we now have P6 calculated properly, let’s use it.

P6 + 6 => Px, (Eq. 5)
13 + 6 = 19 => Px

Which works and we can assign to P8, as we have already calculated P7 to be 17. More exploration, keeping in mind that we have not yet ascertained a solid rule for employing Eq. 7.

P7 + 7 = 17 + 7 – 1 = 23  (Eq. 6, variant ‘-‘)  (correct!)

and using P8,

P8 + 8 = 19 + 8 = 27. (Eq. 5)  (Waa-waa!)

So we see the approach beginning to fail, as a core equation yields a wrong value – 27 is not a prime, and the next prime is 29, so we’re off by -2. Modifying Eq. 5 to produce the proper solution seems unlikely, as it must also apply to all previous primes with an even index.

But what’s catching my eye is that, unlike many failing solutions in programming, this one is trying to hang on. Have some patience …

P9 + 9 – 1 = 23 + 8 = 31   (Eq. 5)  (correct, P11)

P10 + 10 = 29 + 10 = 39   (Eq. 6) (off by +2 instead of -2, P12 is 37)

P11 + 11 – 1 = 31 + 11 – 1 = 41 (Eq. 5)  (correct, P13)

P11 + (11 / 2) = 31 + 5 = 36  (Eq. 7)  (wrong, 37 is correct)

Are we slowly diverging? P12 is off by two by Eq. 5, but generates a prime for Eq. 7, P13 generates a prime properly by Eq. 6. There may be a pattern in the failures, but that would take more calculation, and other duties call.

So this is a mind stretch, which, like jumping jacks, really doesn’t take you anywhere – but does focus the attention on one of those mysteries of mathematics, the prime numbers. Perhaps a slightly more sophisticated set of equations would suffice… the mind does wander down that path sometimes. Even for non-mathematicians like myself.

Bookmark the permalink.

About Hue White

Former BBS operator; software engineer; cat lackey.

Comments are closed.