[GAP Forum] suggestion for additional core operations on polynomials and lists

Alexander Konovalov alexk at mcs.st-andrews.ac.uk
Thu May 31 16:45:12 BST 2012


Dear Mariano, dear Forum,

>> (The naming scheme for functions is sometimes surprising, going from verbs to adjectives to nouns... I hope in some parallel universe GAP has a better naming convention :) )

This may be of an interest - the manual for next version of GAP will have a section on naming conventions, 
shown below. In particular, it explains that a verb normally modify its argument(s) but does not return anything. 
Of course, there may be exceptions…

Best wishes,
Alexander


5.5 Naming Conventions

The way functions are named in GAP might help to memorize or even guess names of library functions.

If a variable name consists of several words then the first letter of each word is capitalized.

If the first part of the name of a function is a verb then the function may modify its argument(s) but does not return anything, for example Append (21.4-5) appends the list given as second argument to the list given as first argument. Otherwise the function returns an object without changing the arguments, for example Concatenation (21.20-1) returns the concatenation of the lists given as arguments.

If the name of a function contains the word "Of" then the return value is thought of as information deduced from the arguments. Usually such functions are attributes (see 13.5). Examples are GeneratorsOfGroup (39.2-3), which returns a list of generators for the group entered as argument, or DiagonalOfMat (24.12-1).

For the setter and tester functions of an attribute Attr the names SetAttr resp. HasAttr are available (see 13.5).

If the name of a function contains the word "By" then the return value is thought of as built in a certain way from the parts given as arguments. For example, creating a group as a factor group of a given group by a normal subgroup can be done by taking the image ofNaturalHomomorphismByNormalSubgroup (39.18-1). Other examples of "By" functions areGroupHomomorphismByImages (40.1-1) and LaurentPolynomialByCoefficients (66.13-1).

Often such functions construct an algebraic structure given by its generators (for example, RingByGenerators (56.1-4)). In some cases, "By" may be replaced by "With" (like e.g. GroupWithGenerators (39.2-2)) or even both versions of the name may be used. The difference between StructByGenerators and StructWithGenerators is that the latter guarantees that the GeneratorsOfStruct value of the result is equal to the given set of generators (see 31.3).

If the name of a function has the form "AsSomething" then the return value is an object (usually a collection which has the same family of elements), which may, for example:

• know more about its own structure (and so support more operations) than its input (e.g. if the elements of the collection form a group, then this group can be constructed using AsGroup (39.2-4));

• discard its additional structure (e.g. AsList (30.3-8) applied to a group will return a list of its elements);

• contain all elements of the original object without duplicates (like e.g. AsSet (30.3-10) does if its argument is a list of elements from the same family);

• remain unchanged (like e.g. AsSemigroup (51.1-5) does if its argument is a group).

If Something and the argument of AsSomething are domains, some further rules apply as explained in Tutorial: Changing the Structure.

If the name of a function fun1 ends with "NC" then there is another function fun2 with the same name except that the NC is missing. NCstands for "no check". When fun2 is called then it checks whether its arguments are valid, and if so then it calls fun1. The functionsSubgroupNC (39.3-1) and Subgroup (39.3-1) are a typical example.

The idea is that the possibly time consuming check of the arguments can be omitted if one is sure that they are unnecessary. For example, if an algorithm produces generators of the derived subgroup of a group then it is guaranteed that they lie in the original group; Subgroup(39.3-1) would check this, and SubgroupNC (39.3-1) omits the check.

Needless to say, all these rules are not followed slavishly, for example there is one operation Zero (31.10-3) instead of two operationsZeroOfElement and ZeroOfAdditiveGroup.

====







More information about the Forum mailing list