% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{report}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[margin=2.0cm,a4paper]{geometry}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{#1}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.50,0.00}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.50,0.00}{\textbf{#1}}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\usepackage{titlesec}
\usepackage{fancyvrb}
\usepackage{fvextra}
\usepackage{enumitem}
\usepackage{pdfpages}

\usepackage{longtable}
\usepackage{etoolbox}

\usepackage{fontspec}
\setmainfont{lmroman10-regular.otf}[
    BoldFont       = lmroman10-bold.otf,
    ItalicFont     = lmroman10-italic.otf,
    BoldItalicFont = lmroman10-bolditalic.otf,
    OpticalSize    = 0
]

\AtBeginEnvironment{longtable}{\fontsize{6}{8}\selectfont}

\newcommand{\chapfnt}{\fontsize{19}{21}}
\newcommand{\secfnt}{\fontsize{14}{17}}
\newcommand{\ssecfnt}{\fontsize{12}{14}}
\newcommand{\sectionbreak}{\clearpage}
\newcommand{\llbracket}{[\![}
\newcommand{\rrbracket}{]\!]}

\titleformat{\chapter}[display]
{\normalfont\chapfnt\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\chapfnt}

\titleformat{\section}
{\normalfont\secfnt\bfseries}{\thesection}{1em}{}

\titleformat{\subsection}
{\normalfont\ssecfnt\bfseries}{\thesubsection}{1em}{}

\titlespacing*{\chapter} {0pt}{50pt}{40pt}
\titlespacing*{\section} {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection} {0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\},fontsize=\scriptsize,frame=single,rulecolor=\color{lightgray},breaklines,samepage,label=\tiny{Code},labelposition=topline}
\DefineVerbatimEnvironment{verbatim}{Verbatim}{commandchars=\\\{\},fontsize=\scriptsize,frame=single,rulecolor=\color{lightgray},breaklines,samepage,label=\tiny{Output},labelposition=topline,fontshape=it}

\setlist{after=\bigskip}

\let\OldRule\rule
\renewcommand{\rule}[2]{\OldRule{0.0\linewidth}{#2}}
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{A Primer on Prime Numbers}
\author{The Publicator using gpt-oss-120b}
\date{}

\begin{document}
\maketitle

{
\setcounter{tocdepth}{2}
\tableofcontents
}
\chapter{A Primer on Prime Numbers}\label{a-primer-on-prime-numbers}

\textbf{Abstract:} This primer offers a comprehensive yet accessible
survey of prime numbers, emphasizing their central role in mathematics
and its applications. Beginning with a motivation for studying primes,
the work outlines its scope and underscores the fundamental nature of
prime concepts. A historical overview traces the evolution of prime
number theory from Euclid's ancient insights to contemporary research,
highlighting pivotal milestones and contributors. Precise definitions of
primes, composites, and related notions are presented alongside basic
properties such as unique factorisation and divisibility criteria. The
classic Euclidean proof of the infinitude of primes is revisited and
complemented by several modern variations, illustrating key logical
techniques. Subsequent sections examine the distribution and density of
primes, introducing prime gaps, Chebyshev functions, and empirical
observations, and culminate in a discussion of the Prime Number Theorem,
its significance, and a sketch of the analytic ideas underlying its
proof. The manuscript surveys deterministic and probabilistic
primality‑testing algorithms - including trial division, Miller‑Rabin,
and AKS - detailing their computational complexities and practical use.
Cryptographic applications are explored, focusing on how primes underpin
RSA, Diffie‑Hellman, and the requirements for secure prime generation.
Special classes of primes such as twin, Mersenne, Fermat, and Sophie
Germain primes are introduced, together with associated open questions.
Major unsolved problems and conjectures, notably the Twin Prime
Conjecture, Goldbach's conjecture, and the Riemann Hypothesis, are
summarized. Finally, the paper reviews computational tools (PARI/GP,
SageMath, Mathematica) for experimental prime research and concludes by
recapping the key ideas, reaffirming the enduring importance of prime
numbers, and suggesting avenues for future investigation.

\section{1. Introduction}\label{introduction}

\subsection{1.1 Why Primes Matter}\label{why-primes-matter}

Prime numbers sit at the very heart of arithmetic: every integer greater
than 1 can be expressed uniquely as a product of primes (the Fundamental
Theorem of Arithmetic). This simple yet powerful fact makes primes the
``building blocks'' of the whole number system, much as atoms are for
matter. Because of this foundational role, any deeper investigation into
number theory inevitably runs into questions about primes - how they
behave, how they can be identified, and how they can be harnessed.

Beyond pure mathematics, primes have become indispensable in modern
technology. Public‑key cryptography, error‑correcting codes, and random
number generation all rely on properties that only prime numbers
possess. Consequently, a solid grasp of primes is not merely an academic
luxury; it is a practical necessity for fields ranging from computer
science to physics.

\subsection{1.2 Scope of This Primer}\label{scope-of-this-primer}

This primer is designed as a self‑contained, graduate‑level introduction
that balances rigorous theory with concrete examples. The reader will be
guided through:

\begin{itemize}
\tightlist
\item
  \textbf{Historical context} - a brief look at how prime number theory
  evolved (see \emph{2. Historical Overview}).\\
\item
  \textbf{Core definitions and properties} - precise language for
  primes, composites, and related concepts (see \emph{3. Definitions and
  Fundamental Properties}).\\
\item
  \textbf{Key theorems and proofs} - including Euclid's proof of
  infinitude, the Prime Number Theorem, and modern variations (see
  \emph{4. Proof of Infinitude of Primes} and \emph{6. The Prime Number
  Theorem}).\\
\item
  \textbf{Algorithmic aspects} - deterministic and probabilistic
  primality tests, with attention to computational complexity (see
  \emph{7. Primality Testing Algorithms}).\\
\item
  \textbf{Applications} - especially cryptographic uses that illustrate
  why large, well‑chosen primes are critical (see \emph{8. Cryptographic
  Applications}).\\
\item
  \textbf{Special families and open problems} - an overview of
  intriguing subclasses of primes and the most famous unsolved
  conjectures (see \emph{9. Special Classes of Primes} and \emph{10.
  Open Problems and Conjectures}).
\end{itemize}

Each chapter builds on the previous ones, so readers can progress from
elementary intuition to current research frontiers without needing
external references.

\subsection{1.3 How This Primer Is
Organized}\label{how-this-primer-is-organized}

The material follows a logical progression:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \textbf{Motivation and big picture} (this section).\\
\item
  \textbf{Chronology} - tracing the development of prime theory from
  Euclid to the present.\\
\item
  \textbf{Foundations} - establishing the language and elementary
  results that will be used throughout.\\
\item
  \textbf{Existence proofs} - demonstrating that primes never run out.\\
\item
  \textbf{Statistical behavior} - exploring how primes are distributed
  among the integers.\\
\item
  \textbf{Asymptotic analysis} - introducing the Prime Number Theorem
  and its consequences.\\
\item
  \textbf{Computational methods} - presenting algorithms for testing and
  generating primes.\\
\item
  \textbf{Real‑world impact} - linking theory to cryptographic
  practice.\\
\item
  \textbf{Special families} - highlighting particularly interesting or
  useful subsets of primes.\\
\item
  \textbf{Frontiers} - summarizing the most compelling open questions.\\
\item
  \textbf{Tools} - reviewing software that aids experimental and
  theoretical work.\\
\item
  \textbf{Conclusion} - reflecting on the journey and pointing toward
  further study.
\end{enumerate}

By the end of the primer, readers should be able to:

\begin{itemize}
\tightlist
\item
  State and prove the basic properties of primes.\\
\item
  Understand why the infinitude of primes is a cornerstone of number
  theory.\\
\item
  Appreciate the deep connections between prime distribution and
  analytic techniques.\\
\item
  Apply primality‑testing algorithms in practical settings.\\
\item
  Recognize the role of primes in securing digital communication.
\end{itemize}

In short, this introduction sets the stage for a comprehensive tour of
prime numbers, emphasizing both their timeless mathematical beauty and
their modern technological relevance.

\section{2. Historical Overview}\label{historical-overview}

\subsection{2.1 Ancient Foundations}\label{ancient-foundations}

The systematic study of prime numbers begins with the Greeks. In
\textbf{Euclid's \emph{Elements}} (c.~300 BCE) the first rigorous proof
that there are infinitely many primes appears (see Section 4,
\emph{Proof of Infinitude of Primes}). Euclid's argument, based on the
construction of a new integer from a finite list of primes, establishes
a template for later existence proofs.

The \emph{sieve of Eratosthenes} (c.~200 BCE) is the earliest known
algorithm for generating primes. Though described only in fragmentary
sources, the method already embodies the idea of eliminating composites
by successive division, a technique that underlies modern computational
tools (Section 11).

Greek mathematicians such as \textbf{Eratosthenes}, \textbf{Hipparchus},
and \textbf{Aristarchus} also investigated the distribution of primes,
noting empirically that they become sparser as numbers grow - a theme
that resurfaces in the Prime Number Theorem (Section 6).

\subsection{2.2 Medieval and Early Modern
Contributions}\label{medieval-and-early-modern-contributions}

During the Islamic Golden Age, scholars such as \textbf{Al‑Karaji}
(c.~1000) and \textbf{Al‑Haytham} (c.~1000) extended Euclidean ideas,
providing commentaries on the infinitude proof and exploring modular
arithmetic. Their work preserved Greek knowledge and introduced new
notation that later European mathematicians would adopt.

In the 13th century, \textbf{Fibonacci} (Leonardo of Pisa) popularized
the \emph{Liber Abaci}, which included the first explicit statement of
the Fundamental Theorem of Arithmetic (the unique factorisation of
integers into primes). This theorem is the cornerstone of Section 3,
\emph{Definitions and Fundamental Properties}.

The 17th century saw a dramatic shift with \textbf{Pierre de Fermat} and
\textbf{Leonhard Euler}. Fermat's ``little theorem'' (1640) linked
primes to modular exponentiation, a result that later becomes central to
primality testing (Section 7). Euler's product formula

\(\sum_{n=1}^{\infty}\frac{1}{n^{s}}=\prod_{p\ \text{prime}}\frac{1}{1-p^{-s}}\)

\begin{enumerate}
\def\labelenumi{(\arabic{enumi})}
\setcounter{enumi}{1736}
\tightlist
\item
  revealed a deep connection between the distribution of primes and the
  analytic properties of the Riemann zeta‑function, foreshadowing the
  analytic approach of the 19th century.
\end{enumerate}

\subsection{2.3 The 18th-19th Century: From Approximation to Rigorous
Asymptotics}\label{the-18th-19th-century-from-approximation-to-rigorous-asymptotics}

\textbf{Legendre} (1798) proposed the first explicit approximation for
the prime‑counting function \(\pi(x)\), suggesting
\(\pi(x)\approx \frac{x}{\log x - B}\) with a constant \(B\). Although
heuristic, Legendre's formula anticipated the later precise asymptotic
statement of the Prime Number Theorem (Section 6).

\textbf{Carl Friedrich Gauss} (1792, private letters) conjectured that
\(\pi(x)\) is well approximated by the logarithmic integral
\(\operatorname{Li}(x)\). His extensive tables of primes and statistical
observations laid the groundwork for modern computational verification.

\textbf{Dirichlet's theorem on arithmetic progressions} (1837) proved
that any linear progression \(a+nd\) with \(\gcd(a,d)=1\) contains
infinitely many primes. This was the first major result showing that
primes are not confined to a single residue class, and it introduced
characters and L‑functions - tools that dominate contemporary analytic
number theory.

\textbf{Chebyshev} (1850s) established the first rigorous bounds for
\(\pi(x)\), showing that there exist constants \(c_1,c_2>0\) such that

\(c_1\frac{x}{\log x}\le \pi(x)\le c_2\frac{x}{\log x}\)

for sufficiently large \(x\). These ``Chebyshev bounds'' are the
historical antecedent of the asymptotic equivalence proved in Section 6.

\subsection{2.4 The Turn of the Century: Riemann, Hadamard, and de la
Vallée
Poussin}\label{the-turn-of-the-century-riemann-hadamard-and-de-la-valluxe9e-poussin}

Bernhard Riemann's seminal 1859 paper \emph{``Über die Anzahl der
Primzahlen''} introduced the complex‑analytic continuation of the
zeta‑function and the now‑famous hypothesis that all non‑trivial zeros
lie on the critical line \(\Re(s)=\tfrac12\). Riemann's explicit formula
linked the zeros of \(\zeta(s)\) to fluctuations in \(\pi(x)\),
providing a powerful framework for understanding the fine structure of
prime distribution.

Building on Riemann's ideas, \textbf{Hadamard} (1896) and \textbf{de la
Vallée Poussin} (1896) independently proved the \textbf{Prime Number
Theorem} (Section 6) by showing that \(\zeta(s)\) has no zeros on the
line \(\Re(s)=1\). Their proofs introduced complex analysis into number
theory in a decisive way and cemented the analytic approach as a central
methodology.

\subsection{2.5 Mid‑20th Century: Sieve Methods, Computational
Breakthroughs, and New
Conjectures}\label{mid20th-century-sieve-methods-computational-breakthroughs-and-new-conjectures}

The development of \textbf{sieve theory} - from Legendre's elementary
sieve to \textbf{Brun's combinatorial sieve} (1919) and later the
\textbf{Selberg sieve} (1947) - provided systematic ways to estimate the
density of primes in various sets. Brun's work, notably his proof that
the sum of reciprocals of twin primes converges (the \emph{Brun
constant}), is a key historical milestone for the twin‑prime problem
discussed in Section 10.

The post‑World‑War II era saw the rise of large‑scale computation.
\textbf{Hardy and Littlewood} (1920s-1930s) formulated the \emph{circle
method}, yielding asymptotic formulas for representations of numbers as
sums of primes (e.g., Goldbach's conjecture). Their \emph{Conjecture B}
(the ``Hardy-Littlewood prime‑pair conjecture'') directly informs modern
investigations of prime gaps.

In the 1970s, the discovery of massive \textbf{Mersenne primes} (Section
9) via the \emph{Great Internet Mersenne Prime Search} (GIMPS)
demonstrated the power of distributed computing. Parallel advances in
algorithmic number theory, culminating in the \textbf{AKS primality
test} (2002), transformed the theoretical landscape by providing a
deterministic polynomial‑time algorithm for primality, a result that
bridges Sections 7 and 11.

\subsection{2.6 21st‑Century Frontiers: Bounded Gaps, Random Models, and
Interdisciplinary
Links}\label{stcentury-frontiers-bounded-gaps-random-models-and-interdisciplinary-links}

The most striking recent breakthrough is \textbf{Yitang Zhang's} 2013
proof that there exists an absolute constant \(B\) such that infinitely
many prime pairs differ by at most \(B\). Subsequent refinements by
\textbf{Maynard} and the Polymath project reduced \(B\) dramatically,
establishing the existence of bounded gaps between primes - a major step
toward the Twin Prime Conjecture (Section 10).

Parallel to analytic advances, \textbf{probabilistic models} (Cramér's
model, Granville's refinements) have deepened our intuition about prime
gaps and the distribution of large gaps, influencing both theoretical
work and the design of heuristic algorithms in Section 7.

Computationally, the synergy between high‑performance hardware and
sophisticated software (PARI/GP, SageMath, Mathematica; see Section 11)
continues to push the frontier of known large primes and to test
conjectures numerically. Projects such as \textbf{PrimeGrid} and
\textbf{Polymath} exemplify the collaborative, open‑science ethos that
now characterises prime‑number research.

Finally, the interplay between prime theory and other fields - random
matrix theory, quantum chaos, and cryptography (Section 8) - underscores
the enduring relevance of the historical trajectory outlined here. Each
epoch, from Euclid's geometric insight to modern analytic breakthroughs,
contributes a layer to the rich tapestry of prime‑number theory that
this primer seeks to illuminate.

\section{3. Definitions and Fundamental
Properties}\label{definitions-and-fundamental-properties}

\subsection{3.1 Prime Numbers and Units}\label{prime-numbers-and-units}

A \textbf{prime number} is an integer \(p\) satisfying three conditions:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \(p\) is a positive integer,\\
\item
  \(p \neq 1\) (the integer 1 is excluded), and\\
\item
  The only positive divisors of \(p\) are \(1\) and \(p\) itself.
\end{enumerate}

In the language of abstract algebra, a prime is a \textbf{non‑unit}
element of the ring \(\mathbb{Z}\) whose only divisors are the trivial
units \(\pm1\) and its associates \(\pm p\).

The integer \(1\) (and its negative \(-1\)) are called \textbf{units} of
\(\mathbb{Z}\). Units are invertible: \(1\cdot1 = 1\) and
\((-1)\cdot(-1)=1\). By convention units are \textbf{not} regarded as
prime or composite; they serve as the neutral factors that do not affect
factorisation.

\subsection{3.2 Composite Numbers}\label{composite-numbers}

An integer \(n\) with \(|n|>1\) that is \textbf{not} prime is called
\textbf{composite}. Equivalently, \(n\) is composite if there exist
integers \(a,b\) with

\(1 < |a| < |n|,\qquad 1 < |b| < |n|,\qquad n = a\cdot b .\)

Thus a composite number possesses a non‑trivial factorisation into
smaller integers.

\emph{Example.} \(12 = 3 \times 4\) shows that 12 is composite, while
\(13\) has no such representation and is therefore prime.

\subsection{3.3 Divisibility and Basic
Criteria}\label{divisibility-and-basic-criteria}

For integers \(a,b\) we write \(a\mid b\) (read ``\(a\) divides \(b\)'')
when there exists an integer \(k\) such that \(b = a k\). The following
elementary facts are used throughout the primer and will reappear in
later sections (e.g., the Euclidean algorithm in Section 7 and the
construction of cryptographic moduli in Section 8).

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.4762}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5238}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Property
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Statement
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Transitivity} & If \(a\mid b\) and \(b\mid c\), then
\(a\mid c\). \\
\textbf{Multiplicativity} & If \(a\mid b\) then \(a\mid b c\) for any
integer \(c\). \\
\textbf{Cancellation} & If \(\gcd(a,c)=1\) and \(a\mid b c\), then
\(a\mid b\). \\
\textbf{Divisor Bounds} & If \(p\) is prime and \(p\mid n\), then
\(p \le |n|\). \\
\textbf{Parity Test} & \(2\mid n\) iff the last binary digit of \(n\) is
0 (equivalently, the decimal unit digit is even). \\
\textbf{3‑Divisibility Test} & \(3\mid n\) iff the sum of the decimal
digits of \(n\) is a multiple of 3. \\
\textbf{5‑Divisibility Test} & \(5\mid n\) iff the last decimal digit of
\(n\) is 0 or 5. \\
\end{longtable}

These criteria provide quick ways to rule out primality without full
factorisation, a theme that will be expanded in Section 7 (primality
testing algorithms).

\subsection{3.4 Uniqueness of Factorisation - The Fundamental Theorem of
Arithmetic}\label{uniqueness-of-factorisation---the-fundamental-theorem-of-arithmetic}

The \textbf{Fundamental Theorem of Arithmetic} (FTA) states that every
integer \(n\) with \(|n|>1\) can be written uniquely (up to ordering and
multiplication by units) as a product of prime powers:

\(n = \pm \prod_{i=1}^{k} p_i^{\,e_i},
\qquad p_i \text{ distinct primes},\; e_i \ge 1 .\)

\emph{Uniqueness} means that if

\(n = \pm \prod_{i=1}^{k} p_i^{\,e_i}
      = \pm \prod_{j=1}^{\ell} q_j^{\,f_j},\)

then \(k=\ell\), the multisets \(\{p_i\}\) and \(\{q_j\}\) coincide, and
the corresponding exponents match: \(e_i = f_i\) after a suitable
re‑ordering.

The FTA is the cornerstone of the ``indivisible atoms'' metaphor
highlighted in \textbf{Section 1 - Introduction}. It guarantees that the
arithmetic of the integers is built from the prime building blocks in a
deterministic way, enabling the later development of:

\begin{itemize}
\tightlist
\item
  \textbf{Euclid's proof of infinitude} (Section 4), which relies on the
  existence of a new prime factor for any finite list of primes.\\
\item
  \textbf{Divisibility criteria} used in primality tests (Section 7).\\
\item
  \textbf{Cryptographic constructions} where the security of RSA hinges
  on the difficulty of recovering the unique prime factors of a large
  composite modulus (Section 8).
\end{itemize}

\subsection{3.5 Greatest Common Divisors and
Coprimality}\label{greatest-common-divisors-and-coprimality}

For non‑zero integers \(a\) and \(b\), the \textbf{greatest common
divisor} (gcd) is the largest positive integer \(d\) such that
\(d\mid a\) and \(d\mid b\). It is denoted \(\gcd(a,b)\). Two integers
are \textbf{coprime} (or relatively prime) when \(\gcd(a,b)=1\).

Key properties that will be repeatedly invoked:

\begin{itemize}
\tightlist
\item
  \textbf{Bezout's Identity} - There exist integers \(x,y\) with
  \(ax + by = \gcd(a,b)\).\\
\item
  \textbf{Euclidean Algorithm} - An efficient method to compute
  \(\gcd(a,b)\); its correctness follows from the division algorithm and
  the transitivity of divisibility.\\
\item
  \textbf{Multiplicative Property} - If \(\gcd(a,b)=1\) then
  \(\gcd(a,bc)=\gcd(a,c)\).
\end{itemize}

These facts underpin the modular arithmetic used in \textbf{Section 7}
(Miller-Rabin test) and \textbf{Section 8} (key generation for RSA,
where the public modulus \(N = pq\) requires \(p\) and \(q\) to be
distinct primes and \(\gcd(p-1,q-1)=2\) for certain security
parameters).

\subsection{3.6 Summary of Fundamental
Properties}\label{summary-of-fundamental-properties}

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.3846}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.6154}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Property
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Why It Matters
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Existence of Prime Factorisation} & Guarantees every integer can
be broken down into primes, enabling systematic study of number
theoretic problems. \\
\textbf{Uniqueness (FTA)} & Provides a canonical representation;
essential for defining arithmetic functions (e.g., \(\tau(n)\),
\(\sigma(n)\)) and for cryptographic security. \\
\textbf{Divisibility Criteria} & Offer quick filters for primality and
composite detection, reducing computational effort. \\
\textbf{Coprimality \& GCD} & Central to solving linear Diophantine
equations, constructing modular inverses, and designing secure
cryptographic protocols. \\
\end{longtable}

With these definitions and elementary properties firmly established, the
reader is equipped to follow the deeper investigations that follow -
starting with Euclid's elegant proof of the infinitude of primes in
\textbf{Section 4}.

\section{4. Proof of Infinitude of
Primes}\label{proof-of-infinitude-of-primes}

\subsection{4.1 Euclid's Classic Proof}\label{euclids-classic-proof}

The earliest and most celebrated argument for the infinitude of primes
appears in \textbf{Euclid's Elements} (c.~300 BCE) and is recalled in
the \emph{Historical Overview} (Section 2). The proof relies only on the
definitions given in Section 3 (prime numbers are the ``atoms'' of the
integers) and on the Fundamental Theorem of Arithmetic (unique
factorisation).

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  \textbf{Assume finiteness.}\\
  Suppose there are only finitely many primes, and list them as\\
  \(p_{1},\,p_{2},\,\dots ,\,p_{k}.\)
\item
  \textbf{Construct a new integer.}\\
  Form the number\\
  \(N = p_{1}p_{2}\cdots p_{k}+1 .\)\\
  By construction, \(N>1\) and is not divisible by any \(p_{i}\) because
  division leaves a remainder of 1.
\item
  \textbf{Apply the Fundamental Theorem of Arithmetic.}\\
  Every integer \(>1\) has a prime divisor. Let \(q\) be a prime
  dividing \(N\). Since none of the listed primes divide \(N\), \(q\)
  cannot belong to the original list.
\item
  \textbf{Derive a contradiction.}\\
  The existence of a prime \(q\) outside the assumed complete list
  contradicts the hypothesis that the list contained \emph{all} primes.
  Hence the set of primes cannot be finite; there are infinitely many.
\end{enumerate}

This argument is purely \emph{constructive} (it exhibits a new prime or
a new composite with a new prime factor) and uses only elementary
divisibility properties, making it accessible to readers after Section
3.

\subsection{4.2 Modern Variations}\label{modern-variations}

While Euclid's proof remains the conceptual backbone, several modern
reformulations sharpen its logical structure or adapt it to different
mathematical settings. The variations below illustrate three common
techniques: \textbf{proof by contradiction}, \textbf{proof by
construction}, and \textbf{proof by infinite descent}.

\subsubsection{4.2.1 Proof by Contradiction Using the Product‑Plus‑One
Idea}\label{proof-by-contradiction-using-the-productplusone-idea}

A direct restatement of Euclid's argument in modern logical notation:

\begin{itemize}
\tightlist
\item
  \textbf{Assumption:} \(\exists\,k\in\mathbb{N}\) such that
  \(\{p_{1},\dots ,p_{k}\}\) is the complete set of primes.\\
\item
  \textbf{Derivation:} Define \(N = \prod_{i=1}^{k}p_{i}+1\).\\
\item
  \textbf{Observation:} For each \(i\), \(N \equiv 1 \pmod{p_{i}}\);
  therefore \(\gcd(N,p_{i})=1\).\\
\item
  \textbf{Conclusion:} By the Fundamental Theorem of Arithmetic (Section
  3), \(N\) possesses a prime divisor \(q\) with \(\gcd(q,p_{i})=1\) for
  all \(i\). Hence \(q\) is not in the list, contradicting the
  assumption.
\end{itemize}

The proof highlights the \emph{contrapositive} logical step: ``If a
finite list existed, a contradiction follows; therefore the list cannot
be finite.''

\subsubsection{4.2.2 Proof by Construction: Euclid's Proof in the
Language of
Ideals}\label{proof-by-construction-euclids-proof-in-the-language-of-ideals}

In the ring of integers \(\mathbb{Z}\), the set of all prime ideals is
in bijection with the set of prime numbers. Consider the ideal generated
by the product of a finite collection of distinct prime ideals
\((p_{1}),\dots ,(p_{k})\): \(I = (p_{1}p_{2}\cdots p_{k}) .\) The
element \(1\) is not in \(I\), so the ideal \(I+(1) = \mathbb{Z}\) is
the whole ring. Adding the element \(1\) to the generator yields the
element \(N = p_{1}p_{2}\cdots p_{k}+1 .\) If the set of prime ideals
were finite, \(N\) would be contained in a maximal ideal generated by
some prime \(q\). Yet \(q\) cannot divide any \(p_{i}\) (as before), so
a new maximal ideal appears, contradicting finiteness. This version
showcases how Euclid's idea extends to abstract algebraic structures.

\subsubsection{4.2.3 Proof by Infinite Descent (Euler's
Variant)}\label{proof-by-infinite-descent-eulers-variant}

Leonhard Euler reformulated Euclid's argument using the \emph{sum of
reciprocals} of the primes. The key observation (see the
\emph{Historical Overview} for Euler's product formula) is that
\(\sum_{p\ \text{prime}} \frac{1}{p}\) diverges. Suppose only finitely
many primes exist; then the sum would be finite, contradicting the
analytic identity
\(\sum_{n=1}^{\infty}\frac{1}{n} = \prod_{p\ \text{prime}}\left(1-\frac{1}{p}\right)^{-1},\)
which links the harmonic series to the product over all primes. Since
the harmonic series diverges, the product - and therefore the set of
primes - must be infinite. This proof employs \emph{infinite descent}:
assuming finiteness forces a bounded quantity where the analytic side
forces unbounded growth.

\subsection{4.3 Logical Techniques
Illustrated}\label{logical-techniques-illustrated}

The proofs above exemplify several logical methods that recur throughout
the primer:

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1618}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.4118}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.4265}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Technique
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
How it appears in Section 4
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Connection to later sections
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Proof by contradiction} & Euclid's original argument and the
modern contrapositive version & Used in Section 6 (Prime Number Theorem)
to rule out certain asymptotic behaviours \\
\textbf{Constructive existence} & Building \(N = p_{1}\cdots p_{k}+1\) &
Mirrors the constructive generation of primes in Section 7 (primality
testing) and Section 11 (software tools) \\
\textbf{Infinite descent} & Euler's reciprocal‑sum argument & Provides a
template for descent arguments in Diophantine problems (Section 10) \\
\textbf{Algebraic abstraction} & Ideal‑theoretic reformulation &
Prepares the reader for algebraic number theory concepts that underlie
modern cryptographic constructions (Section 8) \\
\end{longtable}

