]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/matrix_vector.py
Add the matrix_vector module with only the isomorphism() function for now.
[sage.d.git] / mjo / matrix_vector.py
1 """
2 There is an explicit isomorphism between all finite-dimensional vector
3 spaces. In particular, there is an isomorphism between the m-by-n
4 matrices and `$R^(m \times n)$`. Since most vector operations are not
5 available on Sage matrices, we have to go back and forth between these
6 two vector spaces often.
7 """
8
9 from sage.all import *
10
11 def isomorphism(matrix_space):
12 """
13 Create isomorphism (i.e. the function) that converts elements
14 of a matrix space into those of the corresponding finite-dimensional
15 vector space.
16
17 INPUT:
18
19 - matrix_space: A finite-dimensional ``MatrixSpace`` object.
20
21 OUTPUT:
22
23 - (phi, phi_inverse): If ``matrix_space`` has dimension m*n, then
24 ``phi`` will map m-by-n matrices to R^(m*n).
25 The inverse mapping ``phi_inverse`` will go
26 the other way.
27
28 EXAMPLES:
29
30 sage: M = MatrixSpace(QQ,4,4)
31 sage: (p, p_inv) = isomorphism(M)
32 sage: m = M(range(0,16))
33 sage: p_inv(p(m)) == m
34 True
35
36 """
37 from sage.matrix.matrix_space import is_MatrixSpace
38 if not is_MatrixSpace(matrix_space):
39 raise TypeError('argument must be a matrix space')
40
41 base_ring = matrix_space.base_ring()
42 vector_space = VectorSpace(base_ring, matrix_space.dimension())
43
44 def phi(m):
45 return vector_space(m.list())
46
47 def phi_inverse(v):
48 return matrix_space(v.list())
49
50 return (phi, phi_inverse)