Skip to main content

A python package for prime number utilities.

Project description

Pryme: A Python Module for Working with Prime Numbers

The Pryme package provides various utilities for working with prime numbers. This document outlines the functions available in the package, along with their descriptions and usage.

Dependencies

The package requires the following libraries:

  • math
  • functools (for lru_cache)
  • random
  • sympy
  • itertools (for permutations)

Installation

pip install PrymePython

Usage

import Pryme as pm


x=pm.mersenne(10)
y=pm.sophie(12)
z=pm.twins(23)

print(x)
print(y)
print(z)

Functions

list_primes(n)

Generates a list of all prime numbers up to a given number n using the Sieve of Eratosthenes algorithm.

Parameters:

  • n (int): The upper limit up to which prime numbers are generated.

Returns:

  • List of integers representing prime numbers up to n.

get_primes()

Returns a cached list of all prime numbers up to 2,000,000. If the list has not been created yet, it will be generated.

Returns:

  • List of integers representing prime numbers up to 2,000,000.

is_prime(n)

Determines if a given number n is prime by checking its divisibility.

Parameters:

  • n (int): The number to check.

Returns:

  • Boolean: True if n is prime, otherwise False.

sum_primes(n)

Calculates the sum of all prime numbers up to a given number n.

Parameters:

  • n (int): The upper limit up to which primes are summed.

Returns:

  • Integer: Sum of all prime numbers up to n.

prime_factors(n)

Returns a list of the prime factors of a given number n.

Parameters:

  • n (int): The number for which to find prime factors.

Returns:

  • List of integers representing the prime factors of n.

next_prime(n)

Finds the next prime number greater than n using caching to speed up repeated calls.

Parameters:

  • n (int): The number to find the next prime after.

Returns:

  • Integer: The next prime number greater than n.

previous_prime(n)

Finds the largest prime number smaller than n using caching to speed up repeated calls.

Parameters:

  • n (int): The number to find the previous prime before.

Returns:

  • Integer: The largest prime number smaller than n.

count_primes(n)

Returns the count of all prime numbers up to a given number n.

Parameters:

  • n (int): The upper limit up to which primes are counted.

Returns:

  • Integer: Count of all prime numbers up to n.

prime_product(n)

Calculates the product of all prime numbers up to a given number n.

Parameters:

  • n (int): The upper limit up to which primes are multiplied.

Returns:

  • Integer: Product of all prime numbers up to n.

prime_sum_pairs(n)

Finds pairs of prime numbers whose sum is also a prime.

Parameters:

  • n (int): The upper limit for prime numbers to consider.

Returns:

  • List of tuples: Each tuple contains a pair of primes whose sum is also a prime.

mirror(n)

Generates a list of the first n primes that remain prime when their digits are reversed.

Parameters:

  • n (int): The number of mirror primes to generate.

Returns:

  • List of integers: Mirror primes.

twins(n)

Returns a list of the first n twin prime pairs (pairs of primes that differ by 2).

Parameters:

  • n (int): The number of twin prime pairs to find.

Returns:

  • List of tuples: Each tuple contains a pair of twin primes.

sophie(n)

Finds the first n Sophie Germain primes, which are primes p such that 2p + 1 is also prime.

Parameters:

  • n (int): The number of Sophie Germain primes to find.

Returns:

  • List of integers: Sophie Germain primes.

sexy(n)

Generates the first n sexy prime pairs, where two primes differ by 6.

Parameters:

  • n (int): The number of sexy prime pairs to generate.

Returns:

  • List of tuples: Each tuple contains a pair of sexy primes.

randprime()

Returns a random prime number from the cached list of primes.

Returns:

  • Integer: A random prime number.

cuban_first(n)

Finds the first n Cuban primes of the first kind.

Parameters:

  • n (int): The number of Cuban primes of the first kind to find.

Returns:

  • List of integers: Cuban primes of the first kind.

cuban_second(n)

Finds the first n Cuban primes of the second kind.

Parameters:

  • n (int): The number of Cuban primes of the second kind to find.

Returns:

  • List of integers: Cuban primes of the second kind.

lucas_test(n, k)

Performs the Lucas primality test k times on a number n to determine if it's prime, composite, or possibly composite.

Parameters:

  • n (int): The number to test.
  • k (int): The number of times to perform the test.

Returns:

  • String: "prime", "composite", or "possibly composite".

prime_digit_sum(n)

Checks if the sum of the digits of a prime number is also prime.

Parameters:

  • n (int): The prime number to check.

Returns:

  • Boolean: True if the sum of the digits of n is also prime, otherwise False.

prime_count_estimate(n)

Provides an estimate of the number of prime numbers less than or equal to a given number n using the Prime Number Theorem (PNT).

Parameters:

  • n (int): The upper limit for estimating the count of primes.

Returns:

  • Integer: Estimated count of prime numbers less than or equal to n.

mersenne(n)

Returns the first n Mersenne primes (primes of the form 2^p - 1 where p is also prime).

Parameters:

  • n (int): The number of Mersenne primes to find.

Returns:

  • List of integers: Mersenne primes.

Note: Mersenne Primes are extremeley expensive to compute. The function works fine to return up to 10 mersenne primes but grows slower as it returns more Mersenne primes. It took me roughly 1 minute to generate 20 Mersenne primes. Proceed with caution!

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

prymepython-0.0.11.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

PrymePython-0.0.11-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file prymepython-0.0.11.tar.gz.

File metadata

  • Download URL: prymepython-0.0.11.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for prymepython-0.0.11.tar.gz
Algorithm Hash digest
SHA256 099890962190beb6f1b328b4057c750458c5bfebc6dce24524adb3aa22961edd
MD5 fcd3ee5d2aa29154a9ec50054f7b74de
BLAKE2b-256 5f7a42cd508e2d421b88dd8f29e0914e8392c2f147ee3898788b81f596ccbcee

See more details on using hashes here.

File details

Details for the file PrymePython-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: PrymePython-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for PrymePython-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 3f71656c05ec29c759107f3b967d7802df5c399965e691ca8a8eab3e8c193b51
MD5 38104ae842c9761aca46ca2e735d6359
BLAKE2b-256 f6358138b5b5e82fa83b8862d82a89178ea92bd735766f6040a81e6dff7010a9

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