{
  "id": "primality-test",
  "title": "Primality Test",
  "lang": "en",
  "source_lang": "en",
  "summary": "A primality test determines whether an integer is prime, using methods ranging from trial division to probabilistic algorithms and independently verifiable proofs.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "Primality testing",
    "Prime testing"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/primality-test/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/primality-test/",
      "json": "https://aiwiki.page/zh/primality-test.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A primality test is an algorithm for determining whether a given integer is a prime number: an integer greater than 1 whose only positive divisors are 1 and itself. Primality testing is a central problem in computational number theory and an essential component of many cryptographic systems. Its difficulty depends strongly on the size and structure of the input and on whether the required result is a probable-prime classification or a rigorous proof.\n\nThe simplest tests search for divisors. More advanced methods examine algebraic identities that every prime satisfies, use random choices to detect compositeness, or construct a certificate that can be checked independently. These approaches make it possible to test numbers far beyond the reach of trial division. In 2002, Manindra Agrawal, Neeraj Kayal, and Nitin Saxena established that primality can be decided deterministically in time polynomial in the input length, resolving a longstanding theoretical question.\n\nPrimality testing must be distinguished from finding a number’s prime factors. A test can prove that a number is composite without revealing any nontrivial divisor. This separation explains how cryptographic software can efficiently generate large primes even though factoring products of comparable primes remains computationally difficult."
    },
    {
      "heading": "The decision problem and its computational scale",
      "text": "For a positive integer \\(n\\), the primality decision problem asks whether \\(n>1\\) and no integer \\(d\\) with \\(1<d<n\\) divides \\(n\\). The number 1 is neither prime nor composite; integers greater than 1 that are not prime are composite. Negative integers and zero are not prime under the standard elementary definition. A complete implementation therefore begins with elementary boundary cases rather than applying its main test indiscriminately.\n\nThe relevant measure of input size is usually the number of binary digits,\n\n\\[L=\\lfloor\\log_2 n\\rfloor+1,\\]\n\nnot the numerical value \\(n\\). An algorithm taking roughly \\(\\sqrt n\\) operations is exponential in \\(L\\), since \\(\\sqrt n\\) is approximately \\(2^{L/2}\\). By contrast, an algorithm requiring \\(L^c\\) bit operations for a fixed constant \\(c\\) has polynomial running time. Complexity statements use asymptotic notation and must distinguish bit operations from operations on arbitrarily large integers: multiplying two thousand-bit numbers is not a constant-time operation.\n\nA deterministic test returns the correct answer for every allowed input, without relying on random choices. A probabilistic test uses randomness and may have a precisely bounded chance of accepting a composite number. Important tests have one-sided error: a prime always passes, whereas a composite may pass some trials. A number that passes such a test is called a probable prime relative to the test performed. “Probable prime” describes the available evidence, not a third mathematical category between prime and composite.\n\nA further distinction concerns proof certificates. A primality certificate is finite data that establishes primality and can be checked by a separate verification algorithm. Certificate generation can involve extensive searching or randomized choices while verification remains deterministic. Conversely, a deterministic decision algorithm need not produce a convenient certificate separate from its execution. These distinctions matter when large computational results are independently audited.\n\nPrimality and integer factorization are related but different problems. A factorization immediately settles primality, but many compositeness witnesses give no factor at all. Polynomial-size certificates for primality were known before a deterministic polynomial-time decision algorithm: Vaughan Pratt’s 1975 construction used recursively certified factors of \\(n-1\\). The 2002 AKS result established that primality belongs to the deterministic polynomial-time complexity class P. No comparable classical polynomial-time algorithm is known for general integer factorization."
    },
    {
      "heading": "Trial division, sieving, and elementary preprocessing",
      "text": "The basic observation behind trial division is that every composite integer \\(n\\) has a prime divisor at most \\(\\sqrt n\\). If \\(n=ab\\) with \\(1<a\\leq b\\), then \\(a^2\\leq n\\), and some prime divides \\(a\\). It is therefore sufficient to test divisibility by the primes not exceeding \\(\\sqrt n\\). For example, proving that 97 is prime requires checking only 2, 3, 5, and 7. A divisor is both a compositeness witness and useful additional information.\n\nTesting every integer up to \\(\\sqrt n\\) wastes effort. After removing even candidates, a simple implementation tests only odd divisors. More elaborate wheel factorization skips residue classes divisible by several small primes. A wheel based on \\(2\\), \\(3\\), and \\(5\\), for example, retains only 8 of the 30 residue classes modulo 30. This reduces a constant factor but does not change trial division’s exponential dependence on the bit length of the input.\n\nWhen many small numbers must be classified, a sieve of Eratosthenes is more appropriate than testing each separately. The sieve marks multiples of successive primes, leaving the primes unmarked. In a standard model, sieving all integers through \\(x\\) takes \\(O(x\\log\\log x)\\) elementary marking operations and storage proportional to \\(x\\). A segmented sieve processes shorter intervals, reducing working memory while reusing primes through \\(\\sqrt x\\). Sieving is thus a range-enumeration technique, although it also supplies trial divisors for individual tests.\n\nFor large inputs, trial division usually serves as preprocessing rather than a complete method. A candidate divisible by 3 or 5 should be rejected before performing hundreds of large modular multiplications. If many nearby candidates are being examined, their residues modulo small primes can be updated incrementally. Some implementations combine small primes into machine-word products, allowing several divisibility checks to share arithmetic work. The optimal cutoff depends on integer size, hardware, and the cost of the subsequent test.\n\nPerfect powers form another useful preprocessing category. If \\(n=a^k\\) for integers \\(a>1\\) and \\(k>1\\), then \\(n\\) is composite even when \\(a\\) is not known to be prime. Exact integer-root algorithms can detect such cases without floating-point rounding ambiguity. It is sufficient to examine prime exponents up to \\(\\log_2 n\\), because a composite exponent has a prime divisor. Perfect-power detection is especially important in theoretical algorithms whose later arguments assume the input is not a proper power."
    },
    {
      "heading": "Fermat tests and the limits of congruence evidence",
      "text": "Fermat’s little theorem states that if \\(p\\) is prime and \\(a\\) is not divisible by \\(p\\), then\n\n\\[a^{p-1}\\equiv1\\pmod p.\\]\n\nThis identity turns primality testing into a problem in modular arithmetic. Given an odd candidate \\(n\\), choose \\(a\\) with \\(1<a<n\\), compute its greatest common divisor with \\(n\\), and then evaluate \\(a^{n-1}\\bmod n\\). A nontrivial greatest common divisor exposes a factor. If the greatest common divisor is 1 but the congruence fails, \\(n\\) is certainly composite.\n\nLarge powers are computed using modular exponentiation, not by constructing the full integer \\(a^{n-1}\\). Repeated squaring scans the binary digits of the exponent and needs only \\(O(\\log n)\\) modular multiplications. Intermediate values can be reduced modulo \\(n\\) after each multiplication. This is the basic computational engine behind many practical primality tests: enormous exponents become manageable because the residues remain bounded.\n\nPassing a Fermat test does not prove primality. The composite number\n\n\\[341=11\\cdot31\\]\n\nsatisfies \\(2^{340}\\equiv1\\pmod{341}\\), making it a base-2 Fermat pseudoprime. The term pseudoprime must be qualified by the test and usually by the base: a composite can imitate a prime under one congruence while failing another. For any fixed base, infinitely many composite numbers pass its Fermat test, so increasing input size does not make a single fixed-base test conclusive.\n\nA more fundamental obstruction is a Carmichael number, a composite \\(n\\) satisfying the Fermat congruence for every \\(a\\) relatively prime to \\(n\\). The smallest is\n\n\\[561=3\\cdot11\\cdot17.\\]\n\nKorselt’s criterion, formulated in 1899, characterizes these numbers: a composite \\(n\\) is Carmichael exactly when it is squarefree and \\(p-1\\) divides \\(n-1\\) for every prime divisor \\(p\\) of \\(n\\). In 1994, W. R. Alford, Andrew Granville, and Carl Pomerance proved that infinitely many Carmichael numbers exist.\n\nConsequently, repeating ordinary Fermat tests with coprime bases does not provide a universal error bound that decreases geometrically with the number of rounds. Carmichael numbers pass every such round. Fermat testing remains useful as a quick rejection filter and as a conceptual foundation, but stronger tests examine additional structure in the multiplicative arithmetic modulo a prime. In particular, they inspect intermediate square roots of 1 rather than only the final exponentiation result."
    },
    {
      "heading": "The Miller–Rabin strong probable-prime test",
      "text": "The Miller–Rabin test strengthens Fermat testing by using the fact that over a field, the only solutions of \\(x^2=1\\) are \\(1\\) and \\(-1\\). For an odd candidate \\(n>3\\), write\n\n\\[n-1=2^s d,\\qquad d\\ \\text{odd}.\\]\n\nFor a base \\(a\\) with \\(2\\leq a\\leq n-2\\), compute \\(x=a^d\\bmod n\\). The round passes if \\(x=1\\) or \\(x=-1\\pmod n\\). Otherwise, square \\(x\\) repeatedly, at most \\(s-1\\) times, accepting the round if \\(-1\\) appears.\n\nA prime always passes. Fermat’s theorem says that repeated squaring eventually reaches 1; if the initial value was not already 1, the value immediately preceding the first 1 must be \\(-1\\). For a composite modulus, nontrivial square roots of 1 can exist. Encountering one proves compositeness and may reveal a factor through \\(\\gcd(x-1,n)\\). Alternatively, a round can fail because its sequence never reaches the required values, without directly producing a factor.\n\nFor every odd composite \\(n\\), at most one quarter of bases among \\(1,\\ldots,n-1\\) are strong liars, meaning bases that cause the test to pass. Thus \\(k\\) independent uniformly selected rounds have false-acceptance probability at most\n\n\\[4^{-k}.\\]\n\nThis bound holds for each fixed composite input; it does not assume a random input distribution. Forty independent rounds give a bound of \\(2^{-80}\\). The bound depends on correct base selection and independence, not merely on executing the same round repeatedly.\n\nThe history distinguishes two related results. Gary Miller’s 1976 work gave a deterministic polynomial-time test conditional on an appropriate generalized Riemann hypothesis. Michael Rabin’s 1980 work established the randomized formulation and its unconditional error guarantee. Under the relevant hypothesis, sufficiently small bases include a witness for every composite input, giving a deterministic search bound of order \\((\\log n)^2\\). Without that hypothesis, testing a convenient short list of bases is not a general proof for arbitrarily large integers.\n\nFor bounded machine integers, however, finite base sets can be proved sufficient by number-theoretic bounds and exhaustive computations. Their guarantees depend on the exact upper limit for \\(n\\). One must not apply a base list established for a bounded range to unrestricted integers. In multiprecision libraries, Miller–Rabin is popular because it is simple, fast, easily repeated, and effective after small-factor sieving. Its output should nevertheless distinguish a proven prime from a number that has passed specified probable-prime rounds."
    },
    {
      "heading": "Euler–Jacobi and Lucas-sequence tests",
      "text": "The Solovay–Strassen test, introduced in 1977, uses Euler’s criterion rather than the square-root chain of Miller–Rabin. For an odd prime \\(p\\) and an integer \\(a\\) not divisible by \\(p\\),\n\n\\[a^{(p-1)/2}\\equiv\\left(\\frac ap\\right)\\pmod p,\\]\n\nwhere the right-hand side is the Legendre symbol. For an odd composite candidate \\(n\\), the efficiently computable Jacobi symbol \\(\\left(\\frac an\\right)\\) replaces the Legendre symbol. A mismatch proves compositeness.\n\nFor each odd composite input, at most half of the eligible bases pass the Euler–Jacobi comparison. Independent repetition therefore gives an error bound at most \\(2^{-k}\\) after \\(k\\) rounds. The algorithm helped establish the practical significance of randomized computation, although Miller–Rabin is generally preferred because it offers a stronger worst-case bound per round and favorable implementation costs. The Jacobi symbol itself can be computed using an algorithm resembling the Euclidean algorithm, without factoring \\(n\\).\n\nAnother family uses Lucas sequences. Given integers \\(P,Q\\), define\n\n\\[U_0=0,\\quad U_1=1,\\quad U_k=PU_{k-1}-QU_{k-2},\\]\n\nand let \\(D=P^2-4Q\\). For an odd prime \\(p\\) not dividing \\(2QD\\),\n\n\\[U_{p-\\left(\\frac Dp\\right)}\\equiv0\\pmod p.\\]\n\nThis identity depends on whether the quadratic polynomial with discriminant \\(D\\) splits over the field with \\(p\\) elements or only over a quadratic extension. Efficient doubling formulas evaluate the sequence at large indices using logarithmically many modular operations.\n\nLucas probable-prime tests replace the Legendre symbol by the Jacobi symbol and check the corresponding identities modulo a candidate \\(n\\). Strong Lucas tests use a decomposition of the relevant index into an odd part times a power of 2, somewhat analogous to Miller–Rabin. Parameter selection is an essential part of the specification: different choices of \\(P,Q\\), discriminant-search rules, and acceptance conditions produce different tests and different pseudoprime sets.\n\nThe Baillie–PSW test combines a base-2 strong probable-prime test with a Lucas probable-prime test, commonly a strong Lucas test using Selfridge’s parameter selection, together with preliminary checks such as square detection. No composite counterexample to the standard combination is known. Nevertheless, absence of a known counterexample is not a proof that none exists, and the combination does not automatically inherit a numerical error estimate obtained by multiplying supposedly independent failure probabilities. Its components are deterministic functions of the input and do not come with a general independence theorem."
    },
    {
      "heading": "Proofs from the factors of neighboring integers",
      "text": "A powerful way to prove that \\(n\\) is prime is to know enough of the factorization of \\(n-1\\). The underlying mechanism is multiplicative order. If a residue \\(a\\) modulo a prime divisor \\(p\\) of \\(n\\) has order divisible by a large integer \\(F\\), then \\(F\\mid p-1\\), so \\(p\\geq F+1\\). If every prime divisor must exceed \\(\\sqrt n\\), the candidate cannot be composite. Unlike trial division, the proof can constrain all possible divisors without enumerating them.\n\nOne standard form of Pocklington’s criterion writes\n\n\\[n-1=FR,\\]\n\nwhere the complete prime factorization of \\(F\\) is known and \\(F>\\sqrt n\\). For every distinct prime \\(q\\mid F\\), suppose there is an integer \\(a_q\\) such that\n\n\\[a_q^{n-1}\\equiv1\\pmod n\\]\n\nand\n\n\\[\\gcd\\!\\left(a_q^{(n-1)/q}-1,n\\right)=1.\\]\n\nThen \\(n\\) is prime. Different prime factors \\(q\\) may use different witnesses \\(a_q\\).\n\nTo see why, let \\(p\\) be any prime divisor of \\(n\\). The first congruence makes the order of \\(a_q\\bmod p\\) divide \\(n-1\\); the greatest-common-divisor condition prevents that order from dividing \\((n-1)/q\\). Therefore the order contains the full power of \\(q\\) occurring in \\(n-1\\). Taken over all \\(q\\mid F\\), these constraints imply \\(F\\mid p-1\\). Every prime divisor \\(p\\) is consequently larger than \\(\\sqrt n\\), which is impossible for a composite integer.\n\nFor example, to prove 101 prime, use \\(101-1=100\\) and \\(F=25>\\sqrt{101}\\). The only distinct prime divisor of \\(F\\) is 5. The witness \\(a=2\\) satisfies\n\n\\[2^{100}\\equiv1\\pmod{101},\\qquad 2^{20}\\equiv95\\pmod{101},\\]\n\nand \\(\\gcd(94,101)=1\\). Given the primality of 5, these calculations certify 101 without trial division through every potential factor.\n\nPratt certificates apply a related idea recursively, supplying prime factorizations of \\(n-1\\), suitable order witnesses, and certificates for the smaller primes involved. The recursion ends at 2. Their significance is both computational and logical: primality has succinct, independently checkable proofs. The difficulty is obtaining the required factorizations; a general-purpose primality test cannot assume that \\(n-1\\) factors easily.\n\nCompanion criteria use factors of \\(n+1\\), often through Lucas sequences and algebraic groups whose orders are related to \\(n+1\\). More elaborate methods combine partial information from neighboring integers. These tests are particularly effective when candidates are deliberately constructed so that a large part of \\(n-1\\) or \\(n+1\\) is already factored. They also underpin recursive generation of proven primes, where the construction supplies the evidence that an arbitrary input might lack."
    },
    {
      "heading": "Elliptic-curve and cyclotomic primality proving",
      "text": "Elliptic-curve primality proving, usually abbreviated ECPP, replaces the relatively rigid multiplicative group of size \\(p-1\\) by groups of points on elliptic curves over finite fields. Different curves over the same field have different group orders. This flexibility allows a prover to search for an order with a conveniently large prime factor rather than being restricted to the factorization of one fixed neighboring integer.\n\nFor an elliptic curve \\(E\\) over the field with \\(p\\) elements, Hasse’s bound states\n\n\\[\\left|\\#E(\\mathbb F_p)-(p+1)\\right|\\leq2\\sqrt p.\\]\n\nSuppose a computation modulo a candidate \\(n\\) establishes, under the required nondegeneracy conditions, that a point has order divisible by a certified prime \\(q\\). Reduction modulo every prime divisor \\(p\\mid n\\) then forces \\(q\\) to divide the corresponding curve-group order. If\n\n\\[q>\\left(n^{1/4}+1\\right)^2,\\]\n\nHasse’s bound excludes every \\(p\\leq\\sqrt n\\), proving \\(n\\) prime.\n\nA typical certificate step supplies a curve, a point \\(P\\), an integer \\(m\\), and a large prime factor \\(q\\mid m\\). It verifies that \\([m]P\\) is the identity and that \\([m/q]P\\) remains nonidentity modulo every prime divisor of \\(n\\). In projective coordinates, the latter requirement is enforced through an appropriate coprimality check, not merely by observing a nonzero coordinate modulo \\(n\\). Curve nonsingularity must likewise be guaranteed modulo every prime divisor, usually by checking that the discriminant is relatively prime to \\(n\\).\n\nThe method recursively proves \\(q\\), producing a descending chain of certificates. Shafi Goldwasser and Joe Kilian introduced an elliptic-curve primality approach in 1986, while A. O. L. Atkin developed the complex-multiplication strategy that underlies widely used practical ECPP implementations; François Morain made major implementation and algorithmic contributions. Complex multiplication helps construct curves with prescribed candidate orders, avoiding the need to count points on arbitrary curves at every step. Certificate verification is substantially simpler than certificate discovery.\n\nA different major family is cyclotomic primality proving, associated with Leonard Adleman, Carl Pomerance, Robert Rumely, Henri Cohen, and Hendrik Lenstra. The APR and APR-CL methods use arithmetic involving roots of unity and Jacobi sums to impose strong restrictions on possible prime divisors. They provided important general-purpose deterministic tests before AKS, with nearly polynomial theoretical bounds for suitable versions.\n\nECPP and cyclotomic methods illustrate the distinction between mathematical complexity and practical proof production. A method with an attractive asymptotic theorem need not be fastest at realistic sizes, while a search-based prover can perform extremely well without having a comparably simple unconditional worst-case bound. A rigorously checked ECPP certificate remains a proof regardless of how heuristic choices guided its discovery."
    },
    {
      "heading": "The AKS deterministic polynomial-time algorithm",
      "text": "The AKS primality test rests on a polynomial characterization of primes. If \\(p\\) is prime, then the binomial theorem gives\n\n\\[(X+a)^p\\equiv X^p+a\\pmod p.\\]\n\nEvery intermediate binomial coefficient is divisible by \\(p\\), and \\(a^p\\equiv a\\pmod p\\). Conversely, for \\(n\\geq2\\) and \\(\\gcd(a,n)=1\\), the unrestricted polynomial identity characterizes primality. Checking all coefficients directly would involve a polynomial of degree \\(n\\), making the obvious procedure exponential in the input length.\n\nAKS reduces polynomials modulo both \\(n\\) and \\(X^r-1\\), working in the quotient ring\n\n\\[(\\mathbb Z/n\\mathbb Z)[X]/(X^r-1).\\]\n\nPolynomial degrees are thereby reduced below \\(r\\). The key achievement is proving that a suitably chosen small \\(r\\), together with a bounded collection of congruences\n\n\\[(X+a)^n\\equiv X^n+a\\pmod{n,\\;X^r-1},\\]\n\nsuffices to establish primality once certain exceptional cases have been removed.\n\nA standard presentation first rejects perfect powers. It then finds an integer \\(r\\), relatively prime to \\(n\\), for which the multiplicative order of \\(n\\) modulo \\(r\\) exceeds \\((\\log_2 n)^2\\). Greatest-common-divisor checks with small integers can immediately expose compositeness; if \\(n\\leq r\\) after the appropriate checks, primality follows. Otherwise the algorithm verifies the polynomial congruence for all positive integers \\(a\\) through a bound involving \\(\\sqrt{\\varphi(r)}\\log_2 n\\), where \\(\\varphi\\) is Euler’s totient function.\n\nThe proof combines the order condition with a counting argument. If a composite, non-perfect-power \\(n\\) passed all the congruences, those congruences would generate too many distinct elements in a suitable algebraic setting. The order condition supplies enough independence to force a contradiction. This is why a few scalar congruences resembling Fermat’s theorem are insufficient, while a carefully structured family of polynomial congruences is decisive.\n\nAgrawal, Kayal, and Saxena announced their result in August 2002; the paper “PRIMES is in P” appeared in the Annals of Mathematics in 2004. The algorithm is unconditional, deterministic, and polynomial in \\(\\log n\\). Later analyses and variants improved its running-time bounds. These developments resolved a foundational question without making AKS the usual choice for prime generation.\n\nIts practical disadvantage is the cost of repeated polynomial arithmetic modulo \\(X^r-1\\), involving many large-integer operations rather than a small number of ordinary modular exponentiations. Probable-prime tests and certificate-producing methods generally perform better at commonly encountered sizes. AKS is therefore especially important as a theorem about efficient decidability, not as the default engine of multiprecision arithmetic libraries."
    },
    {
      "heading": "Tests for numbers with special structure",
      "text": "Special forms can support tests much faster than general-purpose methods. A Mersenne prime has the form \\(M_p=2^p-1\\). The exponent \\(p\\) must itself be prime, since a composite exponent gives an algebraic factorization. Prime exponents are not sufficient: \\(2^{11}-1=2047=23\\cdot89\\). Nevertheless, the form admits an exceptionally simple deterministic test.\n\nFor an odd prime exponent \\(p\\), the Lucas–Lehmer test begins with\n\n\\[s_0=4,\\qquad s_{k+1}=s_k^2-2\\pmod{M_p}.\\]\n\nThen\n\n\\[M_p\\text{ is prime}\\quad\\Longleftrightarrow\\quad s_{p-2}=0.\\]\n\nFor \\(p=5\\), the residues modulo 31 are \\(4,14,8,0\\), proving that 31 is prime. The case \\(p=2\\), giving 3, is handled separately. Édouard Lucas developed the underlying ideas in the nineteenth century, and Derrick Henry Lehmer refined the test in the twentieth.\n\nMersenne arithmetic also has a computational advantage: because \\(2^p\\equiv1\\pmod{2^p-1}\\), high binary portions can be folded back into lower positions during reduction. Large implementations combine this structure with fast multiplication, including transform-based methods related to the fast Fourier transform. These efficiencies explain the prominence of Mersenne numbers in searches for exceptionally large primes. At such scales, independent runs and error-detection mechanisms address the possibility of hardware or arithmetic faults.\n\nFor a number\n\n\\[N=k2^m+1,\\qquad k\\ \\text{odd},\\quad 0<k<2^m,\\]\n\nProth’s theorem provides another compact criterion. If some integer \\(a\\) satisfies\n\n\\[a^{(N-1)/2}\\equiv-1\\pmod N,\\]\n\nthen \\(N\\) is prime. Conversely, a prime of this form has suitable witnesses. The large known power of 2 in \\(N-1\\) forces any prime divisor to be too large for compositeness. For example, \\(13=3\\cdot2^2+1\\), and \\(2^6\\equiv-1\\pmod{13}\\), so the criterion proves 13 prime.\n\nFermat numbers are \\(F_m=2^{2^m}+1\\). Pépin’s test states that for \\(m\\geq1\\),\n\n\\[F_m\\text{ is prime}\\quad\\Longleftrightarrow\\quad 3^{(F_m-1)/2}\\equiv-1\\pmod{F_m}.\\]\n\nTheir simple expression does not imply that they are prime: Euler showed that \\(F_5=2^{32}+1\\) is divisible by 641. Pépin’s test can establish compositeness without yielding a factor.\n\nThese criteria are inseparable from their hypotheses. Applying a Lucas–Lehmer recurrence to arbitrary odd integers, or using Proth’s congruence without the size condition on \\(k\\), does not preserve the stated theorem. Their speed comes from exploiting precise algebraic structure, not from a universally valid shortcut."
    },
    {
      "heading": "Prime generation, cryptography, and computational reliability",
      "text": "Primality testing is a central step in public-key cryptography. RSA key generation uses large primes whose product forms a public modulus. Other systems use primes to define finite fields or groups with prescribed subgroup orders. The computational requirements vary: an RSA prime need not have the same structural properties as a modulus used for a finite-field discrete-logarithm system. Testing primality establishes only one of the required properties.\n\nThe prime number theorem explains why random candidate generation is feasible. Near a large number \\(x\\), the density of primes is approximately \\(1/\\ln x\\); among odd candidates it is approximately \\(2/\\ln x\\). For uniformly sampled odd \\(L\\)-bit integers, this suggests roughly\n\n\\[\\frac{L\\ln2}{2}\\]\n\ncandidates per prime, ignoring lower-order effects. For \\(L=1024\\), the estimate is about 355 odd candidates. Small-prime sieving rejects most composites before expensive probable-prime rounds, so this is not the number of full tests normally required.\n\nGeneration pipelines typically select an odd candidate with the desired bit length, eliminate small divisors, run one or more probable-prime tests, and apply any additional structural checks. If a proven prime is required, the pipeline may then invoke ECPP or use a recursive construction with known factors of \\(n-1\\). Generating candidates of a prescribed form changes their distribution, so the elementary density estimate does not automatically apply unchanged to every construction.\n\nError probabilities require careful interpretation. Miller–Rabin’s \\(4^{-k}\\) bound concerns the chance that a fixed composite passes random rounds. It is not automatically the posterior probability that a passing candidate is composite; that depends on the candidate distribution and the prevalence of primes. For multiple composite candidates, a union bound gives at most \\(T4^{-k}\\) for any false acceptance among \\(T\\) independently randomized tests of \\(k\\) rounds each. Stronger average-case bounds exist for particular generation models, but they are distinct from the universal worst-case guarantee.\n\nImplementation correctness is as important as the theorem. Modular multiplication must handle overflow; base sampling must cover its intended range without unintended bias; exact comparisons must handle small inputs and powers of 2 correctly. In adversarial settings, a maliciously chosen candidate can exploit weaknesses in an inadequately specified fixed-base procedure. Test descriptions therefore need to identify the variant, bases or sampling rule, preprocessing, and applicable input range.\n\nFor independently verifiable results, a proof certificate separates trust in a large search program from trust in a smaller verifier. The verifier checks exact arithmetic identities and recursive primality claims rather than accepting a program’s final label. Formal verification can further connect these checks to a machine-checked theorem. In large computations, reproducibility also depends on preserving the exact candidate, certificate data, and verification conditions; a log stating only that a number “passed a prime test” does not specify what mathematical claim has been established."
    }
  ],
  "links": [
    "algorithm",
    "integer",
    "prime-number",
    "number-theory",
    "big-o-notation",
    "sieve-of-eratosthenes",
    "floating-point-arithmetic",
    "fermats-little-theorem",
    "modular-arithmetic",
    "greatest-common-divisor",
    "modular-exponentiation",
    "miller-rabin-primality-test",
    "field-mathematics",
    "euclidean-algorithm",
    "group-theory",
    "elliptic-curve",
    "binomial-theorem",
    "ring-mathematics",
    "fast-fourier-transform",
    "public-key-cryptography",
    "rsa-cryptosystem",
    "finite-field",
    "prime-number-theorem",
    "formal-verification"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}