[GAP Forum] Tuple attribute

Alexander Hulpke hulpke at math.colostate.edu
Wed Dec 31 19:18:46 GMT 2003


Dear GAP Forum,

Jose Morais wrote:

> While I hadn't your answer, I implemented a new GAP object (Pair) which
> is in `IsAttributeStoringRep', but I am having difficulties in defining
I still think that keeping tuples and storingthe attribute in the family is
the cleaner and more efficient solution and will save you in the end a lot
of time recoding methods for tuples. 

> My question is: how can I define a Pair in such a way that it becomes
> suitable for all the operations applicable to Tuples?
The easiest is probably to look at the code for tuples (in `tuples.g?') and
duplicate what is done there.

As it might be of interest anyhow, let me add a few remarks about the error
you got:

> InstallMethod( OneOp, "for pairs", true, [ IsPair ], 0,
>
> Error, required filters [ "IsPair" ]
> for 1st argument do not match a declaration of ONE called from

Method installations have to conform to the declaration of the operation,
but one can skip this test by using `InstallOtherMethod' instead (I seem to
recall that there was a similar question recently).

Operations are typically declared in a `.gd' file, but an operation can be
declared several times for different objects (for example the conjugacy
classes of a group or of a character table), and one might have to find the
right declaration.

With `One' (and its derivatives) the situation is complicated further, in
that this is an operation that the kernel must know about (for example for
calculating x^0). The declaration therefore is a bit mor complicated. (The
declaration in basicim.gd you found is a red herring and will only confuse
things -- lets forget about it for the moment.)

Most arithmetic operations (as also `One') are declared in `arith.gd'. (The
comments in this file give much more detail than I can do here.)
We find the following declaration:

  DeclareOperationKernel("OneMutable",[IsMultiplicativeElementWithOne],ONE);

This means: The operation is initially created (under the name `ONE') in the
kernel. (This is needed to have the kernel know about it. Typically
operations that come from the kernel have a kernel name that is all upper
case and then get declared with a ``proper'' library name.)

In our case, `OneMutable' is the library name, but when you type it into
GAP, you still see the kernel name lurking behind:

  gap> OneMutable;
  <Operation "ONE">

(There are other declarations in `arith.gd' (they have essentially to do with
the fact that we might want to store the `One' of a group as an attribute
and -- if the group elements are potentially mutable, as for example
matrices are -- a stored one should be immutable. They all wrap around
`OneMutable'.)

`OneMutable' is declared for the category `IsMultiplicativeElementWithOne'.
To be able to calculate `One' for your pairs, they have to be declared to
be in this category as well. 

This must happen when you declare `IsPair', it is not sufficient that all
pair objects you create are put in this Category.  (As the installation only
is given `IsPair', the method installation does not know about this fact.
You could change the method installation to `IsPair and
IsMultiplicativeElementWithOne', however. In your second mail you state that
this worked. With this, however you might run into the same problem with
other arithmetic operations.)

> I have this definition for pairs:

  BindGlobal( "PairsType",    NewType( PairsFamily, IsPair and
	  IsExtAElement and IsNearAdditiveElement and IsAdditiveElement and
	  IsNearAdditiveElementWithZero and IsAdditiveElementWithZero and
	  IsNearAdditiveElementWithInverse and IsAdditiveElementWithInverse and
	  IsAdditivelyCommutativeElement and
	  CanEasilySortElements and CanEasilySortElements and
	  IsExtRElement and IsExtLElement and IsMultiplicativeElement and
	  IsMultiplicativeElementWithOne and IsMultiplicativeElementWithZero and
	  IsMultiplicativeElementWithInverse and
	  IsAssociativeElement and
	  IsAttributeStoringRep ));

This is the type, which your objects will get. Personally I would leave out
declarations that are anyhow implied (IsMultiplicativeElementWithInverse
implies IsMultiplicativeElementWithOne implies IsMultiplicativeElement
implies IsAssociativeElement, for example)
I also would try to start with only the categories you really need -- for
monoid elements that would be:

IsMultiplicativeElementWithOne (you might want to use
IsMultiplicativeElementWithInverse instead, if you might want to generalize
to groups or if some elements are invertible)

IsPair,
IsAttributeStoringRep, (I suppose `IsPair' implies IsComponentObject')

and -- if you have an efficient comparison implemented (this filter
essentially makes some methods available that rely on elememt comparison)
CanEasilySortElements.

I also would have `IsMultiplicativeElementWithInverse' and
`IsAssociativeElement' to be implied by `IsPair'.

(The reason for leaving out unnecessary declarations is that these might
trigger methods for other kinds of objects which might assume further
properties. The error you got after changing the declaration:
> 	but if I add to these filters 'IsBasicImageEltRep', then, when I try to
> define a pair I get an error:
> Record: '<rec>.Word' must have an assigned value at
is exactly of this kind -- what gets triggered is a `View' method for
`IsBasicImageEltRep' that assumes that a !.Word component is stored in the
object.)

One last remark: If `IsPair' does not imply `IsMultiplicativeElement' and
`IsAssociativeElement' by its declaration, I think you might end up that
sets of pairs (your monoids) will not know automatically to be
`IsMultiplicativeElementCollection' and `IsAssociativeElementCollection' and
thus are not recognized to be semigroups or monoids though your objects all
will multiply fine. 

Best wishes and a Happy New Year,

  Alexander Hulpke

-- Colorado State University, Department of Mathematics,
Weber Building, 1874 Campus Delivery, Fort Collins, CO 80523-1874, USA
email: hulpke at math.colostate.edu, Phone: ++1-970-4914288
http://www.math.colostate.edu/~hulpke




More information about the Forum mailing list