WorksMathematics
Sharp linear bounds for the EKG sequence
Abstract
We prove that the EKG sequence satisfies for every , with equality only at and , respectively. Discovered by Jonathan Ayres, the sequence starts with and repeatedly takes the least unused positive integer sharing a factor greater than with its predecessor. This proves the sharp linear bounds conjectured by Lagarias, Rains and Sloane, who established coarse bounds at every index. Hofman and Pilipczuk proved the limits , and of on primes, their triples and the other terms, and Haver made these estimates explicit and formalized them in Lean. Our earlier second-order asymptotic also builds on Haver's work. We sharpen Haver's self-improving early-even bound with a shorter prime window and effective large-sieve constants, and control odd terms so that the analytic range meets a finite computation. Lean checks the deduction from the definition, conditional on computed premises; independent programs check those premises, and their correspondence with the formal statements was checked by reading the code. This work has not yet been reviewed by experts. The proofs, the Lean formalization, the programs and the text were produced by AI models, working under the author's direction.
2020 Mathematics Subject Classification: Primary 11B83; Secondary 11N36, 68V15.
Introduction
The EKG sequence, discovered by Jonathan Ayres and studied by Lagarias, Rains and Sloane [13 Introduction], is A064413 in the OEIS [19]. Write . The sequence is defined by
so it begins 1, 2, 4, 6, 3, 9, 12, 8, 10, 5, 15, 18, 14, 7, 21, 24, 16, 20, 22, 11, . . . . It is a permutation of the positive integers [13 Theorem 1] (Theorem 2.5 in the journal version). Its graph has three visible lines (Figure 1): most terms satisfy , while each odd prime is immediately preceded by and followed by , and when we have (and ). Lagarias, Rains and Sloane proved and conjectured sharp linear bounds [13 Conjecture 3, end of §4] (Conjecture 4.3 in the journal version):
Figure 1. Left: for , with the bounds (top) and (bottom) of Theorem 1, attained at and . Right: the largest and smallest values of over each block , , approaching and (dotted). Drawn from the computed sequence.
The sequence satisfies , with equality if and only if , and , with equality if and only if .
Theorem 1. For every integer ,
The lower bound is an equality only for (where ) and the upper bound only for (where ).
Prior work. Lagarias, Rains and Sloane give the pointer rule as an alternative definition [13 eq. (2)] and prove the coarse bounds above [13 Theorems 2–3]. Their Conjecture 2 states when is neither nor for a prime , when , and when [13 Conjecture 2]. Hofman and Pilipczuk [11 Theorems 4.3, 4.17, Lemma 4.5 and Corollary 4.12] proved the full pattern for odd primes, bounded the crossings of a level by composite terms, and proved the leading limits , and for prime, triple-prime and remaining terms, respectively. Haver made these arguments explicit and formalized them in Lean [10 (F2), Theorems 5, 8, 11 and Corollary 12(b)], reducing the pattern’s computed base to the primes , bounding the number of used even numbers above the least missing even number, the spread of the terms above it, and the unused composites below it, and relating the index to that even number by a counting identity. The author [9] then obtained a second-order asymptotic, , for a smoothed version of the sequence (each odd prime and replaced by ), on Haver’s Lean foundation. The present proof uses Haver’s Lean definition of the sequence and Haver’s estimates, and the author’s exact form of the counting identity, as proved Lean theorems.
Haver already closes a self-improving early-even inequality and obtains its leading asymptotic constant by Brun–Titchmarsh [10 Lemma 4, Theorem 5, Remark 6(b)]. The hardest step is to make that inequality close at a frontier reached by a finite computation; Haver’s explicit bound is too weak at that frontier. We shorten the prime window from to integers, where counts the used even numbers above the least missing even number; effective large-sieve constants and odd-term control make the analytic range meet a finite computation.
The proof uses Lean and computations of a finite prefix and an interval-arithmetic certificate. § 9 gives the formal statement and its relation to the theorem; Appendix B describes the computed premises and their checks.
The result is computer-assisted.
Notation and known facts
All logarithms are natural. The notation below separates the three kinds of terms and the errors in the counting identity. The terms frontier, early evens and tick value follow Haver [10 §§1–2]. A state is the moment after have been placed. For a state define:
, the frontier: the least positive even integer not in . It is nondecreasing in , and every even number below is used.
, the number of early evens: even with .
, the least multiple of not in .
A tick value is with an odd prime. is the largest element of that is not a tick value, and is the number of odd with that are not tick values.
, the number of holes: composite with .
, where counts primes.
For example, after we have , the early even 12, so , and since 9 is a tick value.
We use the following facts; each is a Lean theorem in the foundation (§ 9). The parenthesized labels refer to the statements recalled here.
(F1) Pointer rule [13 eq. (2)]. for .
(F2) Prime pattern. For each odd prime there is an index with , and ; the value occurs only at , and indices of distinct primes differ by at least 4. See [11 Theorem 4.3] and [10 (F2)]; the finite checks and detailed attributions are in Appendix B.§ 1.
(F3) Crossings [11 Lemma 4.5], [10]. For a level , at most indices have composite and .
(L7) [10 Lemma 7] for .
(SP) Span [10 Theorem 8]. With and , for .
(EE) Our variant of [10 Lemma 4], from its proof. Call a prime up at state if is prime and ; it is paired if is odd and , and unpaired otherwise. Then . Pairing uses only terms already placed at state , so is required; a prime up with is unpaired.
(CL) Counting identity [10 Corollary 12(b)], in the exact form of [9]. For and ,
Here is the bounded correction in (CL). A crossing of a level is a step from one side of that level to the other; upward and downward refer to its direction. The inequalities in (F3) fix the convention at an endpoint.
Write for the explicit prime-counting bounds in Appendix A; counts primes up to . The following two forms of the large sieve are proved in Lean.
(BT) Primes in short intervals. For real , and integers ,
We use the additive inequality of Montgomery and Vaughan [17 Theorem 1] and their arithmetic lower bound [17, (2.7)}, which they credit to Montgomery [16]. OpenAI’s formalization [18] already supplies the arithmetic large sieve with Farey separation . For (BT) we use separation to obtain the numerator . We also prove , the form in the proof of [17 Lemma 7], whose printed statement is for real .
(LS) Arithmetic large sieve [16, 17]. For an integer , a set of integers in an interval of consecutive integers that avoids one residue class modulo every prime has at most elements.
Strategy
The three kinds of terms behave differently, and each is located through the frontier. If is an odd prime then and by (F2); if then and ; every other term either lies above the frontier , and then at most , or fills a hole below it, and holes lie close to the frontier. The counting identity (CL) relates the index to : is small, and if , and are small compared to , then and the three kinds of terms give near , and .
Everything therefore rests on explicit upper bounds for , and at every state, uniformly in a range of . Haver bounds each by a multiple of (times further factors), so the bounds are relatively small only when is astronomically large. We split the indices into three ranges:
: computed (Section B.1);
: a bootstrap bound for a step function , certified with and on every interval of a cover of (§ 4–§ 6);
: Haver’s bounds alone (§ 7).
The ranges overlap, so every is covered. Range 2 requires the bound on already at .
The early-even bound. Theorem 1 needs sharp constants at every : the lower line sits only above . With Haver’s bound [10 Theorem 5] the argument closes only for very large ; we use it that way for (Lemma 8), far beyond any computation. The quantitative improvement uses a shorter prime window (Lemma 2, Corollary 3): the primes responsible for the excess of lie among the integers just below , so , and a Brun–Titchmarsh bound from the large sieve turns this into . The bound is proved by induction over the moments of the sequence, so it needs no prior bound on : at each moment the earlier ones already satisfy it, and an explicit inequality, checked on intervals of , carries it to the next. At the certified bound is 28,017, against 131,628 from Haver’s bound. A second large-sieve bound controls the odd terms above (Lemma 5). With these, explicit estimates close once ; the computed first terms reach that point (with above by ) and settle every smaller .
Early evens
We bound the primes responsible for early evens. For a state let , with .
Lemma 2. Let be a state and . Every unpaired prime up at state has prime with .
Proof. The prime 2 is never a prime up: , , and for . So is odd, and by (F2) and . Since , , and is nondecreasing, so . Unpairedness forces every multiple of 3 below to be used by the state when (otherwise by (F1), since ); in particular , as is still unused at . Each multiple of 6 with is then used by state , is none of , , , and so was already used at state , where : it is an early even at state . Since there are more than such , so . In the remaining case we have , so every even with lies in and is an early even at state ; hence , which is stronger. ∎
Corollary 3 (Bootstrap). Let , let be a nondecreasing function on the integers, and let bound the number of primes in every block of consecutive integers. Suppose that at every state with , and that
for every even with . Then at every state with .
Proof. Strong induction on . The states have by direct computation of the first terms, and (2) gives , so they satisfy the claim. Let . Every $s < t
has , so by induction and monotonicity . By Lemma 2 the primes of the unpaired prime ups at satisfy , so they lie among consecutive integers, and they are distinct because the sequence does not repeat values. Thus (EE) gives by (2).
The function bounds primes in an interval of length ; the label (BT) refers to the displayed sieve estimate. With (BT), for any integer . For and near this is about , so (2) holds once is a little larger than . This is as , and about at . Haver’s argument counted the same primes through their residues modulo 210, which bounds them only by a fixed fraction of the window; this is where Haver’s factor 12 comes from.
Holes and odd terms above the frontier
The next two lemmas bound and in terms of a bound on . Lemma 4 is Haver’s hole bound [10 Theorem 11] with an arbitrary nondecreasing bound in place of Haver’s explicit one, and with the hypothesis needed only at earlier states.
Lemma 4 (Holes). Let be nondecreasing with for every state , and . Every hole at state satisfies , where is the least prime factor of , and .
Proof. A hole is odd; put and let be the first state with . Every multiple of in is used. If it was placed after then the next term is at most by (F1), a down-crossing of the level ; at most of them were placed before . Up-crossings come from composite bases (at most by (F3)) or from primes with , each of which is matched with its own down-crossing . As ups and downs alternate, the number of multiples of in is at most , which gives the first bound. Summing over the primes the number of odd multiples of in the resulting window gives the second.
Lemma 5 (Odd terms above the frontier). Let be a state, , , and let be an integer. Put and . Then
where is the number of integers with all of whose prime factors exceed .
Proof. At most odd values lie in . Let be another value counted by , and its predecessor. If were even, (F1) with would give ; if were 1 or an odd prime, would be 2 or a tick value (F2); if were a tick value, (F1) with and (L7) would give . So is an odd composite, not a tick value, with . For each prime , by (F1), so the multiples of in are all early evens at : there are at least of them, whence . If the step crosses the level upward, which happens at most times by (F3); otherwise is counted by , and is injective.
The proof uses (F3) at the real level . For the cover we weaken its crossing term to , as in the formal lemma, which counts the odd non-tick excess above the integer . The remaining odd values contribute at most .
By (SP) the numbers counted by lie in an interval of at most integers, , and they avoid the residue modulo every prime ; so (LS) gives for every integer .
The middle range
We now combine the lemmas using a finite table of parameters on adjacent intervals of values of . The inequalities in each row bound the terms of the counting identity. Put , , and .
Definition 6. A row is a tuple of nonnegative integers . With ,
the row is valid if , , , , and
(B)
(Hc)
(P)
(Tk)
(Od)
(Ol)
A cover is a list of valid rows with of the first row equal to , in the first row, each equal to the previous , nondecreasing, and last .
In words: (B) is the bootstrap inequality (2) on the row; (Hc) puts every hole above ; (P) and (Tk) bound the index above and below in terms of , which handles primes and tick values; (Od) bounds the terms above the frontier, and (Ol) the holes filled, for the remaining terms. , , and bound , and on the row.
The published interval certificate (in the Zenodo archive linked below the title) gives a cover with first row . Appendix B.§ 3 displays its first row and describes the finite checks. The condition (P) in Definition 6 is an index inequality; Appendix A uses the same label for the prime-counting bounds.
Theorem 7. Assume a cover exists, the bounds of Theorem 1 for with its equality cases, , and at every state with . Then every with has and . Moreover every state with has .
Proof. Let for and on the -th row’s interval ; it is nondecreasing. Condition (B) and (BT) with give (2) on every row, so Corollary 3 yields at every state with .
Fix a state with in the interval of row . Then for all . Lemma 4 gives , and every hole exceeds , because a hole would give by (Hc) (using ). (SP) gives , and Lemma 5 with and the sieve bound after it give . Since , the identity (CL) yields
By (P), ; by (Tk), .
Now let . Then , and every state has , so the bounds above apply at .
If is an odd prime, take , so . Then , and gives .
If , take , so . Then , and .
Otherwise is even or an odd composite that is not a tick value; take . If then , and (3) with (Od) gives , while . If both bounds follow from and . If , then is a hole at state , so and (Ol) with (3) gives , while .
The far range
For very large Haver’s explicit bounds suffice, without a cover. Ordinary terms here mean even terms and odd composite terms other than the values . The hypothesis below is used only while , to obtain the stated lower bound on at large indices. Once that lower bound is automatic. The subsequent estimates use Haver’s bounds; this is the sense of range 3 in the strategy. In the proof below, (P) means the prime-counting bounds of Appendix A. The numerical estimates follow by substituting those bounds into Haver’s sequence estimates; the accompanying Lean proof contains their derivation (in the Zenodo archive linked below the title).
Lemma 8. Suppose every state with has , and . Then every has and .
Proof. At the states the hypothesis forces . From (P) one derives for . Inserted into Haver’s bounds [10 Theorem 5], (SP), Haver’s hole bound and (CL) (with ), this gives , and at each such state , with , and shows that every hole exceeds . Then the three cases of the proof of Theorem 7 give between and for ordinary terms, and between and for primes and tick values; the binding comparison is .
Proof of the main theorem
Proof of Theorem 1. The computed range supplies the three finite premises of Theorem 7, and the interval certificate supplies its cover. That theorem proves the strict bounds for and the inequality on states required by Lemma 8. The lemma proves the strict bounds for . These ranges overlap and cover every ; the computed bounds for supply both equality cases.
Formal verification
Lean 4 [8, 15] checks the theorem
EKG3.conj3_of_computations :
FiniteFa → FiniteFbP3 → FiniteFcP3 → CertifiedCoverP3 → Conj3Statement.
Its conclusion says: for every , with and , , , and . These integer forms are equivalent to the rational ones in Theorem 1. The sequence in the formal statement is Haver’s greedy sequence with initial terms 1, 2, injectivity, a shared prime factor and minimality as in (1); its indexing starts at zero. Reading the implication from left to right, the four premises are respectively (Fa), (Fb), (Fc) of Appendix B.§ 1, and the cover of Definition 6. They assert the finite bounds, the lower bound on , the bound on before , and the existence of that cover, all about the sequence with no free parameters. The last term, Conj3Statement, is the conclusion just spelled out. Lean checks the analytic inputs and the deduction from these premises; the premises themselves and the correspondence of the programs with those definitions are checked outside Lean. The formal proof uses only Lean’s standard axioms. Appendix B describes the computational checks and dependencies. Reproduction commands and implementation details are in the supplementary checking notes.
Related work. Haver’s work on the Yellowstone permutation, concurrent [1, 2] and later [3, 4, 5], concerns a different greedy permutation; nothing from those papers is used here. Other nearby visiting rules include Applegate, Havermann, Selcoe, Shevelev, Sloane and Zumkeller’s Yellowstone permutation [21], Basistha and Ionaşcu’s coprime permutation [22], and Na’s real-multiplier process [23]. Nothing from these works is used here.
Prime-counting bounds
These formulas specify the prime-counting bounds used in the interval conditions and in the far range. The analytic inputs are explicit and all are proved in Lean. Put , and, for , , .
(P) Prime counting. For , , where with , where and , and ; below 256 both equal . They follow by partial summation from Rosser and Schoenfeld’s [20 Theorem 12]. and for , a weaker form of Chebyshev’s , [7 §V], as proved in Lean in [12].
Computational and formal details
Finite computation
The prime pattern. That follows the first multiple of is [13 Lemma 1] (Lemma 2.1 in the journal version), and that this multiple is is [11 Theorem 4.3]. Hofman and Pilipczuk prove the latter by a crossing count at the level that closes for , and cover smaller by the computation of terms in [13]; Haver [10 Remark 3] closes the same count for every , leaving , which the first 82 terms show. The rest, , the uniqueness of and the spacing, is proved in [10 (F2)]. In the Lean proof the primes are checked on the first terms, by a finite computation, and larger by explicit prime bounds.
The premises of Theorem 7 about the first terms are:
(Fa) for , and , with equality only at and ;
(Fb) ;
(Fc) at every state with .
They are established by computing with the pointer rule (F1), keeping one pointer per prime, and tracking and . We find . The frontier first reaches at , which gives (Fb) since is nondecreasing. The largest at states with is 329; since every state with comes before that crossing, this gives (Fc) for all states, not only those up to . The only equality cases are and .
Two programs written independently, with different factorization methods, memory layouts and formulas for , compute these facts and agree; a third program checks the defining minimality property directly on the first terms.
Formal development
The foundation is Haver’s Lean archive [10] as extended in [9]. The analytic inputs reuse published formalizations: Rosser and Schoenfeld’s Theorem 12 and a form of Chebyshev’s lower bound from the IEANTN project [12] (with interval tools from LeanCert [14]), and the arithmetic large sieve from OpenAI’s formalizations [18], specifically OAI.Ostmann.publishedAdditiveLargeSieve in lean/OAI/NumberTheory/Ostmann/Preliminaries/AdditiveSieveProof.lean. The port preserves the retained statements and proofs; its imports are adapted to the pinned local toolchain. OpenAI’s arithmetic sieve already uses Farey separation . Building on that sieve, we use the stronger separation for (BT), prove the bound from the proof of [17 Lemma 7], and derive (BT) and the bounds (P).
Interval certificate
The certificate has 16,857 rows. Its first row is shown in Table 1; the complete table is in the Zenodo archive linked below the title. Each row supplies the integer parameters of Definition 6. The independent checker verifies the row inequalities, the common endpoints of consecutive intervals, monotonicity of , and the first and last endpoints. The checker uses exact integers and rationals with outward-rounded interval arithmetic.
| Parameter | First row |
| 13,328,000,000 | |
| 13,341,330,000 | |
| 28,017 | |
| 266,194,600 | |
| 4,750 | |
| 7,132,721,000 | |
| 90 |
Table 1. The first row of the interval certificate.
References
- [1]T. Haver, The Yellowstone permutation. III: few large terms, October 22, 2026, earlier on the day of this work’s first public release [6]. doi:10.5281/zenodo.23557280.DOI
- [2]T. Haver, The prime frontier of the Yellowstone permutation is linear, October 22, 2026, earlier on the day of this work’s first public release [6]. doi:10.5281/zenodo.23558450.DOI
- [3]T. Haver, The prime frontier of the Yellowstone permutation falls behind time: limsup R(t)/t < 1, October 23, 2026, after this work’s first public release on October 22, 2026 [6] (later work). doi:10.5281/zenodo.23604646.DOI
- [4]T. Haver, The Yellowstone permutation: limsup R(t)/t ≤ 0.68605, liminf nₙ/p > 1.4576, and Conjecture γ for large n, October 23, 2026, after this work’s first public release on October 22, 2026 [6] (later work). doi:10.5281/zenodo.23604811.
- [5]T. Haver, The Yellowstone permutation: Conjecture γ for all n reduced to a riser law on a finite range, the normality and entry times of primes, and a run certificate, October 23, 2026, after this work’s first public release on October 22, 2026 [6] (later work). doi:10.5281/zenodo.23604970.
- [7]P. L. Chebyshev, Mémoire sur les nombres premiers, J. Math. Pures Appl. 17 (1852), 366–390.
- [8]L. de Moura and S. Ullrich, The Lean 4 theorem prover and programming language, in Automated Deduction—CADE 28, LNCS 12699, Springer, 2021, pp. 625–635. doi:10.1007/978-3-030-79876-5_37.DOI
- [9]P. Graham, The second-order asymptotic of the EKG sequence, version 3, October 20, 2026, manuscript and Lean sources. doi:10.5281/zenodo.23493113.DOI
- [10]T. Haver, Explicit rates for the EKG sequence, version 3, October 4, 2026, manuscript and Lean sources (the Lean archive EKG–Lean4–sources–v2.zip, unchanged from version 2). doi:10.5281/zenodo.23129632.
- [11]P. Hofman and M. Pilipczuk, A few new facts about the EKG sequence, J. Integer Sequences 11 (2008), Article 08.4.2.
- [12]IEANTN contributors (T. Tao et al.), IEANTN, Lean sources, commit ec66e388e6e117c6881367f38665f310edf7cacf, 2026. Rosser–Schoenfeld Theorem 12 by Akula and contributors; Chebyshev bound by T. Tao. https://github.com/teorth/IEANTN.
- [13]J. C. Lagarias, E. M. Rains, and N. J. A. Sloane, The EKG sequence, Experimental Math. 11 (2002), 437–446. doi:10.1080/10586458.2002.10504486; arXiv:math/0204011v1. Numbered locators refer to arXiv version 1 unless marked “journal version”.DOI
- [14]LeanCert contributors, LeanCert, Lean sources, commit 6b11513512c9d27183fb4725bfc291ab38b4a6d7, 2026. https://github.com/alerad/leancert.
- [15]The mathlib Community, The Lean mathematical library, in Proceedings of CPP ’20, ACM, 2020, pp. 367–381. doi:10.1145/3372885.3373824.DOI
- [16]H. L. Montgomery, A note on the large sieve, J. London Math. Soc. 43 (1968), 93–98. doi:10.1112/jlms/s1-43.1.93.DOI
- [17]H. L. Montgomery and R. C. Vaughan, The large sieve, Mathematika 20 (1973), 119–134. doi:10.1112/S0025579300004708.DOI
- [18]OpenAI, math: mathematics formalizations, Lean sources, commit 1581d4cbdd69a0faf34b2089614fe2a814316a6a, 2026. https://github.com/openai/math.
- [19]OEIS Foundation Inc., The On-Line Encyclopedia of Integer Sequences, entry A064413.
- [20]J. B. Rosser and L. Schoenfeld, Approximate formulas for some functions of prime numbers, Illinois J. Math. 6 (1962), 64–94. doi:10.1215/ijm/1255631807.DOI
- [21]David L. Applegate, Hans Havermann, Robert G. S elcoe, Vladimir Shevelev, N. J. A. Sloane and Reinhard Zumkeller, The Yellowstone Permutation, arXiv:1501.01669, first posted January 7, 2015; version 2, March 8, 2015. https://arxiv.org/abs/1501.01669v2.
- [22]Amit Kumar Basistha and Eugen J. Ionascu, A special sequence and primorial numbers, arXiv:2302.02838, first posted February 6, 2023; version 5, November 22, 2023. Rev. Roumaine Math. Pures Appl. 70 (2025), 235–255. https://arxiv.org/abs/2302.02838v5. https://doi.org/10.59277/rrmpa.2025.235.255.
- [23]Sungsoo Na, An integer-visiting process with real multipliers: coverage and rates, version 1.0.0, October 4, 2026. https://doi.org/10.5281/zenodo.23138274.
