OFFSET
1,1
COMMENTS
Technically, alternation requires more than 2 values of something, so the first term is a convention this sequence and its description (that follows).
Each prime prime(m) is followed by a sequence of prime gaps A001223(m+k), k>=0. We classify a subsequence of A001223 as "alternating" if consecutive values alternatingly increase and decrease, which means, if the associated subsequence of the second differences A036263 (one term shorter) always switches sign if the index increases by one. The length is the maximum l>=1 such that A036263(m+k)*A036263(m+k+1) <0 for all 0<=k<l-1.
These lengths in A036263 starting at A036263(m) are 1, 1, 5, 4, 3, 2, 1, 4, 3, 2, 1, 2, 1, 1, 1, 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 7, 6,... for m >=1. The record lengths of 1, 5, 7,... occur at indices i= 1, 3, 29,.. indicating primes A000040(m) = 2, 5, 109,... as listed in this sequence. (Records are defined by a sequence of strictly increasing lengths, as usual in the OEIS; repetition of a length that was recorded earlier cannot define a new record.)
EXAMPLE
a(2) = 5 and A228851(2)=23 indicates the second record is generated by the primes 5, 7, 11, 13, 17, 19 and 23, and also the primes 3 and 29 indirectly, with differences 2 < 4 > 2 < 4 > 2 < 4. The preceding difference of 2 (5-3) is not greater than 2 and the following difference of 6 (29-23) is not smaller than 4.
MAPLE
Aruns := proc(P)
option remember;
local p, sdiff, i, snew, q, r ;
p := P ;
q := nextprime(p) ;
r := nextprime(q) ;
sdiff := p+r-2*q ;
if sdiff = 0 then
return 1;
else
for i from 1 do
p := q ;
q := r ;
r := nextprime(q) ;
snew := p+r-2*q ;
if snew*sdiff < 0 then
sdiff := snew ;
else
return i ;
end if;
end do:
end if;
end proc:
A228850 := proc()
local r, p, i ;
r := 0 ;
p :=2 ;
for i from 1 do
if Aruns(p) > r then
printf("%d\n", p) ;
r := Aruns(p) ;
end if;
p := nextprime(p) ;
end do:
end proc:
A228850() ; # R. J. Mathar, Oct 10 2013
PROG
(PARI) alt(p) = {ok = 1; q = nextprime(p+1); da = q - p; p = q; q = nextprime(p+1); db = q - p; dir = sign(db - da); if (dir == 0, return (0)); nb = 2; while (ok, p = q; q = nextprime(p+1); dc = q - p; if (dir < 0, ok = db < dc, ok = db > dc); if (ok, nb ++); dir = sign(dc - db); db = dc; ); return (nb); }
lista(nn) = {rec = 0; for (n = 1, nn, new = alt(prime(n)); if (new > rec, rec = new; print1(prime(n), ", ")); ); } \\ Michel Marcus, Sep 21 2013
CROSSREFS
KEYWORD
nonn
AUTHOR
James G. Merickel, Sep 05 2013
STATUS
approved