OFFSET
1,1
COMMENTS
S reads like this:
"At position 2, there is a prime in S" [indeed, this is 3]
"At position 3, there is a prime in S" [indeed, this is 5]
"At position 5, there is a prime in S" [indeed, this is 7]
"At position 1, there is a prime in S" [indeed, this is 2]
"At position 7, there is a prime in S" [indeed, this is 11]
"At position 8, there is a prime in S" [indeed, this is 13]
"At position 11, there is a prime in S" [indeed, this is 19]
"At position 13, there is a prime in S" [indeed, this is 23]
"At position 10, there is a prime in S" [indeed, this is 17], etc.
S is built with this rule: when you are about to write a term of S, always use the smallest integer not yet present in S and not leading to a contradiction.
Thus one cannot start with 1; this would read: "At position 1, there is a prime number in S" [no, 1 is not a prime]
So start S with 2 and the rest follows smoothly.
S contains all the primes and they appear in their natural order.
Does the ratio primes/composites in S tend to a limit?
The definition and the comments above are Eric Angelini's original submission. A more formal definition would be "Lexicographically earliest sequence of distinct positive numbers such that k is a term of the sequence iff a(k) is a prime". However, to honor Eric Angelini's memory, we will retain his enigmatic definition. - N. J. A. Sloane, Dec 20 2024
Comments from N. J. A. Sloane, Nov 14 2024 (Start)
Theorem. Let p(k) = k-th prime, c(k) = k-th composite number. For n >= 5, if n is a prime or n = c(2*t+1) for some t, then a(n) = p(k) where k = floor((n+PrimePi(n))/2); otherwise, n = c(2*t) for some t and a(n) = c(2*t+1).
The proof will be added later (see reference).
The theorem implies that the sequence consists of the primes and the odd-subscripted composite numbers.
All of Dean Hickerson's comments below follow from this theorem. (End)
Comments from Dean Hickerson, Aug 11 2006: (Start)
In the limit, exactly half of the terms are primes. Here's a formula, found empirically, for a(n) for n >= 5:
Let pi(n) be the number of primes <= n and p(n) be the n-th prime. Then for n >= 5:
- if n is prime or (n is composite and n+pi(n) is even) then a(n) = p(floor((n+pi(n))/2));
- if n is composite and n+pi(n) is odd and n+1 is composite then a(n) = n+1;
- if n is composite and n+pi(n) is odd and n+1 is prime then a(n) = n+2.
Also, for n >= 5, n is in the sequence iff either n is prime or n+pi(n) is even.
(This could all be proved by induction on n.)
It follows from this that, for n >= 4, the number of primes among a(1), ..., a(n) is exactly floor((n+pi(n))/2). Since pi(n)/n -> 0 as n -> infinity, this is asymptotic to n/2. (End)
REFERENCES
N. J. A. Sloane, The Remarkable Sequences of Éric Angelini, MS in preparation, December 2024.
LINKS
N. J. A. Sloane, Table of n, a(n) for n = 1..20000 [First 1000 terms from Kerry Mitchell]
Eric Angelini, A sequence describing the position of its prime terms, Blog Post, August 2006.
E. Angelini, A sequence describing the position of its prime terms [Cached copy, with permission]
N. J. A. Sloane, "A Handbook of Integer Sequences" Fifty Years Later, arXiv:2301.03149 [math.NT], 2023, p. 9.
N. J. A. Sloane, A Nasty Surprise in a Sequence and Other OEIS Stories, Experimental Mathematics Seminar, Rutgers University, Oct 10 2024, Youtube video; Slides [Mentions this sequence]
MAPLE
chi := proc(n) if n <= 3 then 0 else n - numtheory:-pi(n) - 1; fi; end; # A065855, number of composites <= n
A002808 := proc(n) option remember ; local a ; if n = 1 then 4; else for a from procname(n-1)+1 do if not isprime(a) then return a; end if; end do ; end if; end proc;
A121053 := proc(n) local init, t1;
init := [2, 3, 5, 1, 7];
if n<=5 then return(init[n]); fi;
if isprime(n) or (not isprime(n) and ((chi(n) mod 2) = 1))
then ithprime(floor((n+numtheory:-pi(n))/2));
else t1 := chi(n); A002808(t1+1);
fi; end;
[seq(A121053(n), n=1..120)]; # N. J. A. Sloane, Nov 14 2024
MATHEMATICA
a[1]=2; a[2]=3; a[3]=5; a[4]=1; a[n_ /; PrimeQ[n] || !PrimeQ[n] && EvenQ[n+PrimePi[n]]] := Prime[Floor[(n+PrimePi[n])/2]]; a[n_ /; !PrimeQ[n] && OddQ[n+PrimePi[n]]] := If[!PrimeQ[n+1], n+1, n+2]; Table[a[n], {n, 1, 40}] (* Jean-François Alcover, Mar 21 2011, based on Dean Hickerson's formulas *)
PROG
(Python)
from sympy import isprime, prime, primepi, composite, compositepi
def a(n): return [2, 3, 5, 1, 7][n-1] if n < 6 else prime(n+primepi(n)>>1) if isprime(n) or (c:=compositepi(n))&1 else composite(c+1)
print([a(n) for n in range(1, 81)]) # Michael S. Branicky, Nov 29 2024
(Python) # faster for initial segment of sequence
from sympy import isprime, sieve
from itertools import count, islice
def nextcomposite(n): return next(k for k in count(n+1) if k not in sieve)
def agen(): # generator of terms
alst, chin, pin, nextc = [2, 3, 5, 1, 7], 1, 3, 6
yield from alst
for n in count(6):
if isprimen:=n < nextc: pin += 1
else: chin, nextc = chin + 1, nextcomposite(nextc)
yield sieve[(n+pin)>>1] if isprimen or chin&1 else nextc
print(list(islice(agen(), 80))) # Michael S. Branicky, Nov 29 2024
CROSSREFS
KEYWORD
nonn,nice,changed
AUTHOR
Eric Angelini, Aug 10 2006
STATUS
approved