logo

Orders in Number Theory 📂Number Theory

Orders in Number Theory

Definition 1

Theorem

If $a^{n} \equiv 1 \pmod{p}$, then $\text{ord}_{p} (a) \mid n$.

Explanation

For example, consider $p=7$. $$ \begin{align*} 1^{1} \equiv & 1 \pmod{ 7 } \\ 2^{3} \equiv & 1 \pmod{ 7 } \\ 3^{6} \equiv & 1 \pmod{ 7 } \\ 4^{3} \equiv & 1 \pmod{ 7 } \\ 5^{6} \equiv & 1 \pmod{ 7 } \\ 6^{2} \equiv & 1 \pmod{ 7 } \end{align*} $$ Here, the order of $6$ is $2$, the order of $2, 4$ is $3$, and the order of $3,5$ is $6$.

Especially in the above theorem, if we set $n=p-1$, we can easily verify that $2,3,6$ divides $p-1= 6$. Furthermore, according to Fermat’s Little Theorem, for a prime number $p$, it always holds that $a^{p-1} \equiv 1 \pmod{p}$, thus we know $\text{ord}_{p} (a) \mid (p-1)$ is true.

Proof

If we set $G := \gcd ( \text{ord}_{p} (a) , n )$, then there exists $s,t$ that satisfies $G = \text{ord}_{p}(a) \cdot s + n \cdot t$.

By the definition of order and by assumption, $$ a^{G} = a^{ \text{ord}_{p}(a) \cdot s + n \cdot t} = \left( a^{ \text{ord}_{p}(a) } \right)^s \cdot \left( a^{n} \right)^{t} \equiv 1 \cdot 1 \pmod{p} $$ since $\text{ord}_{p}(a)$ is defined as the smallest natural number $e$ that satisfies $a^{e} \equiv 1 \pmod{p}$, it follows that $G = \text{ord}_{p}(a)$ and, $\text{ord}_{p}(a) \mid p$.

Code

Below is the code written in R language to compute the order. Prime factorization code was used.

prime = read.table("../attachment
                   /cfile8.uf@25411C3C5968BBE322F0D4.txt"); prime = prime[,1]
 
factorize<-function(p)
{
  q=p
  factors<-numeric(0)
  i=1; j=1
  while(q!=1)
  {
    if(q%%prime[i]) {i=i+1}
    else
    {
      q<-q/prime[i]
      factors[j]<-prime[i]
      i=1
      j=j+1
    }
  }
  return(factors)
}
 
order<-function(g,p,h=1) #Calculate a order of g in modulo p
{
  qe<-table(factorize(p-1))
  qe<-rbind(as.numeric(names(qe)),qe)
  divisor<-qe[1,1]^(0:qe[2,1])
  if((length(qe)/2)==1) {return(qe[1,1]^qe[2,1])}
  for(i in 2:(length(qe)/2)) {divisor=c(divisor%*%t(qe[1,i]^(0:qe[2,i])))}
  for(i in divisor) {if((FPM(g,i,p))%%p==1) break;}
  return(i)
}
 
order(1,7)
order(2,7)
order(3,7)
order(4,7)
order(5,7)
order(6,7)

Below is the result of executing the above code.

20190227\_095435.png


  1. Silverman. (2012). A Friendly Introduction to Number Theory (4th Edition): p211. Let us define $\gcd (a, p) = 1$. The smallest natural number $e$ that satisfies $a^{e} \equiv 1 \pmod{p}$ is denoted as $\text{ord}_{p} (a)$, and is defined as the order of $a$ modulo $p$. ↩︎