- # 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.
- V = K.lattice().vector_space()
- W = VectorSpace(V.base_ring(), V.dimension()**2)
-
- C_of_K = K.discrete_complementarity_set()
- tensor_products = [ s.tensor_product(x) for (x,s) in C_of_K ]
-
- # Turn our matrices into long vectors...
- vectors = [ W(m.list()) for m in tensor_products ]
-
- # Create the *dual* cone of the cross-positive operators,
- # expressed as long vectors..
- L = ToricLattice(W.dimension())
- Sigma_dual = Cone(vectors, lattice=L)
-
- # Now compute the desired cone from its dual...
- Sigma_cone = Sigma_dual.dual()
-
- # And finally convert its rays back to matrix representations.
- # But first, make them negative, so we get Z-transformations and
- # not cross-positive ones.
- M = MatrixSpace(V.base_ring(), V.dimension())
-
- return [ -M(v.list()) for v in Sigma_cone.rays() ]
+ if L.base_ring().is_exact() or L.base_ring() is SR:
+ # The "fast method" of creating a vector space based on a
+ # ``lyapunov_like_basis`` is actually slower than this.
+ return all([ s*(L*x) == 0
+ for (x,s) in K.discrete_complementarity_set() ])
+ else:
+ # The only inexact ring that we're willing to work with is SR,
+ # since it can still be exact when working with symbolic
+ # constants like pi and e.
+ raise ValueError('base ring of operator L is neither SR nor exact')
+
+def LL_cone(K):
+ gens = K.lyapunov_like_basis()
+ L = ToricLattice(K.lattice_dim()**2)
+ return Cone([ g.list() for g in gens ], lattice=L, check=False)
+
+def Sigma_cone(K):
+ gens = K.cross_positive_operators_gens()
+ L = ToricLattice(K.lattice_dim()**2)
+ return Cone([ g.list() for g in gens ], lattice=L, check=False)
+
+def Z_cone(K):
+ gens = K.Z_operators_gens()
+ L = ToricLattice(K.lattice_dim()**2)
+ return Cone([ g.list() for g in gens ], lattice=L, check=False)
+
+def pi_cone(K1, K2=None):
+ if K2 is None:
+ K2 = K1
+ gens = K1.positive_operators_gens(K2)
+ L = ToricLattice(K1.lattice_dim()*K2.lattice_dim())
+ return Cone([ g.list() for g in gens ], lattice=L, check=False)