prdtools.math

prdtools.math.SPEED_OF_SOUND: numbers.Number = 343

Speed of sound in meters per second at 20°C (68°F)

prdtools.math.wavelength_meters(freq: int, sos: Optional[numbers.Number] = 343) numbers.Number[source]

Calculate the wavelength of the given frequency in meters

Parameters
prdtools.math.wavelength_cm(freq: int, sos: Optional[numbers.Number] = 343) numbers.Number[source]

Calculate the wavelength of the given frequency in centimeters

Parameters
prdtools.math.frequency_meters(wavelength: numbers.Number, sos: Optional[numbers.Number] = 343) numbers.Number[source]

Calculate the frequency of the given wavelength in meters

Parameters
prdtools.math.frequency_cm(wavelength: numbers.Number, sos: Optional[numbers.Number] = 343) numbers.Number[source]

Calculate the frequency of the given wavelength in centimeters

Parameters
prdtools.math.prim_roots(modulo: int) Iterable[int][source]

Calculate all primitive roots for the given modulo

prdtools.math.is_prim_root(root: int, modulo: int) bool[source]

Determine if the given root is a primitive root of modulo

prdtools.math.has_prim_roots(n: int) bool[source]

Determine if n has any primitive roots

True if \(\varphi (n) = \lambda (n)\)

prdtools.math.num_prim_roots(n: int) int[source]

Return the number of primitive roots of n

Uses the equation \(\varphi (\varphi (n))\)

prdtools.math.is_prime(n: int) bool[source]

Return True if n is a prime number

prdtools.math.is_coprime(a: int, b: int) bool[source]

Return True if a and b are coprime

prdtools.math.iter_divisors(total_size: int) Iterable[Tuple[int, int]][source]

Iterate over all possible numerator/denominator pairs of the given number

prdtools.math.iter_coprimes(total_size: int) Iterable[Tuple[int, int]][source]

Iterate over all coprime pairs for the given number

prdtools.math.prime_root_seq(prime_num: int, prime_root: Optional[int] = None) Iterable[int][source]

Calculate the primitive root sequence \(S_h\) for the given prime and its root

\[S_h = g ^ h \bmod{N}\]

where \(N\) = prime_num, \(g\) = prime_root and \(h\) is the sequence index (starting with 1). The sequence continues until the first repetition of \(S_h\).

Parameters
  • prime_num (int) – Prime number for the sequence

  • prime_root (Optional[int]) – A primitive root of the prime_num. If not given, an attempt will be made to find the first primitive root

prdtools.math.totient(n: int) int[source]

Compute Euler’s totient function \(\varphi (n)\)

prdtools.math.carmichael(n: int) int[source]

Compute the Carmichael function \(\lambda (n)\)