Understanding these logical patterns equips the reader to follow more
sophisticated arguments later in the primer, such as the analytic proof
of the Prime Number Theorem (Section 6) or the probabilistic reasoning
behind Miller-Rabin testing (Section 7).

\subsection{4.4 Extensions and
Generalisations}\label{extensions-and-generalisations}

Beyond the integer setting, the infinitude of ``prime‑like'' objects can
be proved in many algebraic systems:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  \textbf{Gaussian Integers \(\mathbb{Z}[i]\).}\\
  Using a Euclidean norm \(N(a+bi)=a^{2}+b^{2}\), one can mimic Euclid's
  construction to show infinitely many \emph{Gaussian primes}.
\item
  \textbf{Polynomials over a Field.}\\
  In \(\mathbb{F}[x]\) (where \(\mathbb{F}\) is a finite field), the set
  of monic irreducible polynomials is infinite; a product‑plus‑one
  argument works with the degree function as a measure of size.
\item
  \textbf{Arithmetic Progressions (Dirichlet's Theorem).}\\
  Section 2 notes Dirichlet's theorem, which guarantees infinitely many
  primes in any progression \(a, a+d, a+2d,\dots\) with \(\gcd(a,d)=1\).
  The proof uses characters and L‑functions, but the underlying
  \emph{infinitude} theme is a direct generalisation of Euclid's idea.
\end{enumerate}

These extensions illustrate that the logical core of Euclid's proof -
\emph{any finite collection can be outgrown by a simple construction} -
is a versatile tool across number theory.

\subsection{4.5 Summary}\label{summary}

\begin{itemize}
\tightlist
\item
  Euclid's classic proof (Section 2) provides a timeless, elementary
  demonstration that primes are infinite.\\
\item
  Modern variations recast the same idea in the language of
  contradiction, construction, infinite descent, and algebraic
  structures, preparing the reader for the more advanced techniques
  encountered in Sections 5-11.\\
\item
  Recognising the logical patterns in these proofs deepens the
  appreciation of why the infinitude of primes is a cornerstone result,
  echoing the \emph{Fundamental Role} of primes highlighted in the
  Introduction (Section 1).
\end{itemize}

\section{5. Distribution and Density of
Primes}\label{distribution-and-density-of-primes}

\subsection{5.1 Prime Counting Function and Basic
Density}\label{prime-counting-function-and-basic-density}

The primary quantitative tool for describing how primes are spread among
the positive integers is the \textbf{prime‑counting function}

\(\pi(x)=\#\{p\le x\mid p\text{ is prime}\}.\)

Section 3 established the definition of a prime and the Fundamental
Theorem of Arithmetic, which guarantees that every integer
\textgreater{} 1 can be expressed uniquely as a product of primes.
Consequently, \(\pi(x)\) encodes the cumulative ``density'\,' of these
atomic building blocks up to a bound \(x\).

A naïve expectation might be that primes occur with a fixed proportion
of the integers, but empirical data (see §5.4) show a steadily
decreasing frequency. The ratio

\(\frac{\pi(x)}{x}\)

tends to zero as \(x\to\infty\); nevertheless, the product \(x\log x\)
grows at just the right rate to keep \(\pi(x)\) unbounded, a fact that
foreshadows the asymptotic law proved in Section 6 (the Prime Number
Theorem).

\subsection{5.2 Prime Gaps}\label{prime-gaps}

A \textbf{prime gap} is the difference between consecutive primes:

\(g_n = p_{n+1}-p_n,\)

where \(p_n\) denotes the \(n\)-th prime. The infinitude of primes
(Section 4) guarantees infinitely many gaps, but their size exhibits
rich structure.

\begin{itemize}
\item
  \textbf{Small gaps} - Twin primes correspond to gaps of size 2. The
  Twin Prime Conjecture (Section 10) asserts infinitely many such gaps;
  recent progress (Yitang Zhang, Maynard, Polymath) described in Section
  2 shows that gaps bounded by a fixed constant occur infinitely often.
\item
  \textbf{Large gaps} - Cramér's probabilistic model predicts that the
  maximal gap \(G(x)=\max\{g_n\mid p_n\le x\}\) satisfies
\end{itemize}

\(G(x)=O((\log x)^2).\)

Empirical tables (see §5.4) confirm that gaps of order \((\log x)^2\)
appear, though the exact constant remains unknown. The existence of
arbitrarily long gaps follows from a simple construction: for any \(k\)
the numbers

\((k+1)!+2,\; (k+1)!+3,\dots,(k+1)!+k+1\)

are all composite, producing a gap of length \(k\).

\subsection{5.3 Chebyshev Functions}\label{chebyshev-functions}

Before the full analytic machinery of the Prime Number Theorem was
available, Chebyshev introduced two auxiliary functions that capture
prime distribution more smoothly than \(\pi(x)\):

\begin{itemize}
\item
  \textbf{First Chebyshev function}

  \(\theta(x)=\sum_{p\le x}\log p,\)

  the sum of logarithms of primes up to \(x\).
\item
  \textbf{Second Chebyshev function}

  \(\psi(x)=\sum_{n\le x}\Lambda(n),\)

  where \(\Lambda(n)\) is the von Mangoldt function (equal to \(\log p\)
  if \(n=p^k\) for a prime \(p\) and zero otherwise). By construction
  \(\psi(x)\) counts prime powers with the same weight as primes,
  smoothing out the irregularities caused by occasional large gaps.
\end{itemize}

Chebyshev proved the celebrated \textbf{Chebyshev bounds} (see Section
2)

\(A\,\frac{x}{\log x}\le \pi(x)\le B\,\frac{x}{\log x}\)

for suitable constants \(A,B>0\). Equivalently,

\(c_1\,x \le \theta(x) \le c_2\,x,\qquad
c_3\,x \le \psi(x) \le c_4\,x,\)

showing that both \(\theta(x)\) and \(\psi(x)\) grow linearly with
\(x\). These inequalities were the first rigorous step toward the
asymptotic law later formalised in Section 6.

\subsection{5.4 Empirical Observations}\label{empirical-observations}

Computational experiments (Section 11) provide concrete insight into the
abstract concepts above. A brief snapshot of data up to \(10^{9}\)
illustrates the trends:

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.1553}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.1165}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.2136}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.3010}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.2136}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
\(x\)
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
\(\pi(x)\)
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
\(\pi(x)\log x / x\)
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
average gap \(\approx \log x\)
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
maximal gap observed
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\(10^{4}\) & 1229 & 0.92 & 9.2 & 36 \\
\(10^{6}\) & 78498 & 0.96 & 13.8 & 154 \\
\(10^{8}\) & 5761455 & 0.98 & 18.4 & 720 \\
\(10^{9}\) & 50847534 & 0.99 & 20.7 & 1540 \\
\end{longtable}

\begin{itemize}
\tightlist
\item
  The ratio \(\pi(x)\log x / x\) approaches 1, echoing the statement of
  the Prime Number Theorem.\\
\item
  The \textbf{average gap} between consecutive primes near \(x\) is
  roughly \(\log x\), confirming the heuristic that primes become
  sparser at a logarithmic rate.\\
\item
  The \textbf{maximal gaps} grow faster than the average, roughly in
  line with Cramér's \((\log x)^2\) prediction.
\end{itemize}

Plotting \(\theta(x)\) and \(\psi(x)\) against \(x\) reveals smooth,
nearly linear curves with small oscillations that correspond to the
irregular distribution of primes. These oscillations are later explained
by the non‑trivial zeros of the Riemann zeta function (Section 6 and
Section 10).

\subsection{5.5 Bridge to Later Topics}\label{bridge-to-later-topics}

Understanding the distribution and density of primes sets the stage for
the deeper analytic results of Section 6, where the \textbf{Prime Number
Theorem} refines the heuristic \(\pi(x)\sim x/\log x\) into a precise
asymptotic equality. The Chebyshev functions introduced here reappear in
the explicit formulae linking \(\pi(x)\) to the zeros of \(\zeta(s)\), a
cornerstone of the Riemann Hypothesis discussion in Section 10.

Moreover, the statistical picture of prime gaps informs the design of
\textbf{primality testing algorithms} (Section 7) and the selection of
safe primes for \textbf{cryptographic protocols} (Section 8). For
instance, many key‑generation routines avoid primes that lie in
unusually large gaps to reduce the risk of accidental weak parameters.

In summary, the empirical and theoretical tools presented in this
section provide the quantitative language that underpins the remainder
of the primer, from asymptotic theorems to practical applications.

\section{6. The Prime Number Theorem}\label{the-prime-number-theorem}

\subsection{6.1 Statement of the Prime Number
Theorem}\label{statement-of-the-prime-number-theorem}

The \textbf{Prime Number Theorem (PNT)} asserts that the prime‑counting
function

\(\pi(x)=\#\{p\le x\;|\;p\text{ prime}\}\)

satisfies

\(\boxed{\displaystyle \lim_{x\to\infty}\frac{\pi(x)}{x/\log x}=1 } .\)

Equivalently,

\(\pi(x)=\frac{x}{\log x}+o\!\left(\frac{x}{\log x}\right)\qquad (x\to\infty).\)

In words, the density of primes near a large number \(x\) is about
\(1/\log x\).

\subsection{6.2 Why the Theorem Matters}\label{why-the-theorem-matters}

\begin{itemize}
\item
  \textbf{Quantitative insight into distribution.} Section 5 introduced
  the empirical observation that \(\pi(x)\log x/x\) appears to approach
  1. The PNT turns this observation into a rigorous asymptotic law,
  confirming the intuition that primes become sparser but in a precisely
  predictable way.
\item
  \textbf{Foundation for analytic number theory.} The theorem links the
  additive world of integers (counting primes) with the multiplicative
  world of the Riemann zeta‑function \(\zeta(s)=\sum_{n\ge1}n^{-s}\).
  This bridge underlies later topics such as the explicit formulae for
  \(\pi(x)\) (Section 10) and the security analyses of cryptographic
  protocols (Section 8).
\item
  \textbf{Practical approximation.} For algorithm designers (Section 7)
  and cryptographers (Section 8), the PNT provides a quick way to
  estimate how many primes lie below a bound, which is essential when
  generating large random primes of a prescribed size.
\end{itemize}

\subsection{6.3 Sketch of the Analytic
Proof}\label{sketch-of-the-analytic-proof}

The full proof requires complex analysis; here we outline the main
ideas, emphasizing the role of the \textbf{Chebyshev functions}
\(\theta(x)\) and \(\psi(x)\) introduced in Section 5.

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  \textbf{From \(\pi(x)\) to \(\psi(x)\).}\\
  Define the von Mangoldt function

  \(\Lambda(n)=\begin{cases}
  \log p & \text{if } n=p^{k}\text{ for a prime }p\text{ and }k\ge1,\\[4pt]
  0 & \text{otherwise}.
  \end{cases}\)

  Then

  \(\psi(x)=\sum_{n\le x}\Lambda(n)=\sum_{p^{k}\le x}\log p .\)

  One shows that \(\psi(x)\) and \(\pi(x)\) have the same leading
  asymptotic behaviour; indeed

  \(\psi(x)=\pi(x)\log x+O\!\bigl(\pi(x)\bigr).\)
\item
  \textbf{Euler product and logarithmic derivative.}\\
  For \(\Re(s)>1\),

  \(-\frac{\zeta'(s)}{\zeta(s)}=\sum_{n=1}^{\infty}\frac{\Lambda(n)}{n^{s}}.\)

  This Dirichlet series is the Mellin transform of \(\psi(x)\). Thus
  analytic information about \(\zeta(s)\) translates into information
  about \(\psi(x)\).
\item
  \textbf{Zero‑free region.}\\
  Hadamard (1896) and de la Vallée Poussin (1896) proved that
  \(\zeta(s)\neq0\) on the line \(\Re(s)=1\). Their argument uses
  \textbf{Hadamard's factorisation} and bounds on \(\zeta(s)\) in the
  critical strip, yielding a \emph{zero‑free region} of the form

  \(\Re(s)\ge 1-\frac{c}{\log(|\Im s|+2)}\qquad (|\,\Im s\,|\ge 2)\)

  for some constant \(c>0\).
\item
  \textbf{Tauberian step.}\\
  Applying a \textbf{Tauberian theorem} (e.g., Ikehara's theorem) to the
  non‑vanishing of \(\zeta(s)\) on \(\Re(s)=1\) gives

  \(\psi(x)\sim x\quad (x\to\infty).\)

  Because \(\psi(x)\) and \(\pi(x)\) differ only by lower‑order terms,
  we obtain

  \(\pi(x)\sim\frac{x}{\log x}.\)
\item
  \textbf{Chebyshev's inequalities as a warm‑up.}\\
  Earlier, Chebyshev (Section 5) proved constants \(c_{1},c_{2}>0\) with

  \(c_{1}x\le\psi(x)\le c_{2}x\quad (x\ge 2),\)

  establishing that \(\psi(x)\) grows linearly. The zero‑free region
  sharpens this to the exact asymptotic constant 1.
\end{enumerate}

The proof therefore proceeds from the \textbf{Euler product} (linking
primes to \(\zeta\)), through \textbf{complex‑analytic control of
zeros}, to a \textbf{Tauberian conclusion} that translates analytic
growth into the arithmetic statement of the PNT.

\subsection{\texorpdfstring{6.4 Using the PNT to Approximate
\(\pi(x)\)}{6.4 Using the PNT to Approximate \textbackslash pi(x)}}\label{using-the-pnt-to-approximate-pix}

The theorem suggests the simple approximation

\(\boxed{\displaystyle \pi(x)\approx \operatorname{Li}(x)=\int_{2}^{x}\frac{dt}{\log t}} .\)

\begin{itemize}
\item
  \textbf{Why \(\operatorname{Li}(x)\) is better than \(x/\log x\).}\\
  The integral \(\operatorname{Li}(x)\) incorporates the slowly varying
  nature of \(\log t\) and is known (empirically, see Section 5) to be
  closer to the true \(\pi(x)\) for moderate values of \(x\).
\item
  \textbf{Error term.}\\
  The strongest unconditional result (due to Korobov-Vinogradov) gives

  \(\pi(x)=\operatorname{Li}(x)+O\!\bigl(x\,e^{-c(\log x)^{3/5}(\log\log x)^{-1/5}}\bigr),\)

  where \(c>0\). Assuming the Riemann Hypothesis (Section 10) the error
  improves dramatically to

  \(\pi(x)=\operatorname{Li}(x)+O\!\bigl(\sqrt{x}\log x\bigr).\)
\item
  \textbf{Practical computation.}\\
  For generating a random \(k\)-bit prime (Section 8), one often
  estimates the expected number of trials by

  \(\frac{2^{k}}{k\log 2}\approx\frac{2^{k}}{\log(2^{k})},\)

  i.e., the reciprocal of the density \(1/\log(2^{k})\) supplied by the
  PNT. This guides the choice of security parameters in RSA and
  Diffie-Hellman key generation.
\item
  \textbf{Numerical illustration.}\\
  Using the approximation \(\operatorname{Li}(x)\) for \(x=10^{6}\)
  gives \(\operatorname{Li}(10^{6})\approx 78\,628\), while the exact
  count is \(\pi(10^{6})=78\,498\); the relative error is about
  \(0.17\%\). The cruder \(x/\log x\) yields \(72\,382\), a larger error
  of \(7.8\%\). This demonstrates the practical superiority of the
  logarithmic integral, a direct consequence of the PNT.
\end{itemize}

\subsection{6.5 Connections to the Rest of the
Primer}\label{connections-to-the-rest-of-the-primer}

\begin{itemize}
\item
  \textbf{Section 5 (Distribution and Density).} The PNT formalises the
  asymptotic trend hinted at by the empirical data and Chebyshev bounds
  discussed there.
\item
  \textbf{Section 7 (Primality Testing).} Knowledge of prime density
  informs the expected runtime of probabilistic tests such as
  Miller-Rabin, because the probability that a random odd integer of
  size \(x\) is prime is roughly \(1/\log x\).
\item
  \textbf{Section 8 (Cryptographic Applications).} Secure key generation
  relies on the PNT to estimate how many candidates must be examined
  before a suitable prime is found, and to justify the use of ``large
  enough'' modulus sizes.
\item
  \textbf{Section 10 (Open Problems).} The error term in the PNT is
  intimately tied to the location of zeros of \(\zeta(s)\); the Riemann
  Hypothesis would sharpen the error to \(O(\sqrt{x}\log x)\), a central
  conjecture highlighted in that section.
\item
  \textbf{Section 11 (Computational Techniques).} Software packages
  (PARI/GP, SageMath, Mathematica) implement \(\operatorname{Li}(x)\)
  and related approximations, allowing students to experiment with the
  accuracy of the PNT across many orders of magnitude.
\end{itemize}

\subsection{6.6 Summary}\label{summary-1}

The Prime Number Theorem provides the first precise asymptotic
description of how primes are distributed among the integers. Its proof
showcases a beautiful synthesis of elementary number‑theoretic concepts
(Section 3), combinatorial bounds (Section 5), and deep complex‑analytic
machinery (Euler product, zero‑free regions, Tauberian theorems). Beyond
its theoretical elegance, the theorem supplies a practical tool - via
the approximation \(\pi(x)\approx\operatorname{Li}(x)\) - that underpins
algorithmic and cryptographic work throughout the remainder of this
primer.

\section{7. Primality Testing
Algorithms}\label{primality-testing-algorithms}

\subsection{7.1 Deterministic Primality
Tests}\label{deterministic-primality-tests}

Deterministic algorithms guarantee a correct ``prime'' or ``composite''
answer for every input. The most elementary is \textbf{trial division},
which directly applies the divisibility rules from Section 3 (e.g.,
eliminating even numbers, checking divisibility by 3, 5, etc.) and then
tests all primes \(p \le \sqrt{n}\). Its worst‑case time is
\(O(\sqrt{n})\) arithmetic operations, which is exponential in the
number of bits of \(n\) and therefore impractical for large
cryptographic sizes (see the practical usage discussion in Section 8).

More sophisticated deterministic methods include:

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1864}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1864}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.4915}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1356}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Algorithm
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Core Idea
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Complexity (bit‑operations)
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Remarks
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{AKS (Agrawal‑Kayal‑Saxena)} & Uses polynomial congruences
\((x+a)^n \equiv x^n + a \pmod{n}\) for all \(a\) up to a bound derived
from \(\log n\). & \(\tilde{O}((\log n)^6)\) (currently the best proven
bound) & First unconditional polynomial‑time test (Section 2, AKS
highlighted). In practice it is slower than probabilistic tests because
of large hidden constants. \\
\textbf{Elliptic Curve Primality Proving (ECPP)} & Constructs an
elliptic curve with known order and reduces primality of \(n\) to that
of a smaller integer. & Expected \(\tilde{O}((\log n)^5)\) & Provides a
\emph{certificate} of primality that can be verified quickly; widely
used in large‑prime searches (e.g., GIMPS, see Section 2). \\
\textbf{Deterministic variants of Miller-Rabin} (e.g., using known bases
for numbers below a fixed bound) & For numbers below certain thresholds,
a small fixed set of bases suffices to make Miller-Rabin deterministic.
& Same as Miller-Rabin, \(O(k \log^3 n)\) where \(k\) is the number of
bases & Useful for 32‑ or 64‑bit integers; eliminates the probabilistic
``error'' while retaining speed. \\
\end{longtable}

These deterministic methods are essential when a \emph{proof} of
primality is required (e.g., publishing a new record prime, formal
verification, or generating primes for standards that demand
certificates).

\subsection{7.2 Probabilistic Primality
Tests}\label{probabilistic-primality-tests}

Probabilistic algorithms trade a negligible error probability for
dramatically lower running time, making them the workhorses of modern
cryptographic key generation (see Section 8).

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1017}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1864}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3729}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3390}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Test
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Principle
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
One‑round Complexity
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Error Probability
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Fermat test} & Checks Fermat's little theorem:
\(a^{n-1} \equiv 1 \pmod n\) for random base \(a\). & \(O(\log^3 n)\)
(modular exponentiation) & Up to \(1/2\) for Carmichael numbers; rarely
used alone. \\
\textbf{Miller-Rabin} & Writes \(n-1 = 2^s d\) with \(d\) odd; tests
whether \(a^d\) is a non‑trivial square root of 1 modulo \(n\). &
\(O(\log^3 n)\) per base & At most \(1/4\) per round; error drops
exponentially with independent rounds. \\
\textbf{Solovay-Strassen} & Uses Euler's criterion: compare the Jacobi
symbol \((a|n)\) with \(a^{(n-1)/2} \pmod n\). & \(O(\log^3 n)\) & Error
≤ \(1/2\) per round; historically important but slower than
Miller-Rabin. \\
\textbf{Baillie-PSW} (combined strong Lucas + Miller-Rabin) & No known
counter‑examples; combines a Miller-Rabin base‑2 test with a Lucas test.
& Slightly higher than a single Miller-Rabin round & Practically
deterministic for all numbers encountered in practice. \\
\end{longtable}

