galactic.algebras.lattice.examples.arithmetic.core#
Defines classes and function for performing basic arithmetic operations.
Classes
Functions
gcd()See https://en.wikipedia.org/wiki/Greatest_common_divisorlcm()See https://en.wikipedia.org/wiki/Least_common_multipleprime_factors()to get the prime factors of a numberprime_powers()to get the prime powers of a number
- gcd(*elements)#
Compute the greatest common divisor of a collection of integers.
- Parameters:
*elements (
int) β A sequence of integers- Returns:
The greatest common divisor of the arguments
- Return type:
- Raises:
ValueError β If a value cannot be converted to an integer or if the converted value is less than 0
Notes
The greatest common divisor of 0 and 0 is 0.
The greatest common divisor of an empty set is 1.
- lcm(*elements)#
Compute the least common multiple of a collection of integers.
- Parameters:
*elements (
int) β A sequence of integers- Returns:
The least common multiple of the arguments
- Return type:
- Raises:
ValueError β If a value cannot be converted to an integer or if the converted value is less than 0
Notes
The least common multiple of an empty set is 1.
- prime_factors(number=1)#
Compute the prime factors of an integer.
- Parameters:
number (
int, default:1) β The number to decompose- Yields:
int β A prime factor of the number
- Return type:
Notes
Yields 0 if the number is 0.
Yields nothing if the number is 1.
- prime_powers(number=1)#
Compute the prime power decomposition of an integer.
- Parameters:
number (
int, default:1) β The number to decompose- Yields:
tuple[int, int] β A tuple containing a prime factor and its power
- Raises:
ValueError β If the number is negative
- Return type:
Notes
Yields (0, 1) if the number is 0.
Yields nothing if the number is 1.
The prime power decomposition of a prime number is a single tuple with the prime number and power 1.
The prime power decomposition of a composite number is a sequence of tuples, each containing a prime factor and its power.
- class PrimeFactors(value=1)#
Bases:
ElementRepresents a partially ordered relation between integers.
\(a \leq b\) is equivalent to \(a\) being a divisor of \(b\).
- Parameters:
value (
int, default:1) β An integer value- Raises:
ValueError β If the value is not a positive number
- latex()#
Return a LaTeX representation of the number using its prime factorization.
- Returns:
The LaTeX representation
- Return type: