X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fmatrix_vector.py;fp=mjo%2Fmatrix_vector.py;h=e1d1931e6c574053827038a9764bebf9ef0c482e;hb=971bb0a6f516d838ad3ad35745cb49858fda2d12;hp=0000000000000000000000000000000000000000;hpb=68df5e61c6a34482ec8cb3bd24a289593101d5e0;p=sage.d.git diff --git a/mjo/matrix_vector.py b/mjo/matrix_vector.py new file mode 100644 index 0000000..e1d1931 --- /dev/null +++ b/mjo/matrix_vector.py @@ -0,0 +1,50 @@ +""" +There is an explicit isomorphism between all finite-dimensional vector +spaces. In particular, there is an isomorphism between the m-by-n +matrices and `$R^(m \times n)$`. Since most vector operations are not +available on Sage matrices, we have to go back and forth between these +two vector spaces often. +""" + +from sage.all import * + +def isomorphism(matrix_space): + """ + Create isomorphism (i.e. the function) that converts elements + of a matrix space into those of the corresponding finite-dimensional + vector space. + + INPUT: + + - matrix_space: A finite-dimensional ``MatrixSpace`` object. + + OUTPUT: + + - (phi, phi_inverse): If ``matrix_space`` has dimension m*n, then + ``phi`` will map m-by-n matrices to R^(m*n). + The inverse mapping ``phi_inverse`` will go + the other way. + + EXAMPLES: + + sage: M = MatrixSpace(QQ,4,4) + sage: (p, p_inv) = isomorphism(M) + sage: m = M(range(0,16)) + sage: p_inv(p(m)) == m + True + + """ + from sage.matrix.matrix_space import is_MatrixSpace + if not is_MatrixSpace(matrix_space): + raise TypeError('argument must be a matrix space') + + base_ring = matrix_space.base_ring() + vector_space = VectorSpace(base_ring, matrix_space.dimension()) + + def phi(m): + return vector_space(m.list()) + + def phi_inverse(v): + return matrix_space(v.list()) + + return (phi, phi_inverse)