Because each round costs only a few modular exponentiations, a handful
of rounds (typically 20-40 for 1024‑bit numbers) yields an error
probability far below \(2^{-80}\), which is acceptable for virtually all
cryptographic protocols.

\subsection{7.3 Complexity Landscape}\label{complexity-landscape}

The computational cost of a primality test is measured in bit‑operations
as a function of the input size \(L = \log_2 n\). Table 1 summarizes the
asymptotic bounds discussed above, together with the \emph{expected}
number of candidates examined when searching for a random \(L\)-bit
prime. The expected density follows directly from the Prime Number
Theorem (Section 6): the probability that a random odd \(L\)-bit integer
is prime is roughly \(1/(L\ln 2)\).

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1053}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3158}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.5789}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Test
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Asymptotic Cost
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Expected Trials to Find a Prime
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
Trial division (up to \(\sqrt{n}\)) & \(O(2^{L/2})\) - exponential & Not
applicable (too slow) \\
Miller-Rabin (k rounds) & \(O(k L^3)\) & \(\approx L\ln 2\) ≈ 0.69 L
trials \\
Baillie-PSW (single round) & \(O(L^3)\) & Same as Miller-Rabin with
\(k=1\) \\
AKS & \(\tilde{O}(L^6)\) & Same as deterministic: one trial needed \\
ECPP (with certificate) & \(\tilde{O}(L^5)\) (expected) & One trial;
certificate verification \(O(L^2)\) \\
\end{longtable}

\emph{Key observation}: probabilistic tests dominate in practice because
their per‑candidate cost grows only polynomially in \(L\) while the
expected number of candidates is linear in \(L\) (Section 6).
Deterministic tests become competitive only when a \emph{certificate} is
required or when the input size is modest (e.g., 32‑bit integers where a
fixed set of Miller-Rabin bases suffices).

\subsection{7.4 Practical Usage and Implementation
Tips}\label{practical-usage-and-implementation-tips}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \textbf{Pre‑screening with Simple Filters}

  \begin{itemize}
  \tightlist
  \item
    Apply the divisibility rules from Section 3 (evenness, divisibility
    by 3, 5, 7) and a quick \textbf{small‑prime trial division} (e.g.,
    up to the first 100 primes). This eliminates the majority of
    composites before invoking a heavier test.
  \end{itemize}
\item
  \textbf{Choosing a Probabilistic Core}

  \begin{itemize}
  \tightlist
  \item
    For cryptographic key generation (Section 8), the standard pipeline
    is:

    \begin{enumerate}
    \def\labelenumii{\alph{enumii}.}
    \tightlist
    \item
      Generate a random odd \(L\)-bit integer.\\
    \item
      Perform a few rounds of Miller-Rabin with bases \(2,3,5,7,11\) (or
      a deterministic base set for the target size).\\
    \item
      Optionally run a Baillie-PSW or a strong Lucas test for added
      confidence.\\
    \end{enumerate}
  \item
    The combined error probability becomes astronomically small (far
    below the security parameter).
  \end{itemize}
\item
  \textbf{When to Use Deterministic Proofs}

  \begin{itemize}
  \tightlist
  \item
    \textbf{Record‑setting primes}: AKS or ECPP provide verifiable
    certificates that can be independently checked.\\
  \item
    \textbf{Formal verification}: Proof assistants (Coq, Lean) often
    rely on deterministic algorithms to certify primality within a
    proof.\\
  \item
    \textbf{Regulatory standards}: Some standards (e.g., FIPS 186‑4)
    require a proof of primality for certain key sizes; ECPP
    certificates are accepted.
  \end{itemize}
\item
  \textbf{Software Support}

  \begin{itemize}
  \tightlist
  \item
    Libraries highlighted in Section 11 (PARI/GP, SageMath, Mathematica)
    expose high‑level functions such as \texttt{isprime},
    \texttt{is\_probable\_prime}, and \texttt{prime\_certificate}. Under
    the hood they combine the strategies described here, automatically
    selecting the most efficient algorithm for the given size.
  \end{itemize}
\item
  \textbf{Parallel and Distributed Search}

  \begin{itemize}
  \tightlist
  \item
    For massive prime hunts (e.g., Mersenne primes), the workflow is:
    generate candidate exponents, run a fast probabilistic filter, then
    apply a deterministic proof (Lucas-Lehmer for Mersenne numbers, ECPP
    for general primes). This two‑stage approach mirrors the
    ``probabilistic‑deterministic hybrid'' pattern discussed throughout
    the primer.
  \end{itemize}
\end{enumerate}

\subsection{7.5 Selecting the Right Test for Your
Application}\label{selecting-the-right-test-for-your-application}

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2000}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2923}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3231}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1846}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Application
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Typical Bit‑Size
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Recommended Test(s)
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Reasoning
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Embedded devices (e.g., IoT)} & ≤ 256 bits & Fixed‑base
Miller-Rabin (deterministic for this range) + small‑prime trial division
& Low memory, deterministic guarantee needed for certification. \\
\textbf{Standard RSA/DH key generation} & 2048-4096 bits & 20-40 rounds
of Miller-Rabin + optional Baillie-PSW & Provides negligible error; fast
enough for on‑the‑fly key creation. \\
\textbf{Large‑prime research (≥ 10 000 bits)} & ≥ 10 000 bits & ECPP
with certificate generation; fallback to AKS only for verification &
Certificate enables third‑party verification; AKS serves as a
theoretical baseline. \\
\textbf{Academic proof‑checking} & Any size & AKS (for unconditional
polynomial time) or ECPP (for practical certificates) & Guarantees a
proof that can be formally verified. \\
\end{longtable}

In all cases, the \textbf{expected number of candidates} before a prime
is found follows the density estimate from the Prime Number Theorem
(Section 6). For a 2048‑bit modulus, one expects roughly
\(2048 \times \ln 2 \approx 1418\) random odd numbers before hitting a
prime; the cost of each Miller-Rabin round is negligible compared with
the overall generation time.

\subsection{7.6 Summary}\label{summary-2}

\begin{itemize}
\tightlist
\item
  Deterministic tests (trial division, AKS, ECPP) provide absolute
  certainty and, in some contexts, a verifiable certificate.\\
\item
  Probabilistic tests (Miller-Rabin, Baillie-PSW, Solovay-Strassen)
  achieve dramatically lower runtime, with error probabilities that can
  be driven below any security threshold.\\
\item
  Complexity analysis shows a clear trade‑off: exponential cost for
  naïve deterministic methods versus polynomial cost for modern
  algorithms, with the latter dominating practical implementations.\\
\item
  The Prime Number Theorem (Section 6) supplies the expected density of
  primes, guiding how many candidates must be examined on average.\\
\item
  Real‑world implementations (Section 11) combine lightweight
  pre‑screening, fast probabilistic cores, and optional deterministic
  certification to meet the diverse requirements of cryptographic
  systems, large‑scale prime searches, and formal verification.
\end{itemize}

\section{8. Cryptographic
Applications}\label{cryptographic-applications}

\subsection{8.1 RSA and the Role of Large
Primes}\label{rsa-and-the-role-of-large-primes}

RSA (Rivest-Shamir-Adleman) is the archetypal public‑key encryption
scheme. Its security rests on the difficulty of factoring a modulus

\(N = p\;q,\)

where \(p\) and \(q\) are distinct large \textbf{prime numbers} (see
Section 3 for the definition of primes). The Fundamental Theorem of
Arithmetic guarantees that the factorisation of \(N\) into primes is
unique; consequently, knowing only \(N\) gives no information about the
individual primes without solving the integer‑factorisation problem,
which is believed to be computationally infeasible for moduli of size
2048 bits and above.

Key generation proceeds as follows (mirroring the workflow described in
Section 7):

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \textbf{Generate two random odd candidates} of the desired
  bit‑length.\\
\item
  \textbf{Apply a fast pre‑screen} using small‑prime divisibility rules
  (Section 3) and a probabilistic primality test such as Miller-Rabin
  (Section 7).\\
\item
  \textbf{Confirm primality} with a stronger test (e.g., a few
  additional Miller-Rabin rounds or a deterministic certificate via
  ECPP, see Section 7).\\
\item
  \textbf{Compute the modulus} \(N = p q\) and the public exponent \(e\)
  (commonly 65537).\\
\item
  \textbf{Derive the private exponent} \(d\) as the modular inverse of
  \(e\) modulo \(\varphi(N) = (p-1)(q-1)\).
\end{enumerate}

The \textbf{Prime Number Theorem} (Section 6) tells us that the
probability a random \(k\)-bit odd integer is prime is roughly
\(1/(k\ln 2)\). Hence, on average, about \(k\ln 2\) candidates must be
tested before a prime is found, a cost that is negligible compared with
the subsequent modular exponentiations.

\subsection{8.2 Diffie-Hellman Key Exchange and Safe
Primes}\label{diffie-hellman-key-exchange-and-safe-primes}

The Diffie-Hellman (DH) protocol establishes a shared secret over an
insecure channel by exploiting the hardness of the \textbf{discrete
logarithm problem} in a cyclic group \(\mathbb{Z}_p^{\times}\). For
maximal security, the prime modulus \(p\) is chosen to be a \textbf{safe
prime}:

\(p = 2q + 1,\qquad q\ \text{prime}.\)

Here \(q\) is a \textbf{Sophie Germain prime} (Section 9). The subgroup
of order \(q\) has no small factors, which thwarts the Pohlig-Hellman
attack that would otherwise reduce the discrete logarithm problem to
easier sub‑problems in each prime‑order factor of \(p-1\).

The DH key‑exchange steps are:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  Agree on a safe prime \(p\) and a generator \(g\) of the order ‑\(q\)
  subgroup.\\
\item
  Alice selects a secret \(a\in\{1,\dots,q-1\}\) and sends
  \(A = g^{a}\bmod p\).\\
\item
  Bob selects a secret \(b\) and sends \(B = g^{b}\bmod p\).\\
\item
  Both compute the shared secret \(K = g^{ab}\bmod p\) as
  \(K = B^{a}\bmod p = A^{b}\bmod p\).
\end{enumerate}

Because \(p\) is prime, \(\mathbb{Z}_p^{\times}\) is a cyclic group of
order \(p-1 = 2q\). The safe‑prime structure guarantees that the only
non‑trivial subgroups have orders 2 and \(q\), eliminating the
possibility of small‑order attacks.

\subsection{8.3 Requirements for Secure Prime
Generation}\label{requirements-for-secure-prime-generation}

A prime suitable for cryptographic use must satisfy several
\textbf{security criteria} beyond mere primality:

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3529}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3235}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3235}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Requirement
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Rationale
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Reference
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Bit‑length} & Determines the asymptotic hardness of factoring
(RSA) or discrete logarithms (DH). Modern standards recommend ≥ 2048
bits for RSA and ≥ 3072 bits for DH. & Section 6 (PNT) - predicts
density of primes at these sizes. \\
\textbf{Randomness \& Unpredictability} & Prevents an attacker from
pre‑computing a lookup table of candidate primes. Generation must use a
cryptographically secure RNG. & Section 1 (motivation) - primes underpin
digital security. \\
\textbf{Safe‑prime / Sophie Germain property} (for DH) & Eliminates
small‑subgroup attacks. & Section 9 (special classes). \\
\textbf{Absence of small factors in \(p-1\) and \(p+1\)} (for RSA) &
Mitigates Pollard's \(p-1\) and \(p+1\) factorisation methods. & Section
7 (primality testing) - includes trial division by small primes. \\
\textbf{Resistance to known special‑form attacks} & Avoid primes of the
form \(k\cdot 2^{n}+1\) (Fermat‑type) unless deliberately used (e.g.,
for efficient exponentiation). & Section 9 (Fermat primes). \\
\textbf{Certificate of primality (optional)} & Provides a verifiable
proof that the number is prime, useful for standards compliance and
large‑prime records. & Section 7 (ECPP, AKS). \\
\end{longtable}

The \textbf{generation pipeline} typically combines:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \textbf{Random candidate selection} (cryptographically secure RNG).\\
\item
  \textbf{Deterministic pre‑screening} using divisibility rules (Section
  3) and trial division by the first few hundred primes.\\
