- """
- # First we want to intersect ``K`` with ``W``. The easiest way to
- # do this is via cone intersection, so we turn the subspace ``W``
- # into a cone.
- W_cone = Cone(W.basis() + [-b for b in W.basis()], lattice=K.lattice())
- K = K.intersection(W_cone)
-
- # We've already intersected K with the span of K2, so every
- # generator of K should belong to W now.
- K_W_rays = [ W.coordinate_vector(r) for r in K.rays() ]
-
- L = ToricLattice(W.dimension())
- return Cone(K_W_rays, lattice=L)
-
-
-
-def discrete_complementarity_set(K):
- r"""
- Compute a discrete complementarity set of this cone.
-
- A discrete complementarity set of `K` is the set of all orthogonal
- pairs `(x,s)` such that `x \in G_{1}` and `s \in G_{2}` for some
- generating sets `G_{1}` of `K` and `G_{2}` of its dual. Polyhedral
- convex cones are input in terms of their generators, so "the" (this
- particular) discrete complementarity set corresponds to ``G1
- == K.rays()`` and ``G2 == K.dual().rays()``.
-
- OUTPUT:
-
- A list of pairs `(x,s)` such that,
-
- * Both `x` and `s` are vectors (not rays).
- * `x` is one of ``K.rays()``.
- * `s` is one of ``K.dual().rays()``.
- * `x` and `s` are orthogonal.
-
- REFERENCES:
-
- .. [Orlitzky/Gowda] M. Orlitzky and M. S. Gowda. The Lyapunov Rank of an
- Improper Cone. Work in-progress.
-
- EXAMPLES:
-
- The discrete complementarity set of the nonnegative orthant consists
- of pairs of standard basis vectors::
-
- sage: K = Cone([(1,0),(0,1)])
- sage: discrete_complementarity_set(K)
- [((1, 0), (0, 1)), ((0, 1), (1, 0))]
-
- If the cone consists of a single ray, the second components of the
- discrete complementarity set should generate the orthogonal
- complement of that ray::
-
- sage: K = Cone([(1,0)])
- sage: discrete_complementarity_set(K)
- [((1, 0), (0, 1)), ((1, 0), (0, -1))]
- sage: K = Cone([(1,0,0)])
- sage: discrete_complementarity_set(K)
- [((1, 0, 0), (0, 1, 0)),
- ((1, 0, 0), (0, -1, 0)),
- ((1, 0, 0), (0, 0, 1)),
- ((1, 0, 0), (0, 0, -1))]
-
- When the cone is the entire space, its dual is the trivial cone, so
- the discrete complementarity set is empty::
-
- sage: K = Cone([(1,0),(-1,0),(0,1),(0,-1)])
- sage: discrete_complementarity_set(K)
- []
-
- Likewise when this cone is trivial (its dual is the entire space)::
-
- sage: L = ToricLattice(0)
- sage: K = Cone([], ToricLattice(0))
- sage: discrete_complementarity_set(K)
- []
-
- TESTS: