[sage-devel] Re: abstract matrices

341 views
Skip to first unread message

Nicolas M. Thiery

unread,
May 1, 2010, 5:30:34 AM5/1/10
to ross kyprianou, sage-...@googlegroups.com
Dear Ross,

On Mon, Apr 19, 2010 at 06:38:31PM +0930, ross kyprianou wrote:
> (Im trying to finish this in 2-3 weeks to include some results in a
> paper but I understand that may not be possible)

Oops, I just noticed this deadline of yours; I hope you will still
make it! Please find attached a possible refactorisation of your code.
Here is a short extract of the doc (to be run after loading the code):

EXAMPLES::

sage: Alg = SymbolicMatrixAlgebra(QQ)

sage: A = Alg.matrix("A",3,2)
sage: B = Alg.matrix("B",2,3)
sage: C = Alg.matrix("C",2,3)
sage: D = Alg.matrix("D",3,3)

Example 1: Adding/Multiplying matrices of correct size::

sage: A * (B + C)
A B + A C

Example 2: Transposing a sum of matrices::

sage: (B + C).transpose()
C^t + B^t

Example 3: Transposing a product of matrices::

sage: (A * B).transpose()
B^t A^t

Example 4: Inverting a product of matrices::

sage: (A * B)^-1
B^-1 A^-1

Example 5: Multiplying by its inverse::

sage: D * D^-1 # todo: not implemented
I

Enjoy, and let me know how it goes!

Best,
Nicolas
--
Nicolas M. Thiéry "Isil" <nth...@users.sf.net>
http://Nicolas.Thiery.name/

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

Ross Kyprianou

unread,
May 1, 2010, 8:05:35 AM5/1/10
to sage-devel
Nicolas

No worries about deadlines - this looks excellent - thanks!
Will let you know how things go. This gives me lots to work with
Thanks again!

On May 1, 6:30 pm, "Nicolas M. Thiery" <Nicolas.Thi...@u-psud.fr>
wrote:
> Nicolas M. Thiéry "Isil" <nthi...@users.sf.net>http://Nicolas.Thiery.name/
>
> --
> To post to this group, send an email to sage-...@googlegroups.com
> To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/sage-devel
> URL:http://www.sagemath.org
>
>  matrix.sage
> 6KViewDownload

Ross Kyprianou

unread,
May 2, 2010, 3:09:09 AM5/2/10
to sage-devel
This turned out as good as it looked Nicolas
A lot of the planned functionality is already in place with this
initial code - Thanks!

Now it should be possible (for me) to implement some more code (which
is indicated in the second section
(below) i.e. under the section with title "I need to implement
these").
I studied matrix.sage and some of the python scripts in .../devel/sage/
sage/categories
I just need some guidance where to put new code or what to overload.
e.g. I tried to create a
def sum_on_basis(self, w1, w2):
under the code where I saw
def product_on_basis(self, w1, w2):
but that had no effect on the addition bug shown below.

Below, the working functionality is indicated first and below that is
the new work Ill do with
a little guidance. I think the coding I need to do is straight
forward.
The challenge should just be where to put the code associated each bug
below.

e.g. Ive written the fix to the sum bug below but
- do I put it in a _sum_( ) method?
- do I put it in a sum_on_basis(self, w1, w2) method?
- and where (or which class?) do I put these methods in?

Heres the results of some testing...

=====================================
Starting with these definitions...

sage: Alg = SymbolicMatrixAlgebra(QQ)
sage: A = Alg.matrix("A",3,2)
sage: B = Alg.matrix("B",2,3)
sage: C = Alg.matrix("C",2,3)
sage: D = Alg.matrix("D",3,3)

===================================
==== The following worked well ====
===================================

# Conformable matrix sizes for multiplication passes
sage: A*B
A B
sage: B*C.transpose()
B C^t

# Non-Conformable matrix sizes for multiplication is caught
sage: B*C
---------------------------------------------------------------------------
AssertionError Traceback (most recent call
last)
...
AssertionError: Non-conformable matrices: matrix sizes are
incompatible for multiplication

# Additive inverse
sage: D-D
0

#Additive identity (no probs with sizes is intuitively ok)
sage: A+0
A

# Conformable matrix sizes for addition passes
sage: B+C
B + C

# transposes
sage: A.transpose()
A^t

sage: (A+B).transpose()
A^t + B^t

# only square matrices have an inverse (we'll think about pseudo-
inverses later)
sage: ~A
---------------------------------------------------------------------------
AssertionError Traceback (most recent call
last)
...
AssertionError: Can't inverse non square matrix

=====================================
==== I need to implement these ====
=====================================

# Non-Conformable matrix sizes for addition is *NOT* caught
# (Also need to change the unusual reversal of order being printed)
# QUESTION
sage: A+B
B + A

# simplify multiplicative inverse (i.e. return I but not the one from
the symbolic ring)
sage: ~D*D
D^-1 D

# allow ~(A*B) to work (currently crashes with size error because Ive
specified this should be returned as B^-1 A^-1 and neither are square:
but A*B is square so ~(A*B) should return (A*B)^-1 "unsimplified" -
later we can introduce assume(A*B,'invertible')
sage: ~(A*B)

# multiplying by identity (question of size of I arises - see additive
identity example above)
sage: D*I
D
===============================
==== Probably these too ====
===============================
# (a) ~~D returns D but ~~D == D returns false (confusing) i.e.
sage: ~~D
D
sage: ~~D == D
False

# (b) define _pow_() so D^-1 returns ~D

cheers!
Reply all
Reply to author
Forward
0 new messages