galactic.algebras.lattice.examples.arithmetic.core

galactic.algebras.lattice.examples.arithmetic.core#

Defines classes and function for performing basic arithmetic operations.

Classes

Functions


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:

int

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:

int

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:

Iterator[int]

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:

Iterator[tuple[int, int]]

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: Element

Represents 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:

str

property value: int#

Get the integer value.

Returns:

The integer value

Return type:

int