The built-in functions in this topic are useful for investigations in number theory.  Additional functions for this purpose are defined in the utility file NumberTheoryFunctions.mth19ICN1P.


The functions GCD and LCM can take any number of arguments, a vector, or a matrix.  If given a vector (see Vectors and MatricesVectors_and_Matrices ), they are applied to the elements of the vector.  If given a matrix, they are applied to the rows of the matrix, and the results are returned as a vector.


GCD(m1, m2, ..., mn) simplifies to the greatest common divisor of the numbers m1, m2, ..., mn.  For example, GCD(6, 15) simplifies to 3.


LCM(m1, m2, ..., mn) simplifies to the least common multiple of the numbers m1, m2, ..., mn.  For example, LCM([6, 15, 14]) simplifies to 210.  If m or n are not numbers, LCM(m, n) simplifies to the equivalent expression ABS(m·n)/GCD(n, m).


INVERSE_MOD(a, m) simplifies to the inverse of a mod m if it exists, and a question mark otherwise.  For example, to determine the inverse of 37 mod 53, simplify the expression

INVERSE_MOD(37, 53)


POWER_MOD(a, n, m) returns a^n mod m.  For example, to raise 2 to the 500th power mod 100, simplify the expression

POWER_MOD(2, 500, 100)


PRIME?(m) simplifies to true if m is a prime; to false if m is a non-prime number; otherwise it does not simplify further.  A prime is an integer greater than 1 and divisible only by itself and 1.  The methods used to test primality include the prime number sieve, the Rabin-Miller primality test, and the Lucas primality test.  For example,

PRIME?(22564845703)

simplifies to false, since 22564845703 equals 106219 · 212437.


NEXT_PRIME(m) simplifies to the next prime larger than the number m.  It uses the same primality tests as the function PRIME?.  For example,

NEXT_PRIME(1000)

simplifies to 1009.


PREVIOUS_PRIME(m) simplifies to the first prime number smaller than the number m, if one exists; otherwise it simplifies to ?.  It uses the same primality tests as the function PRIME?.  For example,

PREVIOUS_PRIME(1000)

simplifies to 997.


Other Built-in Functions and ConstantsBuilt_in_Functions_and_Constants 

Created with the Personal Edition of HelpNDoc: Free CHM Help documentation generator