## Feature #37

### matrix constructors

**Description**

Comments about matrix constructors: mainly "ring or not ring?"

**IdentityMat(QQ,2)**, **ZeroMat(QQ,2,4)**, **ConcatHor**, **ConcatVer**,**MatrixByRows**, **MatrixByCols**, ....

**Related issues**

### History

#### #1 Updated by Anna Maria Bigatti about 6 years ago

**Subject**changed from*matrix constructor*to*matrix constructors*

JAA: C4 has a function for creating an identity matrix. It also has a means of creating a zero matrix (of specified dimensions, **NewMat**). Presumably similar functions should exist in C5.

AMB: **IdentityMat(QQ,2);** and **ZeroMat(QQ,2,4);** [both in CoCoA-5 and in CoCoALib]

Should we have **ZeroMat(ZZ,3);** as a shortcut for **ZeroMat(ZZ,3,3);**?

JAA: If (when?) C5 has automatic promotion of ring elements then these functions can safely return a matrix over ZZ; otherwise the ring in which the entries reside will have to be specified explicitly as an argument.

----------------------------------------------------------------------

JAA: What would a function such as **ConcatHor** or **ConcatVer** or **BlockMatrix** do when given matrices whose elements belong to different rings? Will automatic promotion occur here too?

----------------------------------------------------------------------

JAA: Just a quick comment about the alternative matrix constructors **MatrixByRows** and **MatrixByCols**. JAA believes that *both matrix dimensions* should be given explicitly when using these ctors: at least one of the dimensions *must* be given explicitly, and to avoid doubt and confusion about which one, it seems simplest to require both (their product can also be used to check that the supplied list of entry values has the correct length). The presence or absence of an argument specifying the ring should be as for the standard matrix ctor (currently JAA+AMB are tending toward not specifying explicitly the ring).

AMB: **MakeMatByRows(2,3,[1,2,3,4,5,6]);** [in CoCoA-5]

----------------------------------------------------------------------

JAA: Consider the example below:

R ::= QQ[x,y,z]; M := matrix(R,[[1,x],[1,y]]); Use S ::= ZZ/(7)[x,y]; M := matrix(R,[[1,x],[1,y]]); // cut-and-pasted

The creation of the matrix M will not work as one might reasonably expect (i.e. creating a matrix whose entries are in R): it will produce an error.

If the ring were not supplied as an argument then M would contain a matrix whose entries lie in S; this might be what was wanted, but it is different from the original matrix!

Here's another example which is close to a "nasty surprise":

R ::= QQ[x,y]; Use S ::= QQ[a,b]; x := 2; y := 3; M := matrix(R,[[1,x],[1,y]]); // cut-and-pasted

Here the matrix construction will presumably succeed, but will not produce the original matrix. It is also easy to create examples producing the wrong result, if we change the definition of the ring R...

#### #2 Updated by Anna Maria Bigatti about 6 years ago

**Category**set to*Philosophy*

#### #3 Updated by Anna Maria Bigatti 10 months ago

**Project**changed from*CoCoA*to*CoCoALib***Category**deleted ()*Philosophy***Target version**set to*CoCoALib-0.99560*

This issue was under "CoCoA" instead of "CoCoALib".

I'm recovering these old and forgotten issues, so we reconsider them.

#### #4 Updated by John Abbott 4 months ago

**Category**set to*Data Structures*

This issue is a bit strange -- it is now quite old, and of questionable relevance now.

Perhaps we should just close it?

#### #5 Updated by Anna Maria Bigatti 4 months ago

**% Done**changed from*50*to*90*

**MatByRows/Cols** is now available in CoCoALib.

All other questions have been dealt with, more or less directly.

#### #6 Updated by Anna Maria Bigatti 4 months ago

**Related to***Design #1116: Port RowMat, ColMat, MatByRows,... to CoCoA-5*added

#### #7 Updated by John Abbott 2 months ago

**Status**changed from*In Progress*to*Closed***% Done**changed from*90*to*100*