Generic common format for function calls

12 views
Skip to first unread message

Peter Luschny

unread,
Nov 23, 2010, 2:33:29 PM11/23/10
to seqcomp
Recently I saw on Richard J. Mathar website a Python3
implementation of some OEIS sequences.

Documentation: oeis_core, oeis_trans and oeis_bulk:
http://www.strw.leidenuniv.nl/~mathar/progs/pdocs/oeis_core.html
http://www.strw.leidenuniv.nl/~mathar/progs/pdocs/oeis_trans.html
http://www.strw.leidenuniv.nl/~mathar/progs/pdocs/oeis_bulk.html

Mathar uses a generic common format for function calls.
From his documents:

** Axxxxx(n)
returns the n-th item of the sequence, where n is defined as
usual depending on the offset. The first meaningful number
is Axxxxxx(offset).

** Axxxxxx(n,k)
returns the item in row n, column k of a triangle or array.

** Axxxxxx_list(n)
returns a list with n items, starting with Axxxxxx(offset).

** Axxxxxx_row(n)
returns all members of the n-th row of the sequence.
The topmost row is obtained by Axxxxx_row(offset).

** isAxxxxxx(n)
returns True or False depending on whether n is in the
sequence or not.

Things could be standardized even further using my 'fingerprint'
setup. http://www.luschny.de/ect/fingerprint.html

Besides row also col, diagrow, and diagcol the characteristics
sum, als (alternating sum), lcm and gcd, min and max (all
relative to rows) could be attached to integer triangles.

Peter Luschny

unread,
Nov 23, 2010, 6:57:26 PM11/23/10
to seqcomp
> On 23 Nov., 20:15, Psychedelic Geometry wrote:

> In my opinion there is a big mess in the code of sequences, there are
> people that enters code that gives a list of numbers instead of a
> function.

> I suggest to use ALWAYS as a function name, in the code, the sequence
> Id for example:

> A005894[n_]:=... instead of a[n_], of f[n_]

> Other unexplored way of coding sequences, that I think is perfectly
> valid, is to program a Characteristic function, this is true, or 1 if
> n is in the sequence false or 0, otherwise.

> This should be notated as: A005894Q[n_]

Hi Enrique!

I copied this piece of your post from the 'Welcome' thread into
this thread because it is here on topic.

Yes, I agree. Especially the difference A005894 and A005894_list
is often confusing. But now we have a place to discuss all this :)

> This should be notated as: A005894Q[n_]

I prefer the proposal of Richard to say isA005894(n) in this
case. This 'is' seems more common practice then the 'Q' (is this
Mathematica style?), and the meaning more easily derived.

Cheers, Peter


Psychedelic Geometry

unread,
Nov 24, 2010, 3:03:56 AM11/24/10
to seqcomp
I see a small issue in the Mathar format, this kind of conventions
should be valid for all programming lenguages, and in Mathematica the
character _ (blank) is a pattern object so this convention can not be
use with Mathematica.

But despite of this things, Mathar's idea looks great.

Cheers, Enrique

Peter Luschny

unread,
Nov 26, 2010, 12:37:15 PM11/26/10
to seqcomp
On 24 Nov., 09:03, Psychedelic Geometry wrote:
> I see a small issue in the Mathar format, this kind of conventions
> should be valid for all programming lenguages, and in Mathematica the
> character _  (blank) is a pattern object so this convention can not be
> use with Mathematica.

Yes, their should be some adjustments to the underlying computing
environment.

I just noticed a small inconvenience with Richard's conventions.
When you enter (say) A000290 := n -> n^2; then A000290 becomes
a link in the database, which makes no sense at this place.
I also noticed some functions of Reinhard Zumkeller who wrote
a000290 in a similar case which avoids this. Maybe I will
switch to this convention.

M. Hasler

unread,
Nov 30, 2010, 8:33:36 PM11/30/10
to seqcomp
Hello there,


> I just noticed a small inconvenience with Richard's conventions.
> When you enter (say) A000290 := n -> n^2; then A000290 becomes
> a link in the database, which makes no sense at this place.

I think the hyperlinking of Axxxxx in the PROG sections is not a
problem,
usually a copy-paste will work well anyway, and in case the function
uses other Ayyyyyy functions this is handy to go there.

Sometimes I want to give a short Axxxxx function which returns the
n'th element,
but also provide an easy possibility to show the list
a(offset)...a(n),
especially when computation of the n-th element implies computation
of
all previous elements (e.g. for calculation of the n-th composite
number).
Sometimes I provide a function where a 2nd optional are allows to
display and/or return these previous elements.
e.g.
Axxx(n, print_all=0)={ ... }

Then Axxx(n) would yield the n-th element, and Axxx(n,1) would in
addition to this result print all preceding elements.
Other varaiations are possible, like
Axxx(n, return_all=0)={ ... } where Axxx(n,1) would return
[a(offset),...,a(n)]
sometimes it is useful to have Axxx(n, verbose=0)={ ... }
where setting verbose to something nonsero would print out information
about the search process, or so.

It is nice to have some "standards" (in principle I agree on Axxx,
Axxx_list, isAxxx),
but often for a given sequence not all possibilities are
"relevant" (especially w.r.t. computational efficiency).

The decision of what to implement among Axxx(n), Axxx_list(),
isAxxx(),... depends IMO often on the nature of the sequence.

(e.g. if computation of T(n,k) is immediate, the Axxx_row, Axxx_col
etc. can be implemented using the elementary definition,
but if it is natural and/or much easier to compute the whole row and/
or column at once, then these functions may make sense.


> I also noticed some functions of Reinhard Zumkeller who wrote
> a000290 in a similar case which avoids this. Maybe I will
> switch to this convention.

in a (very) few cases I use both, A... and a... for distinct things,
usually the former is the function, and the latter is e.g. a (global)
memoization table,
or the list of values (of another sequence, used to calculate Axxx).

This is also needed if one wants co-existence of the function and of a
list of precomputed values
(which in principle should have te same name, since Axxx(n) and
Axxx[n] should be the same)
- of course AxxxL for the list would be a possible (less or more
elegant?) alternative.

Maximilian

On Nov 26, 1:37 pm, Peter Luschny <peter.lusc...@googlemail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages