Showing posts with label building blocks. Show all posts
Showing posts with label building blocks. Show all posts

Saturday, 20 December 2025

Building Block Numbers Revisited

In January of 2025, I created a post titled Building Block Numbers about a very small set of positive integers that can be used to construct all other positive integers. These numbers form OEIS A086424:


A086424 Numbers needed to generate all other natural numbers, only allowing multiplication and addition. Each number can be used only once.


The initial numbers are: 

1, 2, 4, 11, 25, 64, 171, 569, 3406, 27697, 243374, 1759619, 28381401, 222323189, 3416307938, 26838745347, ...

Take my diurnal age today: 28020. Using these building blocks we can represent the number as (permalink):$$28020=(4 \times (171 + (2 \times (11 + 3406))))$$Let's compare this to its represention using products of primes:$$28020=2 \times 2 \times 3 \times 5 \times 467$$At first the difference in economy isn't apparent. Both methods require five numbers. With the first method we cannot repeat any of the numbers but with the second we can. The economy becomes apparent however, when we consider that up to but not including 243374, we only need ten building blocks (1, 2, 4, 11, 25, 64, 171, 569, 3406 and 27697) for every number in the range from 1 to 243373. It is only when we reach 243374 that an additional building block is required. By contrast there are 21494 primes in the same range and each of them is unique and can't be built out of smaller primes.

I got Gemini's NotebookLM to create an infographic and a video about these building blocks:


Infographic created by NotebookLM based on this blog post

The thing about these building blocks is that are independent of the number base being used. Table 1 shows the comparison of the base 10 with bases of 2, 8 and 16.


Table 1: 
permalink
Here is the video:


I've incorporated this way of building a number into the SageMath algorithm that I use to analyse the number associated with my diurnal age. However, as I thought about the code that Gemini had generated I remembered that there would often be more ways than one to represent a number and I realised that Gemini was serving up the first combination of building blocks that it came across. I then got Gemini to modify its code to display all possible solutions. For 28020, this turned out to be a staggering 796 solution. Many of these however, involved multiplication by 1. I asked Gemini to exclude these and the number fell to 166. Many of these involved the unnecessary use of brackets. After removing these, the final number came down to 16.

Found 16 unique, simplified solution(s):

\(28020 = 171 + 25 \times 569 + 3406 \times 4 \)
\(28020 = 4 \times (171 + 2 \times (11 + 3406)) \)
\(28020 = 171 + 27697 + 64 + 11 \times 2 \times 4 \)
\(28020 = 171 + 27697 + 4 \times (11 + 2 + 25) \)
\(28020 = 171 + 27697 + 2 \times (1 + 11 + 64) \)
\(28020 = 1 + 171 + 2 \times 4 \times (11 + 3406 + 64) \)
\(28020 = 1 + 2 + 11 \times (171 + 4 \times (25 + 569)) \)
\(28020 = 171 + 25 + 4 \times (2 \times 64 + 569 \times (1 + 11)) \)
\(28020 = 3406 + 569 + (1 + 2 + 25 \times 64) \times (11 + 4) \)
\(28020 = 1 + 569 + 64 + 2 \times (25 + 4 \times (11 + 3406)) \)
\(28020 = 3406 \times 4 + (1 + 171 + 64) \times (11 + 2 \times 25) \)
\(28020 = 11 + 25 + 171 \times 64 + (1 + 4) \times (2 + 3406) \)
\(28020 = 4 \times (1 + 11 \times (25 + 569) + 2 \times (171 + 64)) \)
\(28020 = 2 \times (3406 + 4 \times (1 + 569 + 11 \times 171)) + 25 \times 64 \)
\(28020 = 3406 + 64 + 2 * (25 + (1 + 4) \times (569 + 11 * 171)) \)
\(28020 = (1 + 4) \times (171 + 3406 + 569 + 2 \times (25 + 11 \times 64)) \)

Looking at these solutions it can be seen that they are ordered by number of terms used, fewer to more numerous. The first two solutions require only five building blocks and thus of course are to be preferred.

Friday, 31 January 2025

Building Block Numbers

