--- /dev/null
+"""
+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)