Showing posts with label pairing. Show all posts
Showing posts with label pairing. Show all posts

Thursday, 13 November 2025

Claude to the Rescue

The number 27983, associated with my diurnal age today, has a property than confers it membership in OEIS A335752: the lexicographically earliest sequence of primes, each two of which sum to a triprime. The sequence begins: 3, 5, 47, 239, 3023, 27983, 53231, ... so let's confirm that these numbers satisfy using 3 as a starting point:
  • \(3 + 5 = 8 =2^3\)
  • \(3 + 47 = 50 = 2 \times 5^2\)
  • \(3 + 239 = 242 = 2 \times 11^2 \)
  • \(3 + 3023 = 3026 = 2 \times 17 \times 89 \)
  • \(3+27983 = 27986 = 2 \times 7 \times 1999\)


The sums above are all triprimes and we will find that any number in the list paired with any other number will produce a triprime. The code for this was included in the OEIS comments but was in Mathematica. I got Gemini to convert it to Python code and then Grok but in both cases the primeomega function was misunderstood with both claiming that primeomega(12) =2 and not 3. 

I didn't fully understand the Python code and was looking to Gemini and then Grok to explain it to me. It was only Claude that succeeded to my satisfaction. Here is the code followed by Claude's explanation. I think Claude will be my go to resource for anything to do with coding.

from sympy import nextprime, primeomega
ps = [3]
for _ in range(10):
    p = nextprime(ps[-1]) 
    while not all(primeomega(x + p) == 3 for x in ps):
        p = nextprime(p)
    ps.append(p)
print(ps)

I'd be happy to explain this code line by line! This code generates a sequence of prime numbers with a special property.

Code Breakdown

from sympy import nextprime, primeomega

