Integer Sequences

This document sprang from tuition being given to students of functional programming.   Some of the students' work on sequences is indexed here.

The coding scheme being used was J, and a free interpreter, and much information about J, can be got from J Software, where there is also an anecdote about J for functional programming.

In planning to use the generation of integer sequences to illustrate certain aspects of J, I suddenly remembered the admirable and noble On-Line Encyclopedia of Integer Sequences.  Looking for many of the sequences I had been generating in that Encyclopedia, I found that several were not yet entered there.  The work below followed from that discovery.

The J code given in the following, and in the subtended texts on combinations, chains, further geometrics palindromes and further primes &c., can be keyed into the interpreter to have computations done.  What is to be keyed in is indented three spaces.  The result, when there is a result, follows immediately without indentation.  Text starting with NB. is a comment and need not be keyed in.

Note: Because some of the illustrative lines are quite long, this document is best viewed using a wide window.


Sums of Prime Factors

   spf =: +/@q:   NB. defines spf
   spf 1+i.15     NB. applies spf to 1 .. 15
0 2 3 4 5 5 7 6 6 7 11 7 13 9 8

This is A001414 in the Online Encyclopedia.  An obvious variation on this theme is to use only one of any prime factors which are repeated.

   snpf =: +/@~.@q:   NB. defines snpf
   snpf 1+i.15        NB. applies snpf to 1 .. 15
0 2 3 2 5 5 7 2 3 7 11 5 13 9 8

This is A008472 in the Online Encyclopedia.  A perhaps not quite so obvious variation on this theme is to treat 1 as a prime factor.

   sopf =: +/@(1&,)@q:   NB. defines sopf
   sopf 1+i.15           NB. applies sopf to 1 .. 15
1 3 4 5 6 6 8 7 7 8 12 8 14 10 9

This sequence rather trivially follows from spf, so it is a little surprising to find it as A036288.  So, to complete the pattern, we define sonpf.

   sonpf =: +/@(1&,)@~.@q:   NB. defines sonpf
   sonpf 1+i.15              NB. applies sonpf to 1 .. 15
1 3 4 3 6 6 8 3 4 8 12 6 14 10 9

Curiously, this did not appear in the Encyclopedia, but has been accepted as A074372

   pnpf =: */@~.@q:   NB. defines pnpf
   pnpf 1+i.15        NB. applies pnpf to 1 .. 15
1 2 3 2 5 6 7 2 3 10 11 6 13 14 15

The product of the distinct prime factors is closely related to the sum snpf, but is given in the Encyclopedia in A007947 as the largest square free number dividing n

These sequences are used in chains and combinations.


Geometric Integers

   sq =: *:           NB. defines sq
   sq 1+i.15          NB. applies sq to 1 .. 15
1 4 9 16 25 36 49 64 81 100 121 144 169 196 225

This very simple sequence is in the Encyclopedia as A000290

   tr =: -:@* >:      NB. defines tr
   tr 1+i.15          NB. applies tr to 1 .. 15
1 3 6 10 15 21 28 36 45 55 66 78 91 105 120

These are triangular integers, n(n+1)/2, half the product of two consecutive integers, A000217.  These are integers because one of any two consecutive integers is even, so the product is always divisible by two.  The same is true, of course, of any two integers whose difference is three.

   ts =: -:@* 3&+     NB. defines ts
   ts 1+i.15          NB. applies ts to 1 .. 15
2 5 9 14 20 27 35 44 54 65 77 90 104 119 135

This sequence is n(n+3)/2, at A000096, where it is given starting at zero.  Aesthetically, this sequence should start at one.

   tt =: <:@-:@* 3&+     NB. defines tt
   tt 1+i.15             NB. applies tt to 1 .. 15
1 4 8 13 19 26 34 43 53 64 76 89 103 118 134

This sequence, n(n+3)/2 - 1, is A034586, but it (and ts) are trivially different from tr.

   (tt-tr) 1+i.15
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Clearly, there is little new in these geometric integers, but other sequences can be derived by combinations of functions from the two groups.  There are also further geometric sequences available.