This site is supported by donations to The OEIS Foundation.

User:M. F. Hasler/Programs/Naming conventions

From OeisWiki
Jump to: navigation, search

I use and recommend the following conventions for naming programs on OEIS:

  • Axxx for a program supposed to compute Axxx(n), the term of index n of the sequence Axxx (which is not necessarily the n-th term, given that the sequence may start at an offset different from 1).
  • is_Axxx for a program which takes as argument some integer m and returns true or false (or something equivalent: nonzero and zero,...) depending on whether m is a member of the sequence or not. (This is the characteristic function of the set represented by strictly increasing sequences, or more generally the characteristic function of the range (= image) of the sequence.)
The underscore "_" is here rather a technical artefact. Indeed, similar standard functions in current CAS usually do not feature it (like isprime(), ispower(),... in PARI/GP, Maple, ...). The motivation is that with the "_" (but not without it) the OEIS software will recognize the Axxx as a sequence ID and "hyperlink" it: This allows you click it to get to that sequence and the corresponding PROGRAM, when is_Axxx(...) is used somewhere else.
Some CAS may not allow or discourage this naming convention. E.g., languages that do not allow uppercase letters or underscores or numerical digits in program names (all of this exists). In Mathematica the standard convention follows the pattern of PrimeQ[m_] to check whether m is prime, so AxxxQ[m_] could be used instead of is_Axxx.
  • Axxx_vec(Nmax) / list_Axxx(LIM) for a program which returns a vector of the first Nmax terms of the sequence, or a program which "lists" (whatever this means) the terms of Axxx up to the limit LIM.

Sometimes, the list_Axxx functionality can be implemented as "side effect" in the function Axxx, namely, by allowing a second, optional parameter which, when given, would either print out all the "intermediate" terms up to Axxx(n), or return a certain subsequence as a vector. In many cases this would be a very natural and/or efficient alternative to computing terms a(1), ..., a(n) each through an independent call to the function Axxx.

Such additional functionality should of course be duly commented, e.g., "Give optional 2nd argument show_all = 1 to print out ..." or "Give optional second argument m>0 to return the list of [a(m),...,a(n)] instead of just a(n)."