-
- """
- # 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 the discrete complementarity set of this cone.
-
- The complementarity set of a cone is the set of all orthogonal pairs
- `(x,s)` such that `x` is in the cone, and `s` is in its dual. The
- discrete complementarity set is a subset of the complementarity set
- where `x` and `s` are required to be generators of their respective
- cones.
-
- For polyhedral cones, the discrete complementarity set is always
- finite.
-
- OUTPUT:
-
- A list of pairs `(x,s)` such that,
-
- * Both `x` and `s` are vectors (not rays).
- * `x` is a generator of this cone.
- * `s` is a generator of this cone's dual.
- * `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:
-
- The complementarity set of the dual can be obtained by switching the
- components of the complementarity set of the original cone::
-
- sage: set_random_seed()
- sage: K1 = random_cone(max_ambient_dim=6)
- sage: K2 = K1.dual()
- sage: expected = [(x,s) for (s,x) in discrete_complementarity_set(K2)]
- sage: actual = discrete_complementarity_set(K1)
- sage: sorted(actual) == sorted(expected)