\item
  \textbf{Probabilistic primality testing} (Miller-Rabin, 20-40 rounds)
  to achieve an error probability below \(2^{-80}\) (Section 7).\\
\item
  \textbf{Optional deterministic certification} (ECPP) when a formal
  proof is required (Section 7).
\end{enumerate}

\subsection{8.4 Practical Considerations and
Standards}\label{practical-considerations-and-standards}

\begin{itemize}
\tightlist
\item
  \textbf{Library support} - Modern cryptographic libraries (OpenSSL,
  Bouncy Castle, libsodium) implement the above pipeline and expose
  high‑level APIs for RSA/DH key generation. They internally rely on the
  algorithms discussed in Sections 7 and 11 (software tools).\\
\item
  \textbf{Parameter validation} - Standards such as \textbf{FIPS 186‑4}
  and \textbf{NIST SP 800‑57} prescribe minimum bit‑lengths, safe‑prime
  generation methods, and the number of Miller-Rabin rounds.\\
\item
  \textbf{Performance vs.~security trade‑off} - For constrained devices,
  deterministic Miller-Rabin with a fixed set of bases (e.g.,
  \{2,3,5,7,11\}) offers a good balance, while server‑grade systems can
  afford the extra cost of ECPP certificates for auditability.\\
\item
  \textbf{Side‑channel resistance} - Prime generation must avoid timing
  leaks; constant‑time implementations of modular exponentiation and
  primality tests are recommended (see Section 7 for algorithmic
  complexity considerations).
\end{itemize}

\subsection{8.5 Future Directions}\label{future-directions}

\begin{itemize}
\tightlist
\item
  \textbf{Post‑quantum safe primes} - Lattice‑based schemes do not
  require large primes, but hybrid protocols may still use RSA/DH for
  compatibility; research is ongoing into generating primes that remain
  hard for quantum algorithms (e.g., Grover‑accelerated factoring).\\
\item
  \textbf{Prime‑generation accelerators} - Hardware random‑number
  generators combined with on‑chip Miller-Rabin engines can reduce
  latency for TLS handshakes.\\
\item
  \textbf{Formal verification} - Integrating deterministic certificates
  (ECPP) with proof assistants (Coq, Lean) to produce machine‑checked
  proofs of primality, enhancing trust in critical infrastructure.
\end{itemize}

These developments continue the theme introduced in the
\textbf{Introduction} (Section 1): primes are not only a deep
mathematical object but also a living foundation of secure digital
communication.

\section{9. Special Classes of Primes}\label{special-classes-of-primes}

\subsection{9.1 Twin Primes}\label{twin-primes}

Twin primes are pairs of primes \((p,\,p+2)\) that differ by the
smallest possible even gap. The first few examples are
\((3,5),\,(5,7),\,(11,13),\,(17,19)\). Their study is intimately linked
to the \textbf{prime‑gap} discussion in Section 5, where gaps of size 2
are highlighted as the most mysterious.

\textbf{Key properties}

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.4348}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5652}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Property
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Description
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Infinitude conjecture} & The \emph{Twin Prime Conjecture} (see
Section 10) asserts that there are infinitely many such pairs. Despite
the infinitude of primes proved in Section 4, no proof of this stronger
statement is known. \\
\textbf{Density heuristic} & Heuristics based on the Hardy-Littlewood
prime‑pair constant predict that the number of twin primes ≤ \(x\) is
asymptotically \(\displaystyle 2C_2\frac{x}{(\log x)^2}\), where
\(C_2\approx0.66016\). This follows the same \(\frac{x}{\log x}\)
scaling of \(\pi(x)\) (Section 6) but with an extra \(\log x\) in the
denominator, reflecting the rarity of the gap 2. \\
\textbf{Empirical evidence} & Computational searches (Section 11) have
verified twin‑prime pairs up to at least \(10^{15}\); the current record
twin‑prime pair exceeds \(10^{30}\). \\
\textbf{Connection to bounded gaps} & Yitang Zhang's 2013 breakthrough
(mentioned in Section 2) proved the existence of infinitely many prime
pairs with a bounded gap \(<70\,\!000\,000\); subsequent Polymath
refinements reduced this bound dramatically, providing strong indirect
support for the twin‑prime conjecture. \\
\end{longtable}

\textbf{Open questions}

\begin{itemize}
\tightlist
\item
  Prove the Twin Prime Conjecture.\\
\item
  Determine the exact value of the twin‑prime constant \(C_2\).\\
\item
  Understand the distribution of larger prime constellations (e.g.,
  prime triplets) in the framework of the Hardy-Littlewood k‑tuple
  conjecture (Section 10).
\end{itemize}

\subsection{9.2 Mersenne Primes}\label{mersenne-primes}

A \textbf{Mersenne prime} has the form \(M_p = 2^{p}-1\) where the
exponent \(p\) itself is prime. The name honors Marin Mersenne, who
catalogued many such numbers in the 17th century.

\textbf{Key properties}

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.4348}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5652}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Property
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Description
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Necessary condition} & If \(M_p\) is prime, then \(p\) must be
prime (converse is false; many prime exponents yield composite Mersenne
numbers). \\
\textbf{Perfect‑number link} & Euclid's theorem (Section 3) shows that
an even perfect number is exactly \(\frac{M_p(p+1)}{2}\) when \(M_p\) is
prime; Euler proved the converse. Thus every Mersenne prime generates a
perfect number, and no odd perfect numbers are known. \\
\textbf{Distribution} & The known Mersenne primes are extremely sparse;
only 51 have been discovered (as of 2026) via the GIMPS project. Their
indices \(p\) grow roughly exponentially, reflecting the rapid growth of
\(2^{p}\). \\
\textbf{Testing} & The \textbf{Lucas-Lehmer test} is a deterministic,
fast algorithm specialized for Mersenne numbers. It exploits the
algebraic structure of \(2^{p}-1\) and is far more efficient than the
general‑purpose tests described in Section 7. \\
\end{longtable}

\textbf{Open questions}

\begin{itemize}
\tightlist
\item
  Are there infinitely many Mersenne primes? This remains an open
  problem, analogous to the infinitude of twin primes.\\
\item
  Can a density model be formulated that predicts the expected gaps
  between successive Mersenne exponents?
\end{itemize}

\subsection{9.3 Fermat Primes}\label{fermat-primes}

Fermat primes are numbers of the form \(F_n = 2^{2^{n}}+1\) with
\(n\ge 0\). Pierre de Fermat conjectured that all such numbers are
prime; Euler disproved this for \(n=5\).

\textbf{Key properties}

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.4348}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5652}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Property
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Description
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Known examples} & The only confirmed Fermat primes are
\(F_0=3,\;F_1=5,\;F_2=17,\;F_3=257,\;F_4=65537\). For \(n\ge5\) every
\(F_n\) examined up to at least \(n=32\) is composite. \\
\textbf{Geometric significance} & A regular polygon with \(F_n\) sides
is constructible with straightedge and compass; this classical result
ties Fermat primes to the theory of constructible numbers (Section
3). \\
\textbf{Testing} & Because \(F_n\) has a very special form, specialized
primality proofs (e.g., Pepin's test) are far more efficient than
generic algorithms from Section 7. \\
\textbf{Connection to cryptography} & While Fermat primes are not used
directly in RSA or DH, their constructibility property inspired early
cryptographic protocols based on cyclotomic fields. \\
\end{longtable}

\textbf{Open questions}

\begin{itemize}
\tightlist
\item
  Does any Fermat prime exist beyond \(F_4\)? No proof of finiteness is
  known.\\
\item
  Can a deeper algebraic reason be identified for the apparent scarcity
  of Fermat primes?
\end{itemize}

\subsection{9.4 Sophie Germain Primes}\label{sophie-germain-primes}

A prime \(p\) is a \textbf{Sophie Germain prime} if \(2p+1\) is also
prime; the latter prime is called a \emph{safe prime}. These pairs are
central to the Diffie-Hellman key‑exchange discussed in Section 8, where
safe primes protect against small‑subgroup attacks.

\textbf{Key properties}

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.4348}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5652}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Property
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Description
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Safety condition} & If \(p\) is Sophie Germain, then the safe
prime \(q=2p+1\) has a large prime factor \((q-1)/2\), which is useful
for cryptographic group order selection. \\
\textbf{Density heuristic} & Heuristics analogous to those for twin
primes suggest that the number of Sophie Germain primes ≤ \(x\) is about
\(2C_{SG}\frac{x}{(\log x)^2}\) with a constant
\(C_{SG}\approx0.660\). \\
\textbf{Empirical data} & Searches using the software of Section 11 have
identified Sophie Germain primes with thousands of digits; the current
record exceeds \(10^{7}\) bits. \\
\textbf{Testing} & The Lucas-Lehmer-Riesel test (a variant of the
Lucas-Lehmer test) can efficiently verify the primality of the
associated safe prime, complementing the Miller-Rabin pipeline of
Section 7. \\
\end{longtable}

\textbf{Open questions}

\begin{itemize}
\tightlist
\item
  Prove that there are infinitely many Sophie Germain primes (a
  conjecture parallel to the Twin Prime Conjecture).\\
\item
  Determine precise constants governing their distribution.
\end{itemize}

\subsection{9.5 Synthesis and Outlook}\label{synthesis-and-outlook}

The families described above illustrate how imposing \textbf{additional
algebraic constraints} on the generic prime definition (Section 3)
yields sequences with striking arithmetic and geometric features, yet
each family also spawns deep unsolved problems. Their study leverages
many tools introduced earlier:

\begin{itemize}
\tightlist
\item
  \textbf{Distribution insights} from Sections 5 and 6 provide the
  heuristic frameworks for expected densities.\\
\item
  \textbf{Primality‑testing algorithms} (Section 7) are specialized for
  each form (Lucas-Lehmer for Mersenne, Pepin for Fermat, Miller-Rabin
  plus safe‑prime checks for Sophie Germain).\\
\item
  \textbf{Cryptographic relevance} (Section 8) motivates the practical
  generation of safe primes and motivates continued research on
  efficient, provably secure prime‑generation pipelines.\\
\item
  \textbf{Computational experimentation} (Section 11) remains the
  primary engine for discovering new members of these families and for
  testing conjectural density formulas.
\end{itemize}

The open questions listed for each class are collected and expanded in
Section 10, where they are placed in the broader landscape of
prime‑number research. Progress on any of these families often yields
new techniques that reverberate through the entire theory of primes,
underscoring the central role of \emph{special classes} in the ongoing
quest to understand the integers.

\section{10. Open Problems and
Conjectures}\label{open-problems-and-conjectures}

\subsection{10.1 Twin Prime Conjecture}\label{twin-prime-conjecture}

The \textbf{Twin Prime Conjecture} asserts that there are infinitely
many prime pairs \((p,\,p+2)\). Section 9 introduced twin primes as the
smallest possible prime gaps and highlighted the heuristic density\\
\(\sim 2C_{2}\frac{x}{(\log x)^{2}},\qquad C_{2}\approx0.66016,\)\\
derived from the Hardy-Littlewood prime‑pair conjecture. Empirical
verification extends beyond \(10^{30}\) (Section 9), and the
breakthrough bounded‑gap result of Yitang Zhang (2013) together with the
Polymath refinements (Section 2) established the existence of infinitely
many prime pairs with a fixed maximal gap, but the gap = 2 case remains
open.

\textbf{Relevance:}\\
- A resolution would settle a central question about the fine‑scale
structure of the prime distribution introduced in Section 5 (prime
gaps).\\
- It would sharpen error‑term estimates in the \textbf{Prime Number
Theorem} (Section 6) because the conjectured density directly influences
the secondary term in \(\pi(x)\).\\
- Many probabilistic models of primes (Cramér, Granville) and sieve
methods (Brun, Selberg) are calibrated against the twin‑prime heuristic;
confirming the conjecture would validate a large body of analytic
machinery.

