- V = K.lattice().vector_space()
-
- C_of_K = discrete_complementarity_set(K)
-
- matrices = [x.tensor_product(s) for (x,s) in C_of_K]
-
- # Sage doesn't think matrices are vectors, so we have to convert
- # our matrices to vectors explicitly before we can figure out how
- # many are linearly-indepenedent.
- #
- # The space W has the same base ring as V, but dimension
- # dim(V)^2. So it has the same dimension as the space of linear
- # transformations on V. In other words, it's just the right size
- # to create an isomorphism between it and our matrices.
- W = VectorSpace(V.base_ring(), V.dimension()**2)
-
- def phi(m):
- r"""
- Convert a matrix to a vector isomorphically.
- """
- return W(m.list())
-
- vectors = [phi(m) for m in matrices]
-
- return (W.dimension() - W.span(vectors).rank())