Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #33 Dec 12 2020 21:12:34
%S 4,2,4,2,4,6,2,6,4,2,4,2,4,6,2,6,4,2,4,2,4,6,2,6,4,2,4,2,4,6,2,6,4,2,
%T 4,2,4,6,2,6,4,2,4,2,4,6,2,6,4,2,4,2,4,6,2,6,4,2,4,2,4,6,2,6,4,2,4,2,
%U 4,6,2,6,4,2,4,2,4,6,2,6,4,2,4,2,4,6,2
%N Differences between terms of compacting Eratosthenes sieve for prime(4) = 7.
%C P(x) is a function which represents a prime number at a ordinal x.
%C This pattern, dp(x) is a sequence of the differences between consecutive prime numbers as described by p(x).
%C For P(4), dp(4)is the relative offsets of the next 7 primes: 7, +4 = 11, +2 = 13, +4 = 17, +2 = 19, +4 = 23, +6 = 29, +2 = 31
%C The Eratosthenes sieve can be expressed as follows. Start with S1 = [2, 3, 4, 5, ...] the list of numbers bigger than 1. Removing all multiples of the first element 2 yields the list S2 = [3, 5, 7, 9, ...]. Removing all multiples of the first element 3 yields S3 = [5, 7, 11, 13, 17, 19, ...], Removing all multiples of the first element 5 yields S4 = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, ...], and so on. The list of first differences of S4 is [4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2, ...] which is this sequence. - _Michael Somos_, Mar 12 2014
%H Christopher J. Hanson, <a href="http://www.codeproject.com/Articles/716180/The-structure-of-prime-numbers-and-twin-prime-gaps">The structure of prime numbers and twin prime gaps</a>
%F a(n + 8) = a(n). - _Michael Somos_, Mar 10 2014
%F a(n) = 4*((n+2) mod 2) + 2*((n+1) mod 2) + 4*(f(8,n+2)+f(8,n)) - 2*f(8,n+1), where f(x,n)= floor(n/x)-floor((n-1)/x). - _Gary Detlefs_, Nov 16 2020
%o (PARI) {a(n) = my(A); if( n<1, 0, A = vector( n*28 + 48, k, k+1); for( i = 1, 3, A = select( k -> k%prime(i), A) ); polcoeff( (1 - x) * Ser( select( k -> k>7 && (k%7) == 0, A) / 7), n)) }; /* _Michael Somos_, Mar 10 2014 */
%o (C#)
%o // dp(4) = GeneratePrimeDifferencialPattern( 4 );
%o static void GeneratePrimeDifferencialPattern( int ordinal )
%o {
%o // Contract
%o if( ordinal < 1 )
%o throw new ArgumentOutOfRangeException( "ordinal" );
%o // Local data
%o int size = 1 << 18;
%o int[] numberLine = Enumerable.Range( 2, size ).ToArray();
%o int pointer = 0;
%o // Apply sieve: for each integer greater than 1
%o while( pointer < numberLine.Length )
%o {
%o // Locals
%o int x = numberLine[pointer];
%o int index = pointer;
%o List<int> pattern = new List<int>();
%o int skips = 0;
%o int count = 0;
%o bool counting = true;
%o // Find all products
%o for( int n = x + x; n < size; n += x )
%o {
%o // Fast forward through number-line
%o while( numberLine[++index] < n )
%o skips++;
%o // If the number was not already removed
%o if( numberLine[index] == n )
%o {
%o // Add skip count to pattern
%o pattern.Add( numberLine[index] );
%o // Mark as not prime
%o numberLine[index] = 0;
%o // Reset skips
%o if( counting )
%o {
%o count++;
%o if( skips <= 2 )
%o counting = false;
%o }
%o skips = 0;
%o }
%o // Otherwise we've skipped again
%o else skips++;
%o }
%o // Reduce number-line
%o numberLine = numberLine.Where( n => n > 0 ).ToArray();
%o // If we have a pattern we want
%o if( pattern.Any() && pointer == ordinal - 1 )
%o {
%o // Report pattern
%o int prime = numberLine[ordinal-1];
%o var d = pattern.Take( count ).ToArray();
%o List<int> dp = new List<int>();
%o for( int y = 1; y < count; y++ )
%o dp.Add( ( d[y] - d[y - 1] ) / prime );
%o System.Console.WriteLine( "Pattern P({0}) = {1} :: dp({0}) = {2}", pointer + 1, numberLine[pointer], String.Join( ", ", dp ) );
%o return;
%o }
%o // Move number-line pointer forward
%o pointer++;
%o }
%o }
%Y Cf. A236175-A236180, A236185-A236190.
%Y Cf. A007775
%K nonn
%O 1,1
%A _Christopher J. Hanson_, Jan 21 2014
%E Edited by _Michael Somos_, Mar 12 2014. (Added code and comments, refined description.)