Primes

com.phasmidsoftware.number.core.numerical.Primes
object Primes

Object providing utility methods related to prime numbers, including generating primes, checking primality, applying mathematical functions, and working with predefined sets of prime numbers and special cases such as Carmichael numbers.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Primes.type

Members list

Value members

Concrete methods

def bigInts(x: BigInt): LazyList[BigInt]

Create a lazy list of BigInts starting with x.

Create a lazy list of BigInts starting with x.

Value parameters

x

the first BigInt that is required.

Attributes

Returns

a LazyList[BigInt] whose head is x.

def eSieve(m: Int): List[Prime]

Generates a list of prime numbers less than or equal to a given upper bound using the Sieve of Eratosthenes algorithm.

Generates a list of prime numbers less than or equal to a given upper bound using the Sieve of Eratosthenes algorithm.

Value parameters

m

the upper bound (inclusive) for the prime numbers to be generated.

Attributes

Returns

a list of prime numbers represented as Prime objects, where each prime is less than or equal to the given upper bound.

def piApprox(x: BigInt): Double

Method to yield the "prime counting function" aka "piApprox" for a given number. The result is an approximation to the number of primes not greater than x.

Method to yield the "prime counting function" aka "piApprox" for a given number. The result is an approximation to the number of primes not greater than x.

Value parameters

x

the ordinal position in the list of primes of the prime number required.

Attributes

Returns

an approximation to the kth prime number.

def probablePrimes(f: Prime => Boolean): List[Prime]

Filters and returns a finite list of prime numbers based on a given predicate. Throws a PrimeException if the filter does not yield a finite list of primes.

Filters and returns a finite list of prime numbers based on a given predicate. Throws a PrimeException if the filter does not yield a finite list of primes.

Value parameters

f

the predicate function applied to candidate primes. Only primes for which this function returns true will be included in the result.

Attributes

Returns

a finite list of primes that satisfy the given predicate.

Note

Throws PrimeException if the predicate results in an infinite list of primes.

def randomPrime(bits: Int): Prime

Method to generate a random prime of size bits bits.

Method to generate a random prime of size bits bits.

Value parameters

bits

the size of the resulting Prime in bits.

Attributes

Returns

a Prime number with certainly 2.pow(-100).

def smallPrimes(x: BigInt): LazyList[Prime]

Method to yield a lazy list of all probable primes smaller than x.

Method to yield a lazy list of all probable primes smaller than x.

Attributes

Returns

a LazyList[Prime].

Concrete fields

lazy val allPrimes: LazyList[Prime]

Method to yield a lazy list of all probable primes.

Method to yield a lazy list of all probable primes.

Attributes

Returns

a LazyList[Prime].

val carmichael: SortedSet[BigInt]

The first Carmichael numbers, i.e numbers which satisfy Fermat's little theorem but are composite.

The first Carmichael numbers, i.e numbers which satisfy Fermat's little theorem but are composite.

Attributes

val hundredPrimes: SortedSet[Prime]

The first 100 true primes.

The first 100 true primes.

Attributes