I'm in the process of writing a PermutationMatrix class (applications: 
friendly interface to permuted decompositions, etc.):

         sage: P = permutation_matrix([0, 2, 1]); P
         [1 0 0]
         [0 0 1]
         [0 1 0]
         sage: parent(P)
         Full MatrixSpace of 3 by 3 sparse matrices over Integer Ring
         sage: P * A # calls A.matrix_from_rows([0, 2, 1])
         ...and so on


My goal is to allow to treat a permutation (stored efficiently) as much 
as possible like an (immutable) sparse matrix. When doing this I'm 
growing aware of some issues with matrices and mutability.

1) A matrix transpose() is currently always mutable in all 
implementations. This is a rather huge issue here. Would it be OK to 
have the transpose of an immutable matrix always be immutable, unless 
mutable=True is passed?

Having P.transpose() be mutable requires conversion to a less efficient 
mutable matrix loosing the permutation-ness. This has a few other 
applications as well (caching transposes, automatically making use of 
matrix decompositions already computed for the transpose).

2) In the same spirit, change_ring sometimes returns an immutable matrix 
(if no change was needed and self is returned), and sometimes not:

    Always returns a copy (unless self is immutable, in which case
    returns self).

This is hardly a useful IMO -- would it be OK to change it so that one 
had to pass mutable=True to get a mutable matrix, and otherwise it was 
always immutable? This would allow PermutationMatrix to change rings to 
another permutation matrix.

3) Perhaps more controversial: Allow immutability to propagate. 
Currently, "2*P*A" can be much slower than "2*(P*A)" because "2*P" must 
be a mutable matrix. If the product of two immutable matrices, or an 
immutable matrix with a scalar, was itself immutable, this would be 
trivial to speed up (2*P would be a new "permutation matrix" simply 
returning 2 instead of 1).

Again, this might have applications to cached matrix decompositions 
(transform existing decompositions rather than recompute), though I'm 
not sure if that is useful.

-- 
Dag Sverre

-- 
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