What’s in a Number?

I have been working on a computational number model for a couple of years now, it has given me some insights including those that led to the Colldilocks set. I call it PSpace, a model where only primes exist. I won’t go into the details here, but suggest that besides the Colldilocks Set, I have discovered a new approach to searching for prime numbers.

When we talk about numbers, we have some very concrete terms that help us understand the nature of the Natural Numbers. The Natural Numbers are the positive integers, and probably gave us the first practical application of number theory which is captured in the concept of cardinality. When we left the world of the hunter/gatherer and began to pursue agriculture and domestication of animals for help in fulfilling our basic need for food, we needed an abstract means by which we could measure and control production. In short, we left the world of one, the one next meal, the one next hunt for fruits, vegetables, and protein to meet caloric needs. When we began to produce, rather than hunt, we produced surplus. And surplus needed to be managed. Now, instead of hunting for one animal, we had to manage a flock and a field of produce. To manage a flock or baskets of grain, fruits, and vegetables we needed to know how many. How many cattle. How many sheep.

We needed to handle addition and subtraction to handle the herd replenishments by births or outside acquisition, and the losses by consumption or predation. Through time, we became more complex in our number theory through qualitative concepts such as Ordinality. We began to recognize the aspects of even and odd numbers, powers like squares and cubes, and basic aspects like prime and composite. Concepts grow and change. We changed our means of counting from notches on a stick, to knots on a rope, to stylus impressions on clay, and finally to glyphs on paper. Roman numerals gave way to numerical digits. We have standardized on the base ten number systems so that our representation of a magnitude could be grasped within the human mind as a series of the sums of products. The number 437 for instance is understood to be a shorthand for 4 * 100 + 3 * ten + 7 * 1. We created number systems as tally shortcuts for the cognitive limitations of our own brains. But suppose we would like to know how a number is factored. It may be easy to understand that 4 is 2 * 2, and 53 is a prime with only 1 and 53 as factors. But what about 40437121?

Factoring very large numbers is very hard and is the foundation of all internet security. The security of Public Key Infrastructure is based on this fact that allows me to publish my public key with no fear that my private key can be calculated because my public key is so large that a computer cannot factor it in reasonable time. But what if we could create a numerical model based on a dimensional space representing only the products of primes that could be searched via some heuristics that could map any given magnitude to its location in the space? This is one of my investigations. My world is PSpace which is a directed graph of nodes with three edge types. Diversity is the edge that manifests numerical difference. Purity is the edge that manifests numerical purity. Finally, Harmony is the edge that produces numerical hybridization. I will reserve further elaboration of this model to a future posting, but for now I can introduce a second discovery based on this model.

What follows is a python program that utilizes this conceptual model to generate the PSpace and produce the list of primes between one and N. It varies from our current sieve models, whether we use Eratosthenes, Sundaram, Atkins, or a wheel sieve, in that it only requires a single iterative loop for whatever value you choose for N. The sieve algorithms require multiple iterative loops, at least one for marking the truthfulness of primality for the current iteration’s magnitude, and then a final iteration to traverse the sieve to reap the primes. In the generation of the PSpace, we not only discover the prime numbers, but also record the factorization of all nodes within PSpace.

PSpacePrimes.py

#
#   Author:        Derwin Charles Skipp
#   Created Date:  16-Mar-2021
#   Description:   This program will generate primes using the PSpace hanging vector method
#
import math
import string
import sys

#   Program Globals

limit = int(pow(2, 20))        # set 1M as default limit
PSpace = {}
totalCalculations = 0
totalDiversityNonprime = 0
totalDiversityPrime = 1        # Must count 2 as the first prime
totalPurity = 0
totalHarmony = 0


# Hanging vectors for prime search

diversityHangingVector = {}
purityHangingVector = {}
harmonyHangingVector = {}

# Primes list

primesList = []

#
#   I like printf
#
def printf(format, *values):
    print(format % values, flush=True)

#
#
#
def prompt(prompt):
    print(prompt +": ", end='', flush=True),
    response = str(sys.stdin.readline())
    return response.rstrip()

#
#    Construct and populate a new PSpace node
#
def newNode(magnitude, parent, diversity, purity, harmony, dbase, dtail, ptail, htail):
    thisNode = {}
    thisNode["magnitude"] = magnitude
    thisNode["parent"] = parent
    thisNode["diversity"] = diversity
    thisNode["purity"] = purity
    thisNode["harmony"] = harmony
    thisNode["dbase"] = dbase
    thisNode["dtail"] = dtail
    thisNode["ptail"] = ptail
    thisNode["htail"] = htail
    return thisNode


##############################################################
#                                                            #
#   Generate the PSpace sequentially using hanging vectors   #
#                                                            #
##############################################################

