Ask Your Question
2

How to get a vector space generated by a list of matrices?

asked 2013-05-15 04:22:33 +0200

anonymous user

Anonymous

updated 2013-05-15 04:24:26 +0200

Sage is very nice.

I want to get a matrix space. For example,

  • F=GF(p)
  • V= " vector space over F generated by [M1, M2, ... ,Mn] ,which Mi are n by n matrices with its coefficients in F "

V consist of matrices. In general, how can I get such V?

Many thanks~

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-05-15 06:18:52 +0200

tmonteil gravatar image

updated 2013-05-15 09:04:14 +0200

Unfortunately, VectorSpace seems only to consider row vectors, not matrices, as elements. So i do not know whether it is possible out of the box. A possible workaround is to "unfold" your matrices to vectors, do your computations in the span, and then refold result vector to get a matrix back. Folding and unfolding being isomorphisms of vector spaces, you should be safe with your computations.

Here is an example:

sage: p = 5
sage: F = GF(p)
sage: MM = MatrixSpace(F,2,3) ; MM
Full MatrixSpace of 2 by 3 dense matrices over Finite Field of size 5

sage: M1 = MM.random_element() ; M1
[2 0 0]
[1 4 3]

sage: M2 = MM.random_element() ; M2
[2 3 4]
[4 0 3]

sage: V = VectorSpace(F, MM.dimension()) ; V
Vector space of dimension 6 over Finite Field of size 5

sage: def unfold(M):
....:     return V(M.list())

sage: def refold(UM):
....:     return MM(UM.list())

sage: UM1 = unfold(M1)
sage: UM2 = unfold(M2)
sage: refold(UM1) == M1
True

sage: sp = V.span([UM1, UM2]) ; sp
Vector space of degree 6 and dimension 2 over Finite Field of size 5
Basis matrix:
[1 0 0 3 2 4]
[0 1 3 1 2 0]

sage: UM1 + UM2 in sp
True
sage: UM3 = sp.random_element()
sage: M3 = refold(UM3) ; M3
[2 4 2]
[0 2 3]

sage: M3 in MM
True
edit flag offensive delete link more

Comments

Um~ I got it. Very thanks. Since GAP has the commands "VectorSpace( field , [generators] )" that can make a vector space generated by a list of matrices, I think Sage also have an easy method. But I couldn't find it not yet. :-( Your advice is very helpful. :-)

Semin gravatar imageSemin ( 2013-05-15 10:38:15 +0200 )edit

So effectively you are using coordinate vectors for your matrices (relative to a standard basis for the vector space of matrices), and then doing all of the computations in F^n. That sounds like a reasonable thing to do for vector spaces other than F^n.

Jason Grout gravatar imageJason Grout ( 2013-05-16 07:31:03 +0200 )edit
1

answered 2013-05-15 12:07:27 +0200

tmonteil gravatar image

@Semin : Actually, you can use gap if you want, since it is included in Sage:

sage: p = 5
sage: F = GF(p)
sage: MM = MatrixSpace(F,2,3) ; MM
Full MatrixSpace of 2 by 3 dense matrices over Finite Field of size 5

sage: M1 = MM.random_element() ; M1
[3 2 1]
[3 1 2]
sage: M2 = MM.random_element() ; M2
[2 0 4]
[0 3 4]

sage: sp = gap.VectorSpace(F,[M1,M2]) ; sp
VectorSpace( GF(5), [ [ [ Z(5)^3, Z(5), Z(5)^0 ], [ Z(5)^3, Z(5)^0, Z(5) ] ], 
  [ [ Z(5), 0*Z(5), Z(5)^2 ], [ 0*Z(5), Z(5)^3, Z(5)^2 ] ] ] )

sage: M1 + M2 in sp
True

sage: A = sp.Random() ; A
[ [ Z(5)^3, 0*Z(5), Z(5)^0 ], [ 0*Z(5), Z(5), Z(5)^0 ] ]

But then, how to get the matrix A back as a Sage object ?

edit flag offensive delete link more

Comments

The following works for me to get back a Sage matrix: "MM(list(A))"

vdelecroix gravatar imagevdelecroix ( 2013-05-15 13:49:02 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-05-15 04:22:33 +0200

Seen: 2,884 times

Last updated: May 15 '13