Skip to main content

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!

Metadata

Release files for PrymePython 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PrymePython 0.0.12
File Size Uploaded
prymepython-0.0.12.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PrymePython 0.0.12
File Interpreter ABI Platform
PrymePython-0.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / prymepython-0.0.12.tar.gz

Download URL prymepython-0.0.12.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
11e93e053caff77e8f901fc1a0f39b0fcc3404559bfd3d17954f3d19d1e383b1
BLAKE2b-256 checksum
How to use checksums
7ae56fe3d8a1c44fa19a5dbe2c685a35d9ac510dc64f4335fb0c2c2ee9de89f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / PrymePython-0.0.12-py3-none-any.whl

Download URL PrymePython-0.0.12-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
277eec11d80e4b294bb27f2e66f6baa0f8b7c87765b609ec3787e4256088d525
BLAKE2b-256 checksum
How to use checksums
ba10fd942438718599e3976f3b659f541ab2d1b4bc6e1e1df5cdb9b4a0a32d8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files

0.0.11

2 release files

0.0.10

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page