Number Theory - Maple Help

 Number Theory

The NumberTheory package updates and replaces the numtheory package. There are several new applications and examples that use the new NumberTheory commands and, in addition, many commands have been added to the context menu.

$\mathrm{with}\left(\mathrm{NumberTheory}\right)$

 $\left[{\mathrm{AreCoprime}}{,}{\mathrm{CalkinWilfSequence}}{,}{\mathrm{CarmichaelLambda}}{,}{\mathrm{ContinuedFraction}}{,}{\mathrm{ContinuedFractionPolynomial}}{,}{\mathrm{CyclotomicPolynomial}}{,}{\mathrm{Divisors}}{,}{\mathrm{FactorNormEuclidean}}{,}{\mathrm{HomogeneousDiophantine}}{,}{\mathrm{ImaginaryUnit}}{,}{\mathrm{InhomogeneousDiophantine}}{,}{\mathrm{IntegralBasis}}{,}{\mathrm{InverseTotient}}{,}{\mathrm{IsCyclotomicPolynomial}}{,}{\mathrm{IsMersenne}}{,}{\mathrm{IsSquareFree}}{,}{\mathrm{IthMersenne}}{,}{\mathrm{JacobiSymbol}}{,}{\mathrm{KroneckerSymbol}}{,}{\mathrm{Landau}}{,}{\mathrm{LargestNthPower}}{,}{\mathrm{LegendreSymbol}}{,}{\mathrm{Möbius}}{,}{\mathrm{ModExtendedGCD}}{,}{\mathrm{ModularLog}}{,}{\mathrm{ModularRoot}}{,}{\mathrm{ModularSquareRoot}}{,}{\mathrm{Moebius}}{,}{\mathrm{MultiplicativeOrder}}{,}{\mathrm{Möbius}}{,}{\mathrm{NearestLatticePoint}}{,}{\mathrm{NextSafePrime}}{,}{\mathrm{NumberOfIrreduciblePolynomials}}{,}{\mathrm{NumberOfPrimeFactors}}{,}{\mathrm{Ω}}{,}{\mathrm{Φ}}{,}{\mathrm{PrimeCounting}}{,}{\mathrm{PrimeFactors}}{,}{\mathrm{PrimitiveRoot}}{,}{\mathrm{PseudoPrimitiveRoot}}{,}{\mathrm{QuadraticResidue}}{,}{\mathrm{RepeatingDecimal}}{,}{\mathrm{RootsOfUnity}}{,}{\mathrm{SumOfDivisors}}{,}{\mathrm{SumOfSquares}}{,}{\mathrm{ThueSolve}}{,}{\mathrm{Totient}}{,}{\mathrm{λ}}{,}{\mathrm{μ}}{,}{\mathrm{φ}}{,}{\mathrm{π}}{,}{\mathrm{σ}}{,}{\mathrm{τ}}{,}{\mathrm{ϕ}}\right]$ (1)

 MathApps  Sieve of Eratosthenes abc Conjecture Collatz Conjecture Fibonacci Numbers Goldbach's Conjecture Pascal's Triangle GCD and Euclid's Algorithm Euler's Identity The Juggler Sequence The 196 Algorithm

Many NumberTheory commands are available in the right-click context menu. For example, fractions can be shown as either a RepeatingDecimal or a ContinuedFraction:

Repeated Decimal

 1 Enter a fraction. For example, enter 3/7.

$\frac{3}{7}$

 2 Right-click (Control-click for Macintosh) the fraction, and then select Show as Repeating Decimal.

$\frac{3}{7}$$\stackrel{\text{repeated decimal}}{=}$${0.}\stackrel{{&conjugate0;}}{{428571}}$



Continued Fraction

 1 Enter a fraction. For example, enter 3/7.

$\frac{3}{7}$

 2 Right-click (Control-click for Macintosh) the fraction, and then select Show as Continued Fraction.

$\frac{3}{7}$$\stackrel{\text{continued fraction}}{=}$${0}{+}\frac{{1}}{{2}{+}\frac{{1}}{{3}{+}{0}}}$

Examples: Prime Numbers

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The top level ithprime(i) command returns the ith prime. For example, the first ten primes are given by the following sequence:

$\mathrm{seq}\left(\mathrm{ithprime}\left(i\right),i=1..10\right)$

 ${2}{,}{3}{,}{5}{,}{7}{,}{11}{,}{13}{,}{17}{,}{19}{,}{23}{,}{29}$ (1.1)

The top level isprime command determines if a given number is prime:

$\mathrm{isprime}\left(28\right)$

 ${\mathrm{false}}$ (1.2)

$\mathrm{isprime}\left(29\right)$

 ${\mathrm{true}}$ (1.3)

The Divisors command can also verify that a number is prime. If the divisors of a given integer are only 1 and itself, then the number is prime.

$\mathrm{Divisors}\left(28\right)$

 $\left\{{1}{,}{2}{,}{4}{,}{7}{,}{14}{,}{28}\right\}$ (1.4)

$\mathrm{Divisors}\left(29\right)$

 $\left\{{1}{,}{29}\right\}$ (1.5)

The SumOfDivisors command returns the sum of the divisors of an integer:

$\mathrm{SumOfDivisors}\left(28\right)$

 ${56}$ (1.6)

The top level ifactor command gives the integer factorization of an integer:

$\mathrm{ifactor}\left(28\right)$

 ${{}\left({2}\right)}^{{2}}{}\left({7}\right)$ (1.7)

The PrimeFactors command returns a list of factors for a given integer that are primes without multiplicity:

$\mathrm{PrimeFactors}\left(28\right)$

 $\left\{{2}{,}{7}\right\}$ (1.8)

