Skip to content

More on Niven Numbers

Vector 14:4, page 120

programming techniques mathematics and statistics

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 120

I am not going to repeat here what a NIVEN number is as I also did not know its meaning (see the articles in Vector Vol. 14.2 & 14.3). I am, on the other hand, astonished that Joseph De Kerf should show a function with scalar loops. It must surely be a copy from a version in C or Fortran. In fact, one of the best qualities of APL is handling in bulk (here a vector) which, by contrast, gives a bad performance in other cases. It is not thus a question of finding a new mathematical trick (algorithm) but simply of understanding the APL language and applying it.

Example: the last character of a vector is not:

max←(↑⍴candidates)⊃candidates

but simply

max←¯1↑candidates

I have chosen a solution which differs a little from those of Joseph De Kerf and David Piper. The argument of the function is not the nth NIVEN but the tranche which terminates:

≥ NIVEN_NO

You will see I have an example in g) NIVEN_E

Description and/or examples of each function in the logical sequence of development (the dossier is a single session log in direct execution mode):

  • Presented in IBM-APL2 (ver. 1.02/PS2/DOS 7.0)
  • Similar results in IBM APL2/2 (OS2 ver .1 service level 11)
a) NIVEN_X simple vector; corresponds to NIVENE by David or A=W
b) NIVEN_Z recursive form in diminishing tranches (if N is large)
c) NIVEN_L same function but in loops by tranche (DO_UNTIL)
d) NIVEN_V question "Is it a Niven?" with possible limits
e) NIVEN_B list of Niven numbers in another base (2 to 10)
f) NIVEN_H Niven numbers to base 16 in hexadecimal notation
g) NIVEN_E Similar to NIVEN_L (external loop) for EACH tranche

I have saved this variant to the last to show you what it allows me to see about the progressive distribution of Niven numbers. In fact if one takes the intervals between the numbers the difference is not significant. On the other hand we can see that the ratio between one tranche and another is constant (see n00000). It is now up to you to extract from this a new theory in order to receive the APL Nobel prize!

h) P_NIVENE

To complete the account of the problem I have added my version of David’s code, as well as an execution of David’s P_NIVENe, for those of you who find that my code is "Write Only".

i) & j) Timing tables of results for N=10,000 and N=100,000.
k) XTIME A simple timing routine (without graphics).

All this material is available on disk:

2 WinWord documents of about 30K
1 listing .log (APL2 - PS2, Editor 3) of 10K
2 workspaces .atf & .ws of approx. 100 K each

Please send 5¼″ disk (either capacity) or 3½″ disk (either capacity) to Claude Henriod [address omitted] with your return address.