How many primes are there up to a given number? Jiayan Ni’s proof changes the cost of getting the exact answer. The prime counting function can now be computed in deterministic time, improving on the best-known exponent of one-half that dates to 1987. The same research gives subpolynomial bounds for adding the primes up to and finding one between and . The mathematical turn is to express primality using Ramanujan’s sums of complex roots of unity, then translate those sums into arithmetic constraints a counting algorithm can solve. The result is an asymptotic advance with no demonstrated practical speedup.
Table of Contents
1. What Is the Prime Counting Function and What Does the New Proof Establish?
The prime counting function counts primes less than or equal to . An approximation such as describes how the count grows, while the exact value tells you precisely how many primes qualify. Theorem A computes the sum of prime numbers , Theorem B computes , and Theorem C outputs a prime in for positive . For the formal input , the third machine returns 2.
At , the same four primes, 2, 3, 5 and 7, determine both the sum and the count. The search task needs a prime beyond the cutoff. The later bisection example shows how evaluations of the sum supply it. The theorem statements and numbering here follow the expanded manuscript dated November 21, 2026.
2. Why Prime Counting Faced a 39-Year Complexity Barrier
The sieve of Eratosthenes marks multiples of primes up to the square root of the cutoff, then counts the survivors. Its familiar operation bound is . The Meissel–Lehmer method instead counts integers that survive partial sieving and corrects for composites using smaller prime counts. Later refinements brought this combinatorial route to roughly time without producing a list of every prime.
In 1987, Lagarias and Odlyzko took an analytic route. A contour integral involving the zeta function gave an exact counting procedure with running time . Hirsch, Kessler and Mendlovic later reached the same leading exponent by elementary methods, also covering the prime sum. The half-power stood as the best-known upper bound for 39 years.
A prime counting function formula can encode the answer exactly and still be expensive to evaluate. For deterministic prime finding, even an efficient test for one candidate leaves the problem of choosing which candidates to test. Scanning successive integers can cost as many tests as the size of a prime gap, which is why the new proof looks for a way to answer a question about an entire interval at once.
3. What Does Subpolynomial Time Actually Mean?
The numerical value measures the size of the search range. The length of the input measures how many binary digits the machine reads. For these are related by the following formula.
The manuscript bounds the number of machine steps by an exponential in , up to constants in the exponent, as grows. Since is on the order of , rewriting the bound in terms of gives
Little-o means the exponent tends to zero. Consequently the upper bound eventually grows more slowly than for every fixed . In input bits the bound is subexponential because its exponent grows more slowly than . A polynomial bound in would require a substantially stronger guarantee. Likewise, the asymptotic comparison yields no measurement of how long the prime counting algorithm takes on an input of any particular length.
4. The AI-Assisted Proof Explained in Six Stages
The proof starts with an exact prime indicator, passes through complex analysis and returns to integers. The intermediate changes of representation keep each counting query small enough for the available engine.
- Reformulate primality. Combine two arithmetic functions so that only primes contribute to the sum.
- Eliminate factorization. Replace Möbius values with Ramanujan sums. Describe their indices using divisibility and coprimality, with one bounded witness for each valid coprime pair.
- Transform analytic functions. Move evaluations to a common real interval and use samples on a circle to approximate all four analytic factors by rational expressions.
- Control the error. Build certified coefficient tables and choose enough binary precision for rounding the assembled result to recover the exact integer.
- Build counting networks. Use quotient and remainder constraints for the rational expressions and encode each weight as a number of assignments.
- Construct the algorithms. Assemble counts into a prime sum, change the weight to count primes, or compare sums to narrow an interval until a prime is isolated.
5. How the Exponential Time Hypothesis Breakthrough Powers Prime Counting
The Exponential Time Hypothesis posits an exponential-time requirement in the number of variables for 3-SAT. The upstream work Ni uses supplies subexponential algorithms related to #3-SAT, the task of counting satisfying assignments of a Boolean formula with clauses of up to three literals. Its tensor networks encode constraints through local arrays that vanish on invalid assignments. Summing the product over shared binary indices counts the assignments that satisfy the system.
Ni uses this machinery through a counting package. Each query describes a system of bounded integer variables with constraints built from operations such as addition, multiplication and comparison. The engine evaluates the number of solutions. Theorem 2.8 handles polynomially many queries to a package even when a later query depends on an earlier answer. Both the query procedures and postprocessing can take polynomial time in the input length.
The runtime for a package depends on the total number of shared bits in one network. Linear padding allows room for the query description and variable widths while keeping the new input length proportional to . A polynomial increase in shared bits could wipe out the subexponential bound in the original input length. Ni’s contribution is the reduction that keeps the queries within this budget.
6. Möbius Inversion and Ramanujan Sums

The Möbius function is zero when a prime square divides , and equals for a product of distinct primes, with . The von Mangoldt function equals at powers of a prime and zero otherwise. For , multiplying the two singles out primes.
At 5 the numerator with the minus sign is . At 9 the Möbius factor vanishes, and at 6 the von Mangoldt factor vanishes. To remove dependence on factorization, Möbius inversion first writes . Then Ramanujan’s identity replaces each Möbius value with a sum of roots of unity. Write for the integers with and .
For , the two roots at angles of 120 and 240 degrees have opposite imaginary parts and real parts that add to minus one. Substituting the identity for both Möbius factors and multiplying each indicator by its weight yields the following formula.
Divisibility becomes the equation . For and , coprimality is equivalent to the existence of a bounded Bézout witness satisfying , with and . The inverse of modulo fixes , then the equation fixes . Uniqueness means adding these variables leaves each coprime pair counted once. Modulus 1 uses its own branch.
7. Cauchy Quadrature: Turning Complex Analysis Into Rational Arithmetic
Each summand has two phase factors, a logarithm and a reciprocal logarithm. Computing those functions within every constraint system would make it hard to keep the bit budget linear. The Cauchy integral formula gives a different representation. For an analytic function , its value inside a circle can be recovered from a weighted integral of its values on the circle. The manuscript samples that integral at equally spaced nodes around .
A phase uses the argument . For a logarithm at a positive integer , take and , so the scaled argument lies in and the function to sample is . The reciprocal uses the inverse of that function with , as its original input is at least 2. Thus all evaluations use the same interior segment.
For analytic on a neighborhood of the disk of radius around , with there, Theorem 4.1 gives the following uniform estimate on .
Equal spacing cancels the Fourier modes whose frequencies are not multiples of . Analyticity makes the surviving high-frequency terms geometrically small. Once the coefficients are tabulated, one kernel requires only a fixed number of arithmetic operations on the input ratio and node coordinates.
8. How Approximate Calculations Recover Exact Prime Counts
Choose a precision parameter with . The construction uses nodes, represents nodes and coefficients with binary places, and truncates the kernel components toward zero at binary places. The tables store Gaussian integers, which have integer real and imaginary parts, scaled by a power of two. Rational series with explicit tail bounds generate these tables in polynomial time. Any table meeting the certified tolerance is sufficient.
One factor incurs error at most . The two exact phases have magnitude one, the reciprocal logarithm is bounded by two, and the remaining logarithm is bounded by . Replacing the factors one at a time bounds the difference between the exact and approximate products by . The number of terms is at most : for each , the identity leaves at most triples of divisor and residue indices. Each weight is at most . Hence the approximate sum satisfies
For example, an approximate real part of 16.8 would recover the exact sum 17 at cutoff 10. The certified inequality ensures this rounding step is valid for every input.
9. The Counting Network: Turning Weighted Sums Into Solution Counts

After fixed-point scaling, each kernel component has a sign and an integer magnitude. The magnitude is a quotient , where is a nonnegative numerator and . The network enforces and . For a fixed numerator and denominator, the quotient and remainder are unique. Expansion of the four quadrature factors then groups terms by node choices, dyadic scales, components and signs. Coefficients that depend only on the query are applied outside the network.
Each query counts assignments corresponding to products. To encode , allow and . Each of the three choices of admits four choices of , giving 12 assignments. Likewise, four variables with upper bounds given by the kernel quotients produce their product as a multiplicity. One more variable with upper bound supplies the prime-sum weight. If any quotient is zero, the assignment contributes zero, as required.
The full description has 72 variables, 33 equations and 132 product slots. Each variable uses bits at the chosen precision. Apart from the intended multiplicity choices, the arithmetic auxiliaries are determined by the summation indices and query. This gives linear size in shared bits even though the constraints can have many solutions. The queries number only polynomially many because there are four factors and polynomially many choices of nodes and scales. Their signed counts reconstruct the fixed-point numerator before final rounding.
10. Three Algorithms, One Proof: Prime Counting, Summation and Finding

