Integer
Integer
Integer()Methods
| Name | Description |
|---|---|
chinese_remainder |
Solve the Chinese remainder theorem for the equations: x = n1 mod m1 and x = n2 mod m2. |
extended_gcd |
Compute the greatest common divisor of the numbers a and b and the Bézout coefficients. |
factor |
Factor the 64-bit number n into its prime factors and return a list of tuples (p, e) where p is a prime factor and e is its exponent. |
gcd |
Compute the greatest common divisor of the numbers a and b. |
is_prime |
Check if the 64-bit number n is a prime number. |
lcm |
Compute the least common multiple of the numbers a and b. |
prime_iter |
Create an iterator over all 64-bit prime numbers starting from start. |
solve_integer_relation |
Use the PSLQ algorithm to find a vector of integers a that satisfies a.x = 0, where every element of a is less than max_coeff, using a specified tolerance and number of iterations |
totient |
Compute the Euler totient function of the number n, i.e., the number of integers less than n that are coprime to n. |
chinese_remainder
Integer.chinese_remainder(n1: int, m1: int, n2: int, m2: int) -> intSolve the Chinese remainder theorem for the equations: x = n1 mod m1 and x = n2 mod m2.
Parameters
n1(int) The first residue.m1(int) The modulus for the first congruence.n2(int) The second residue.m2(int) The modulus for the second congruence.
extended_gcd
Integer.extended_gcd(a: int, b: int) -> tuple[int, int, int]Compute the greatest common divisor of the numbers a and b and the Bézout coefficients.
Parameters
a(int) The first integer.b(int) The second integer.
factor
Integer.factor(n: int) -> Sequence[tuple[int, int]]Factor the 64-bit number n into its prime factors and return a list of tuples (p, e) where p is a prime factor and e is its exponent.
Parameters
n(int) The integer to factor.
gcd
Integer.gcd(a: int, b: int) -> intCompute the greatest common divisor of the numbers a and b.
Parameters
a(int) The first integer.b(int) The second integer.
is_prime
Integer.is_prime(n: int) -> boolCheck if the 64-bit number n is a prime number.
Parameters
n(int) The integer to test for primality.
lcm
Integer.lcm(a: int, b: int) -> intCompute the least common multiple of the numbers a and b.
Parameters
a(int) The first integer.b(int) The second integer.
prime_iter
Integer.prime_iter(start: int = 1) -> Iterator[int]Create an iterator over all 64-bit prime numbers starting from start.
Parameters
start(int) The starting index or value.
solve_integer_relation
Integer.solve_integer_relation(
x: Sequence[int | float | complex | Decimal],
tolerance: float | Decimal,
max_coeff: int | None = None,
gamma: float | Decimal | None = None,
) -> Sequence[int]Use the PSLQ algorithm to find a vector of integers a that satisfies a.x = 0, where every element of a is less than max_coeff, using a specified tolerance and number of iterations. The parameter gamma must be more than or equal to 2/sqrt(3).
Examples
Solve a 32.0177=b*pi+c*e where b and c are integers:
r = Integer.solve_integer_relation([-32.0177, 3.1416, 2.7183], 1e-5, 100)
print(r) # [1,5,6]Parameters
x(Sequence[int | float | complex | Decimal]) The numeric vector for which an integer relation is sought.tolerance(float | Decimal) The tolerance used to accept an integer relation.max_coeff(int | None) The maximum coefficient size to consider.gamma(float | Decimal | None) The PSLQ gamma parameter controlling the reduction strategy.
totient
Integer.totient(n: int) -> intCompute the Euler totient function of the number n, i.e., the number of integers less than n that are coprime to n.
Parameters
n(int) The integer whose Euler totient should be computed.