Sequences of Primes

The nature of the code given in the following examples is explained in the index document.

Many interesting integer sequences can be derived from prime numbers.  The calculations given below explore such derivations.

Simply Primes

The starting point for the next few sequences is the prime numbers themselves.


   p: i.20          NB. the first twenty
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71

This sequence is in the Encyclopedia as the appropriately early A000040 (unfortunately, 40 isn't prime!).

The two simplest derivations from these are the first differences, and half the first differences (dropping 2, the first prime).


   fdp =: 2&(-~/\p:)              NB. first difference of primes
   fdp i.21              NB. the first twenty
1 2 2 4 2 4 2 4 6 2 6 4 2 4 6 6 2 6 4 2
   -:fdp>:i.21          NB. the first twenty
1 1 2 1 2 1 2 3 1 3 2 1 2 3 3 1 3 2 1 3

These sequences are A001223 and A028334, respectively.

Analogous to these are the first sums, and half the first sums (dropping 2, the first prime).


   2+/\p: i.21              NB. the first twenty
5 8 12 18 24 30 36 42 52 60 68 78 84 90 100 112 120 128 138 144
   -:2+/\p:>:i.21          NB. the first twenty
4 6 9 12 15 18 21 26 30 34 39 42 45 50 56 60 64 69 72 76

The second of these sequences is A024675, described as the average of two consecutive odd primes, being sometimes called interprimes.

The interesting thing about the interprimes is their unprimeness.