\subsection{10.2 Goldbach's Conjecture}\label{goldbachs-conjecture}

\textbf{Goldbach's conjecture} (strong form) posits that every even
integer \(2n\ge 4\) can be expressed as the sum of two primes. Section 9
noted the conjecture's connection to the Hardy-Littlewood circle method,
while Section 5's discussion of prime gaps and empirical data show that
the conjecture holds for all even numbers up to at least
\(4\times10^{18}\) (verified with the computational tools of Section
11).

\textbf{Relevance:}\\
- It links additive and multiplicative aspects of primes, complementing
the multiplicative focus of the \textbf{Fundamental Theorem of
Arithmetic} (Section 3).\\
- A proof would likely require new insights into the distribution of
primes in short intervals, extending the Chebyshev function analysis of
Section 5 and the zero‑free region techniques of the \textbf{Prime
Number Theorem} (Section 6).\\
- The conjecture underlies many heuristic arguments in cryptographic
key‑generation (Section 8), where the abundance of prime pairs
influences the expected runtime of random‑prime searches.

\subsection{10.3 Riemann Hypothesis}\label{riemann-hypothesis}

The \textbf{Riemann Hypothesis (RH)} states that all non‑trivial zeros
of the Riemann zeta‑function \(\zeta(s)\) lie on the critical line
\(\Re(s)=\tfrac12\). Section 2 traced the origin of this hypothesis to
Riemann's 1859 paper, and Section 6 showed how the zero‑free region on
\(\Re(s)=1\) yields the \textbf{Prime Number Theorem}. Under RH, the
error term in the PNT improves to\\
\(\pi(x)=\operatorname{Li}(x)+O(\sqrt{x}\log x),\)\\
far sharper than the unconditional bound quoted in Section 6.

\textbf{Relevance:}\\
- RH governs the fluctuations of \(\pi(x)\), \(\theta(x)\), and
\(\psi(x)\) (Section 5), providing a unified explanation for the
observed regularity of prime distribution.\\
- Many conditional results in analytic number theory - such as the
density of twin primes, the distribution of gaps, and the validity of
the \textbf{Goldbach conjecture} for large numbers - are proved assuming
RH.\\
- In cryptography (Section 8), RH‑based estimates refine the expected
number of trials to find a random prime of a given size, influencing
key‑generation efficiency.

\subsection{10.4 Other Prominent
Conjectures}\label{other-prominent-conjectures}

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2182}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2182}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2727}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2909}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Conjecture
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Statement
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Section Links
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Why It Matters
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{Legendre's Conjecture} & There is at least one prime between
\(n^{2}\) and \((n+1)^{2}\) for every \(n\ge1\). & Relates to the
density results of Section 5 and the asymptotics of Section 6. &
Provides a simple yet deep statement about prime occurrence in short
intervals. \\
\textbf{Cramér's Conjecture} & The maximal prime gap \(g_{n}\) satisfies
\(g_{n}=O((\log p_{n})^{2})\). & Directly concerns the prime‑gap
discussion of Section 5 and the heuristic models mentioned in Section 9.
& Sets a benchmark for the extreme behavior of gaps, influencing sieve
bounds. \\
\textbf{Hardy-Littlewood k‑Tuple Conjecture} & Generalizes the
twin‑prime heuristic to any admissible pattern of \(k\) linear forms. &
Extends the twin‑prime density (Section 9) to broader constellations;
informs sieve methods of Section 2. & Unifies many prime‑pattern
conjectures and predicts frequencies of complex constellations. \\
\textbf{Infinitude of Sophie‑Germain Primes} & There are infinitely many
primes \(p\) such that \(2p+1\) is also prime. & Section 9 introduced
Sophie‑Germain primes and their role in safe‑prime generation (Section
8). & Critical for constructing secure Diffie-Hellman groups and for
understanding prime‑pair phenomena. \\
\textbf{Goldbach's Weak Conjecture (now a theorem)} & Every odd integer
\(>5\) is the sum of three primes. & Proven (2013) using the circle
method; serves as a template for attacking the strong conjecture. &
Demonstrates the power of analytic techniques that may eventually
resolve the strong form. \\
\end{longtable}

These conjectures collectively map the frontier of our understanding of
prime distribution, additive representations, and extremal behavior.

\subsection{10.5 Impact on Research and
Applications}\label{impact-on-research-and-applications}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  \textbf{Theoretical Development} - Solving any of the above problems
  would trigger a cascade of new results. For example, a proof of the
  Twin Prime Conjecture would likely yield refined error terms for
  \(\pi(x)\) and could unlock stronger versions of the
  \textbf{Hardy-Littlewood} conjectures, reshaping the landscape
  described in Sections 5 and 6.
\item
  \textbf{Algorithmic Consequences} - Many primality‑testing heuristics
  (Section 7) and prime‑generation pipelines (Section 8) rely on the
  assumed abundance of certain prime families. Confirmed densities would
  allow tighter bounds on expected runtime and could lead to
  deterministic alternatives for tasks currently handled
  probabilistically.
\item
  \textbf{Computational Exploration} - Section 11 emphasizes the role of
  software (PARI/GP, SageMath, Mathematica) in testing conjectures up to
  astronomical limits. Continued advances in hardware and algorithms
  will push these limits further, providing more data to guide or refute
  conjectural models.
\item
  \textbf{Cryptographic Security} - While current standards do not
  depend on the truth of these conjectures, their resolution could
  affect security assessments. For instance, a proof that prime gaps are
  never larger than \((\log x)^{2}\) (Cramér) would tighten worst‑case
  estimates for safe‑prime generation, influencing parameter choices in
  protocols described in Section 8.
\item
  \textbf{Interdisciplinary Links} - The open problems intersect with
  random matrix theory, quantum chaos, and even physics (via the
  statistical properties of zeta zeros). Their study thus continues to
  foster cross‑disciplinary collaboration, echoing the historical
  narrative of Section 2.
\end{enumerate}

In summary, the unsolved questions highlighted here are not isolated
curiosities; they are the keystones of the modern theory of primes,
shaping both deep mathematical insight and practical technologies. Their
eventual resolution will mark a watershed moment for number theory and
its many applications.

\section{11. Computational Techniques and
Software}\label{computational-techniques-and-software}

\subsection{11.1 Overview of Computational
Approaches}\label{overview-of-computational-approaches}

Experimental investigation of prime numbers has become an indispensable
complement to the theoretical results presented in Sections 5-10. Modern
software packages provide:

\begin{itemize}
\tightlist
\item
  \textbf{High‑precision arithmetic} (arbitrary‑length integers, modular
  exponentiation) required for the large‑scale primality tests discussed
  in Section 7.\\
\item
  \textbf{Built‑in prime‑related functions} (prime counting, sieves,
  factorisation) that implement the definitions and properties of
  Section 3 and the distribution tools of Section 5.\\
\item
  \textbf{Interfaces to cryptographic libraries} (Section 8) for
  generating RSA‑size or safe primes with provable security guarantees.
\end{itemize}

These capabilities enable researchers to:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \textbf{Generate and test large primes} (hundreds to millions of bits)
  for both theoretical experiments and practical key generation.\\
\item
  \textbf{Collect statistical data} on prime gaps, Chebyshev functions,
  and the error term in the Prime Number Theorem (Section 6).\\
\item
  \textbf{Explore special families} (Section 9) such as Mersenne,
  Fermat, and Sophie‑Germain primes using dedicated algorithms.
\end{enumerate}

Below we review three flagship systems - \textbf{PARI/GP},
\textbf{SageMath}, and \textbf{Mathematica} - and illustrate how they
integrate the algorithms of Sections 7 and 8.

\subsection{11.2 PARI/GP}\label{parigp}

\textbf{PARI/GP} is a C‑based computer algebra system optimized for
number‑theoretic computations. Its strengths for prime research are:

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.2571}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3714}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3714}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Feature
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Description
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Typical Use
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\texttt{prime(n)} & Returns the \emph{n}‑th prime. & Quick lookup for
small‑scale experiments (Section 5). \\
\texttt{isprime(p)} & Deterministic Miller-Rabin for 64‑bit integers;
AKS for larger inputs. & Direct implementation of the deterministic
tests from Section 7. \\
\texttt{nextprime(p)} & Smallest prime \textgreater{} p. & Efficient
prime‑search loops for generating candidate RSA moduli. \\
\texttt{primepi(x)} & Exact value of Pi(x). & Empirical verification of
the Prime Number Theorem (Section 6). \\
\texttt{znprimroot(p)} & Primitive root modulo p. & Needed for
Diffie-Hellman safe‑prime generation (Section 8). \\
\texttt{factor(n)} & Full factorisation (trial division + Pollard‑Rho).
& Checks that a candidate is truly prime and validates certificates. \\
\end{longtable}

\textbf{Example: Generating a 1024‑bit RSA prime}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{\textbackslash{}\textbackslash{} Choose a random 1024‑bit integer}
\NormalTok{p = random(2\^{}1023, 2\^{}1024);}
\NormalTok{\textbackslash{}\textbackslash{} Pre‑screen with small‑prime trial division}
\NormalTok{while (vecsum(isprime(p) == 0) || !isprime(p),}
\NormalTok{  p = random(2\^{}1023, 2\^{}1024);}
\NormalTok{);}
\NormalTok{print("Found 1024‑bit prime: ", p);}
\end{Highlighting}
\end{Shaded}

PARI/GP's \texttt{isprime} automatically switches to a deterministic AKS
test for numbers beyond the 64‑bit range, guaranteeing correctness
without external certificates - useful when a formal proof is required
(Section 7).

\subsection{11.3 SageMath}\label{sagemath}

\textbf{SageMath} (Sage) is a Python‑based ecosystem that bundles
PARI/GP, NTL, GMP, and many other libraries under a unified interface.
Its prime‑related toolbox includes:

\begin{itemize}
\tightlist
\item
  \texttt{sage.primes.prime\_range(a,\ b)} - iterator over all primes in
  \([a,b)\).\\
\item
  \texttt{sage.primes.is\_prime(p,\ proof=False)} - probabilistic
  Miller-Rabin (default) or deterministic (when \texttt{proof=True}).\\
\item
  \texttt{sage.rings.integer.Integer.is\_pseudoprime()} - quick Fermat
  test for early filtering.\\
\item
  \texttt{sage.crypto.prime\_generator()} - high‑level routine that
  follows the pipeline described in Section 8 (random candidate → trial
  division → Miller-Rabin → optional ECPP certificate).
\end{itemize}

Sage also provides \textbf{plotting utilities} for visualising Pi(x),
θ(x), and ψ(x), facilitating the empirical studies of Sections 5 and 6.

\textbf{Example: Verifying the Twin‑Prime Heuristic up to 10⁸}

\begin{Shaded}
\begin{Highlighting}[]
\ImportTok{from}\NormalTok{ sage.}\BuiltInTok{all} \ImportTok{import} \OperatorTok{*}

\KeywordTok{def}\NormalTok{ twin\_prime\_count(limit):}
\NormalTok{    count }\OperatorTok{=} \DecValTok{0}
    \ControlFlowTok{for}\NormalTok{ p }\KeywordTok{in}\NormalTok{ prime\_range(}\DecValTok{3}\NormalTok{, limit):}
        \ControlFlowTok{if}\NormalTok{ is\_prime(p}\OperatorTok{+}\DecValTok{2}\NormalTok{):}
\NormalTok{            count }\OperatorTok{+=} \DecValTok{1}
    \ControlFlowTok{return}\NormalTok{ count}

\NormalTok{limit }\OperatorTok{=} \DecValTok{10}\OperatorTok{\^{}}\DecValTok{8}
\NormalTok{tp }\OperatorTok{=}\NormalTok{ twin\_prime\_count(limit)}
\BuiltInTok{print}\NormalTok{(}\StringTok{"Twin primes ≤"}\NormalTok{, limit, }\StringTok{":"}\NormalTok{, tp)}
\BuiltInTok{print}\NormalTok{(}\StringTok{"Heuristic estimate:"}\NormalTok{, }\DecValTok{2}\OperatorTok{*}\FloatTok{0.66016}\OperatorTok{*}\NormalTok{limit}\OperatorTok{/}\NormalTok{(log(limit)}\OperatorTok{\^{}}\DecValTok{2}\NormalTok{))}
\end{Highlighting}
\end{Shaded}

Running this script yields data that can be compared with the
conjectural density from Section 9, illustrating the tight feedback loop
between computation and theory.

\subsection{11.4 Mathematica}\label{mathematica}

