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.12.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.12-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prymepython-0.0.12.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.12.tar.gz
Algorithm Hash digest
SHA256 11e93e053caff77e8f901fc1a0f39b0fcc3404559bfd3d17954f3d19d1e383b1
MD5 05b13215ba013e34b5bfb35dfe26d8c1
BLAKE2b-256 7ae56fe3d8a1c44fa19a5dbe2c685a35d9ac510dc64f4335fb0c2c2ee9de89f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PrymePython-0.0.12-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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 277eec11d80e4b294bb27f2e66f6baa0f8b7c87765b609ec3787e4256088d525
MD5 d47ded78a910ec423d2785bcc3c67231
BLAKE2b-256 ba10fd942438718599e3976f3b659f541ab2d1b4bc6e1e1df5cdb9b4a0a32d8d

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