Skip to main content

Library of functions to classify prime numbers

Project description

primeclassify

A library of functions to classify prime numbers

Each classification function takes an argument, p, which is assumed to be a prime number. There also are optional arguments tout and store. tout is the maximum processing time the function may take and store is the maximum number of data values it can store. These are self enforced. Some have additional optional arguments.

Generally, classifications that depend on a number base assume base 10.

Each returns one of:

  • False (p not a member of that classification), or
  • None (could not complete test), or
  • something other than False or None (p a member of that classification) — usually True, but sometimes additional information (such as, for twin primes, which primes it is a twin of)

A return value of None may mean it is literally unknown whether p is in that classification, or just that the function doesn't know and doesn't care to find out. For example, the largest known Mersenne prime is M82,589,933 = 282,589,933 − 1, but the mer function will return 'None' for any 'p' larger than M127.

There are in addition a few utility functions.

Example usage

from primeclassify import pc
import sympy

x = 137
# pc functions do not check for primality, do that first
if not sympy.isprime(x):
    print (f"{x} is not prime")
# Test if x is a Chen prime
# Limit time to 0.01 seconds, storage to 1000 numbers
if pc.chen(x, tout=.01, stor=1000):
    print (f"{x} is a Chen prime")

Output is

137 is a Chen prime

Classification functions

Utility functions

  • class_from_list (p, thelist, complete, limit=None) Used internally
  • describe(p, tout=0, stor=0, extras={higgs: (2,), williams: (3, 10)}) Returns a list of classifications passed by p. Functions are called with tout=tout, stor=stor. extras give limits for additional arguments.
  • test_classify (fn, limit1, limit2=-1, tout=0, stor=0, extra=None) Calls function fn for primes p in range [2, limit1] or [limit1, limit2], with tout=tout, stor=stor, and prints results. extra is extra argument for functions that take one.

Classifications not included

These are not integer primes:

These are just too hard for me to code!


Author: Rich Holmes
Source repository: https://gitlab.com/rsholmes/primeclassify

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

primeclassify-0.1.4.tar.gz (7.6 kB view hashes)

Uploaded Source

Built Distribution

primeclassify-0.1.4-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page