#   This is the heart of the single threaded sequential generation of the PSpace 
#   It is a search to find thisNode's parent node and set the proper vector
#   to point to this new but not yet connected PSpace node.
#   It will either be the last determined prime's uncalculated vector and thus a new prime,
#   or match a precalculated hanging vector.
#   There are two options:
#   if magnitude matches a hangingVector, a calculated magnitude vector for an existing
#       PSpace node that does not have a corresponding PSpace node
#       update parent node hangingVector to thisNode and remove from hangingVector dictionary
#       calculate each hangingVector for thisNode and add them to hangingVector dictionary
#       populate thisNode's remaining attributes
#   else we found a prime!
#       set parentNode to lastPrime
#       insert this magnitude into primesList
#       set last found prime node to thisNode's parent and set diversityVector to thisNode
#       calculate parentNodes harmonyVector hangingVector for thisNode and add it to the hangingVector dictionary
#       populate thisNode's remaining attributes

# 
#   createPSpaceNode
#
def createPSpaceNode(magnitude): 
    global PSpace
    global totalCalculations
    global totalDiversityNonprime
    global totalDiversityPrime
    global totalPurity
    global totalHarmony
    global diversityHangingVector
    global purityHangingVector
    global harmonyHangingVector
    #   Note, since the probabilities of a node being a diversity,
    #   purity, harmony, or primary diversity (prime) occur with
    #   rising probabilities, they are tested for in that order;
    #   however, since primes occur with more frequency in a 
    #   magnitude bound pspace, they still have to wait until 
    #   all hanging vectors are checked.

    #   If this magnitude in the diversity hanging vector, we found a diversity node
    if magnitude in diversityHangingVector:
        #   We found a diversity composite
        totalDiversityNonprime += 1
        #
        #   update parent node hangingVector to thisNode and remove from hangingVector dictionary
        #
        parentMagnitude = diversityHangingVector[magnitude]
        parentNode = PSpace[parentMagnitude]
        del diversityHangingVector[magnitude]
        #
        #   calculate each hangingVector for this Node and add them to hangingVector dict
        #
        dbase = parentNode["dbase"]
        dtail = parentNode["dtail"] +1
        ptail = parentNode["ptail"] +1
        htail = parentNode["htail"] +1
        diversity = dbase * primesList[dtail]
        #
        #   since we are creating a magnitude bound PSpace, do not create a PSpace node > limit
        #
        if diversity <= limit:
            diversityHangingVector[diversity] = magnitude
        else:
            return
        purity    = magnitude * primesList[ptail]
        if purity <= limit:
            purityHangingVector[purity] = magnitude
        harmony   = magnitude * primesList[htail]
        if harmony <= limit:
            harmonyHangingVector[harmony] = magnitude
        #   Add 3 for diversity, purity, and harmony to total calculations
        totalCalculations += 3
        #   create thisNode and add it to PSpace
        thisNode = newNode(magnitude, parentMagnitude, diversity, purity, harmony, dbase, dtail, ptail, htail)
        PSpace[magnitude] = thisNode

    #   If this magnitude in the purity hanging vector, we found a purity node
    elif magnitude in purityHangingVector:
        #   We found a purity composite
        totalPurity += 1
        #
        #   update parent node hangingVector to thisNode and remove from hangingVector dict
        #
        parentMagnitude = purityHangingVector[magnitude]
        parentNode =PSpace[parentMagnitude]
        del purityHangingVector[magnitude]
        #   calculate each hangingVector for thisNode and add them to hangingVector dicts
        diversity = "";   # There is no diversity vector on a purity node!
        dbase = magnitude
        dtail = parentNode["dtail"]
        ptail = parentNode["ptail"]
        htail = ptail +1
        purity = magnitude * primesList[ptail]
        if purity <= limit:
            purityHangingVector[purity] = magnitude
        harmony = magnitude * primesList[htail]
        if harmony <= limit:
            harmonyHangingVector[harmony] = magnitude
        #   Add 2 for purity and harmony to total calculations
        totalCalculations += 2
        #   create thisNode and add it to PSpace
        thisNode = newNode(magnitude, parentMagnitude, diversity, purity, harmony, dbase, dtail, ptail, htail)
        PSpace[magnitude] = thisNode

    #   If this magnitude in the harmony hanging vector, we found a harmony node
    elif magnitude in harmonyHangingVector:
        totalHarmony += 1
        #   Get parent node
        parentMagnitude = harmonyHangingVector[magnitude]
        parentNode = PSpace[parentMagnitude]
        del harmonyHangingVector[magnitude]
        #
        #   calculate each hangingVector for thisNode and add them to hangingVector dict
        #
        dbase = parentNode["magnitude"]
        ptail = parentNode["htail"]
        htail = parentNode["htail"] +1
        dtail = htail
        diversity = dbase * primesList[dtail]
        diversityHangingVector[diversity] = magnitude
        purity  = magnitude * primesList[ptail]
        if purity <= limit:
            purityHangingVector[purity] = magnitude
        harmony = magnitude * primesList[htail]
        if harmony <= limit:
            harmonyHangingVector[harmony] = magnitude
        #   Add 3 for diversity, purity, and harmony to total calculations
        totalCalculations += 3
        #   create thisNode and add it to PSpace
        thisNode = newNode(magnitude, parentMagnitude, diversity, purity, harmony, dbase, dtail, ptail, htail)
        PSpace[magnitude] = thisNode
        #   Delete the completed parent PSpace node since it is no longer necessary for future calculations
        # del PSpace[parentMagnitude]
    #  PSpace conjecture 1: If this magnitude is not in a hanging vector then we found a prime!
    else:
        totalDiversityPrime += 1
        printf("%d", magnitude)
        #   get parentNode which will be the last prime magnitude
        lastPrimePtr = len(primesList) - 1
        lastPrime = primesList[lastPrimePtr]
        parentNode = PSpace[lastPrime]
        parentMagnitude = parentNode["magnitude"]
        #   insert this magnitude into primesList
        primesList.append(magnitude)
        #   set parent's diversity vector to thisNode's magnitude
        parentNode["diversity"] = magnitude
        #
        #   calculate parentNode's hanging harmonyVector and add to the harmonyHangingVector dict
        #
        parentHarmony = parentMagnitude * magnitude
        if parentHarmony <= limit:
            #
            #   now you can update the parent prime PSpace node with updated vectors
            #
            parentNode["harmony"] = parentHarmony
            harmonyHangingVector[parentHarmony] = parentMagnitude
        #
        #   calculate this node's hanging purity vector and add it to the hangingPurity dict
        #
        dbase     = magnitude
        dtail     = parentNode["dtail"] +1
        ptail     = parentNode["ptail"] +1
        htail     = parentNode["htail"] +1
        purity = magnitude * magnitude
        if purity < limit:
            purityHangingVector[purity] = magnitude
        #  Add 2 for purity, and parent harmony to total calculations
        totalCalculations += 2
        #   create thisNode and add it to PSpace
        thisNode = newNode(magnitude, parentMagnitude, "", purity, "", dbase, dtail, ptail, htail) # diversity & harmony are Unknown at this point
        PSpace[magnitude] = thisNode

