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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file primeclassify-0.1.4.tar.gz.

File metadata

  • Download URL: primeclassify-0.1.4.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for primeclassify-0.1.4.tar.gz
Algorithm Hash digest
SHA256 72a528bc5e7d0078a6f6ae62772ccf5235d26dd42420d2853d15ab93b6fd93fb
MD5 41b50038e9f781cc1893f5f600d83fda
BLAKE2b-256 30c810ca87d198e281cf1d4357ecf3e50d62816a466e83caf07f6d3da11c3bba

See more details on using hashes here.

File details

Details for the file primeclassify-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: primeclassify-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for primeclassify-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 625138e39de2312ae06d494e5d9ca12f97eb1bf88cbcd048231bf470d8a7213e
MD5 7dd6ddfbdeefcceff5470973dfca2fc5
BLAKE2b-256 6dd0dfa2df05815122a9d2788ff87282139d664afda7b444dee60df11fd40e2c

See more details on using hashes here.

Supported by

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