[GAP Forum] IsMatrix

Alexander Konovalov alexander.konovalov at gmail.com
Mon Nov 22 10:06:51 GMT 2010


On 14 Nov 2010, at 04:00, Dr. Ashish Kumar Das wrote:

> Dear all,
> I am confused with the command IsMatrix. In GAP a matrix is a list of
> lists of equal length whose entries lie in a common ring. But if I
> type  mat:=[[1,2,3],[2,3]]; and then run IsMatrix(mat); I get the
> reply 'true'. Moreover, If I run DimensionsMat(mat); I get the reply
> '[2,3]'. Can any one tell me why does this happen?

Dear Dr. Ashish Kumar Das, 

The answer that you are getting here is really what is expected.
The confusion here actually arises because of an incomplete GAP
documentation, which will be clarified in the next GAP release. 

For the sake of performance and optimal method selection, IsMatrix 
is implemented in a way that it does not check that all lists have 
the same length, so IsMatrix is allowed to return 'true' for 
objects that does not strictly correspond to the definition of
matrix to be "a list of lists of equal length whose entries lie in 
a common ring".

This convention, allows, for example, to distinguish a matrix from 
other types of objects for the method selection, saving time by
not checking each time that all its rows have the same length. 

If you want to check the latter condition, you need to call
"IsRectangularTable" which will became documented in the next 
GAP release:

gap> mat:=[[1,2,3],[2,3]];
[ [ 1, 2, 3 ], [ 2, 3 ] ]
gap> IsRectangularTable(mat);
false
gap> m:=[[1,2,3],[2,3,0]];
[ [ 1, 2, 3 ], [ 2, 3, 0 ] ]
gap> IsRectangularTable(m);  
true

In addition, note a call to "IsSomething" may be a filter which
checks that the object belongs to the certain category of GAP 
objects, and does not check the mathematical property of an 
argument, like in the example:

gap> IsGroup([(),(1,2)]);  
false
gap> G:=AsGroup([(),(1,2)]); 
Group([ (1,2) ])
gap> IsGroup(G);            
true

See chapter 13 "Types of Objects" of the reference manual for more 
details.

Hope this helps,
Alexander




More information about the Forum mailing list