Prime functions & generators¶
- boring_math.number_theory.is_prime(n: int, /) bool¶
is prime
Test if argument is a prime number, uses Wilson’s Theorem.
- param n:
Integer to check if prime.
- returns:
True only if n is prime.
- boring_math.number_theory.primes(start: int = 2, end: int | None = None) Iterator[int]¶
primes
Generate all primes p where start <= p <= end.
- param start:
First value to check, defaults to 2.
- param end:
Optional last value to check.
- yields:
All primes between start and end inclusive.
Warning
If end is not given, returned iterator is infinite.
- boring_math.number_theory.primes_capped(start: int, end: int) Iterator[int]¶
primes capped
Generate all primes
start <= p <= end.- param start:
First value to check.
- param start:
Last value to check.
- yields:
All primes p where
start <= p <= end.
- boring_math.number_theory.primes_wilson(start: int = 2) Iterator[int]¶
primes via Wilson’s theorem
Prime number generation using Wilson’s Theorem.
- param start:
First value to check, defaults to 2.
- yields:
Prime numbers tarting from n.
Note
Wilson’s Theorem:
∀(n>1) n is prime if and only if (n-1)! % n ≡ -1