Arithmetic Functions - Maple Help

Home : Support : Online Help : Mathematics : Number Theory : Examples : Arithmetic Functions

Number Theory: Arithmetic Functions

Getting Started

Many commands in this example worksheet are available at Maple's top level, meaning that no packages are required to be loaded. While any command in the Number Theory package can be referred to using the long form, for example, NumberTheory:-Totient, it is often easier to load the package and then use the short form command names as well.

 > restart;
 > with(NumberTheory):

Examples

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 the gcd is 7.

Euler's totient function is also known as Euler's phi function, and is denoted as $\mathrm{\phi }\left(n\right)$ or $\mathrm{\varphi }\left(n\right)$.  As such, $\mathrm{\phi }\left(n\right)$ and $\mathrm{\varphi }\left(n\right)$ 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]$ (1)

To visualize the first hundred values for phi(n):

 > $\mathrm{plots}:-\mathrm{pointplot}\left(\left[\mathrm{seq}\left(\left[n,\mathrm{Totient}\left(n\right)\right],n=2..100\right)\right],\mathrm{labels}=\left["n",\phi \left(n\right)\right],\mathrm{symbol}=\mathrm{solidcircle},\mathrm{color}="MidnightBlue",\mathrm{size}=\left[600,"golden"\right]\right)$

The PrimeCounting (or pi) command returns the number of primes less than an integer, $n$.

 > $\left[\mathrm{PrimeCounting}\left(21\right),\mathrm{pi}\left(21\right)\right]$
 $\left[{8}{,}{8}\right]$ (2)

To visualize the first hundred values for pi(n):

 > $\mathrm{plots}:-\mathrm{pointplot}\left(\left[\mathrm{seq}\left(\left[n,\mathrm{PrimeCounting}\left(n\right)\right],n=2..100\right)\right],\mathrm{labels}=\left["n",\pi \left(n\right)\right],\mathrm{symbol}=\mathrm{soliddiamond},\mathrm{color}="Crimson",\mathrm{size}=\left[600,"golden"\right]\right)$

Comparing pi(n) with phi(n) for the first forty values for n:

 > $\mathrm{plots}:-\mathrm{display}\left(\mathrm{DynamicSystems}:-\mathrm{DiscretePlot}\left(\left[\mathrm{seq}\left(i-0.1,i=2..40\right)\right],\left[\mathrm{seq}\left(\mathrm{PrimeCounting}\left(n\right),n=2..40\right)\right],\mathrm{style}=\mathrm{stem},\mathrm{symbol}=\mathrm{soliddiamond},\mathrm{color}="Crimson",\mathrm{legend}="pi"\right),\mathrm{DynamicSystems}:-\mathrm{DiscretePlot}\left(\left[\mathrm{seq}\left(i+0.1,i=2..40\right)\right],\left[\mathrm{seq}\left(\mathrm{Totient}\left(n\right),n=2..40\right)\right],\mathrm{style}=\mathrm{stem},\mathrm{symbol}=\mathrm{solidcircle},\mathrm{color}="MidnightBlue",\mathrm{legend}="Totient"\right),\mathrm{linestyle}=\mathrm{dot},\mathrm{transparency}=0.1,\mathrm{size}=\left[800,400\right],\mathrm{axis}\left[2\right]=\left[\mathrm{gridlines}=\left[\mathrm{thickness}=0,\mathrm{color}="LightGrey"\right]\right]\right)$

The Moebius function is defined as a multiplicative arithmetic function mu(r), where:

r = 1 if r is a square-free positive integer with an even number of prime factors

r = -1 if r is a square-free positive integer with an odd number of prime factors

r = 0 if r has a squared prime factor

For example, mu(2) = $-1$ because 2 is a square-free positive integer which has one prime factor. mu(4) = $0$ since 4 is not a square-free positive integer. The first 75 values for the Moebius function are plotted below:

 > $\mathrm{plots}:-\mathrm{pointplot}\left(\left[\mathrm{seq}\left(\left[n,\mathrm{Moebius}\left(n\right)\right],n=1..75\right)\right],\mathrm{labels}=\left["n",\mu \left(n\right)\right],\mathrm{symbolsize}=15,\mathrm{symbol}=\mathrm{box},\mathrm{color}="OrangeRed",\mathrm{size}=\left[600,400\right],\mathrm{tickmarks}=\left[\mathrm{default},\left[-1,0,1\right]\right]\right)$