Simon King wrote:
Hi Dima!

On 10 Jan., 13:47, Dima Pasechnik <dimp...@gmail.com> wrote:
On Jan 10, 7:04 pm, javier <vengor...@gmail.com> wrote:
well, there no "static type" matrices in GAP (well, unless you work
with, say, matrix Lie algebras, and have multiplication overloaded).
They are just lists of lists of right sizes, with entries in a common
ring.

I am surprised to hear that Sage is less flexible here

And I am surpised to hear that GAP has no proper matrices. Certainly a
matrix is MUCH more than a list of lists. For example, in order to
have a mathematical meaning, the marks of a matrix have to belong to
the same ring.

(ok ,there
could be, say, special matrices, say, dense numeric
and bit matrices, that deserve a special treatment, but otherwise this
seems strange...)

You seriously think that matrix multiplication, determinant, echelon
form etc. should be done with lists of lists? I doubt that this can be
any good. I acknowledge that GAP's main purpose is groups and not
linear algebra. But providing fast linear algebra is certainly an
objective of Sage.

What does all that mean for the sage() method of the GAP interface?

Do I understand correctly that IsMatrix just states that the object is
a list of lists of the same size?

Then, perhaps sage() could have an optional argument. For example, if
the user reckons that some GAP object L is formed by "matrices" (e.g.,
it is a list of lists of lists of the same size), then L.sage
(AsMatrix=True) would return a list of sage matrices, whereas L.sage()
would return a list of lists of lists.

But then, it would be challenging to make sage(AsMatrix=True) work for
a matrix of matrices...



Two comments. First of all, we can deal with matrices of matrices, though it isn't as natural as I had hoped. Here's the first thing that I tried:

sage: mm=matrix(MatrixSpace(ZZ,2),2)
sage: mm[0]
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/grout/.sage/temp/tiny/2005/_home_grout__sage_init_sage_0.py in <module>()

/home/grout/sage/local/lib/python2.6/site-packages/sage/matrix/matrix0.so in sage.matrix.matrix0.Matrix.__getitem__ (sage/matrix/matrix0.c:5314)()

/home/grout/sage/local/lib/python2.6/site-packages/sage/matrix/matrix1.so in sage.matrix.matrix1.Matrix.row (sage/matrix/matrix1.c:7428)()

/home/grout/sage/local/lib/python2.6/site-packages/sage/structure/factory.so in sage.structure.factory.UniqueFactory.__call__ (sage/structure/factory.c:919)()

/home/grout/sage/local/lib/python2.6/site-packages/sage/structure/factory.so in sage.structure.factory.UniqueFactory.get_object (sage/structure/factory.c:1125)()

/home/grout/sage/local/lib/python2.6/site-packages/sage/modules/free_module.pyc in create_object(self, version, key) 343 raise TypeError, "Argument sparse (= %s) must be True or False" % sparse
    344
--> 345         if not base_ring.is_commutative():
346 raise TypeError, "The base_ring must be a commutative ring."
    347

AttributeError: 'MatrixSpace_generic' object has no attribute 'is_commutative'


Since we can create a matrix of matrices appropriately, maybe we can fix up a few things to make it make sense?

But there's also another way to get the "dynamically typed" matrices through the generality of the symbolic ring. Here, I create a symbolic matrix. Since symbolic objects wrap any other objects, I set the first element of the matrix to a 2x2 identity matrix, and another element to a real number. Printing is a little messed up, but you can see it's doing the right thing here.

sage: mmsr=matrix(SR,2)
sage: mmsr[0,0]=SR(matrix(ZZ,2,2,1))
sage: mmsr
[[1 0]
[0 1]           0]
[          0           0]
sage: mmsr[0,0]
[1 0]
[0 1]
sage: mmsr[0,1]=RR(e)
sage: mmsr
[     [1 0]
[0 1] 2.71828182845905]
[               0                0]
sage: mmsr[0,0]
[1 0]
[0 1]
sage: mmsr[0,1]
2.71828182845905

Thanks,

Jason

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to