\textbf{Mathematica} offers a symbolic‑numeric environment with a rich
set of built‑in prime functions, ideal for both exploratory research and
formal proof assistance.

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5263}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.4737}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Function
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Purpose
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\texttt{Prime{[}n{]}} & \emph{n}‑th prime (exact). \\
\texttt{PrimeQ{[}n{]}} & Probabilistic primality test (Miller-Rabin)
with adjustable certainty. \\
\texttt{NextPrime{[}n{]}} & Smallest prime \textgreater{} n. \\
\texttt{PrimePi{[}x{]}} & Exact Pi(x). \\
\texttt{PrimeNu{[}n{]}} & Number of prime factors of \emph{n} (useful
for studying smoothness). \\
\texttt{PrimeZetaP{[}s{]}} & Zeta‑type series over primes, employed in
analytic investigations of Section 6. \\
\texttt{FindInstance{[}PrimeQ{[}x{]}\ \&\&\ x\ \textgreater{}\ 2\^{}1023,\ x,\ Integers{]}}
& Directly searches for a large prime, leveraging Mathematica's internal
parallelism. \\
\end{longtable}

Mathematica also integrates
\textbf{NumberTheory\texttt{**\ and\ **PrimeNumberTheory}} packages that
implement the Lucas-Lehmer test for Mersenne primes (Section 9) and the
Baillie‑PSW test (Section 7).

\textbf{Example: Searching for a new Mersenne prime candidate}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{(* Test exponents up to 10\^{}6 *)}
\FunctionTok{Do}\OperatorTok{[}
  \FunctionTok{If}\OperatorTok{[}\FunctionTok{PrimeQ}\OperatorTok{[}\FunctionTok{p}\OperatorTok{]}\NormalTok{ \&\& LucasLehmerTest}\OperatorTok{[}\DecValTok{2}\SpecialCharTok{\^{}}\FunctionTok{p} \SpecialCharTok{{-}} \DecValTok{1}\OperatorTok{],}
    \FunctionTok{Print}\OperatorTok{[}\StringTok{"Mersenne prime found: 2\^{}"}\OperatorTok{,} \FunctionTok{p}\OperatorTok{,} \StringTok{"{-}1"}\OperatorTok{]}
  \OperatorTok{],}
  \OperatorTok{\{}\FunctionTok{p}\OperatorTok{,} \DecValTok{2}\OperatorTok{,} \DecValTok{10}\SpecialCharTok{\^{}}\DecValTok{6}\OperatorTok{\}}
\OperatorTok{]}
\end{Highlighting}
\end{Shaded}

The \texttt{LucasLehmerTest} function is highly optimized and can be run
on a cluster via Mathematica's \texttt{ParallelDo}, mirroring the
distributed searches of GIMPS mentioned in Section 2.

\subsection{11.5 Interoperability and Workflow
Integration}\label{interoperability-and-workflow-integration}

A typical research workflow that bridges the theoretical material of
earlier sections might look like:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \textbf{Define the problem} (e.g., ``estimate the average gap between
  primes near 2⁶⁴'').\\
\item
  \textbf{Select a platform}:

  \begin{itemize}
  \tightlist
  \item
    Use \textbf{PARI/GP} for fast low‑level arithmetic and exact Pi(x)
    values.\\
  \item
    Switch to \textbf{SageMath} when Python's data‑analysis libraries
    (NumPy, pandas) are needed for statistical processing.\\
  \item
    Employ \textbf{Mathematica} for symbolic manipulation of the
    Chebyshev functions and for generating publication‑ready plots.\\
  \end{itemize}
\item
  \textbf{Implement the algorithm} from Section 7 (Miller-Rabin →
  optional ECPP).\\
\item
  \textbf{Validate} results against known tables (e.g., the OEIS entries
  for twin primes, Mersenne primes) and against the theoretical
  predictions of Sections 5-6.\\
\item
  \textbf{Document} the experiment using notebooks (Jupyter for Sage,
  Mathematica notebooks, or PARI/GP scripts) to ensure reproducibility -
  a practice encouraged throughout the primer.
\end{enumerate}

\subsection{11.6 Additional Resources}\label{additional-resources}

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3704}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1852}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.4444}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Resource
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
URL
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Highlights
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\textbf{PARI/GP Manual} & \url{https://pari.math.u-bordeaux.fr/doc.html}
& Complete reference for prime functions, including \texttt{bnfcertify}
for ECPP certificates. \\
\textbf{SageMath Documentation - Number Theory} &
\url{https://doc.sagemath.org/html/en/reference/number_theory/index.html}
& Tutorials on prime sieves, primality testing, and cryptographic key
generation. \\
\textbf{Mathematica Documentation - Prime Functions} &
\url{https://reference.wolfram.com/language/guide/PrimeNumbers.html} &
Examples of parallel prime searches and symbolic prime‑related
identities. \\
\textbf{The PrimePages (GIMPS)} & \url{https://primes.utm.edu/} &
Up‑to‑date list of known Mersenne primes and a description of the
Lucas-Lehmer test. \\
\textbf{Open-source Cryptographic Libraries} & OpenSSL, Bouncy Castle,
libsodium & Implement the prime‑generation pipeline of Section 8; source
code useful for benchmarking. \\
\end{longtable}

\subsection{11.7 Best Practices for Reliable Prime
Experiments}\label{best-practices-for-reliable-prime-experiments}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \textbf{Use multiple independent tests} - combine a fast probabilistic
  Miller-Rabin pass with a deterministic certificate (ECPP) when the
  prime will be used in security‑critical contexts (Section 8).\\
\item
  \textbf{Record the random seed} - reproducibility of large‑prime
  searches depends on the underlying pseudo‑random generator.\\
\item
  \textbf{Validate against known benchmarks} - compare
  \texttt{primepi(x)} with published tables to catch implementation
  errors.\\
\item
  \textbf{Leverage parallelism} - both SageMath and Mathematica provide
  simple constructs (\texttt{@parallel}, \texttt{ParallelDo}) to
  distribute the search for large primes across CPU cores or clusters.\\
\item
  \textbf{Stay current with library updates} - newer versions of PARI/GP
  and SageMath regularly incorporate algorithmic improvements (e.g.,
  faster ECPP variants) that can reduce the time to certify a
  record‑size prime.
\end{enumerate}

By integrating these tools and practices, researchers can efficiently
explore the rich landscape of prime numbers, test conjectures from
Section 10, and generate the cryptographically strong primes required in
modern applications (Section 8).

\section{12. Conclusion}\label{conclusion}

\subsection{12.1 Recap of Key Ideas}\label{recap-of-key-ideas}

The primer has traced a coherent narrative from the \textbf{fundamental
role of primes} (Section 1) through their \textbf{formal definitions and
the uniqueness of factorisation} (Section 3). Euclid's classic proof of
the \textbf{infinitude of primes} (Section 4) established that the set
of primes never exhausts, a theme that reappears in modern analytic and
algebraic contexts.

Sections 5 and 6 quantified how primes are \textbf{distributed among the
integers}, introducing the prime‑counting function Pi(x), Chebyshev's
functions θ(x) and ψ(x), and culminating in the \textbf{Prime Number
Theorem} (Section 6), which gives the asymptotic law Pi(x) ≈ x/ln x.
These results underpin the \textbf{expected density of primes} used
throughout the book.

Algorithmic considerations were covered in \textbf{primality testing}
(Section 7), where deterministic methods (AKS, ECPP) and probabilistic
tests (Miller-Rabin, Baillie-PSW) were compared, and their
\textbf{complexity} linked back to the density estimates of Section 6.
The \textbf{cryptographic applications} (Section 8) demonstrated how the
same theoretical foundations enable secure public‑key systems such as
RSA and Diffie-Hellman, with concrete criteria for generating safe
primes.

Special families of primes - \textbf{twin, Mersenne, Fermat, Sophie
Germain} (Section 9) - illustrate how additional algebraic constraints
affect density and motivate dedicated testing algorithms. The
\textbf{open problems} (Section 10) highlight the frontier of
prime‑number research, while \textbf{computational tools} (Section 11)
provide the experimental platform that bridges theory and practice.

Together, these parts form a self‑contained journey: from
\textbf{historical origins} to \textbf{modern theory}, from \textbf{pure
mathematics} to \textbf{real‑world technology}, and from \textbf{proved
results} to \textbf{still‑open conjectures}.

\subsection{12.2 Enduring Importance of Prime
Numbers}\label{enduring-importance-of-prime-numbers}

\begin{itemize}
\item
  \textbf{Mathematical Bedrock} - Primes are the ``atoms'' of the
  integers (Section 1) and the \textbf{Fundamental Theorem of
  Arithmetic} (Section 3) guarantees a unique prime factorisation for
  every integer \textgreater{} 1. This property is the cornerstone of
  countless theorems, from Euclid's infinitude proof (Section 4) to the
  analytic machinery behind the Prime Number Theorem (Section 6).
\item
  \textbf{Algorithmic Engine} - Efficient \textbf{primality testing}
  (Section 7) and \textbf{prime generation} (Section 8) rely on the
  statistical regularities described in Sections 5 and 6. The ability to
  produce large, provably prime numbers is what makes modern
  \textbf{public‑key cryptography} feasible.
\item
  \textbf{Catalyst for Interdisciplinary Research} - The distribution of
  primes connects number theory with \textbf{complex analysis} (via the
  Riemann zeta function), \textbf{probability} (Cramér's and Granville's
  models), and even \textbf{physics} (random‑matrix analogies). Open
  conjectures (Section 10) continue to inspire new techniques in
  \textbf{sieve theory}, \textbf{analytic number theory}, and
  \textbf{computational experimentation} (Section 11).
\item
  \textbf{Technological Backbone} - Secure communications, digital
  signatures, blockchain protocols, and many other critical
  infrastructures depend on the hardness of problems rooted in prime
  factorisation and discrete logarithms. As computational power grows,
  the \textbf{prime‑based security paradigm} remains a moving target
  that drives both mathematical innovation and engineering safeguards.
\end{itemize}

\subsection{12.3 Directions for Further
Study}\label{directions-for-further-study}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  \textbf{Deepening Analytic Understanding}

  \begin{itemize}
  \tightlist
  \item
    Pursue tighter error bounds for the Prime Number Theorem under the
    \textbf{Riemann Hypothesis} (Section 10) and explore its
    implications for prime‑gap statistics (Section 5).\\
  \item
    Investigate \textbf{zero‑density estimates} for ζ(s) and related
    L‑functions to refine predictions for special prime families
    (Section 9).
  \end{itemize}
\item
  \textbf{Advancing Sieve and Probabilistic Methods}

  \begin{itemize}
  \tightlist
  \item
    Extend modern combinatorial sieves (Brun, Selberg) to obtain
    quantitative results for \textbf{twin primes}, \textbf{Sophie
    Germain primes}, and more general admissible k‑tuples (Section 9).\\
  \item
    Develop hybrid deterministic‑probabilistic algorithms that reduce
    the constant factors in \textbf{primality testing} while preserving
    provable guarantees (Section 7).
  \end{itemize}
\item
  \textbf{Post‑Quantum Prime Generation}

  \begin{itemize}
  \tightlist
  \item
    Study \textbf{quantum‑resistant prime constructions}, such as primes
    suitable for lattice‑based schemes or isogeny‑based protocols,
    building on the secure‑prime criteria of Section 8.\\
  \item
    Design hardware‑accelerated pipelines (e.g., FPGA, ASIC) that
    integrate the \textbf{computational techniques} of Section 11 with
    side‑channel‑resistant implementations.
  \end{itemize}
\item
  \textbf{Computational Exploration and Data‑Driven Conjectures}

  \begin{itemize}
  \tightlist
  \item
    Leverage the interoperability of \textbf{PARI/GP, SageMath, and
    Mathematica} (Section 11) to generate massive datasets for testing
    conjectures like \textbf{Cramér's} and \textbf{Hardy-Littlewood
    k‑tuple} predictions.\\
  \item
    Apply machine‑learning tools to detect hidden patterns in prime
    gaps, distribution of special primes, and the behavior of ζ(s)
    zeros, potentially guiding new theoretical breakthroughs.
  \end{itemize}
\item
  \textbf{Educational Extensions}

  \begin{itemize}
  \tightlist
  \item
    Create interactive modules that let students experiment with the
    \textbf{prime‑generation pipeline} (Section 8) and visualize the
    convergence of Pi(x) to x/ln x (Section 6).\\
  \item
    Develop open‑source notebooks that integrate the \textbf{theoretical
    proofs} (Sections 4-6) with \textbf{computational experiments}
    (Section 11), fostering a hands‑on approach to prime‑number
    research.
  \end{itemize}
\end{enumerate}

By pursuing these avenues, readers can continue the tradition of
\textbf{bridging pure theory and practical application} that has defined
the study of prime numbers from Euclid to the present day. The landscape
remains rich with unanswered questions, and each new insight promises
both mathematical elegance and tangible impact on the digital world.

\end{document}
