Max Horn
They usually...
Let's look at these a bit closer!
"Matrices are represented in GAP by lists of row vectors [...]"
gap> mat:=[[1,2,3],[4,5,6],[7,8,9]];;
gap> IsMatrix(mat);
true
"The vectors must all have the same length, and their elements must lie in a common ring."
gap> mat:=[[1,2],[3]];;
gap> IsMatrix(mat);
true
gap> IsRectangularTable(mat);
false
gap> DimensionsMat(mat);
fail
gap> mat:=[[0,1],[2,3]];;
gap> mat^-1;
[ [ -3/2, 1/2 ], [ 1, 0 ] ]
Eigenvalues
, at least allow you to specify a base field or ring.
gap> DefaultFieldOfMatrix(mat);
Rationals
gap> R:=DefaultRing(mat); LeftActingDomain(R);
( Integers^[ 2, 2 ] )
Integers
gap> id:=IdentityMat(3);;
gap> m1:=[];;
gap> m2:=[[]];;
gap> m3:=EmptyMatrix(0);
EmptyMatrix( 0 )
gap> m4:=[ EmptyRowVector(FamilyObj(42)) ];
[ <empty row vector> ]
gap> m5:=IdentityMat(0); # NullMapMatrix
<null map>
gap> TransposedMat(m1);
[ ]
gap> TransposedMat(m2);
[ ]
gap> TransposedMat(m3);
[ ]
gap> TransposedMat(m4);
[ ]
gap> TransposedMat(m5);
[ ]
gap> id:=IdentityMat(3);;
gap> m1:=[];;
gap> m2:=[[]];;
gap> m3:=EmptyMatrix(0);
EmptyMatrix( 0 )
gap> m4:=[ EmptyRowVector(FamilyObj(42)) ];
[ <empty row vector> ]
gap> m5:=IdentityMat(0); # NullMapMatrix
<null map>
gap> DimensionsMat(m1);
Error, no method found!
gap> DimensionsMat(m2);
Error, no method found!
gap> DimensionsMat(m3);
[ 0, 0 ]
gap> DimensionsMat(m4);
[ 1, 0 ]
gap> DimensionsMat(m5);
Error, no method found!
gap> id:=IdentityMat(3);;
gap> m1:=[];;
gap> m2:=[[]];;
gap> m3:=EmptyMatrix(0);
EmptyMatrix( 0 )
gap> m4:=[ EmptyRowVector(FamilyObj(42)) ];
[ <empty row vector> ]
gap> m5:=IdentityMat(0); # NullMapMatrix
<null map>
gap> id*m1;
Error, Inner product multiplication of lists: no summands
gap> id*m2;
[ [ ], [ ], [ ] ]
gap> id*m3;
EmptyMatrix( 0 )
gap> id*m4;
[ <empty row vector>, <empty row vector>, <empty row vector> ]
gap> id*m5;
[ [ ], [ ], [ ] ]
gap> id:=IdentityMat(3);;
gap> m1:=[];;
gap> m2:=[[]];;
gap> m3:=EmptyMatrix(0);
EmptyMatrix( 0 )
gap> m4:=[ EmptyRowVector(FamilyObj(42)) ];
[ <empty row vector> ]
gap> m5:=IdentityMat(0); # NullMapMatrix
<null map>
gap> m1*id;
Error, Inner product multiplication of lists: no summands
gap> m2*id;
Error, Inner product multiplication of lists: no summands
gap> m3*id;
EmptyMatrix( 0 )
gap> m4*id;
Error, no method found!
gap> m5*id;
<null map>
First
and FirstOp
?
gap> list := List([1..1000], i -> i^2);;
gap> for i in [1..10^4] do First(list,ReturnFalse); od; time;
205
gap> for i in [1..10^4] do FirstOp(list,ReturnFalse); od; time;
209
gap> list := List([1..1000], i -> [i^2]);;
gap> for i in [1..10^4] do First(list,ReturnFalse); od; time;
208
gap> for i in [1..10^4] do FirstOp(list,ReturnFalse); od; time;
499
gap> list := List([1..1000], i -> [[i^2]]);;
gap> for i in [1..10^4] do First(list,ReturnFalse); od; time;
201
gap> for i in [1..10^4] do FirstOp(list,ReturnFalse); od; time;
1227
gap> list := List([1..1000], i -> [[i^2]]);;
gap> TNUM_OBJ(list);
[ 22, "list (plain)" ]
gap> KnownTruePropertiesOfObject(list);
[ "IsFinite", "IsSmallList", "IsRectangularTable" ]
gap> TNUM_OBJ(list);
[ 26, "list (plain,dense)" ]
gap> MakeImmutable(list);;
gap> TNUM_OBJ(list);
[ 27, "list (plain,dense,imm)" ]
gap> KnownTruePropertiesOfObject(list);
[ "IsFinite", "IsSmallList", "IsRectangularTable" ]
gap> TNUM_OBJ(list);
[ 49, "list (plain,rect table,imm)" ]
gap> for i in [1..10^4] do First(list,ReturnFalse); od; time;
210
gap> for i in [1..10^4] do FirstOp(list,ReturnFalse); od; time;
202
There are many ways to store a matrix, e.g.
mat[i][j]
mat[i]
, then extract j
-th entry
mat
isn't a list-of-rows, no "row object" exists!
mat[i]
returns a "proxy object" which reference mat
and stores i