From 971bb0a6f516d838ad3ad35745cb49858fda2d12 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 Nov 2014 22:00:27 -0500 Subject: [PATCH] Add the matrix_vector module with only the isomorphism() function for now. --- mjo/matrix_vector.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 mjo/matrix_vector.py 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) -- 2.44.2