The prime numbers are considered the building blocks of the positive integers because every composite number can be expressed as a product of prime numbers. However, the OEIS A086424 offers an alternative set of building blocks:


A086424 Numbers needed to generate all other natural numbers, only allowing multiplication and addition. Each number can be used only once.


These numbers are: 

1, 2, 4, 11, 25, 64, 171, 569, 3406, 27697, 243374, 1759619, 28381401, 222323189, 3416307938, 26838745347

Here is an extract from the OEIS comments:
  • 10 is not in the sequence because (4+1)*2 = 10.
  • 11 is in the sequence because there is no way to get 11 by using the earlier terms.
  • 509 is not in the sequence because
    509 = (1+25)*(2+11)+171.
The number associated with my diurnal age today is 27697 and this is the first number that cannot be expressed in terms of the numbers 1, 2, 4, 11, 25, 64, 171, 569 and 3406 using only multiplication or addition and using each number only once. From now on, up to but not including 243374, every number can be expressed in terms of 1, 2, 4, 11, 25, 64, 171, 569, 3406 and 27697. This is a big deal.

GEMINI WAS ABLE TO CHANGE PARI CODE
TO PYTHON AFTER A FEW TRIES

The OEIS comments offer some PARI code to generate this list of numbers and, after many errors on the part of Gemini, I was able to get to produce some working PYTHON code that will do the same job, albeit slowly. Here is the code:

from sage.all import *

def Ww(v):
    """
    Calculates the Ww function for a given list of integers.
    Args:
        v: A list of integers.
    Returns:
        A list of integers resulting from the Ww function.
    """
    if len(v) == 2:
        return [v[0], v[1], v[0] + v[1], v[0] * v[1]]
    else:
        V = []
        for i in range(len(v)):
            for j in range(i + 1, len(v)):
                t = v[:i] + v[i+1:j] + v[j+1:]
                if t:
                    V.extend(Ww(t + [v[i] + v[j]]))
                    V.extend(Ww(t + [v[i] * v[j]]))
        return sorted(set(V))  # Remove duplicates
a = [Integer(1), Integer(2), Integer(4)]
for n in range(3, 10):
    V = Ww(a)
    for i in range(2 * a[-1], len(V) + 1):
        if V[i - 1] > i:
            a.append(i)
            print(f"a = {a}")
            break
    else:
        print(f"No solution found for n = {n}")  
 

EVERY NUMBER UP TO BUT NOT INCLUDING 27697
CAN BE EXPRESSED IN TERMS OF
1, 2, 4, 11, 25, 64, 171, 569 and 3406
USING ONLY ADDITION AND MULTIPLICATION
AND USING ONE NUMBER ONLY ONCE

Of course the execution of this code on SageMathCell will quickly time out and it will only generate the numbers up to 171. However, running it in a Jupyter notebook on an M1 Macbook Air, it will generate the numbers up to 3406 fairly quickly but after an hour or so it never got to 27697 so I stopped it. 

I asked Gemini to come up with an algorithm in Python to express a given number in terms of these new "building blocks" but it consistently failed so I gave up. However, it will be easy initially for numbers greater than 27697. For example:

  • 27698 = 27697 + 1
  • 27699 = 27697 + 2
  • 27700 = 27697 + 2 + 1
  • 27701 = 27697 + 4 etc.

I'll continue to do this as an exercise associated with my daily number analysis. Figure 1 shows an analysis of the building block numbers and their factors. It can be seen that the only prime numbers are 2, 11, 569 and 27697. It should be noted that the property these numbers have collectively is NOT base dependent.

Figure 1

These particular building blocks are remarkably economical considering how many unique primes we would require to "build" all the numbers from 2 to 27697. It is in fact 3020. These blocks only require nine blocks: 1, 2, 4, 11, 25, 64, 171, 569 and 3406. They become even more economical for larger numbers. For example in the range up to 243373 (one less than 243374), we require 21494 unique primes but only ten of our new building blocks: 1, 2, 4, 11, 25, 64, 171, 569, 3406 and 27697. However, unlike the prime building blocks, representations using these new building blocks are not unique. For example, 12 can be represented as 11 + 1 or (1 + 2) * 4. Remember, bracketing is allowed.