For Theorem A, the machine generates the certified tables, asks for the counts and combines them with integer coefficients over a common denominator. For Theorem B, the variable that contributes choices is given just one choice. Every prime then contributes one to the rounded output. The same error budget applies because the weight has decreased.
For Theorem C, every prime contributes a positive term to the difference of two prefix sums. For integers , this gives the test
Bertrand’s postulate supplies an initial interval containing a prime for . Starting with , compare with . The sum rises from 17 to 41, so retain . At 12 the sum is 28, so retain . At 11 the sum is also 28, and the interval singles out 11. The paper bounds the total by prime-sum evaluations, and each uses the same sum algorithm. This settles the weak Polymath4 problem of finding primes deterministically in subexponential time in their digit length. The interval decision result also applies without the interval-length restriction in the project’s conjecture.
11. How Lean Verified the Prime Counting Proof
The independent Lean specification imports only Mathlib. It uses Mathlib’s prime counting function and states three endpoints for timed deterministic multi-stack Turing machines. Each endpoint asserts that a machine halts within the specified bound and returns the required answer. The prime-finding endpoint specifies the output by primality and its bounds, without encoding bisection in the specification.
Ni reports a source build of the dependencies, a fresh replay using leanchecker --fresh and a Comparator check against the independent statements. Comparator had the exported proofs accepted by the Lean kernel and by nanoda, a separate kernel implementation. Both checks ran on one machine. The release provides reproduction scripts for others to run.
The author credits GPT-6 Astra with assisting the algorithmic constructions linking the counting engine to the three problems. GPT-6 Astra and Claude Fable 5.2 took the main role in formalization. The proof stages above follow the published mathematical dependencies. The paper documents those roles without identifying which tool first proposed any particular proof step.
12. Beyond Prime Counting: Generalizations and Remaining Open Problems
Theorem 10.4 extends the method to integer-valued totals of admissible sums. Their summation domains need bounded arithmetic descriptions, and their analytic factors need efficiently generated certified tables. The integrality of the total makes exact rounding possible. The corollaries cover fixed polynomial weights on primes and both counting and summing primes in fixed arithmetic progressions. They also cover the Mertens function, the cumulative sum of Möbius values, where the Ramanujan phase suffices without a logarithm.
The paper reports Lean proofs of the general theorem and corollaries in the development checkout. The independently specified, dual-kernel-checked endpoints belong to the tagged release and cover Theorems A–C. Polynomial time in the input length remains open for both exact prime counting and deterministic prime finding. The explicit padding factor of 2049 illustrates the scale of the construction. The manuscript leaves the overall runtime constant unextracted and the practical crossover unknown.
The prime counting function now has a faster asymptotic upper bound because the proof turns analytic expressions into counts without exceeding a linear bit budget. Follow Binary Verse AI for more research explainers that trace how results like this are proved.
What is the prime counting function?
The prime counting function, denoted by , gives the exact number of primes less than or equal to . For example, , because 2, 3, 5 and 7 are the four primes up to 10.
Is there an exact formula for counting prime numbers?
Yes. Exact prime-counting formulas and algorithms predate this research. The new AI-assisted proof improves the best-known deterministic time bound from to .
How does the new prime counting algorithm work?
It combines Möbius inversion, Ramanujan sums and Cauchy quadrature to express the calculation as bounded arithmetic counting problems. A subexponential counting engine evaluates them, and certified rounding recovers the exact integer.
Does the proof depend on the Riemann hypothesis?
No. All three main theorems are unconditional and require no conjectures about the distribution of primes.
What does time mean?
The running-time upper bound grows more slowly than every fixed positive power of . This bound alone guarantees neither constant time nor polynomial time in the number of input bits.
Has the deterministic prime-finding problem been solved?
The proof settles the weak form of the Polymath4 problem by establishing deterministic prime finding in subexponential time in the number of digits. The stronger polynomial-time version remains open.
Is the new prime counting algorithm practically faster?
No practical speedup has been demonstrated. The manuscript establishes an asymptotic improvement, reports large constants in the construction and gives no practical crossover size.