#   findPSpacePrimes
#   Generate the root and first primary diversity node, and search for the next magnitude's location in the PSpace
#   with Node Magnitude, Node Type, Node Parent, Diversity, Purity, Harmony, DBase, dtail , pTail, and hTail
def findPSpacePrimes(): 
    #   prime the PSpace with the non prime and non composite anomalous root node of magnitude 1
    #   Note: The axiomatic declaration of 2 as the first prime is a programatic optimization to prevent the need
    #   to add a conditional check for first prime found within the createPSpaceNode() found prime code
    #   This way we do not have to make the determination of the root node update vs the prior prime node update
    #   But really, the determination of the primality of 2 would be found since all hanging vectors would be empty
    #   The root node with magnitude 1 is anomylous as the only PSpace node with undefined purity and harmony vectors
    #   The first prime node with magnitude 2 is anomylous as the only PSpace diversity node with an even magnitude
    #   All other PSpace nodes behave themselves with purity nodes lacking a defined diversity vector
    #   Call me, we can discuss.
    thisNode = newNode(1, "", 2, -1, -1, 1, 1, 1, 1)
    PSpace[1] = thisNode
    thisNode = newNode(2, 1, -1, 4, -1, 2, 0, 0, 1);
    PSpace[2] = thisNode
    printf("2")
    #   prime the primesList
    primesList.append(2)
    #    prime the purity hanging vector with 2^2
    purityHangingVector[4] = 2
    #    Generate the rest of PSpace up to defined limit
    for magnitude in range(3, limit+1):
        createPSpaceNode(magnitude)

###############################
#                             #
#   P R O G R A M   M A I N   #
#                             #
###############################

if (len(sys.argv) - 1) > 0:
    limit = int(sys.argv[1])
else:
    limit = 1000000
findPSpacePrimes()
print("Total calculations: {}    There are {} primes between 1 and {}".format(totalCalculations, len(primesList), limit ))
print("Total Diversity: nonprime {}   prime {}   Total Purity: {}   Total Harmony: {}".format(totalDiversityNonprime, totalDiversityPrime, totalPurity, totalHarmony))
print("Total Nodes {}".format(totalDiversityNonprime + totalDiversityPrime + totalPurity + totalHarmony + 1))

Please, let me know your thoughts about this PSpace prime search.

  • Update: 2022/05/30 PSpacePrimes.py updated to remove horrific bug producing erroneous prime list.
This entry was posted in Primes, PSpace and tagged , . Bookmark the permalink.

Leave a comment