+ sage: n = ZZ.random_element().abs()
+ sage: K = Cone([[0] * n], ToricLattice(n))
+ sage: K.is_trivial()
+ True
+ sage: L = ToricLattice(n^2)
+ sage: pi_of_K = positive_operator_gens(K)
+ sage: actual = Cone([p.list() for p in pi_of_K], lattice=L).lineality()
+ sage: actual == n^2
+ True
+ sage: K = K.dual()
+ sage: K.is_full_space()
+ True
+ sage: pi_of_K = positive_operator_gens(K)
+ sage: actual = Cone([p.list() for p in pi_of_K], lattice=L).lineality()
+ sage: actual == n^2
+ True
+ sage: K = Cone([(1,0),(0,1),(0,-1)])
+ sage: pi_of_K = positive_operator_gens(K)
+ sage: actual = Cone([p.list() for p in pi_of_K]).lineality()
+ sage: actual == 2
+ True
+
+ A cone is proper if and only if its cone of positive operators
+ is proper::
+
+ sage: set_random_seed()
+ sage: K = random_cone(max_ambient_dim=5)
+ sage: pi_of_K = positive_operator_gens(K)
+ sage: L = ToricLattice(K.lattice_dim()**2)
+ sage: pi_cone = Cone([p.list() for p in pi_of_K], lattice=L)
+ sage: K.is_proper() == pi_cone.is_proper()
+ True
+ """
+ # Matrices are not vectors in Sage, so we have to convert them
+ # to vectors explicitly before we can find a basis. We need these
+ # two values to construct the appropriate "long vector" space.
+ F = K.lattice().base_field()
+ n = K.lattice_dim()
+
+ tensor_products = [ s.tensor_product(x) for x in K for s in K.dual() ]
+
+ # Convert those tensor products to long vectors.
+ W = VectorSpace(F, n**2)
+ vectors = [ W(tp.list()) for tp in tensor_products ]
+
+ # Create the *dual* cone of the positive operators, expressed as
+ # long vectors. WARNING: check=True is necessary even though it
+ # makes Cone() take forever. For an example take
+ # K = Cone([(1,0,0),(0,0,1),(0,0,-1)]).
+ pi_dual = Cone(vectors, ToricLattice(W.dimension()))
+
+ # Now compute the desired cone from its dual...
+ pi_cone = pi_dual.dual()
+
+ # And finally convert its rays back to matrix representations.
+ M = MatrixSpace(F, n)
+ return [ M(v.list()) for v in pi_cone.rays() ]
+
+
+def Z_transformation_gens(K):
+ r"""
+ Compute generators of the cone of Z-transformations on this cone.