Imports two functions from SymPy:
  • nextprime(\(n\)): Returns the next prime number greater than \(n\)
  • primeomega(\(n\)): Returns the total number of prime factors of \(n\) (counting multiplicity). For example, primeomega(12) = 3 because 12 = 2² × 3 (two 2's and one 3)
ps = [3]

Initializes the sequence with the first prime number 3. This list will store our special sequence of primes.

for _ in range(10):

Loops 10 times to find 10 more primes (so we'll have 11 total including the initial 3). The underscore _ is used when we don't need the loop variable.

p = nextprime(ps[-1])

Gets the next prime after the last element in our list. 
  • ps[-1] accesses the last element of the list
  • Initially, this gives nextprime(3) = 5
  • This is our candidate prime to add to the sequence
while not all(primeomega(x + p) == 3 for x in ps):
    p = nextprime(p)

This is the key part! It checks if the candidate prime \(p\) satisfies a special condition:
  • For every number \(x\) already in our list ps
  • The sum \(x + p\) must have exactly 3 prime factors (counting multiplicity)
  • If this condition fails for any \(x\), we move to the next prime candidate
  • This continues until we find a prime where all sums have exactly 3 prime factors
ps.append(p)

Adds the qualified prime to our sequence once it passes the test.

print(ps)

Prints the final sequence** of primes.

Example Walkthrough

Let's trace the first iteration:
1. Start with ps = [3]
2. Try p = 5: Check if 3 + 5 = 8 = 2³ has 3 prime factors ✓ (yes, three 2's)
3. Add 5 to list: ps = [3, 5]
4. Try p = 7: Check 3 + 7 = 10 = 2 × 5 (only 2 factors) ✗
5. Try p = 11: Check 3 + 11 = 14 = 2 × 7 (only 2 factors) ✗
6. Continue until finding a prime that works with both 3 and 5...

This creates a sequence where each new prime maintains the property that when added to any previous prime in the sequence, the result always has exactly 3 prime factors!

*************************

Now if we change the condition to primeomega = 2, we get the following sequence: 3, 7, 19, 139, 859, 8179, 173059, ... where it can be seen there is a big jump from 8179 to 173059. Testing this out using 3 again we see that:
  • \(3+7=10=2 \times 5\)
  • \(3+19=22=2 \times 11\)
  • \(3+139=142=2 \times 71\)
  • \(3+859=862=2 \times 431\)
  • \(3+8179=8182=2 \times 4091\)
  • \(3+173059=173062=2 \times 86531\)
The sequence is included in the OEIS as A113875: slowest growing sequence of primes having the prime-pairwise-average property: if i<j, (a(i)+a(j))/2 is prime. This makes sense in that 2 seems to be the common factor is all of the sums. 

The sequence with additional (very large) terms looks like this:
3, 7, 19, 139, 859, 8179, 173059, 1026199, 1827139, 15828679, 13187242759, 18732483199, 912492556939, 9130567625119

When we set primeomega = 4 we get the following sequence: 3, 13, 137, 1193, 4373, 26017, 33889, 495433, ... which is NOT listed in the OEIS. Again let's use 3 as our test number:
  • \(3+13=16=2^4\)
  • \(3+137=140=2^2 \times 5 \times 7\)
  • \(3+1193=1196=2^2 \times 13 \times 23\)
  • \(3+4373=4376=2^3 \times 547\)
  • \(3+26017=26020=2^2 \times 5 \times 1301\)
  • \(3+33889=33892=2^2 \times 37 \times 229\)
  • \(3+495433=495436=2^2 \times 29 \times 4271\)
That's probably a good place to stop.

Monday, 12 August 2024

Numbers With Elusive Home Primes

I was surprised to find that the number associated with my diurnal age today, 27525, is a number for which a home prime is not able to be ascertained. See Figure 1 where the algorithm applied to this number quits after 50 concatenations fail to generate a prime.


Figure 1: permalink

However, what surprised me even further was that the very next number, 27526, is also a number for which a home prime is not able to be ascertained. Such pairs are not unprecedented, the first being 714 and 715 followed by 1138 and 1139. See my blog post Home Primes from 2nd May 2021. The very first number for which a home prime cannot be found is 49.

After 27526, the next number 27527 is prime and I've written about this number in a post What's Special About 27527 on 10th August 2024. After that, 27528 requires ten steps and 27529 is a prime. I'll continue to monitor the home primes for forthcoming numbers. There's no way of knowing whether these numbers for which home primes are currently unobtainable will not eventually be found to reach home primes once quantum computers are focused on the problem.

Tuesday, 27 July 2021

Semiprimes that Approximate Whole Numbers

I've written about semiprimes on many occasions dating back to my earliest posts. These posts are:

Thus far however, I've not considered semiprimes that closely approximate whole numbers. However, today I turned 26413 days old and this number is a semiprime with prime factors of 61 and 433. If the smaller factor is divided into the larger, we get:$$\frac{433}{61} \approx 7.09836065573770$$This is fairly close to 7 but I thought I'd investigate the first one million natural numbers, using SageMathCell, to see which semiprimes yielded the closest approximations. I thought \( \pm 0.1\) was a fair distance limit to set and by this criterion 26413 just sneaks in. Figure 1 shows a table with the initial semiprimes that qualified, ranked in order of successively smaller differences between the ratio of prime factors and 7.


Figure 1: permalink to SageMathCell

What struck me as odd about this table is that 25681 and 26413 have identical differences with the ratio of the former being just below 7 and the latter just above. The reason for this becomes clear once we look at the average of these two numbers, 26047, and compare the factorisation of all three:$$ 25681 =61 \times 421\\26047=7 \times 61^2\\26413=61 \times 433$$Let's rewrite the factorisation of the average so that we have:$$ 25681 =61 \times 421\\26047=61 \times 427\\26413=61 \times 433$$Let's divide all three by \(61^2\) to get:$$ \begin{align} \frac{25681}{61^2}&=\frac{421}{61}=7-\frac{6}{61}\\ \frac{26047}{61^2}&=7\\ \frac{26413}{61^2}&=\frac{433}{61}=7+\frac{6}{61} \end{align} $$Notice how \( \dfrac{6}{61} \approx 0.0983606557377049 <0.1\). Up to one million, there are the following such pairs of semiprimes that are equidistant from 7 because of the same mechanism. See Figure 2.


Figure 2: permalink to SageMathCell

Getting back to the closest approximations to 7, Figure 3 shows the top contenders. It can be seen that, generally speaking, the approximations get closer as the numbers get larger. We can surmise that for there exists semiprimes \(p \times q \) with \(p<q\) such that:$$ \lvert \frac{q}{p}-7 \rvert < \epsilon \text{ for any } \epsilon \text{ , no matter how small}$$

Figure 3: permalink to SageMathCell

So in the range up to one million, there are 307 semiprimes \(p \times q \) that meet the criterion and they all fit in within the brackets as shown in Figure 4. Infinitely many such semiprime ratios can be fitted into the space between the brackets.


Figure 4

These calculations of course can be carried out for any number, not just 7, and the algorithm I developed in SageMath allows for the number to be changed. For example, Figure 5 shows the semiprimes in the range up to one million that approximate 11 most closely within the range \( \pm 0.1 \):


Figure 5: permalink to SageMathCell

Figure 6 shows that there are again pairs of semiprimes that are equidistant from 11, one above and one below:


Figure 6: permalink to SageMathCell

Let's look at the first row in Figure 6: 946097 and 942581 with an average of 944339. This will serve to give us practice in understanding why such pairs exist.$$ 946097 =293 \times 3229\\944339=11 \times 293^2\\942581=293 \times 3217$$Again rewrite the factorisation of the average so that we have:$$ 946097 =293 \times 3229\\944339=293 \times 3223\\942581=293 \times 3217$$Let's divide all three by \(293^2\) to get:$$ \begin{align} \frac{946097}{293^2}&=\frac{3229}{293}=11+\frac{6}{293}\\ \frac{944339}{293^2}&=11\\ \frac{942581}{293^2}&=\frac{3217}{293}=11-\frac{6}{293} \end{align} $$Again we note that \( \dfrac{6}{293} \approx 0.0204778156996587 <0.1\).

Let's designate the whole number that we are interested in as \(n\). So far we've looked at 7 and 11 as specific examples. In general, these semiprime pairs occur when there exists a multiple of \(n\) of the form \(n \times p^2\) where \(p\) is a prime. This number can be written as \(np \times p\). The two semiprimes, one above and one below, must contain this \(p\) as one of their factors with the other factors being \( np-a \) and \( np+a \) respectively, where \(a\) is some integer. Thus we have three numbers in arithmetic progression:$$p \times (np-a), np \times p,p \times (np+a)$$Dividing all terms by \(p^2\) gives:$$n-\frac{a}{p}, \, n, \, n+\frac{a}{p}$$with \(\dfrac{a}{p}\) needing to be less than an agreed size e.g. 0.1.