A simple Python module for working with prime numbers, created by Munashe Mukweya.
- Introduction
- Features
- Installation
- Usage
- Functions
- firstNPrimes(n)
- isPrime(n)
- differences(n)
- sumOfPrimes(n)
- theNthPrime(n)
- sumOfDifferences(n)
- primeCounting(n)
- lcm(n)
- primeSlice(start, stop)
- primeDifferenceSlice(start, stop)
- modifyValues(array, operation, operand)
- randomPrimeSlice(start, stop, length)
- randomDifferencesSlice(start, stop, length)
- graphDifferences(n)
- graphPrimes(stop, operation, operand, start)
- sacksSpiral(n, coordinateRange, dotSize)
- differenceSpiral(n, coordinateRange, dotSize)
- Contributing
- License
This Python module provides a collection of functions for visualizing and performing operations with prime numbers. It is a simple tool for mathematical analysis and educational purposes.
- Generate the first 'n' prime numbers.
- Calculate the differences between successive prime numbers.
- Check a number for primality
- Find the 'n'-th prime number.
- Perform mathematical operations on prime numbers.
- Visualize prime numbers using graphical representations, including Sacks Spiral and graphs.
You can install this module using pip:
pip install wwp
To use this module, you can import all functions...
from wwp import *
...or specific functions
from wwp import _function_name_
Then you can use the function/s provided in the module
Returns an array containing the first 'n' prime numbers along the number line.
Arguments:
n (int): The number of prime numbers to generate.
Returns:
list: A list of the first 'n' prime numbers.
None: If 'n' is equal to 0.
Returns True if 'n' is prime and False if it is not.
Arguments:
n (int): The number to check for primality.
Returns:
Boolean: True if 'n' is prime and False if it is not.
None: If 'n' is equal to 0.
Returns an array containing the differences between successive prime numbers up to the 'n'-th prime.
Arguments:
n (int): The number of prime numbers to consider for difference calculation.
Returns:
list: A list of the differences between successive prime numbers.
None: If 'n' is equal to 0.
Calculates the sum of the first 'n' prime numbers.
Arguments:
n (int): The first 'n' prime numbers to add up.
Returns:
int: The sum of the first n prime numbers.
None: If 'n' is equal to 0.
Returns the 'n'-th prime number.
Arguments:
n (int): The position of the prime number.
Returns:
int: The 'n'-th prime number.
None: If 'n' is equal to 0.
Calculates the sum of differences between the first 'n' prime numbers.
Arguments:
n (int): The first 'n' prime numbers to consider.
Returns:
int: The sum of the differences between the first 'n' prime numbers.
None: If 'n' is equal to 0.
Returns the number of primes less than 'n'.
Arguments:
n (int): The positive integer for which you want to count the prime numbers less than it.
Returns:
int: The number of prime numbers less than 'n'.
None: If 'n' is equal to 0.
Calculates the lowest common multiple of the first 'n' primes.
Arguments:
n (int): The first 'n' prime numbers to consider.
Returns:
int: The lowest common multiple of the first 'n' prime numbers
None: If 'n' is equal to 0.
Returns an array of prime numbers between 'start' and 'stop' (inclusive).
Arguments:
start (int): The starting integer for the range.
stop (int): The ending integer for the range.
Returns:
list: A list of prime numbers within the inclusive range from 'start' to 'stop'.
Returns an array of the differences between successive prime numbers between 'start' and 'stop' (inclusive).
Arguments:
start (int): The starting integer for the range.
stop (int): The ending integer for the range.
Returns:
list: A list of the differences between the prime numbers within the inclusive range from 'start' to 'stop'.
Modifies an array using the specified 'operation' and 'operand' values.
Arguments:
array (arr): An array of integer values.
operation (str): The operation to perform on the prime numbers within the range. Valid values are "multiply" or "*", "divide" or "/", "subtract" or "-", "add" or "+", and "exponent" or "^".
operand (int, float or expression): The value to use as the operand for the specified operation.
Returns:
list: A list of integers after applying the specified 'operation' and 'operand'.
Generates a random selection of prime numbers within the inclusive range from 'start' to 'stop'.
Arguments:
start (int): The starting integer for the range.
stop (int): The ending integer for the range.
length (int): The number of prime numbers to include in the random selection.
Returns:
list: A list of prime numbers randomly selected from within the inclusive range between 'start' and 'stop'.
None: 'length' is equal to 0.
Generates a random selection of differences between successive prime numbers within the inclusive range from 'start' to 'stop'.
Arguments:
start (int): The starting integer for the range.
stop (int): The ending integer for the range.
length (int): The number of differences to include in the random range.
Returns:
list: A list of the differences between prime numbers randomly selected from within the inclusive range between 'start' and 'stop'.
None: 'length' is equal to 0.
Graphs the differences between the first 'n' successive prime numbers.
Arguments:
n (int): The number of successive prime numbers to consider for generating the graph.
Returns:
This function doesn't return any value; it generates and displays a graph.
None: if 'n' is equal to 0.
Plots and displays a graph comparing a set of regular and modified prime numbers.
Arguments:
stop (int): The ending integer for the range of primes.
operation (str, optional): The mathematical operation to apply to the prime numbers. Valid values are "multiply" or "*", "divide" or "/", "subtract" or "-", "add" or "+", and "exponent" or "^". Defaults to addition ("+").
operand (int, float, or expression, optional): The value to use as the operand for the specified operation. Defaults to 0.
start (int, optional): The starting integer for the range. Defaults to 1.
Returns:
This function doesn't return any value; it generates and displays a graph.
Draws a Sacks Spiral representation of the first 'n' prime numbers.
Arguments:
n (int): The first 'n' prime numbers to consider for drawing the Sacks Spiral.
coordinateRange (int, optional): The coordinate system's range for both axis. Defaults to 100.
dotSize (int, optional): The size of dots representing the prime numbers. Defaults to 5.
Returns:
This function doesn't return any value; it generates and displays a drawing.
Draws a spiral using the same rules of the Sacks Spiral using non-repeating differences
between the primes instead of the primes themselves. Uses turtle graphics library.
Arguments:
n (int): The limit of differences to consider for drawing the spiral.
coordinateRange (int, optional): The coordinate system's range for both axis. Defaults to 15.
dotSize (int, optional): The size of dots representing the differences. Defaults to 10.
Returns:
This function doesn't return any value; it generates and displays a graph.
If you wish to change or add something to the module you are welcome to. Just fork the repository, make your changes, create a pull request and wait for approval.
This project is licensed under the MIT License - see the LICENSE file for details.