Prime number theorem


The prime number theorem (PNT) describes the approximate distribution of primes among the positive integers. As integers get larger, primes get rarer at a rate quantified by this theorem.

The prime-counting function \(\pi(x)\), which returns the number of primes less than or equal to \(x\), has the following asymptotic behavior: $$\lim_{{x \to \infty}} \pi(x) = \frac{x}{\ln(x)}$$ Therefore, for large \(x\), the function \(\frac{x}{\ln(x)}\) closely approximates \(\pi(x).\)
A graph of the prime-counting function.
A graph of the prime-counting function.[1]

This leads to a few useful applications. First of all, if you wanted to get an idea of roughly how many primes exist among the first \(512\) positive integers, you'd just need to calculate \(\frac{512}{\ln(512)} \approx 82.\)

Furthermore, if you wanted to estimate the probability of selecting a prime out of the first \(512\) positive integers, you'd just need to calculate \(\frac{82}{512} \approx 0.16.\)

Generally, the probability of selecting a prime out of the first \(x\) positive integers can be estimated using the formula \(\frac{1}{\ln(x)}.\)

The prime number theorem is also useful for generating large primes because it gives you an estimate of how many times you'd need to randomly generate an integer in a specific range before you're likely to get one that passes a primality test. Without going into specifics, the number of random trials necessary depends on the number of digits of the prime you are trying to generate, rather than its magnitude, which is why this method of generating primes is efficient.

⚠ Why would you want to generate a large prime? Well, to give an example, prime-sized hash tables can benefit from minimized collisions and enhanced probing. So, if you need space for \(n\) entries in your hash table, it's better to generate a prime number greater than or equal to \(n\) and use that as the hash table's size, allowing you to enjoy the benefits of the unique mathematical properties of primes. (According to Euclid's theorem, you'll always be able to find a large enough prime!)
⚠ Also, it should be noted that the generation of large prime numbers is essential in cryptography.
Contents

References


  1. PrimePi.svg: Bender2k14, CC BY-SA 3.0, via Wikimedia Commons.
Logic & Proofs
IntegerRational numberInequalityReal numberTheoremProofStatementProof by exhaustionUniversal generalizationCounterexampleExistence proofExistential instantiationAxiomLogicTruthPropositionCompound propositionLogical operationLogical equivalenceTautologyContradictionLogic lawPredicateDomainQuantifierArgumentRule of inferenceLogical proofDirect proofProof by contrapositiveIrrational numberProof by contradictionProof by casesSummationDisjunctive normal form
Set Theory
SetElementEmpty setUniversal setSubsetPower setCartesian productStringBinary stringEmpty stringSet operationSet identitySet proof
Functions
FunctionFloor functionCeiling functionInverse function
Algorithms
AlgorithmPseudocodeCommandAsymptotic notationTime complexityAtomic operationBrute-force algorithm
Relations
RelationReflexive relationSymmetric relationTransitive relationRelation compositionEquivalence relationEquivalence class
Number Theory
Integer divisionLinear combinationDivision algorithmModular arithmeticPrime factorizationGreatest common divisorLeast common multiplePrimality testFactoring algorithmEuclid's theoremPrime number theoremEuclidean algorithm
Induction
Proof by inductionFibonacci sequenceProof by strong inductionWell-ordering principleSequenceFactorialRecursive definition
Combinatorics
Rule of productRule of sumBijection rulePermutationCombinationComplement ruleExperimentOutcomeSample spaceEventProbabilityProbability distributionUniform distributionMultisetSixfold wayInclusion-exclusion principlePigeonhole principle
Graph Theory
GraphWalkSubgraphRegular graphComplete graphEmpty graphCycle graphHypercube graphBipartite graphComponentEulerian circuitEulerian trailHamiltonian cycleHamiltonian pathTreeHuffman treeSubstringForestPath graphStarSpanning treeWeighted graphMinimum spanning treeGreedy algorithmPrim's algorithm
Recursion
RecursionRecursive algorithmCorrectness proofDivide-and-conquer algorithmSorting algorithmMerge sort