9.36 IntegerNumberTheoryFunctions¶

The IntegerNumberTheoryFunctions package contains a variety of operations of interest to number theorists. Many of these operations deal with divisibility properties of integers. (Recall that an integer a divides an integer b if there is an integer c such that b = a * c.)

The operation divisorsdivisorsIntegerNumberTheoryFunctions returns a list of the divisors of an integer.

div144 := divisors(144)


 [1,2,3,4,6,8,9,12,16,18,24,36,48,72,144]

Type: List Integer

You can now compute the number of divisors of 144 and the sum of the divisors of 144 by counting and summing the elements of the list we just created.

#(div144)


 15

Type: PositiveInteger

reduce(+,div144)


 403

Type: PositiveInteger

Of course, you can compute the number of divisors of an integer n, usually denoted d(n), and the sum of the divisors of an integer n, usually denoted (n), without ever listing the divisors of n.

In FriCAS, you can simply call the operations numberOfDivisorsnumberOfDivisorsIntegerNumberTheoryFunctions and sumOfDivisorssumOfDivisorsIntegerNumberTheoryFunctions.

numberOfDivisors(144)


 15

Type: PositiveInteger

sumOfDivisors(144)


 403

Type: PositiveInteger

The key is that d(n) and (n) are multiplicative functions. This means that when n and m are relatively prime, that is, when n and m have no prime factor in common, then d(nm) = d(n) d(m) and (nm) = (n) (m). Note that these functions are trivial to compute when n is a prime power and are computed for general n from the prime factorization of n. Other examples of multiplicative functions are (n), the sum of the k-th powers of the divisors of n and , the number of integers between 1 and n which are prime to n. The corresponding FriCAS operations are called sumOfKthPowerDivisorssumOfKthPowerDivisorsIntegerNumberTheoryFunctions and eulerPhieulerPhiIntegerNumberTheoryFunctions.

An interesting function is λ(n), the Möbius λ function, defined as follows: λ(1) = 1, λ(n) = 0, when n is divisible by a square, and λ=(-1)k, when n is the product of k distinct primes. The corresponding FriCAS operation is moebiusMumoebiusMuIntegerNumberTheoryFunctions. This function occurs in the following theorem:

Theorem (Möbius Inversion Formula):
Let f(n) be a function on the positive integers and let F(n) be

defined by F(n)=∑d|nf(n) sum of f(n) over d | n where the sum is taken over the positive divisors of n. Then the values of f(n) can be recovered from the values of F(n): f(n)=∑d|nλ(n)F(nd) where again the sum is taken over the positive divisors of n.

When f(n) = 1, then F(n) = d(n). Thus, if you sum over the positive divisors d of n, you should always get 1.

f1(n) == reduce(+,[moebiusMu(d) * numberOfDivisors(quo(n,d)) for d in


divisors(n)])

Void

f1(200)


 1

Type: PositiveInteger

f1(846)


 1

Type: PositiveInteger

Similarly, when f(n) = n, then F(n) = (n). Thus, if you sum λ(d) (n/d) over the positive divisors d of n, you should always get n.

f2(n) == reduce(+,[moebiusMu(d) * sumOfDivisors(quo(n,d)) for d in


divisors(n)])

Void

f2(200)


 200

Type: PositiveInteger

f2(846)


 846

Type: PositiveInteger

The Fibonacci numbers are defined by F(1)=F(2)=1 and F(n)=F(n-1)+F(n-2) for n=3,4,….

The operation fibonaccifibonacciIntegerNumberTheoryFunctions computes the n-th Fibonacci number.

fibonacci(25)


 75025

Type: PositiveInteger

[fibonacci(n) for n in 1..15]


 [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610]

Type: List Integer

Fibonacci numbers can also be expressed as sums of binomial coefficients.

fib(n) == reduce(+,[binomial(n-1-k,k) for k in 0..quo(n-1,2)])


Void

fib(25)


 75025

Type: PositiveInteger

[fib(n) for n in 1..15]


 [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610]

Type: List Integer

Quadratic symbols can be computed with the operations legendrelegendreIntegerNumberTheoryFunctions and jacobijacobiIntegerNumberTheoryFunctions. The Legendre symbol (ap) is defined for integers a and p with p an odd prime number. By definition, (ap) = +1, when a is a square (mod p), (ap) = -1, when a is not a square (mod p), and (ap) = 0, when a is divisible by p.

You compute (ap) via the command legendre(a,p).

legendre(3,5)


 -1

Type: Integer

legendre(23,691)


 -1

Type: Integer

The Jacobi symbol (an) is the usual extension of the Legendre symbol, where n is an arbitrary integer. The most important property of the Jacobi symbol is the following: if K is a quadratic field with discriminant d and quadratic character χ, then χ(n)=(d/n). Thus, you can use the Jacobi symbol to compute, say, the class numbers of imaginary quadratic fields from a standard class number formula.

This function computes the class number of the imaginary quadratic field with discriminant d.

h(d) == quo(reduce(+, [jacobi(d,k) for k in 1..quo(-d, 2)]), 2 -


jacobi(d,2))

Void

h(-163)


1

Type: PositiveInteger

h(-499)


3

Type: PositiveInteger

h(-1832)


 26

Type: PositiveInteger