[seqfan] Re: Maple program
peter.luschny at gmail.com
Sun Oct 25 11:24:44 CET 2020
A program for the OEIS is also a publication on which further
criteria, such as legibility and comprehensibility, are applied.
Often, one-liners do not meet these criteria but are intended
to show the writer's technical mastery and tend towards CodeGolf.
So it is advantageous to read the notes of Charles Greathouse :
"Programs should be kept to a minimum reasonable size (but
please don't golf)."
Good readability still allows a wide range of styles. Mathar
seems to prefer the procedural style, the loops. I'm
more of a fan of Leslie Lamport, who once said in a lecture
in Heidelberg: "As soon as you write 'for' you have lost."
The functional style breaks a program down into small individual
functions, which are then put together.
My solution looks like this:
gpf := n -> max(NumberTheory:-PrimeFactors(n)): # A006530
isA081258 := n -> evalb(gpf(n^3 - 1) <= n):
A081258List := upto -> select(isA081258, [`$`(2..upto)]):
According to Charles, the first two lines, the is-function,
are enough, while the list-function and the actual call should
not be listed. I add them mostly because I would like to
generate the sequence after a copy-and-paste without any
further action on my part.
The type of program, as described here, is generally applicable
for so-called 'lists.' Please note that these lists have the
offset '1' by definition, so this is /not/ the lower limit of
the selection range! In fact, in the present case, this is 2,
not 1. (Such distinctions are an eternal source of confusion
in the OEIS.)
So we have indeed found a bug in Mathar's program: Since his
for-loop starts with 1, he also generates a '1', but this is
not a term of the list!
Moreover, this does not lead to an error due to one (of several)
bugs in Maple's 'numtheory' module. Bugs hide bugs. (You should
switch to the new 'NumberTheory' module as soon as possible,
or, better, to SageMath.) The current version quits Mathar's
program with the error message:
Error, (in NumberTheory:-PrimeFactors) cannot represent
all prime factors of 0.
More information about the SeqFan