The NumberOfPrimeFactors command returns the number of Prime Factors of an integer, counted with multiplicity:

$\mathrm{NumberOfPrimeFactors}\left(28\right)$

 ${3}$ (1.9)

The top level nextprime (or prevprime) commands return the next (or previous) prime number after (or before) the given integer:

$\mathrm{nextprime}\left(29\right)$

 ${31}$ (1.10)

The PrimeCounting command returns the number of primes less than a given integer:

$\mathrm{PrimeCounting}\left(31\right)$

 ${11}$ (1.11)

Two integers are relatively prime (coprime) if their greatest common divisor (gcd) is 1. The AreCoprime command tests if a sequence of integers or Gaussian integers are coprime:

$\mathrm{AreCoprime}\left(5,8\right)$

 ${\mathrm{true}}$ (1.12)

$\mathrm{AreCoprime}\left(2,8\right)$

 ${\mathrm{false}}$ (1.13)

The following plot shows the coprimes for the integers 1 to 15:

An integer is called square-free if it is not divisible by the square of another number other than 1. All prime numbers are square-free:

$\mathrm{IsSquareFree}\left(31\right)$

 ${\mathrm{true}}$ (1.14)

$\mathrm{IsSquareFree}\left(7\cdot 101\right)$

 ${\mathrm{true}}$ (1.15)

$\mathrm{IsSquareFree}\left(3\cdot {7}^{2}\right)$

 ${\mathrm{false}}$ (1.16)

Mersenne Primes

Mersenne Primes are prime numbers that are one less than a power of 2. These are numbers of the form:

${\mathbit{M}}_{\mathbit{n}}\mathbf{=}{\mathbf{2}}^{\mathbit{n}}\mathbf{-}\mathbf{1}$, where n is a positive integer.

The IthMersenne(i) command returns the exponent for the ith Mersenne prime number:

$\mathrm{IthMersenne}\left(4\right)$

 ${7}$ (1.1.1)

${2}^{7}-1$

 ${127}$ (1.1.2)

$\mathrm{isprime}\left({2}^{7}-1\right)$

 ${\mathrm{true}}$ (1.1.3)

The nextprime command returns the next prime number after the current value.

 ${131}$ (1.1.4)

The IsMersenne(n) command checks if a positive integer, n, is a Mersenne exponent such that ${2}^{n}-1$ is a Mersenne prime:

${2}^{2}-1$

 ${3}$ (1.1.5)

$\mathrm{IsMersenne}\left(2\right)$

 ${\mathrm{true}}$ (1.1.6)

${2}^{11}-1$

 ${2047}$ (1.1.7)

$\mathrm{IsMersenne}\left(11\right)$

 ${\mathrm{false}}$ (1.1.8)

$\mathrm{ifactor}\left({2}^{11}-1\right)$

 ${}\left({23}\right){}\left({89}\right)$ (1.1.9)



Examples: Arithmetic Functions

Euler's Totient Function

Euler's totient function is an arithmetic function that counts the positive integers less than or equal to a given value $n$ that are coprime to $n$. For a positive integer $n$, another number $k$ is said to be coprime, or relatively prime, if the greatest common divisor $\mathrm{gcd}\left(n,k\right)=1$. For example, 14 and 15 are coprime because the gcd of 14 and 15 is 1, but 14 and 21 are not coprime since their gcd is 7.

Euler's totient function is also known as Euler's phi function, denoted as $\mathrm{φ}\left(n\right)$ or $\mathrm{ϕ}\left(n\right)$.  As such, phi(n) and varphi(n) are aliases for the Totient command.

$\left[\mathrm{Totient}\left(21\right),\mathrm{\phi }\left(21\right),\mathrm{\varphi }\left(21\right)\right]$

 $\left[{12}{,}{12}{,}{12}\right]$ (2.1.1)

To visualize the first thousand values for $\mathrm{φ}\left(n\right)$:

The PrimeCounting(n) (or pi(n)) command returns the number of primes less than an integer n. The following plot compares pi(n) with phi(n) for the first 40 values for n:

Möbius function

The Möbius function is defined as a multiplicative arithmetic function, $\mathrm{μ}\left(r\right)$, where:

 • when r is a square-free positive integer with an even number of prime factors
 • when r is a square-free positive integer with an odd number of prime factors
 • when r has a squared prime factor

For example,  because 2 is a square-free positive integer which has 1 prime factor.  since 4 is not a square-free positive integer.

The first 75 values for the Möbius function are plotted below:



Examples: Calkin-Wilf Tree

The vertices of the Calkin-Wilf tree are labeled with rational numbers $\frac{a}{b}$. The root vertex is defined to be  and for any vertex $\frac{a}{b}$, its children are $\frac{a}{a+b}$ and $\frac{a+b}{b}$. Every positive rational number occurs exactly once in the Calkin-Wilf tree.

The first 16 terms of the Calkin-Wilf sequence are:

$\mathrm{seq}\left(\mathrm{CalkinWilfSequence}\left(n\right),n=1..16\right)$

 ${1}{,}\frac{{1}}{{2}}{,}{2}{,}\frac{{1}}{{3}}{,}\frac{{3}}{{2}}{,}\frac{{2}}{{3}}{,}{3}{,}\frac{{1}}{{4}}{,}\frac{{4}}{{3}}{,}\frac{{3}}{{5}}{,}\frac{{5}}{{2}}{,}\frac{{2}}{{5}}{,}\frac{{5}}{{3}}{,}\frac{{3}}{{4}}{,}{4}{,}\frac{{1}}{{5}}$ (3.1)

The Calkin-Wilf tree can be created using the GraphTheory package:

n = 15

n = 31

$\mathrm{DrawTree}\left(15\right);$