\documentclass[11pt]{article}
\usepackage{amsmath}
%\usepackage{fullpage}
%\usepackage{epic}
%\usepackage{eepic}
%\usepackage{psfig}

%\newcommand{\proof}[1]{
%{\noindent {\it Proof.} {#1} \rule{2mm}{2mm} \vskip \belowdisplayskip}
%}


%\newtheorem{lemma}{Lemma}[section]
%\newtheorem{theorem}[lemma]{Theorem}
%\newtheorem{claim}[lemma]{Claim}
%\newtheorem{definition}[lemma]{Definition}
%\newtheorem{corollary}[lemma]{Corollary}

%Theorems and likes
\newtheorem{assumption}{Assumption}[section]
\newtheorem{theorem}{Theorem}[section]
\newtheorem{fact}{Fact}[section]
\newtheorem{claim}{Claim}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{example}{Example}[section]
\newtheorem{definition}{Definition}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{exercise}{Exercise}[section]
\newtheorem{observation}{Observation}[section]


\newcommand{\bproof}{\noindent{\it Proof}}
%\newcommand{\eproof}{\hspace*{\fill}$\Box$~~~~~\bigskip}
\newcommand{\eproof}{\hspace*{\fill}\rule{2mm}{2mm}~~~~~\bigskip}
\newenvironment{proof}{\bproof: }{\eproof}

% symbols and notation
\newcommand{\defeq}{\stackrel{\rm def}{=}}


\setlength{\oddsidemargin}{0in} \setlength{\topmargin}{0in}
\setlength{\textwidth}{6in} \setlength{\textheight}{8in}

\begin{document}

\setlength{\fboxrule}{.5mm}\setlength{\fboxsep}{1.2mm}
\newlength{\boxlength}\setlength{\boxlength}{\textwidth}
\addtolength{\boxlength}{-4mm}
\begin{center}\framebox{\parbox{\boxlength}{\bf
CS 681: Computational Number Theory and Algebra \hfill Lecture 14
\\\\
A Polynomial time algorithm for Primality Testing
\\\\
Lecturer: Manindra Agrawal \hfill Scribe: Chandan Saha
%\\
\begin{flushright}
%date
Septembor 9, 2005
\end{flushright}
}}\end{center} \vspace{5mm}


In the previous lecture we have proved the two size reduction
lemma. It follows that: \\
\\
 \textit{If}
\begin{enumerate}
\item $T = \lbrace X^j+a \mid 0 \leq j < r, 0 \leq a \leq 2
\sqrt{r} lgn \rbrace $ \item $p > t > 4log^{2}n$ \item $\psi$ is
linear on $T$
\end{enumerate}
\textit {then $n = p^j$ for some $j \in N.$}\\
\section{The Algorithm and its correctness}
\subsection{Algorithm}
Input: integer $n > 1$.
\begin{enumerate}
\item Test if $n=m^j$ for some $j>1$. If yes output COMPOSITE.
\item Find the smallest $r$ such that $order_{r}(n) > 4log^{2}n$.
\item If $1 < (a,n) <n$ for some $a \leq r$, output COMPOSITE.
\item If $n < r$, output PRIME. \item For $1 \leq a \leq 2
\sqrt{r} log n$ do \\
if $((X + a)^n \neq X^n + a ($ mod $    X^r - 1, n))$ , output
COMPOSITE. \item output PRIME.
\end{enumerate}

\subsection{Correctness}
\begin{theorem}
The algorithm above returns PRIME if and only if n is prime.
\end{theorem}
\begin{lemma}
If n is PRIME, the algorithm returns PRIME.
\end{lemma}
\begin{proof}
If $n$ is prime then either the algorithm outputs PRIME in Step 4
or else the condition tested in Step 5 never holds and the
algorithm returns PRIME in Step 6.
\end{proof}
\begin{lemma}
If the algorithm returns PRIME then $n$ is prime.
\end{lemma}
\begin{proof}
If the algorithm returns PRIME in Step 4 then $n$ is indeed prime.
For the rest of the proof, consider that the algorithm returns
PRIME in Step 6. This implies that,
\begin{align*}
\psi(X+a) &= (X+a)^n \text{  ( mod } n, X^r - 1) \\
            &= X^n + a \text{  ( mod } n, X^r - 1) \\
            &= \psi(X) + a \text{  ( mod } n, X^r - 1)
\end{align*}
for $0 \leq a \leq \ 2 \sqrt{r} log n$. Replacing $X$ by $X^j$ we
get,
\begin{align*}
\psi(X^j+a) &= \psi(X^j) + a \text{  ( mod } n, X^{jr} - 1) \\
            &= \psi(X^j) + a \text{  ( mod } n, X^{r} - 1) \\
            &= \psi(X^j) + a \text{  ( mod } p, h(X))
\end{align*}
By definition, $G = \lbrace \phi^{i}\psi^{j}(X) \mid i,j \geq 0 ,
X \in F \rbrace = \lbrace X^{n^{j}p^{i}} \rbrace $. Choose the
irreducible factor $h(x)$ of the polynomial $x^r-1$ in $F_p[x]$
that has an $r^{th}$ primitive root of unity over the field $F_p$
(this can always be done). This choice of $h(x)$ makes $t = \mid
\lbrace n^{i}p^{j} (r) \mid i,j \geq 0 \rbrace \mid$. This implies
that $t \geq order_{r}(n) > 4log^2n$. Also we have $r \geq t$ and
$p > r$ (from Step 3). Therefore, $n = p^j$ for some $j$. Since at
Step 6 we have that $n \neq m^j$ for any $m$ and any $j>1$, we get
$n = p$.
\end{proof}
\section{Time Complexity Analysis}
We will need the following fact about the lcm of the first $m$
numbers.
\begin{lemma}\label{lem:LCM}
Let LCM(m) denotes the lcm of the first m numbers. For $m \geq 7$
we have $LCM(m) \geq 2^m$.
\end{lemma}
The following lemma bounds the magnitude of $r$.
\begin{lemma}\label{lem:bound}
There exists an $r \leq 16log^{5}n$ such that $order_{r}(n) >
4log^{2}n$.
\end{lemma}
\begin{proof}
Consider the product
\begin{equation*}
A = n \cdot \prod_{j = 1}^{4 log^{2}n}(n^j - 1)
\end{equation*}
Say an $r$ is \emph{bad} if either $r \mid n$ or $order_{r}(n)
\leq 4log^{2}n$. It is easy to see that all \emph{bad} $r's$
divide $A$. Moreover,
\begin{equation*}
A < n \cdot n^{\sum_1^{4log^{2}n}j} \leq 2^{16log^{5}n}
\end{equation*}
Therefore by Lemma \ref{lem:LCM} there exists an $r \leq
16log^{5}n$ such that $r$ does not divide $A$, implying that $r$
is not $\emph{bad}$. If now $(r,n) = 1$ then we are done. If
$(r,n) > 1$ then $s = \frac{r}{(r,n)}$ does not divide $A$ and $s$
is relatively prime to $n$. This implies that $order_{s}(n) >
4log^{2}n$.
\end{proof}
\begin{theorem}
The asymptotic time complexity of the algorithm is
\~{O}$(log^{21/2}n)$.
\end{theorem}
\begin{proof}
Time taken in Step 1 is \~{O}$(log^{3}n)$. In Step 2, time spent
to check if $order_{r}(n) > 4log^{2}n$ is \~{O}$(log^{2}n)$ for
any $r$ ($log r$ factor hidden). Therefore, Step 2 takes
\~{O}$(rlog^{2}n)$ total time. Execution of Step 3 can be done in
\~{O}$(rlog n)$ time. Time taken to compute $(X+a)^n$ and $X^n$ in
the ring $Z_{n}[X]/(X^{r} - 1)$ is \~{O}$(r log^2 n)$ (hiding the
$log r$ factor) for any fixed $a$. Therefore, total time spent in
Step 4 is \~{O}$(r^{\frac{3}{2}} log^3 n)$. The theorem follows
from Lemma \ref{lem:bound}.
\end{proof}
\end{document}
