gap icon indicating copy to clipboard operation
gap copied to clipboard

Matrix objects do not belong to `IsAssociativeElement` and there're no filters to identify collections of matrix objects

Open james-d-mitchell opened this issue 3 years ago • 1 comments

In the current master branch

Observed behaviour

gap> coll := [Matrix(Integers, [[0, 2, 1], [1, 0, 1], [0, 2, 1]]),
>     Matrix(Integers, [[5, 1, 1], [0, 0, 1], [2, 4, 3]])];
[ <3x3-matrix over Integers>, <3x3-matrix over Integers> ]
gap> IsAssociativeElement(coll[1]);
false
gap> IsMultiplicativeElementCollection(coll);
false

Expected behaviour

Multiplication of square matrices is associative, so ideally, IsAssociativeElement(coll[1]); would return true, and equally IsMultiplicativeElementCollection(coll); would return true too. It'd be useful if there was a category IsMatrixObjCollection too, not sure if that should be a separate issue.

I encountered this issue when trying to resolve the issues in the Semigroups package caused by https://github.com/gap-system/gap/commit/3e9fb2ab45457f97807bea4762358dc0489adf9a. After this change it is not longer even possible to create semigroups consisting of integer matrices. Prior to this change it was possible with the Semigroups package loaded (since 2015).

james-d-mitchell avatar Mar 05 '22 13:03 james-d-mitchell

Thanks for the reports. Let's see:

Multiplication of square matrices is associative if and only if the entries of these matrices are associative. But I agree that in general, it would be desirable for IsAssociativeElement to be set for MatrixObj type instances with entries in an associative ring!

The documentation says:

##  An element <A>obj</A> in the category <Ref Filt="IsAssociativeElement"/>
##  knows that the multiplication of any elements in the family of <A>obj</A>
##  is associative.

Based on this, I think we need to be more careful about the family object we use for our MatrixObj instances. (Ah, if only someone had time to complete #2973)

Indeed, we should do that anyway: I just noticed that we do Objectify( NewType(CollectionsFamily(FamilyObj(basedomain)) ... to create the IsPlistMatrixRep instances, and that seems problematic: we mark matrices as collections of their coefficients... Which is not unreasonable per se, but it breaks with the current conventions where matrix objects are of course collections of collections of their coefficients. And the CollectionsFamily() function has some code dealing with IsOddAdditiveNestingDepthFamily resp. adding the IsOddAdditiveNestingDepthObject filter, and I suspect that also adds to the problems here sigh.

Anyway, compressed matrices seem to get at least the IsAssociativeElement bit right. But note that even for those, IsMultiplicativeElementCollection(coll) and IsAssociativeElementCollection(coll) return false:

gap> coll := [ ImmutableMatrix(GF(5), Z(5)^0*[[0, 2, 1], [1, 0, 1], [0, 2, 1]]), ImmutableMatrix(GF(5), Z(5)^0*[[5, 1, 1], [0, 0, 1], [2, 4, 3]] ) ];;
gap> IsAssociativeElement(coll[1]);
true
gap> IsAssociativeElementCollection(coll);
false
gap> IsMultiplicativeElementCollection(coll);
false

I've not dug deep on the "collection" bit, but in the end, bear in mind that mutable plain lists, as used here, don't carry a real type object, but rather the type is computed dynamically, and in general keeps track of only a tiny select portion of possible filters/flags.

fingolfin avatar Mar 05 '22 23:03 fingolfin