randomsymplectic.dnary_arithmetic

int_to_dnary(n, d, result_list_size=None)

Decomposes a base 10 integer into a list of its -nary digits.

See also dnary_to_int.

Parameters:
  • n (int) –

    The base 10 integer to be factored into its -nary digits.

  • result_list_size (int | None, default: None ) –

    The length of the list to return; if None, will use the minimum number of digits to result the input integer in -nary. Defaults to None.

Raises:
  • ValueError

    Invalid input parameters.

Returns:
  • list[int]

    A list of the -nary digits of n The list has elements such that

dnary_to_int(digits, d)

Given a list of the -nary digits of a number, return that number in base 10.

See also int_to_dnary.

Parameters:
  • digits (list[int]) –

    A list of the -nary digits of a number.

Returns:
  • int

    The number in base 10.

dnary_inverse(n, d)

Calculates the multiplicative inverse of n in if it exists.

If is prime and , the integer is guaranteed to exist. For general , exists if .

Parameters:
  • n (int) –

    The integer to invert.

  • d (int) –

    The modulus to invert by.

Returns:
  • int | None

    The integer such that , or None if such an integer does not exist.