Elementary functions¶
- boring_math.number_theory.gcd(m: int, n: int, /) int¶
gcd - greatest common divisor
Uses Euclidean algorithm to compute the gcd of two integers.
- param m:
First int for gcd calculation.
- param n:
Second int for gcd calculation.
- returns:
The gcd of the absolute values of m and n.
Note
mathematically the gcd of 0 and 0 does not exist
taking
gcd(0, 0) = 1Better choice than
math.gcd(0, 0) = 0.More mathematically justifieda.
Eliminates lcm & coprime having to edge case test.
- boring_math.number_theory.lcm(m: int, n: int, /) int¶
lcm - least common multiple
Find the least common multiple (lcm) of two integers.
- param m:
First int for lcm calculation.
- param n:
Second int for lcm calculation.
- returns:
The lcm of the absolute values of m and n.
- boring_math.number_theory.coprime(m: int, n: int, /) tuple[int, int]¶
coprime
Make 2 integers coprime by dividing out their common factors.
- param m:
First int for coprime calculation.
- param n:
Second int for coprime calculation.
- returns:
The coprimed values with original signs, also
(0, 0)whenn = m = 0.
- boring_math.number_theory.iSqrt(n: int, /) int¶
iSqrt - integer square root
Takes the integer square root of a non-negative integer.
- param n:
Integer whose integer square root is to be found.
- returns:
The unique
msuch thatm*m <= n < (m+1)*(m+1)- raises ValueError:
if
n < 0.
- boring_math.number_theory.isSqr(n: int, /) bool¶
isSqr
Determine if argument is a perfect square.
- param n:
Integer to check.
- returns:
True only if integer argument is a perfect square.