- n = V.dimension()
- B = list(V.basis())
-
- def inner_product(v, w):
- # An inner product function that works for both matrices and
- # vectors.
- if callable(getattr(v, 'inner_product', None)):
- return v.inner_product(w)
- elif callable(getattr(v, 'matrix_space', None)):
- # V must be a matrix space?
- return (v*w.transpose()).trace()
- else:
- raise ValueError('inner_product only works on vectors and matrices')
-
- def apply(L, x):
- # A "call" that works for both matrices and functions.
- if callable(getattr(L, 'matrix_space', None)):
- # L is a matrix, and we need to use "multiply" to call it.
- return L*x
- else:
- # If L isn't a matrix, try this. It works for python
- # functions at least.
- return L(x)
-
- entries = []
- for j in range(n):
- for i in range(n):
- entry = inner_product(apply(T,B[i]), B[j])
- entries.append(entry)
-
- # Construct the matrix space in which our return value will lie.
- W = MatrixSpace(V.base_ring(), n, n)
-
- # And make a matrix out of our list of entries.
- A = W(entries)
-
- return A
+ if is_MatrixSpace(M):
+ basis_space = M
+ basis = list(M.basis())
+ else:
+ basis_space = M[0].matrix_space()
+ basis = M
+
+ (phi, phi_inv) = basis_representation(M)
+
+ # Get a basis for the image space. Since phi is an isometry,
+ # it takes one basis to another.
+ image_basis = [ phi(b) for b in basis ]
+
+ # Now construct the image space itself equipped with our custom basis.
+ W = VectorSpace(basis_space.base_ring(), len(basis))
+ W = W.span_of_basis(image_basis)
+
+ return matrix.column( W.coordinates(phi(L(b))) for b in basis )