1% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved. 2% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk. 3\newcommand{\IntegerNumberTheoryFunctionsXmpTitle}{IntegerNumberTheoryFunctions} 4\newcommand{\IntegerNumberTheoryFunctionsXmpNumber}{9.40} 5% 6% ===================================================================== 7\begin{page}{IntegerNumberTheoryFunctionsXmpPage}{9.40 IntegerNumberTheoryFunctions} 8% ===================================================================== 9\beginscroll 10 11% 12% 13% 14% 15% 16 17 18 19 20The \spadtype{IntegerNumberTheoryFunctions} package contains a variety of 21operations of interest to number theorists. 22%-% \HDindex{number theory}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 23Many of these operations deal with divisibility properties of integers. 24(Recall that an integer \spad{a} divides an integer \spad{b} if there is 25an integer \spad{c} such that \spad{b = a * c}.) 26 27\xtc{ 28The operation \spadfunFrom{divisors}{IntegerNumberTheoryFunctions} 29returns a list of the divisors of an integer. 30}{ 31\spadpaste{div144 := divisors(144) \bound{div144}} 32} 33\xtc{ 34You can now compute the number of divisors of \spad{144} and the sum of 35the divisors of \spad{144} by counting and summing the elements of the 36list we just created. 37}{ 38\spadpaste{\#(div144) \free{div144}} 39} 40\xtc{ 41}{ 42\spadpaste{reduce(+,div144) \free{div144}} 43} 44 45Of course, you can compute the number of divisors of an integer \spad{n}, 46usually denoted \spad{d(n)}, and the sum of the divisors of an integer 47\spad{n}, usually denoted \spad{sigma(n)}, 48%-% \HDindex{sigma@{$\sigma$}}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 49without ever listing the divisors of \spad{n}. 50 51\xtc{ 52In \Language{}, you can simply call the operations 53\spadfunFrom{numberOfDivisors}{IntegerNumberTheoryFunctions} and 54\spadfunFrom{sumOfDivisors}{IntegerNumberTheoryFunctions}. 55}{ 56\spadpaste{numberOfDivisors(144)} 57} 58\xtc{ 59}{ 60\spadpaste{sumOfDivisors(144)} 61} 62 63The key is that \spad{d(n)} and 64\spad{sigma(n)} 65are ``multiplicative functions.'' 66This means that when \spad{n} and \spad{m} are relatively prime, that is, when 67\spad{n} and \spad{m} have no prime factor in common, then 68\spad{d(nm) = d(n) d(m)} and 69\spad{sigma(nm) = sigma(n) sigma(m)}. 70Note that these functions are trivial to compute when \spad{n} is a prime 71power and are computed for general \spad{n} from the prime factorization 72of \spad{n}. 73Other examples of multiplicative functions are 74\spad{sigma\_k(n)}, the sum of the \eth{k} powers of 75the divisors of \spad{n} and \spad{phi(n)}, the 76number of integers between 1 and \spad{n} which are prime to \spad{n}. 77The corresponding \Language{} operations are called 78\spadfunFrom{sumOfKthPowerDivisors}{IntegerNumberTheoryFunctions} and 79\spadfunFrom{eulerPhi}{IntegerNumberTheoryFunctions}. 80%-% \HDindex{phi@{$\varphi$}}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 81%-% \HDindex{Euler!phi function@{$\varphi$ function}}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 82 83An interesting function is \spad{mu(n)}, 84%-% \HDindex{mu@{$\mu$}}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 85the Moebius mu function, defined 86%-% \HDindex{Moebius@{M\"{o}bius}!mu function@{$\mu$ function}}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 87as follows: 88\spad{mu(1) = 1}, \spad{mu(n) = 0}, 89when \spad{n} is divisible by a 90square, and 91\spad{mu(n) = (-1) ^ k}, when \spad{n} 92is the product of \spad{k} distinct primes. 93The corresponding \Language{} operation is 94\spadfunFrom{moebiusMu}{IntegerNumberTheoryFunctions}. 95This function occurs in the following theorem: 96 97\noindent 98{\bf Theorem} (Moebius Inversion Formula): \newline 99%\newline\indent{5} 100Let \spad{f(n)} be a function on the positive integers and let \spad{F(n)} 101be defined by 102\spad{F(n) =} sum of \spad{f(n)} over \spad{d | n} 103where the sum is taken over the positive divisors of \spad{n}. 104Then the values of \spad{f(n)} can be recovered from the values of 105\spad{F(n)}: 106\spad{f(n) =} sum of \spad{mu(n) F(n/d)} over \spad{d | n}, 107where again the sum is taken over the positive divisors of \spad{n}. 108 109\xtc{ 110When \spad{f(n) = 1}, then \spad{F(n) = d(n)}. 111Thus, if you sum \spad{mu(d) d(n/d)} 112over the positive divisors 113\spad{d} of \spad{n}, you should always get \spad{1}. 114}{ 115\spadpaste{f1(n) == reduce(+,[moebiusMu(d) * numberOfDivisors(quo(n,d)) for d in divisors(n)]) \bound{f1}} 116} 117\xtc{ 118}{ 119\spadpaste{f1(200) \free{f1}} 120} 121\xtc{ 122}{ 123\spadpaste{f1(846) \free{f1}} 124} 125\xtc{ 126Similarly, when \spad{f(n) = n}, then \spad{F(n) = sigma(n)}. 127Thus, if you sum 128\spad{mu(d) sigma (n/d)} over the positive divisors 129\spad{d} of \spad{n}, you should always get \spad{n}. 130}{ 131\spadpaste{f2(n) == reduce(+,[moebiusMu(d) * sumOfDivisors(quo(n,d)) for d in divisors(n)]) \bound{f2}} 132} 133\xtc{ 134}{ 135\spadpaste{f2(200) \free{f2}} 136} 137\xtc{ 138}{ 139\spadpaste{f2(846) \free{f2}} 140} 141 142%-% \HDindex{Moebius@{M\"{o}bius}!inversion formula}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 143%-% \HDindex{Dirichlet series}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 144%-% \HDindex{series!Dirichlet}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 145%-% \HDindex{zeta@$\zeta$}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 146%-% \HDindex{Riemann!zeta function@{$\zeta$ function}}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 147 148The Fibonacci numbers are defined by \spad{F(1) = F(2) = 1} and 149%-% \HDindex{Fibonacci numbers}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 150\spad{F(n) = F(n-1) + F(n-2)} for \spad{n = 3,4, ...}. 151\xtc{ 152The operation \spadfunFrom{fibonacci}{IntegerNumberTheoryFunctions} 153computes the \eth{n} Fibonacci number. 154}{ 155\spadpaste{fibonacci(25)} 156} 157\xtc{ 158}{ 159\spadpaste{[fibonacci(n) for n in 1..15]} 160} 161\xtc{ 162Fibonacci numbers can also be expressed as sums of binomial coefficients. 163}{ 164\spadpaste{fib(n) == reduce(+,[binomial(n-1-k,k) for k in 0..quo(n-1,2)]) \bound{fib}} 165} 166\xtc{ 167}{ 168\spadpaste{fib(25) \free{fib}} 169} 170\xtc{ 171}{ 172\spadpaste{[fib(n) for n in 1..15] \free{fib}} 173} 174 175Quadratic symbols can be computed with the operations 176\spadfunFrom{legendre}{IntegerNumberTheoryFunctions} and 177\spadfunFrom{jacobi}{IntegerNumberTheoryFunctions}. 178The Legendre symbol 179%-% \HDindex{Legendre!symbol}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 180\spad{(a/p)} 181is defined for integers \spad{a} and 182\spad{p} with \spad{p} an odd prime number. 183By definition, \spad{(a/p) = +1}, 184when \spad{a} is a square \spad{(mod p)}, 185\spad{(a/p) = -1}, 186when \spad{a} is not a square \spad{(mod p)}, and 187\spad{(a/p) = 0}, 188when \spad{a} is divisible by \spad{p}. 189\xtc{ 190You compute \spad{(a/p)} 191via the command \spad{legendre(a,p)}. 192}{ 193\spadpaste{legendre(3,5)} 194} 195\xtc{ 196}{ 197\spadpaste{legendre(23,691)} 198} 199The Jacobi symbol \spad{(a/n)} 200is the usual extension of the Legendre 201symbol, where \spad{n} is an arbitrary integer. 202The most important property of the Jacobi symbol is the following: 203if \spad{K} is a quadratic field with discriminant \spad{d} and quadratic 204character \spad{chi}, 205then \spad{chi}\spad{(n) = (d/n)}. 206Thus, you can use the Jacobi symbol 207%-% \HDindex{Jacobi symbol}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 208to compute, say, the class numbers of 209%-% \HDindex{class number}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 210imaginary quadratic fields from a standard class number formula. 211%-% \HDindex{field!imaginary quadratic}{IntegerNumberTheoryFunctionsXmpPage}{9.40}{IntegerNumberTheoryFunctions} 212\xtc{ 213This function computes the class number of the imaginary 214quadratic field with discriminant \spad{d}. 215}{ 216\spadpaste{h(d) == quo(reduce(+, [jacobi(d,k) for k in 1..quo(-d, 2)]), 2 - jacobi(d,2)) \bound{h}} 217} 218\xtc{ 219}{ 220\spadpaste{h(-163) \free{h}} 221} 222\xtc{ 223}{ 224\spadpaste{h(-499) \free{h}} 225} 226\xtc{ 227}{ 228\spadpaste{h(-1832) \free{h}} 229} 230\endscroll 231\autobuttons 232\end{page} 233% 234