py3nt.functions.unary package

Submodules

py3nt.functions.unary.divisor_functions module

Divisor functions.

py3nt.functions.unary.divisor_functions.generate_divisors(n: int, factorizer: None | FactorizationFactory = None, factorization: None | dict[int, int] = None) ndarray[source]

Generate all positive divisors of a positive integer.

Parameters:
  • n (int) – A positive integer.

  • factorizer (Optional[FactorizationFactory], optional) – If specified, factorizer is used to factorize \(n\), by default None.

  • factorization (Optional[dict[int, int]], optional) – If specified, used as prime factorization of \(n\), by default None. Cannot be None if factorizer is also None.

Returns:

An unsorted numpy array of divisors: \({d\in\mathbb{N}:d\mid n}\).

Return type:

np.ndarray

Raises:

ValueError – If both factorizer and factorizer are None.

py3nt.functions.unary.divisor_functions.number_of_divisors(n: int, factorizer: None | FactorizationFactory, factorization: None | dict[int, int] = None) int[source]
Parameters:
  • n (int) – A positive integer.

  • factorizer (FactorizationFactory) – If a factorizer object is provided, then it is used to factorize \(n\) first. The prime factorization is used to calculate the divisor sum. Otherwise all positive integers not exceeding \(n\) are checked.

Returns:

Number of divisors of \(n\).

Return type:

int

py3nt.functions.unary.divisor_functions.sigma_kth(n: int, k: int, factorizer: FactorizationFactory | None, factorization: None | dict[int, int] = None) int[source]

Calculate the divisor sum function \(\sigma_{k}(n)=\sum_{d\mid n}d^{k}\).

Parameters:
  • n (int) – A positive integer.

  • k (int) – A positive integer.

  • factorizer (FactorizationFactory) – If a factorizer object is provided, then it is used to factorize \(n\) first. The prime factorization is used to calculate the divisor sum. Otherwise all positive integers not exceeding \(n\) are checked.

Returns:

Divisor sigma function \(\sum_{d\mid n}d^{k}\).

Return type:

int

py3nt.functions.unary.divisor_functions.sum_of_divisors(n: int, factorizer: None | FactorizationFactory, factorization: None | dict[int, int] = None) int[source]
Parameters:
  • n (int) – A positive integer.

  • factorizer (FactorizationFactory) – If a factorizer object is provided, then it is used to factorize \(n\) first. The prime factorization is used to calculate the divisor sum. Otherwise all positive integers not exceeding \(n\) are checked.

Returns:

Sum of divisors of \(n\).

Return type:

int

py3nt.functions.unary.totient module

Totient functions

py3nt.functions.unary.totient.carmichael(n: int, factorizer: None | FactorizationFactory = None, factorization: None | dict[int, int] = None) int[source]

Carmichael function \(\lambda(n)\). Also known as the universal exponent \(\pmod{n}\). Calculated using the prime factorization of \(n=p_{1}^{e_{1}}\cdots p_{k}^{e_{k}}\)

\[\begin{split}\lambda(2^{k+2}) = 2^{k}\\ \lambda(p^{k}) = p^{k-1}(p-1)\\ \lambda(ab) = \mbox{lcm}(\lambda(a), \lambda(b))\end{split}\]

if \(p\) is an odd prime and \(\gcd(a,b)=1\). Use this on the prime factorization.

Parameters:
  • n (int) – A positive integer.

  • factorizer (Optional[FactorizationFactory]) – If a factorizer object is provided, then it is used to factorize \(n\) first. The prime factorization is used to calculate the value.

  • factorization (Optional[dict]) – A dictionary of prime factorization. Keys must be primes. Values must be the corresponding multiplicities.

Returns:

\(\lambda(n)\).

Return type:

int

Raises:

ValueError – If \(n\) is not positive or both factorization and factorizer are None.

py3nt.functions.unary.totient.jordan(n: int, k: int, factorizer: None | FactorizationFactory = None, factorization: None | dict[int, int] = None) int[source]

Calculate Jordan’s Totient function of \(n\): The number of positive integer tuples \((a_{1},\ldots,a_{k})\) not exceeding \(n\). A generation of Euler’s Totient function.

\[\begin{split}J_{k}(n) = n^{k}\prod_{p\mid n}\left(1-\dfrac{1}{p^{k}}\right)\\ \varphi(n) = J_{1}(n)\end{split}\]
Parameters:
  • n (int) – A positive integer.

  • k (int) – A positive integer.

  • factorizer (Optional[FactorizationFactory]) – If a factorizer object is provided, then it is used to factorize \(n\) first. The prime factorization is used to calculate the value.

  • factorization (Optional[dict]) – A dictionary of prime factorization. Keys must be primes. Values must be the corresponding multiplicities.

Returns:

\(J_{k}(n)\).

Return type:

int

Raises:

ValueError – If both factorizer and factorization are none.

Module contents