Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Bib Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

13 Types of Objects
 13.1 Families
 13.2 Filters
 13.3 Categories
 13.4 Representation
 13.5 Attributes
 13.6 Setter and Tester for Attributes
 13.7 Properties
 13.8 Other Filters
 13.9 Types

13 Types of Objects

Every GAP object has a type. The type of an object is the information which is used to decide whether an operation is admissible or possible with that object as an argument, and if so, how it is to be performed (see Chapter 78).

For example, the types determine whether two objects can be multiplied and what function is called to compute the product. Analogously, the type of an object determines whether and how the size of the object can be computed. It is sometimes useful in discussing the type system, to identify types with the set of objects that have this type. Partial types can then also be regarded as sets, such that any type is the intersection of its parts.

The type of an object consists of two main parts, which describe different aspects of the object.

The family determines the relation of the object to other objects. For example, all permutations form a family. Another family consists of all collections of permutations, this family contains the set of permutation groups as a subset. A third family consists of all rational functions with coefficients in a certain family.

The other part of a type is a collection of filters (actually stored as a bit-list indicating, from the complete set of possible filters, which are included in this particular type). These filters are all treated equally by the method selection, but, from the viewpoint of their creation and use, they can be divided (with a small number of unimportant exceptions) into categories, representations, attribute testers and properties. Each of these is described in more detail below.

This chapter does not describe how types and their constituent parts can be created. Information about this topic can be found in Chapter 79.

Note: Detailed understanding of the type system is not required to use GAP. It can be helpful, however, to understand how things work and why GAP behaves the way it does.

A discussion of the type system can be found in [BL98].

13.1 Families

The family of an object determines its relationship to other objects.

More precisely, the families form a partition of all GAP objects such that the following two conditions hold: objects that are equal w.r.t. = lie in the same family; and the family of the result of an operation depends only on the families of its operands.

The first condition means that a family can be regarded as a set of elements instead of a set of objects. Note that this does not hold for categories and representations (see below), two objects that are equal w.r.t. = need not lie in the same categories and representations. For example, a sparsely represented matrix can be equal to a densely represented matrix. Similarly, each domain is equal w.r.t. = to the sorted list of its elements, but a domain is not a list, and a list is not a domain.

Families are probably the least obvious part of the GAP type system, so some remarks about the role of families are necessary. When one uses GAP as it is, one will (better: should) not meet families at all. The two situations where families come into play are the following.

First, since families are used to describe relations between arguments of operations in the method selection mechanism (see Chapter 78, and also Chapter 13), one has to prescribe such a relation in each method installation (see 78.3); usual relations are ReturnTrue (5.4-1) (which means that any relation of the actual arguments is admissible), IsIdenticalObj (12.5-1) (which means that there are two arguments that lie in the same family), and IsCollsElms (which means that there are two arguments, the first being a collection of elements that lie in the same family as the second argument).

Second –and this is the more complicated situation– whenever one creates a new kind of objects, one has to decide what its family shall be. If the new object shall be equal to existing objects, for example if it is just represented in a different way, there is no choice: The new object must lie in the same family as all objects that shall be equal to it. So only if the new object is different (w.r.t. the equality =) from all other GAP objects, we are likely to create a new family for it. Note that enlarging an existing family by such new objects may be problematic because of implications that have been installed for all objects of the family in question. The choice of families depends on the applications one has in mind. For example, if the new objects in question are not likely to be arguments of operations for which family relations are relevant (for example binary arithmetic operations), one could create one family for all such objects, and regard it as the family of all those GAP objects that would in fact not need a family. On the other extreme, if one wants to create domains of the new objects then one has to choose the family in such a way that all intended elements of a domain do in fact lie in the same family. (Remember that a domain is a collection, see Chapter 12.4, and that a collection consists of elements in the same family, see Chapter 30 and Section 13.1.)

Let us look at an example. Suppose that no permutations are available in GAP, and that we want to implement permutations. Clearly we want to support permutation groups, but it is not a priori clear how to distribute the new permutations into families. We can put all permutations into one family; this is how in fact permutations are implemented in GAP. But it would also be possible to put all permutations of a given degree into a family of their own; this would for example mean that for each degree, there would be distinguished trivial permutations, and that the stabilizer of the point 5 in the symmetric group on the points 1, 2, ..., 5 is not regarded as equal to the symmetric group on 1, 2, 3, 4. Note that the latter approach would have the advantage that it is no problem to construct permutations and permutation groups acting on arbitrary (finite) sets, for example by constructing first the symmetric group on the set and then generating any desired permutation group as a subgroup of this symmetric group.

So one aspect concerning a reasonable choice of families is to make the families large enough for being able to form interesting domains of elements in the family. But on the other hand, it is useful to choose the families small enough for admitting meaningful relations between objects. For example, the elements of different free groups in GAP lie in different families; the multiplication of free group elements is installed only for the case that the two operands lie in the same family, with the effect that one cannot erroneously form the product of elements from different free groups. In this case, families appear as a tool for providing useful restrictions.

As another example, note that an element and a collection containing this element never lie in the same family, by the general implementation of collections; namely, the family of a collection of elements in the family Fam is the collections family of Fam (see CollectionsFamily (30.2-1)). This means that for a collection, we need not (because we cannot) decide about its family.

A few functions in GAP return families, see CollectionsFamily (30.2-1) and ElementsFamily (30.2-3).

13.1-1 FamilyObj
‣ FamilyObj( obj )( function )

returns the family of the object obj.

The family of the object obj is itself an object, its family is FamilyOfFamilies.

It should be emphasized that families may be created when they are needed. For example, the family of elements of a finitely presented group is created only after the presentation has been constructed. Thus families are the dynamic part of the type system, that is, the part that is not fixed after the initialisation of GAP.

Families can be parametrized. For example, the elements of each finitely presented group form a family of their own. Here the family of elements and the finitely presented group coincide when viewed as sets. Note that elements in different finitely presented groups lie in different families. This distinction allows GAP to forbid multiplications of elements in different finitely presented groups.

As a special case, families can be parametrized by other families. An important example is the family of collections that can be formed for each family. A collection consists of objects that lie in the same family, it is either a nonempty dense list of objects from the same family or a domain.

Note that every domain is a collection, that is, it is not possible to construct domains whose elements lie in different families. For example, a polynomial ring over the rationals cannot contain the integer 0 because the family that contains the integers does not contain polynomials. So one has to distinguish the integer zero from each zero polynomial.

Let us look at this example from a different viewpoint. A polynomial ring and its coefficients ring lie in different families, hence the coefficients ring cannot be embedded naturally into the polynomial ring in the sense that it is a subset. But it is possible to allow, e.g., the multiplication of an integer and a polynomial over the integers. The relation between the arguments, namely that one is a coefficient and the other a polynomial, can be detected from the relation of their families. Moreover, this analysis is easier than in a situation where the rationals would lie in one family together with all polynomials over the rationals, because then the relation of families would not distinguish the multiplication of two polynomials, the multiplication of two coefficients, and the multiplication of a coefficient with a polynomial. So the wish to describe relations between elements can be taken as a motivation for the introduction of families.

13.1-2 NewFamily
‣ NewFamily( name[, req[, imp[, famfilter]]] )( function )

NewFamily returns a new family fam with name name. The argument req, if present, is a filter of which fam shall be a subset. If one tries to create an object in fam that does not lie in the filter req, an error message is printed. Also the argument imp, if present, is a filter of which fam shall be a subset. Any object that is created in the family fam will lie automatically in the filter imp.

The filter famfilter, if given, specifies a filter that will hold for the family fam (not for objects in fam).

Families are always represented as component objects (see 79.2). This means that components can be used to store and access useful information about the family.

13.2 Filters

A filter is a special unary GAP function that returns either true or false, depending on whether or not the argument lies in the set defined by the filter. Filters are used to express different aspects of information about a GAP object, which are described below (see 13.3, 13.4, 13.5, 13.6, 13.7, 13.8).

Presently any filter in GAP is implemented as a function which corresponds to a set of positions in the bitlist which forms part of the type of each GAP object, and returns true if and only if the bitlist of the type of the argument has the value true at all of these positions.

The intersection (or meet) of two filters filt1, filt2 is again a filter, it can be formed as

filt1 and filt2

See 20.4 for more details.

For example, IsList and IsEmpty is a filter that returns true if its argument is an empty list, and false otherwise. The filter IsGroup (39.2-7) is defined as the intersection of the category IsMagmaWithInverses (35.1-4) and the property IsAssociative (35.4-7).

A filter that is not the meet of other filters is called a simple filter. For example, each attribute tester (see 13.6) is a simple filter. Each simple filter corresponds to a position in the bitlist currently used as part of the data structure representing a type.

Every filter has a rank, which is used to define a ranking of the methods installed for an operation, see Section 78.3. The rank of a filter can be accessed with RankFilter (13.2-1).

13.2-1 RankFilter
‣ RankFilter( filt )( function )

For simple filters, an incremental rank is defined when the filter is created, see the sections about the creation of filters: NewCategory (13.3-4), NewRepresentation (13.4-4), NewAttribute (13.5-3), NewProperty (13.7-4), NewFilter (13.8-1). For an arbitrary filter, its rank is given by the sum of the incremental ranks of the involved simple filters; in addition to the implied filters, these are also the required filters of attributes (again see the sections about the creation of filters). In other words, for the purpose of computing the rank and only for this purpose, attribute testers are treated as if they would imply the requirements of their attributes.

13.2-2 NamesFilter
‣ NamesFilter( filt )( function )

NamesFilter returns a list of names of the implied simple filters of the filter filt, these are all those simple filters imp such that every object in filt also lies in imp. For implications between filters, see ShowImpliedFilters (13.2-4) as well as sections 78.8, NewCategory (13.3-4), NewRepresentation (13.4-4), NewAttribute (13.5-3), NewProperty (13.7-4).

13.2-3 FilterByName
‣ FilterByName( name )( function )

finds the filter with name name in the global FILTERS list. This is useful to find filters that were created but not bound to a global variable.

13.2-4 ShowImpliedFilters
‣ ShowImpliedFilters( filter )( function )

Displays information about the filters that may be implied by filter. They are given by their names. ShowImpliedFilters first displays the names of all filters that are unconditionally implied by filter. It then displays implications that require further filters to be present (indicating by + the required further filters).

gap> ShowImpliedFilters(IsNilpotentGroup);
Implies:
   IsListOrCollection
   IsCollection
   IsDuplicateFree
   IsExtLElement
   CategoryCollections(IsExtLElement)
   IsExtRElement
   CategoryCollections(IsExtRElement)
   CategoryCollections(IsMultiplicativeElement)
   CategoryCollections(IsMultiplicativeElementWithOne)
   CategoryCollections(IsMultiplicativeElementWithInverse)
   IsGeneralizedDomain
   IsMagma
   IsMagmaWithOne
   IsMagmaWithInversesIfNonzero
   IsMagmaWithInverses
   IsAssociative
   HasMultiplicativeNeutralElement
   IsGeneratorsOfSemigroup
   IsSimpleSemigroup
   IsRegularSemigroup
   IsInverseSemigroup
   IsCompletelyRegularSemigroup
   IsGroupAsSemigroup
   IsMonoidAsSemigroup
   IsOrthodoxSemigroup
   IsSupersolvableGroup
   IsSolvableGroup
   IsNilpotentByFinite


May imply with:
+IsFinitelyGeneratedGroup
   IsPolycyclicGroup

13.2-5 FiltersType
‣ FiltersType( type )( operation )
‣ FiltersObj( object )( operation )

returns a list of the filters in the type type, or in the type of the object object respectively.

gap> FiltersObj(fail);
[ <Category "IsBool">, <Representation "IsInternalRep"> ]
gap> FiltersType(TypeOfTypes);
[ <Representation "IsPositionalObjectRep">, <Category "IsType">, <Representation "IsTypeDefaultRep"> ]

13.3 Categories

The categories of an object are filters (see 13.2) that determine what operations an object admits. For example, all integers form a category, all rationals form a category, and all rational functions form a category. An object which claims to lie in a certain category is accepting the requirement that it should have methods for certain operations (and perhaps that their behaviour should satisfy certain axioms). For example, an object lying in the category IsList (21.1-1) must have methods for Length (21.17-5), IsBound\[\] (21.2-1) and the list element access operation \[\] (21.2-1).

An object can lie in several categories. For example, a row vector lies in the categories IsList (21.1-1) and IsVector (31.14-14); each list lies in the category IsCopyable (12.6-1), and depending on whether or not it is mutable, it may lie in the category IsMutable (12.6-2). Every domain lies in the category IsDomain (31.9-1).

Of course some categories of a mutable object may change when the object is changed. For example, after assigning values to positions of a mutable non-dense list, this list may become part of the category IsDenseList (21.1-2).

However, if an object is immutable then the set of categories it lies in is fixed.

All categories in the library are created during initialization, in particular they are not created dynamically at runtime.

The following list gives an overview of important categories of arithmetic objects. Indented categories are to be understood as subcategories of the non indented category listed above it.

    IsObject
        IsExtLElement
        IsExtRElement
            IsMultiplicativeElement
                IsMultiplicativeElementWithOne
                    IsMultiplicativeElementWithInverse
        IsExtAElement
            IsAdditiveElement
                IsAdditiveElementWithZero
                    IsAdditiveElementWithInverse

Every object lies in the category IsObject (12.1-1).

The categories IsExtLElement (31.14-8) and IsExtRElement (31.14-9) contain objects that can be multiplied with other objects via * from the left and from the right, respectively. These categories are required for the operands of the operation *.

The category IsMultiplicativeElement (31.14-10) contains objects that can be multiplied from the left and from the right with objects from the same family. IsMultiplicativeElementWithOne (31.14-11) contains objects obj for which a multiplicatively neutral element can be obtained by taking the 0-th power obj^0. IsMultiplicativeElementWithInverse (31.14-13) contains objects obj for which a multiplicative inverse can be obtained by forming obj^-1.

Likewise, the categories IsExtAElement (31.14-1), IsAdditiveElement (31.14-3), IsAdditiveElementWithZero (31.14-5) and IsAdditiveElementWithInverse (31.14-7) contain objects that can be added via + to other objects, objects that can be added to objects of the same family, objects for which an additively neutral element can be obtained by multiplication with zero, and objects for which an additive inverse can be obtained by multiplication with -1.

So a vector lies in IsExtLElement (31.14-8), IsExtRElement (31.14-9) and IsAdditiveElementWithInverse (31.14-7). A ring element must additionally lie in IsMultiplicativeElement (31.14-10).

As stated above it is not guaranteed by the categories of objects whether the result of an operation with these objects as arguments is defined. For example, the category IsMatrix (24.2-1) is a subcategory of IsMultiplicativeElementWithInverse (31.14-13). Clearly not every matrix has a multiplicative inverse. But the category IsMatrix (24.2-1) makes each matrix an admissible argument of the operation Inverse (31.10-8), which may sometimes return fail. Likewise, two matrices can be multiplied only if they are of appropriate shapes.

Analogous to the categories of arithmetic elements, there are categories of domains of these elements.

    IsObject
        IsDomain
            IsMagma
                IsMagmaWithOne
                    IsMagmaWithInversesIfNonzero
                        IsMagmaWithInverses
            IsAdditiveMagma
                IsAdditiveMagmaWithZero
                    IsAdditiveMagmaWithInverses
            IsExtLSet
            IsExtRSet

Of course IsDomain (31.9-1) is a subcategory of IsObject (12.1-1). A domain that is closed under multiplication * is called a magma and it lies in the category IsMagma (35.1-1). If a magma is closed under taking the identity, it lies in IsMagmaWithOne (35.1-2), and if it is also closed under taking inverses, it lies in IsMagmaWithInverses (35.1-4). The category IsMagmaWithInversesIfNonzero (35.1-3) denotes closure under taking inverses only for nonzero elements, every division ring lies in this category.

Note that every set of categories constitutes its own notion of generation, for example a group may be generated as a magma with inverses by some elements, but to generate it as a magma with one it may be necessary to take the union of these generators and their inverses.

13.3-1 IsCategory
‣ IsCategory( object )( function )

returns true if object is a category (see 13.3), and false otherwise.

Note that GAP categories are not categories in the usual mathematical sense.

13.3-2 CategoriesOfObject
‣ CategoriesOfObject( object )( operation )

returns a list of the names of the categories in which object lies.

gap> g:=Group((1,2),(1,2,3));;
gap> CategoriesOfObject(g);
[ "IsListOrCollection", "IsCollection", "IsExtLElement",
  "CategoryCollections(IsExtLElement)", "IsExtRElement",
  "CategoryCollections(IsExtRElement)",
  "CategoryCollections(IsMultiplicativeElement)",
  "CategoryCollections(IsMultiplicativeElementWithOne)",
  "CategoryCollections(IsMultiplicativeElementWithInverse)",
  "CategoryCollections(IsAssociativeElement)",
  "CategoryCollections(IsFiniteOrderElement)", "IsGeneralizedDomain",
  "CategoryCollections(IsPerm)", "IsMagma", "IsMagmaWithOne",
  "IsMagmaWithInversesIfNonzero", "IsMagmaWithInverses" ]

13.3-3 CategoryByName
‣ CategoryByName( name )( function )

returns the category with name name if it is found, or fail otherwise.

13.3-4 NewCategory
‣ NewCategory( name, super[, rank] )( function )

NewCategory returns a new category cat that has the name name and is contained in the filter super, see 13.2. This means that every object in cat lies automatically also in super. We say also that super is an implied filter of cat.

For example, if one wants to create a category of group elements then super should be IsMultiplicativeElementWithInverse (31.14-13) or a subcategory of it. If no specific supercategory of cat is known, super may be IsObject (12.1-1).

The optional third argument rank denotes the incremental rank (see 13.2) of cat, the default value is 1.

13.3-5 DeclareCategory
‣ DeclareCategory( name, super[, rank] )( function )

does the same as NewCategory (13.3-4) and then binds the result to the global variable name. The variable must previously be writable, and is made read-only by this function.

13.3-6 CategoryFamily
‣ CategoryFamily( cat )( function )

For a category cat, CategoryFamily returns the family category of cat. This is a category in which all families lie that know from their creation that all their elements are in the category cat, see 13.1.

For example, a family of associative words is in the category CategoryFamily( IsAssocWord ), and one can distinguish such a family from others by this category. So it is possible to install methods for operations that require one argument to be a family of associative words.

CategoryFamily is quite technical, and in fact of minor importance.

See also CategoryCollections (30.2-4).

13.4 Representation

The representation of an object is a set of filters (see 13.2) that determines how an object is actually represented. For example, a matrix or a polynomial can be stored sparsely or densely; all dense polynomials form a representation. An object which claims to lie in a certain representation is accepting the requirement that certain fields in the data structure be present and have specified meanings.

13.4-1 Basic Representations of Objects
‣ IsInternalRep( obj )( representation )
‣ IsDataObjectRep( obj )( representation )
‣ IsPositionalObjectRep( obj )( representation )
‣ IsComponentObjectRep( obj )( representation )

GAP distinguishes four essentially different ways to represent objects. First there are the representations IsInternalRep for internal objects such as integers and permutations, and IsDataObjectRep for other objects that are created and whose data are accessible only by kernel functions. The data structures underlying such objects cannot be manipulated at the GAP level.

All other objects are either in the representation IsComponentObjectRep or in the representation IsPositionalObjectRep, see 79.2 and 79.3.

An object can belong to several representations in the sense that it lies in several subrepresentations of IsComponentObjectRep or of IsPositionalObjectRep. The representations to which an object belongs should form a chain and either two representations are disjoint or one is contained in the other. So the subrepresentations of IsComponentObjectRep and IsPositionalObjectRep each form trees. In the language of Object Oriented Programming, we support only single inheritance for representations.

These trees are typically rather shallow, since for one representation to be contained in another implies that all the components of the data structure implied by the containing representation, are present in, and have the same meaning in, the smaller representation (whose data structure presumably contains some additional components).

Objects may change their representation, for example a mutable list of characters can be converted into a string.

All representations in the library are created during initialization, in particular they are not created dynamically at runtime.

Examples of subrepresentations of IsPositionalObjectRep are IsModulusRep, which is used for residue classes in the ring of integers, and IsDenseCoeffVectorRep, which is used for elements of algebras that are defined by structure constants.

An important subrepresentation of IsComponentObjectRep is IsAttributeStoringRep (13.5-5), which is used for many domains and some other objects. It provides automatic storing of all attribute values (see Section 13.5).

13.4-2 IsRepresentation
‣ IsRepresentation( object )( function )

returns true if object is a representation (see 13.4), and false otherwise.

13.4-3 RepresentationsOfObject
‣ RepresentationsOfObject( object )( operation )

returns a list of the names of the representations object has.

gap> g:=Group((1,2),(1,2,3));;
gap> RepresentationsOfObject(g);
[ "IsComponentObjectRep", "IsAttributeStoringRep" ]

13.4-4 NewRepresentation
‣ NewRepresentation( name, super[, slots[, req]] )( function )

NewRepresentation returns a new representation rep that has the name name and is a subrepresentation of the representation super. This means that every object in rep lies automatically also in super. We say also that super is an implied filter of rep.

Each representation in GAP is a subrepresentation of exactly one of the four representations IsInternalRep (13.4-1), IsDataObjectRep (13.4-1), IsComponentObjectRep (13.4-1), IsPositionalObjectRep (13.4-1). The data describing objects in the former two can be accessed only via GAP kernel functions, the data describing objects in the latter two is accessible also in library functions, see 79.2 and 79.3 for the details.

The optional third and fourth arguments slots and req are (and always were) unused and are only provided for backwards compatibility. Note that slots was required (but still unused) before GAP 4.12.

The incremental rank (see 13.2) of rep is 1.

Examples for the use of NewRepresentation can be found in 79.2, 79.3, and also in 81.3.

13.4-5 DeclareRepresentation
‣ DeclareRepresentation( name, super[, slots[, req]] )( function )

does the same as NewRepresentation (13.4-4) and then binds the result to the global variable name. The variable must previously be writable, and is made read-only by this function.

13.5 Attributes

The attributes of an object describe knowledge about it.

An attribute is a unary operation without side-effects.

An object may store values of its attributes once they have been computed, and claim that it knows these values. Note that store and know have to be understood in the sense that it is very cheap to get such a value when the attribute is called again.

The value returned by an attribute is in general immutable (see 12.6), except if the attribute had been specially constructed as mutable attribute, see NewAttribute (13.5-3).

Note that functions installed as methods for attributes may return mutable objects, the attribute returns the value of Immutable (12.6-3) for the result. Thus it is recommended that these methods ensure their return values are immutable, e.g., by calling MakeImmutable (12.6-4) if this is possible, in order to avoid that Immutable (12.6-3) creates an unnecessary copy of the object.

It depends on the representation of an object (see 13.4) which attribute values it stores. An immutable object in the representation IsAttributeStoringRep (13.5-5) stores all attribute values once they are computed.

Note that it is impossible to get rid of a stored attribute value because the system may have drawn conclusions from the old attribute value, and just removing the value might leave the data structures in an inconsistent state. If necessary, a new object can be constructed.

Each method that is installed for an attribute via InstallMethod (78.3-1) must require exactly one argument, and this must lie in the filter filter that was entered as second argument of NewAttribute (13.5-3) resp. NewProperty (13.7-4).

As for any operation, for attributes one can install a method taking an argument that does not lie in filt via InstallOtherMethod (78.3-2), or a method for more than one argument. For example, IsTransitive (41.10-1) is an attribute for a G-set that can also be called for the two arguments, being a group G and its action domain. If attributes are called with more than one argument then the return value is not stored in any of the arguments.

Properties are a special form of attributes that have the value true or false, see section 13.7.

Examples of attributes for multiplicative elements are Inverse (31.10-8), One (31.10-2), and Order (31.10-10). Size (30.4-6) is an attribute for domains, Centre (35.4-5) is an attribute for magmas, and DerivedSubgroup (39.12-3) is an attribute for groups.

13.5-1 IsAttribute
‣ IsAttribute( object )( function )

returns true if object is an attribute (see 13.5), and false otherwise.

13.5-2 KnownAttributesOfObject
‣ KnownAttributesOfObject( object )( operation )

returns a list of the names of the attributes whose values are known for object.

gap> g:=Group((1,2),(1,2,3));;Size(g);;
gap> KnownAttributesOfObject(g);
[ "Size", "OneImmutable", "NrMovedPoints", "MovedPoints",
  "GeneratorsOfMagmaWithInverses", "MultiplicativeNeutralElement",
  "HomePcgs", "Pcgs", "StabChainMutable", "StabChainOptions" ]

13.5-3 NewAttribute
‣ NewAttribute( name, filter[, "mutable"][, rank] )( function )

NewAttribute returns a new attribute getter with name name that is applicable to objects with the property filter.

Contrary to the situation with categories and representations, the tester of the new attribute does not imply filter. This is exactly because of the possibility to install methods that do not require filter.

For example, the attribute Size (30.4-6) was created with second argument a list or a collection, but there is also a method for Size (30.4-6) that is applicable to a character table, which is neither a list nor a collection.

For the optional third and fourth arguments, there are the following possibilities.

When a value of such mutable attribute is set then this value itself is stored, not an immutable copy of it, and it is the user's responsibility to set an object that is mutable. This is useful for an attribute whose value is some partial information that may be completed later. For example, there is an attribute ComputedSylowSubgroups for the list holding those Sylow subgroups of a group that have been computed already by the function SylowSubgroup (39.13-1), and this list is mutable because one may want to enter groups into it as they are computed.

If no argument for rank is given, then the rank of the tester is 1.

Each method for the new attribute that does not require its argument to lie in filter must be installed using InstallOtherMethod (78.3-2).

13.5-4 DeclareAttribute
‣ DeclareAttribute( name, filter[, "mutable"][, rank] )( function )

does the same as NewAttribute (13.5-3) and then binds the result to the global variable name. The variable must previously be writable, and is made read-only by this function. It also binds read-only global variables with names Hasname and Setname for the tester and setter of the attribute (see Section 13.6).

13.5-5 IsAttributeStoringRep
‣ IsAttributeStoringRep( obj )( representation )

Objects in this representation have default methods to get stored values of attributes and –if they are immutable– to store attribute values automatically once they have been computed. (These methods are called the system getter and the system setter of the attribute, respectively.)

As a consequence, for immutable objects in IsAttributeStoringRep, subsequent calls to an attribute will return the same object.

Mutable objects in IsAttributeStoringRep are allowed, but attribute values are not stored automatically in them. Such objects are useful because they may later be made immutable using MakeImmutable (12.6-4), at which point they will start storing all attribute values.

Note that one can force an attribute value to be stored in a mutable object in IsAttributeStoringRep, by explicitly calling the attribute setter. This feature should be used with care. For example, think of a mutable matrix whose rank or trace gets stored, and the values later become wrong when somebody changes the matrix entries.

gap> g:= Group( (1,2)(3,4), (1,3)(2,4) );;
gap> IsAttributeStoringRep( g );
true
gap> HasSize( g );  Size( g );  HasSize( g );
false
4
true
gap> r:= 7/4;;
gap> IsAttributeStoringRep( r );
false
gap> Int( r );  HasInt( r );
1
false

13.6 Setter and Tester for Attributes

For every attribute, the attribute setter and the attribute tester are defined.

To check whether an object belongs to an attribute attr, the tester of the attribute is used, see Tester (13.6-1). To store a value for the attribute attr in an object, the setter of the attribute is used, see Setter (13.6-2).

13.6-1 Tester
‣ Tester( attr )( function )

For an attribute attr, Tester(attr) is a filter (see 13.2) that returns true or false, depending on whether or not the value of attr for the object is known. For example, Tester( Size )( obj ) is true if the size of the object obj is known.

13.6-2 Setter
‣ Setter( attr )( function )

For an attribute attr, Setter(attr) is called automatically when the attribute value has been computed for an immutable object which does not already have a value stored for attr. One can also call the setter explicitly, for example, Setter( Size )( obj, val ) sets val as size of the object obj if the size was not yet known.

For each attribute attr that is declared with DeclareAttribute (13.5-4) resp. DeclareProperty (13.7-5), tester and setter are automatically made accessible by the names Hasattr and Setattr, respectively. For example, the tester for Size (30.4-6) is called HasSize, and the setter is called SetSize.

gap> g:=Group((1,2,3,4),(1,2));;Size(g);
24
gap> HasSize(g);
true
gap> SetSize(g,99);
gap> Size(g);
24

For two properties prop1 and prop2, the intersection prop1 and prop2 (see 13.2) is again a property for which a setter and a tester exist. Setting the value of this intersection to true for a GAP object means to set the values of prop1 and prop2 to true for this object.

gap> prop:= IsFinite and IsCommutative;
<Property "(IsFinite and IsCommutative)">
gap> g:= Group( (1,2,3), (4,5) );;
gap> Tester( prop )( g );
false
gap> Setter( prop )( g, true );
gap> Tester( prop )( g );  prop( g );
true
true

It is not allowed to set the value of such an intersection to false for an object.

gap> Setter( prop )( Rationals, false );
You cannot set an "and-filter" except to true
not in any function
Entering break read-eval-print loop ...
you can 'quit;' to quit to outer loop, or
you can type 'return true;' to set all components true
(but you might really want to reset just one component) to continue
brk>

13.6-3 AttributeValueNotSet
‣ AttributeValueNotSet( attr, obj )( function )

If the value of the attribute attr is already stored for obj, AttributeValueNotSet simply returns this value. Otherwise the value of attr( obj ) is computed and returned without storing it in obj. This can be useful when large attribute values (such as element lists) are needed only once and shall not be stored in the object.

gap> HasAsSSortedList(g);
false
gap> AttributeValueNotSet(AsSSortedList,g);
[ (), (4,5), (1,2,3), (1,2,3)(4,5), (1,3,2), (1,3,2)(4,5) ]
gap> HasAsSSortedList(g);
false

The normal behaviour of attributes (when called with just one argument) is that once a method has been selected and executed, and has returned a value the setter of the attribute is called, to (possibly) store the computed value. In special circumstances, this behaviour can be altered dynamically on an attribute-by-attribute basis, using the functions DisableAttributeValueStoring (13.6-5) and EnableAttributeValueStoring (13.6-6).

In general, the code in the library assumes, for efficiency, but not for correctness, that attribute values will be stored (in suitable objects), so disabling storing may cause substantial computations to be repeated.

13.6-4 InfoAttributes
‣ InfoAttributes( info class )

This info class (together with InfoWarning (7.4-8)) is used for messages about attributes. Messages are shown under the following circumstances:

13.6-5 DisableAttributeValueStoring
‣ DisableAttributeValueStoring( attr )( function )

disables the usual call of Setter( attr ) when a method for attr returns a value. In consequence the values will never be stored. Note that attr must be an attribute and not a property.

13.6-6 EnableAttributeValueStoring
‣ EnableAttributeValueStoring( attr )( function )

enables the usual call of Setter( attr ) when a method for attr returns a value. In consequence the values may be stored. This will usually have no effect unless DisableAttributeValueStoring (13.6-5) has previously been used for attr. Note that attr must be an attribute and not a property.

gap> g := Group((1,2,3,4,5),(1,2,3));
Group([ (1,2,3,4,5), (1,2,3) ])
gap> KnownAttributesOfObject(g);
[ "LargestMovedPoint", "GeneratorsOfMagmaWithInverses",
  "MultiplicativeNeutralElement" ]
gap> SetInfoLevel(InfoAttributes,3);
gap> DisableAttributeValueStoring(Size);
#I  Disabling value storing for Size
gap> Size(g);
60
gap> KnownAttributesOfObject(g);
[ "OneImmutable", "LargestMovedPoint", "NrMovedPoints",
  "MovedPoints", "GeneratorsOfMagmaWithInverses",
  "MultiplicativeNeutralElement", "StabChainMutable",
  "StabChainOptions" ]
gap> Size(g);
60
gap> EnableAttributeValueStoring(Size);
#I  Enabling value storing for Size
gap> Size(g);
60
gap> KnownAttributesOfObject(g);
[ "Size", "OneImmutable", "LargestMovedPoint", "NrMovedPoints",
  "MovedPoints", "GeneratorsOfMagmaWithInverses",
  "MultiplicativeNeutralElement", "StabChainMutable",
  "StabChainOptions" ]

13.7 Properties

The properties of an object are those of its attributes (see 13.5) whose values can only be true or false.

The main difference between attributes and properties is that a property defines two sets of objects, namely the usual set of all objects for which the value is known, and the set of all objects for which the value is known to be true.

(Note that it makes no sense to consider a third set, namely the set of objects for which the value of a property is true whether or not it is known, since there may be objects for which the containment in this set cannot be decided.)

For a property prop, the containment of an object obj in the first set is checked again by applying Tester( prop ) to obj, and obj lies in the second set if and only if Tester( prop )( obj ) and prop( obj ) is true.

If a property value is known for an immutable object then this value is also stored, as part of the type of the object. To some extent, property values of mutable objects also can be stored, for example a mutable list all of whose entries are immutable can store whether it is strictly sorted. When the object is mutated (for example by list assignment) the type may need to be adjusted.

Important properties for domains are IsAssociative (35.4-7), IsCommutative (35.4-9), IsAnticommutative (56.4-6), IsLDistributive (56.4-3) and IsRDistributive (56.4-4), which mean that the multiplication of elements in the domain satisfies ( a * b ) * c = a * ( b * c ), a * b = b * a, a * b = - ( b * a ), a * ( b + c ) = a * b + a * c, and ( a + b ) * c = a * c + b * c, respectively, for all a, b, c in the domain.

13.7-1 IsProperty
‣ IsProperty( object )( function )

returns true if object is a property (see 13.7), and false otherwise.

13.7-2 KnownPropertiesOfObject
‣ KnownPropertiesOfObject( object )( operation )

returns a list of the names of the properties whose values are known for object.

13.7-3 KnownTruePropertiesOfObject
‣ KnownTruePropertiesOfObject( object )( operation )

returns a list of the names of the properties known to be true for object.

gap> g:=Group((1,2),(1,2,3));;
gap> KnownPropertiesOfObject(g);
[ "IsEmpty", "IsTrivial", "IsNonTrivial", "IsFinite",
  "CanEasilyCompareElements", "CanEasilySortElements",
  "IsDuplicateFree", "IsGeneratorsOfMagmaWithInverses",
  "IsAssociative", "IsFinitelyGeneratedMagma",
  "IsGeneratorsOfSemigroup", "IsSimpleSemigroup",
  "IsRegularSemigroup", "IsInverseSemigroup",
  "IsCompletelyRegularSemigroup", "IsCompletelySimpleSemigroup",
  "IsGroupAsSemigroup", "IsMonoidAsSemigroup", "IsOrthodoxSemigroup",
  "IsFinitelyGeneratedMonoid", "IsFinitelyGeneratedGroup",
  "IsSubsetLocallyFiniteGroup", "KnowsHowToDecompose",
  "IsInfiniteAbelianizationGroup", "IsNilpotentByFinite",
  "IsTorsionFree", "IsFreeAbelian" ]
gap> Size(g);
6
gap> KnownPropertiesOfObject(g);
[ "IsEmpty", "IsTrivial", "IsNonTrivial", "IsFinite",
  "CanEasilyCompareElements", "CanEasilySortElements",
  "IsDuplicateFree", "IsGeneratorsOfMagmaWithInverses",
  "IsAssociative", "IsFinitelyGeneratedMagma",
  "IsGeneratorsOfSemigroup", "IsSimpleSemigroup",
  "IsRegularSemigroup", "IsInverseSemigroup",
  "IsCompletelyRegularSemigroup", "IsCompletelySimpleSemigroup",
  "IsGroupAsSemigroup", "IsMonoidAsSemigroup", "IsOrthodoxSemigroup",
  "IsFinitelyGeneratedMonoid", "IsFinitelyGeneratedGroup",
  "IsSubsetLocallyFiniteGroup", "KnowsHowToDecompose",
  "IsPerfectGroup", "IsSolvableGroup", "IsPolycyclicGroup",
  "IsInfiniteAbelianizationGroup", "IsNilpotentByFinite",
  "IsTorsionFree", "IsFreeAbelian" ]
gap> KnownTruePropertiesOfObject(g);
[ "IsNonTrivial", "IsFinite", "CanEasilyCompareElements",
  "CanEasilySortElements", "IsDuplicateFree",
  "IsGeneratorsOfMagmaWithInverses", "IsAssociative",
  "IsFinitelyGeneratedMagma", "IsGeneratorsOfSemigroup",
  "IsSimpleSemigroup", "IsRegularSemigroup", "IsInverseSemigroup",
  "IsCompletelyRegularSemigroup", "IsCompletelySimpleSemigroup",
  "IsGroupAsSemigroup", "IsMonoidAsSemigroup", "IsOrthodoxSemigroup",
  "IsFinitelyGeneratedMonoid", "IsFinitelyGeneratedGroup",
  "IsSubsetLocallyFiniteGroup", "KnowsHowToDecompose",
  "IsSolvableGroup", "IsPolycyclicGroup", "IsNilpotentByFinite" ]

13.7-4 NewProperty
‣ NewProperty( name, filter[, rank] )( function )

NewProperty returns a new property prop with name name (see also 13.7). The filter filter describes the involved filters of prop. As in the case of attributes, filter is not implied by prop.

The optional third argument rank denotes the incremental rank (see 13.2) of the property prop itself, i.e. not of its tester; the default value is 1.

13.7-5 DeclareProperty
‣ DeclareProperty( name, filter[, rank] )( function )

does the same as NewProperty (13.7-4) and then binds the result to the global variable name. The variable must previously be writable, and is made read-only by this function. It also binds read-only global variables with names Hasname and Setname for the tester and setter of the property (see Section 13.6).

13.8 Other Filters

There are situations where one wants to express a kind of knowledge that is based on some heuristic.

For example, the filters (see 13.2) CanEasilyTestMembership (39.26-1) and CanEasilyComputePcgs (45.2-3) are defined in the GAP library. Note that such filters do not correspond to a mathematical concept, contrary to properties (see 13.7). Also it need not be defined what easily means for an arbitrary GAP object, and in this case one cannot compute the value for an arbitrary GAP object. In order to access this kind of knowledge as a part of the type of an object, GAP provides filters for which the value is false by default, and it is changed to true in certain situations, either explicitly (for the given object) or via a logical implication (see 78.8) from other filters.

For example, a true value of CanEasilyComputePcgs (45.2-3) for a group means that certain methods are applicable that use a pcgs (see 45.1) for the group. There are logical implications to set the filter value to true for permutation groups that are known to be solvable, and for groups that have already a (sufficiently nice) pcgs stored. In the case one has a solvable matrix group and wants to enable methods that use a pcgs, one can set the CanEasilyComputePcgs (45.2-3) value to true for this particular group.

A filter filt of the kind described here is different from the other filters introduced in the previous sections. In particular, filt is not a category (see 13.3) or a property (see 13.7) because its value may change for a given object, and filt is not a representation (see 13.4) because it has nothing to do with the way an object is made up from some data. filt is similar to an attribute tester (see 13.6), the only difference is that filt does not refer to an attribute value; note that filt is also used in the same way as an attribute tester; namely, the true value may be required for certain methods to be applicable.

In order to change the value of filt for an object obj, one can use logical implications (see 78.8) or SetFilterObj (13.8-3), ResetFilterObj (13.8-4).

13.8-1 NewFilter
‣ NewFilter( name[, implied][, rank] )( function )

NewFilter returns a simple filter with name name (see 13.8).

The optional argument implied, if given, must be a filter, meaning that for each object in the new filter, also implied will be set. Note that resetting the new filter with ResetFilterObj (13.8-4) does not reset implied. If the new filter is intended to be set or reset manually for existing objects then the argument implied will cause trouble; if the filter is not intended to be set or reset manually then perhaps calling NewCategory (13.3-4) is more appropriate than calling NewFilter.

The optional argument rank denotes the incremental rank (see 13.2) of the filter, the default value is 1.

The default value of the new simple filter for each object is false.

13.8-2 DeclareFilter
‣ DeclareFilter( name[, implied][, rank] )( function )

does the same as NewFilter (13.8-1) and then binds the result to the global variable name. The variable must previously be writable, and is made read-only by this function.

13.8-3 SetFilterObj
‣ SetFilterObj( obj, filter )( function )

SetFilterObj sets the value of filter (and of all filters implied by filter) for obj to true.

This may trigger immediate methods.

13.8-4 ResetFilterObj
‣ ResetFilterObj( obj, filter )( function )

ResetFilterObj sets the value of filter for obj to false. (Implied filters of filt are not touched. This might create inconsistent situations if applied carelessly).

13.9 Types

We stated above (see 13) that, for an object obj, its type is formed from its family and its filters. There is also a third component, used in a few situations, namely defining data of the type.

13.9-1 TypeObj
‣ TypeObj( obj )( function )

returns the type of the object obj.

The type of an object is itself an object.

Two types are equal if and only if the two families are identical, the filters are equal, and, if present, also the defining data of the types are equal.

13.9-2 DataType
‣ DataType( type )( function )

The last part of the type, defining data, has not been mentioned before and seems to be of minor importance. It can be used, e.g., for cosets U g of a group U, where the type of each coset may contain the group U as defining data. As a consequence, two such cosets mod U and V can have the same type only if U = V. The defining data of the type type can be accessed via DataType.

13.9-3 NewType
‣ NewType( family, filter[, data] )( function )

NewType returns the type given by the family family and the filter filter. The optional third argument data is any object that denotes defining data of the desired type.

For examples where NewType is used, see 79.2, 79.3, and the example in Chapter 81.

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Bib Ind

generated by GAPDoc2HTML