Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/matrix.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1280,9 +1280,19 @@ InstallOtherMethod( ConstructingFilter,
v -> IsPlistRep );

InstallOtherMethod( BaseDomain,
"generic method for a matrix that is a plain list",
"generic method for a plain list matrix",
[ IsMatrix and IsPlistRep ],
mat -> BaseDomain( mat[1] ) );
mat -> BaseDomain( Concatenation( mat ) ) );

InstallOtherMethod( BaseDomain,
"generic method for a plain list matrix over a finite field",
[ IsMatrix and IsPlistRep and IsFFECollColl ],
DefaultFieldOfMatrix );

InstallOtherMethod( BaseDomain,
"generic method for a plain list over the cyclotomics",
[ IsMatrix and IsPlistRep and IsCyclotomicCollColl ],
DefaultFieldOfMatrix );

InstallOtherMethod( OneOfBaseDomain,
"generic method for a matrix that is a plain list",
Expand Down
62 changes: 62 additions & 0 deletions tst/testinstall/MatrixObj/BaseDomain.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
gap> START_TEST("BaseDomain.tst");

#
gap> m := [[1,2],[3,4]];;
gap> BaseDomain(m);
Rationals
gap> BaseDomain(Matrix(m));
Rationals
gap> BaseDomain(Matrix(Rationals, m));
Rationals
gap> BaseDomain(Matrix(Integers, m));
Integers

# FIXME: BUG:
#gap> BaseDomain(Matrix(GF(2), m));
#Rationals
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently Matrix(GF(2), m) returns a copy of m.
The NewMatrix method in question calls ConvertToMatrixRep and ignores the fail result.
I think this method should signal an error.

(Well, we should first agree that we want an error message here.
The documentation states that the matrix entries need not lie in the base ring of the matrix but may also "naturally embed in the sense that addition and multiplication automatically work with elements of the base domain".
The condition about arithmetic operations is satisfied for integers and elements of GF(2) but we are not in the situation of an embedding; perhaps the documentation should be made more precise here.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that wording was specifically there based on discussion with @frankluebeck, to allow having entries equal to immediate integer objects like 0 and 1, which are much more efficient than general ring elements. I.e. this was strictly intended for optimization purposes.

However, I always felt this is "iffy", and I would reject it for this constructor. Of course a matrix type may use integer objects internally, to fill entries (as, indeed, the new matrix type over Z/nZ defined by @hulpke does); and the implementor may also provide special constructors which accept as input such immediate integers (and anything else that they see fit), but IMHO the default methods should not be required to do so...

Of course checking whether elements are inside a given domain can be expensive. So perhaps we'd want a (set of) MatrixNC methods which don't perform these checks (and/or a "nocheck" option, or whatever). But arguably the default ways to construct MatrixObj instances should IMHO reject "obvious" nonsense.


#
gap> m := [[1,2],[3,4/3]];;
gap> BaseDomain(m);
Rationals
gap> BaseDomain(Matrix(m));
Rationals
gap> BaseDomain(Matrix(Rationals, m));
Rationals

# FIXME: BUG:
# gap> BaseDomain(Matrix(Integers, m));
#Integers
#gap> BaseDomain(Matrix(GF(2), m));
#Rationals

#
gap> m := [[1,2],[3,4]] * Z(2);;
gap> BaseDomain(m);
GF(2)
gap> BaseDomain(Matrix(m));
GF(2)
gap> BaseDomain(Matrix(GF(2), m));
GF(2)

# FIXME: BUG:
#gap> BaseDomain(Matrix(Rationals, m));
#Rationals

#
gap> m := [[1,2],[3,Z(4)]] * Z(2);;
gap> BaseDomain(m);
GF(2^2)
gap> BaseDomain(Matrix(m));
GF(2^2)
gap> BaseDomain(Matrix(GF(4), m));
GF(2^2)
gap> BaseDomain(Matrix(GF(2), m));
Error, ConvertToVectorRepNC: Vector cannot be written over GF(2)

# FIXME: BUG:
#gap> BaseDomain(Matrix(Rationals, m));
#Rationals

#
gap> STOP_TEST("BaseDomain.tst");
1 change: 0 additions & 1 deletion tst/testinstall/grpreps.tst
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ gap> List( res2[2], r -> [ r.field, r.dimension ] );

#
gap> STOP_TEST( "grpreps.tst" );