]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/cone/cone.py
Add SEEALSO blocks and inexact ring error tests.
[sage.d.git] / mjo / cone / cone.py
index 3f5a4fed4e1c49853f00eafcf6084744223ca296..aeec0c90b5f582c8ba858d4b616fff191fb6d529 100644 (file)
-# Sage doesn't load ~/.sage/init.sage during testing (sage -t), so we
-# have to explicitly mangle our sitedir here so that "mjo.cone"
-# resolves.
-from os.path import abspath
-from site import addsitedir
-addsitedir(abspath('../../'))
-
 from sage.all import *
+from sage.geometry.cone import is_Cone
 
-def rename_lattice(L,s):
+def is_positive_on(L,K):
     r"""
-    Change all names of the given lattice to ``s``.
-    """
-    L._name = s
-    L._dual_name = s
-    L._latex_name = s
-    L._latex_dual_name = s
+    Determine whether or not ``L`` is positive on ``K``.
 
-def span_iso(K):
-    r"""
-    Return an isomorphism (and its inverse) that will send ``K`` into a
-    lower-dimensional space isomorphic to its span (and back).
+    We say that ``L`` is positive on a closed convex cone ``K`` if
+    `L\left\lparen x \right\rparen` belongs to ``K`` for all `x` in
+    ``K``. This property need only be checked for generators of ``K``.
 
-    EXAMPLES:
+    To reliably check whether or not ``L`` is positive, its base ring
+    must be either exact (for example, the rationals) or ``SR``. An
+    exact ring is more reliable, but in some cases a matrix whose
+    entries contain symbolic constants like ``e`` and ``pi`` will work.
 
-    The inverse composed with the isomorphism should be the identity::
+    INPUT:
 
-        sage: K = random_cone(max_dim=10)
-        sage: (phi, phi_inv) = span_iso(K)
-        sage: phi_inv(phi(K)) == K
-        True
+    - ``L`` -- A matrix over either an exact ring or ``SR``.
 
-    The image of ``K`` under the isomorphism should have full dimension::
+    - ``K`` -- A polyhedral closed convex cone.
 
-        sage: K = random_cone(max_dim=10)
-        sage: (phi, phi_inv) = span_iso(K)
-        sage: phi(K).dim() == phi(K).lattice_dim()
-        True
+    OUTPUT:
 
-    The isomorphism should be an inner product space isomorphism, and
-    thus it should preserve dual cones (and commute with the "dual"
-    operation). But beware the automatic renaming of the dual lattice.
-    OH AND YOU HAVE TO SORT THE CONES::
+    If the base ring of ``L`` is exact, then ``True`` will be returned if
+    and only if ``L`` is positive on ``K``.
 
-        sage: K = random_cone(max_dim=10, strictly_convex=False, solid=True)
-        sage: L = K.lattice()
-        sage: rename_lattice(L, 'L')
-        sage: (phi, phi_inv) = span_iso(K)
-        sage: sorted(phi_inv( phi(K).dual() )) == sorted(K.dual())
-        True
+    If the base ring of ``L`` is ``SR``, then the situation is more
+    complicated:
 
-    We may need to isomorph twice to make sure we stop moving down to
-    smaller spaces. (Once you've done this on a cone and its dual, the
-    result should be proper.) OH AND YOU HAVE TO SORT THE CONES::
-
-        sage: K = random_cone(max_dim=10, strictly_convex=False, solid=False)
-        sage: L = K.lattice()
-        sage: rename_lattice(L, 'L')
-        sage: (phi, phi_inv) = span_iso(K)
-        sage: K_S = phi(K)
-        sage: (phi_dual, phi_dual_inv) = span_iso(K_S.dual())
-        sage: J_T = phi_dual(K_S.dual()).dual()
-        sage: phi_inv(phi_dual_inv(J_T)) == K
-        True
+    - ``True`` will be returned if it can be proven that ``L``
+      is positive on ``K``.
+    - ``False`` will be returned if it can be proven that ``L``
+      is not positive on ``K``.
+    - ``False`` will also be returned if we can't decide; specifically
+      if we arrive at a symbolic inequality that cannot be resolved.
 
-    """
-    phi_domain = K.sublattice().vector_space()
-    phi_codo = VectorSpace(phi_domain.base_field(), phi_domain.dimension())
+    .. SEEALSO::
 
-    # S goes from the new space to the cone space.
-    S = linear_transformation(phi_codo, phi_domain, phi_domain.basis())
+          :func:`is_cross_positive_on`,
+          :func:`is_Z_operator_on`,
+          :func:`is_lyapunov_like_on`
 
-    # phi goes from the cone space to the new space.
-    def phi(J_orig):
-        r"""
-        Takes a cone ``J`` and sends it into the new space.
-        """
-        newrays = map(S.inverse(), J_orig.rays())
-        L = None
-        if len(newrays) == 0:
-            L = ToricLattice(0)
+    EXAMPLES:
 
-        return Cone(newrays, lattice=L)
+    Nonnegative matrices are positive operators on the nonnegative
+    orthant::
 
-    def phi_inverse(J_sub):
-        r"""
-        The inverse to phi which goes from the new space to the cone space.
-        """
-        newrays = map(S, J_sub.rays())
-        return Cone(newrays, lattice=K.lattice())
+        sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
+        sage: L = random_matrix(QQ,3).apply_map(abs)
+        sage: is_positive_on(L,K)
+        True
 
+    TESTS:
 
-    return (phi, phi_inverse)
+    The identity operator is always positive::
 
+        sage: set_random_seed()
+        sage: K = random_cone(max_ambient_dim=8)
+        sage: L = identity_matrix(K.lattice_dim())
+        sage: is_positive_on(L,K)
+        True
 
+    The "zero" operator is always positive::
 
-def discrete_complementarity_set(K):
-    r"""
-    Compute the discrete complementarity set of this cone.
+        sage: K = random_cone(max_ambient_dim=8)
+        sage: R = K.lattice().vector_space().base_ring()
+        sage: L = zero_matrix(R, K.lattice_dim())
+        sage: is_positive_on(L,K)
+        True
 
-    The complementarity set of this cone is the set of all orthogonal
-    pairs `(x,s)` such that `x` is in this cone, and `s` is in its
-    dual. The discrete complementarity set restricts `x` and `s` to be
-    generators of their respective cones.
+    Everything in ``K.positive_operators_gens()`` should be
+    positive on ``K``::
 
-    OUTPUT:
+        sage: K = random_cone(max_ambient_dim=5)
+        sage: all([ is_positive_on(L,K)                     # long time
+        ....:       for L in K.positive_operators_gens() ]) # long time
+        True
+        sage: all([ is_positive_on(L.change_ring(SR),K)     # long time
+        ....:       for L in K.positive_operators_gens() ]) # long time
+        True
 
-    A list of pairs `(x,s)` such that,
+    Technically we could test this, but for now only closed convex cones
+    are supported as our ``K`` argument::
 
-      * `x` is in this cone.
-      * `x` is a generator of this cone.
-      * `s` is in this cone's dual.
-      * `s` is a generator of this cone's dual.
-      * `x` and `s` are orthogonal.
+        sage: K = [ vector([1,2,3]), vector([5,-1,7]) ]
+        sage: L = identity_matrix(3)
+        sage: is_positive_on(L,K)
+        Traceback (most recent call last):
+        ...
+        TypeError: K must be a Cone.
 
-    EXAMPLES:
+    We can't give reliable answers over inexact rings::
 
-    The discrete complementarity set of the nonnegative orthant consists
-    of pairs of standard basis vectors::
+        sage: K = Cone([(1,2,3), (4,5,6)])
+        sage: L = identity_matrix(RR,3)
+        sage: is_positive_on(L,K)
+        Traceback (most recent call last):
+        ...
+        ValueError: The base ring of L is neither SR nor exact.
 
-        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::
+    if not is_Cone(K):
+        raise TypeError('K must be a Cone.')
+    if not L.base_ring().is_exact() and not L.base_ring() is SR:
+        raise ValueError('The base ring of L is neither SR nor exact.')
 
-        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))]
+    if L.base_ring().is_exact():
+        # This should be way faster than computing the dual and
+        # checking a bunch of inequalities, but it doesn't work if
+        # ``L*x`` is symbolic. For example, ``e in Cone([(1,)])``
+        # is true, but returns ``False``.
+        return all([ L*x in K for x in K ])
+    else:
+        # Fall back to inequality-checking when the entries of ``L``
+        # might be symbolic.
+        return all([ s*(L*x) >= 0 for x in K for s in K.dual() ])
 
-    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)
-        []
+def is_cross_positive_on(L,K):
+    r"""
+    Determine whether or not ``L`` is cross-positive on ``K``.
 
-    TESTS:
+    We say that ``L`` is cross-positive on a closed convex cone``K`` if
+    `\left\langle L\left\lparenx\right\rparen,s\right\rangle \ge 0` for
+    all pairs `\left\langle x,s \right\rangle` in the complementarity
+    set of ``K``. This property need only be checked for generators of
+    ``K`` and its dual.
 
-    The complementarity set of the dual can be obtained by switching the
-    components of the complementarity set of the original cone::
+    To reliably check whether or not ``L`` is cross-positive, its base
+    ring must be either exact (for example, the rationals) or ``SR``. An
+    exact ring is more reliable, but in some cases a matrix whose
+    entries contain symbolic constants like ``e`` and ``pi`` will work.
 
-        sage: K1 = random_cone(max_dim=10, max_rays=10)
-        sage: K2 = K1.dual()
-        sage: expected = [(x,s) for (s,x) in discrete_complementarity_set(K2)]
-        sage: actual = discrete_complementarity_set(K1)
-        sage: actual == expected
-        True
+    INPUT:
 
-    """
-    V = K.lattice().vector_space()
+    - ``L`` -- A matrix over either an exact ring or ``SR``.
 
-    # Convert the rays to vectors so that we can compute inner
-    # products.
-    xs = [V(x) for x in K.rays()]
-    ss = [V(s) for s in K.dual().rays()]
+    - ``K`` -- A polyhedral closed convex cone.
 
-    return [(x,s) for x in xs for s in ss if x.inner_product(s) == 0]
+    OUTPUT:
 
+    If the base ring of ``L`` is exact, then ``True`` will be returned if
+    and only if ``L`` is cross-positive on ``K``.
 
-def LL(K):
-    r"""
-    Compute the space `\mathbf{LL}` of all Lyapunov-like transformations
-    on this cone.
+    If the base ring of ``L`` is ``SR``, then the situation is more
+    complicated:
 
-    OUTPUT:
+    - ``True`` will be returned if it can be proven that ``L``
+      is cross-positive on ``K``.
+    - ``False`` will be returned if it can be proven that ``L``
+      is not cross-positive on ``K``.
+    - ``False`` will also be returned if we can't decide; specifically
+      if we arrive at a symbolic inequality that cannot be resolved.
 
-    A list of matrices forming a basis for the space of all
-    Lyapunov-like transformations on the given cone.
+    .. SEEALSO::
+
+          :func:`is_positive_on`,
+          :func:`is_Z_operator_on`,
+          :func:`is_lyapunov_like_on`
 
     EXAMPLES:
 
-    The trivial cone has no Lyapunov-like transformations::
+    The identity operator is always cross-positive::
+
+        sage: set_random_seed()
+        sage: K = random_cone(max_ambient_dim=8)
+        sage: L = identity_matrix(K.lattice_dim())
+        sage: is_cross_positive_on(L,K)
+        True
+
+    The "zero" operator is always cross-positive::
 
-        sage: L = ToricLattice(0)
-        sage: K = Cone([], lattice=L)
-        sage: LL(K)
-        []
+        sage: K = random_cone(max_ambient_dim=8)
+        sage: R = K.lattice().vector_space().base_ring()
+        sage: L = zero_matrix(R, K.lattice_dim())
+        sage: is_cross_positive_on(L,K)
+        True
 
-    The Lyapunov-like transformations on the nonnegative orthant are
-    simply diagonal matrices::
+    TESTS:
 
-        sage: K = Cone([(1,)])
-        sage: LL(K)
-        [[1]]
+    Everything in ``K.cross_positive_operators_gens()`` should be
+    cross-positive on ``K``::
 
-        sage: K = Cone([(1,0),(0,1)])
-        sage: LL(K)
-        [
-        [1 0]  [0 0]
-        [0 0], [0 1]
-        ]
+        sage: K = random_cone(max_ambient_dim=5)
+        sage: all([ is_cross_positive_on(L,K)                     # long time
+        ....:       for L in K.cross_positive_operators_gens() ]) # long time
+        True
+        sage: all([ is_cross_positive_on(L.change_ring(SR),K)     # long time
+        ....:       for L in K.cross_positive_operators_gens() ]) # long time
+        True
 
-        sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
-        sage: LL(K)
-        [
-        [1 0 0]  [0 0 0]  [0 0 0]
-        [0 0 0]  [0 1 0]  [0 0 0]
-        [0 0 0], [0 0 0], [0 0 1]
-        ]
-
-    Only the identity matrix is Lyapunov-like on the `L^{3}_{1}` and
-    `L^{3}_{\infty}` cones [Rudolf et al.]_::
-
-        sage: L31 = Cone([(1,0,1), (0,-1,1), (-1,0,1), (0,1,1)])
-        sage: LL(L31)
-        [
-        [1 0 0]
-        [0 1 0]
-        [0 0 1]
-        ]
-
-        sage: L3infty = Cone([(0,1,1), (1,0,1), (0,-1,1), (-1,0,1)])
-        sage: LL(L3infty)
-        [
-        [1 0 0]
-        [0 1 0]
-        [0 0 1]
-        ]
+    Technically we could test this, but for now only closed convex cones
+    are supported as our ``K`` argument::
 
-    TESTS:
+        sage: L = identity_matrix(3)
+        sage: K = [ vector([8,2,-8]), vector([5,-5,7]) ]
+        sage: is_cross_positive_on(L,K)
+        Traceback (most recent call last):
+        ...
+        TypeError: K must be a Cone.
 
-    The inner product `\left< L\left(x\right), s \right>` is zero for
-    every pair `\left( x,s \right)` in the discrete complementarity set
-    of the cone::
+    We can't give reliable answers over inexact rings::
 
-        sage: K = random_cone(max_dim=8, max_rays=10)
-        sage: C_of_K = discrete_complementarity_set(K)
-        sage: l = [ (L*x).inner_product(s) for (x,s) in C_of_K for L in LL(K) ]
-        sage: sum(map(abs, l))
-        0
+        sage: K = Cone([(1,2,3), (4,5,6)])
+        sage: L = identity_matrix(RR,3)
+        sage: is_cross_positive_on(L,K)
+        Traceback (most recent call last):
+        ...
+        ValueError: The base ring of L is neither SR nor exact.
 
     """
-    V = K.lattice().vector_space()
+    if not is_Cone(K):
+        raise TypeError('K must be a Cone.')
+    if not L.base_ring().is_exact() and not L.base_ring() is SR:
+        raise ValueError('The base ring of L is neither SR nor exact.')
 
-    C_of_K = discrete_complementarity_set(K)
+    return all([ s*(L*x) >= 0
+                 for (x,s) in K.discrete_complementarity_set() ])
 
-    tensor_products = [s.tensor_product(x) for (x,s) in C_of_K]
+def is_Z_operator_on(L,K):
+    r"""
+    Determine whether or not ``L`` is a Z-operator on ``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)
+    We say that ``L`` is a Z-operator on a closed convex cone``K`` if
+    `\left\langle L\left\lparenx\right\rparen,s\right\rangle \le 0` for
+    all pairs `\left\langle x,s \right\rangle` in the complementarity
+    set of ``K``. It is known that this property need only be checked
+    for generators of ``K`` and its dual.
 
-    # Turn our matrices into long vectors...
-    vectors = [ W(m.list()) for m in tensor_products ]
+    A matrix is a Z-operator on ``K`` if and only if its negation is a
+    cross-positive operator on ``K``.
 
-    # Vector space representation of Lyapunov-like matrices
-    # (i.e. vec(L) where L is Luapunov-like).
-    LL_vector = W.span(vectors).complement()
+    To reliably check whether or not ``L`` is a Z operator, its base
+    ring must be either exact (for example, the rationals) or ``SR``. An
+    exact ring is more reliable, but in some cases a matrix whose
+    entries contain symbolic constants like ``e`` and ``pi`` will work.
 
-    # Now construct an ambient MatrixSpace in which to stick our
-    # transformations.
-    M = MatrixSpace(V.base_ring(), V.dimension())
+    INPUT:
 
-    matrix_basis = [ M(v.list()) for v in LL_vector.basis() ]
+    - ``L`` -- A matrix over either an exact ring or ``SR``.
 
-    return matrix_basis
+    - ``K`` -- A polyhedral closed convex cone.
 
+    OUTPUT:
 
+    If the base ring of ``L`` is exact, then ``True`` will be returned if
+    and only if ``L`` is a Z-operator on ``K``.
 
-def lyapunov_rank(K):
-    r"""
-    Compute the Lyapunov (or bilinearity) rank of this cone.
+    If the base ring of ``L`` is ``SR``, then the situation is more
+    complicated:
 
-    The Lyapunov rank of a cone can be thought of in (mainly) two ways:
+    - ``True`` will be returned if it can be proven that ``L``
+      is a Z-operator on ``K``.
+    - ``False`` will be returned if it can be proven that ``L``
+      is not a Z-operator on ``K``.
+    - ``False`` will also be returned if we can't decide; specifically
+      if we arrive at a symbolic inequality that cannot be resolved.
 
-    1. The dimension of the Lie algebra of the automorphism group of the
-       cone.
+    .. SEEALSO::
 
-    2. The dimension of the linear space of all Lyapunov-like
-       transformations on the cone.
+          :func:`is_positive_on`,
+          :func:`is_cross_positive_on`,
+          :func:`is_lyapunov_like_on`
 
-    INPUT:
+    EXAMPLES:
 
-    A closed, convex polyhedral cone.
+    The identity operator is always a Z-operator::
 
-    OUTPUT:
+        sage: set_random_seed()
+        sage: K = random_cone(max_ambient_dim=8)
+        sage: L = identity_matrix(K.lattice_dim())
+        sage: is_Z_operator_on(L,K)
+        True
 
-    An integer representing the Lyapunov rank of the cone. If the
-    dimension of the ambient vector space is `n`, then the Lyapunov rank
-    will be between `1` and `n` inclusive; however a rank of `n-1` is
-    not possible (see the first reference).
+    The "zero" operator is always a Z-operator::
 
-    .. note::
+        sage: K = random_cone(max_ambient_dim=8)
+        sage: R = K.lattice().vector_space().base_ring()
+        sage: L = zero_matrix(R, K.lattice_dim())
+        sage: is_Z_operator_on(L,K)
+        True
 
-        In the references, the cones are always assumed to be proper. We
-        do not impose this restriction.
+    TESTS:
 
-    .. seealso::
+    Everything in ``K.Z_operators_gens()`` should be a Z-operator
+    on ``K``::
 
-        :meth:`is_proper`
+        sage: K = random_cone(max_ambient_dim=5)
+        sage: all([ is_Z_operator_on(L,K)            # long time
+        ....:       for L in K.Z_operators_gens() ]) # long time
+        True
+        sage: all([ is_Z_operator_on(L.change_ring(SR),K) # long time
+        ....:       for L in K.Z_operators_gens() ])      # long time
+        True
 
-    ALGORITHM:
+    Technically we could test this, but for now only closed convex cones
+    are supported as our ``K`` argument::
 
-    The codimension formula from the second reference is used. We find
-    all pairs `(x,s)` in the complementarity set of `K` such that `x`
-    and `s` are rays of our cone. It is known that these vectors are
-    sufficient to apply the codimension formula. Once we have all such
-    pairs, we "brute force" the codimension formula by finding all
-    linearly-independent `xs^{T}`.
+        sage: L = identity_matrix(3)
+        sage: K = [ vector([-4,20,3]), vector([1,-5,2]) ]
+        sage: is_Z_operator_on(L,K)
+        Traceback (most recent call last):
+        ...
+        TypeError: K must be a Cone.
 
-    REFERENCES:
 
-    .. [Gowda/Tao] M.S. Gowda and J. Tao. On the bilinearity rank of a proper
-       cone and Lyapunov-like transformations, Mathematical Programming, 147
-       (2014) 155-170.
+    We can't give reliable answers over inexact rings::
 
-    .. [Orlitzky/Gowda] M. Orlitzky and M. S. Gowda. The Lyapunov Rank of an
-       Improper Cone. Work in-progress.
+        sage: K = Cone([(1,2,3), (4,5,6)])
+        sage: L = identity_matrix(RR,3)
+        sage: is_Z_operator_on(L,K)
+        Traceback (most recent call last):
+        ...
+        ValueError: The base ring of L is neither SR nor exact.
 
-    .. [Rudolf et al.] G. Rudolf, N. Noyan, D. Papp, and F. Alizadeh, Bilinear
-       optimality constraints for the cone of positive polynomials,
-       Mathematical Programming, Series B, 129 (2011) 5-31.
+    """
+    return is_cross_positive_on(-L,K)
 
-    EXAMPLES:
 
-    The nonnegative orthant in `\mathbb{R}^{n}` always has rank `n`
-    [Rudolf et al.]_::
+def is_lyapunov_like_on(L,K):
+    r"""
+    Determine whether or not ``L`` is Lyapunov-like on ``K``.
 
-        sage: positives = Cone([(1,)])
-        sage: lyapunov_rank(positives)
-        1
-        sage: quadrant = Cone([(1,0), (0,1)])
-        sage: lyapunov_rank(quadrant)
-        2
-       sage: octant = Cone([(1,0,0), (0,1,0), (0,0,1)])
-        sage: lyapunov_rank(octant)
-        3
+    We say that ``L`` is Lyapunov-like on a closed convex cone ``K`` if
+    `\left\langle L\left\lparenx\right\rparen,s\right\rangle = 0` for
+    all pairs `\left\langle x,s \right\rangle` in the complementarity
+    set of ``K``. This property need only be checked for generators of
+    ``K`` and its dual.
 
-    The `L^{3}_{1}` cone is known to have a Lyapunov rank of one
-    [Rudolf et al.]_::
+    An operator is Lyapunov-like on ``K`` if and only if both the
+    operator itself and its negation are cross-positive on ``K``.
 
-        sage: L31 = Cone([(1,0,1), (0,-1,1), (-1,0,1), (0,1,1)])
-        sage: lyapunov_rank(L31)
-        1
+    To reliably check whether or not ``L`` is Lyapunov-like, its base
+    ring must be either exact (for example, the rationals) or ``SR``. An
+    exact ring is more reliable, but in some cases a matrix whose
+    entries contain symbolic constants like ``e`` and ``pi`` will work.
 
-    Likewise for the `L^{3}_{\infty}` cone [Rudolf et al.]_::
+    INPUT:
 
-        sage: L3infty = Cone([(0,1,1), (1,0,1), (0,-1,1), (-1,0,1)])
-        sage: lyapunov_rank(L3infty)
-        1
+    - ``L`` -- A matrix over either an exact ring or ``SR``.
 
-    The Lyapunov rank should be additive on a product of cones
-    [Rudolf et al.]_::
+    - ``K`` -- A polyhedral closed convex cone.
 
-        sage: L31 = Cone([(1,0,1), (0,-1,1), (-1,0,1), (0,1,1)])
-        sage: octant = Cone([(1,0,0), (0,1,0), (0,0,1)])
-        sage: K = L31.cartesian_product(octant)
-        sage: lyapunov_rank(K) == lyapunov_rank(L31) + lyapunov_rank(octant)
-        True
+    OUTPUT:
+
+    If the base ring of ``L`` is exact, then ``True`` will be returned if
+    and only if ``L`` is Lyapunov-like on ``K``.
 
-    Two isomorphic cones should have the same Lyapunov rank [Rudolf et al.]_.
-    The cone ``K`` in the following example is isomorphic to the nonnegative
-    octant in `\mathbb{R}^{3}`::
+    If the base ring of ``L`` is ``SR``, then the situation is more
+    complicated:
 
-        sage: K = Cone([(1,2,3), (-1,1,0), (1,0,6)])
-        sage: lyapunov_rank(K)
-        3
+    - ``True`` will be returned if it can be proven that ``L``
+      is Lyapunov-like on ``K``.
+    - ``False`` will be returned if it can be proven that ``L``
+      is not Lyapunov-like on ``K``.
+    - ``False`` will also be returned if we can't decide; specifically
+      if we arrive at a symbolic inequality that cannot be resolved.
 
-    The dual cone `K^{*}` of ``K`` should have the same Lyapunov rank as ``K``
-    itself [Rudolf et al.]_::
+    .. SEEALSO::
 
-        sage: K = Cone([(2,2,4), (-1,9,0), (2,0,6)])
-        sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
+          :func:`is_positive_on`,
+          :func:`is_cross_positive_on`,
+          :func:`is_Z_operator_on`
+
+    EXAMPLES:
+
+    Diagonal matrices are Lyapunov-like operators on the nonnegative
+    orthant::
+
+        sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
+        sage: L = diagonal_matrix(random_vector(QQ,3))
+        sage: is_lyapunov_like_on(L,K)
         True
 
     TESTS:
 
-    The Lyapunov rank should be additive on a product of cones
-    [Rudolf et al.]_::
+    The identity operator is always Lyapunov-like::
 
-        sage: K1 = random_cone(max_dim=10, max_rays=10)
-        sage: K2 = random_cone(max_dim=10, max_rays=10)
-        sage: K = K1.cartesian_product(K2)
-        sage: lyapunov_rank(K) == lyapunov_rank(K1) + lyapunov_rank(K2)
+        sage: set_random_seed()
+        sage: K = random_cone(max_ambient_dim=8)
+        sage: L = identity_matrix(K.lattice_dim())
+        sage: is_lyapunov_like_on(L,K)
         True
 
-    The dual cone `K^{*}` of ``K`` should have the same Lyapunov rank as ``K``
-    itself [Rudolf et al.]_::
+    The "zero" operator is always Lyapunov-like::
 
-        sage: K = random_cone(max_dim=10, max_rays=10)
-        sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
+        sage: K = random_cone(max_ambient_dim=8)
+        sage: R = K.lattice().vector_space().base_ring()
+        sage: L = zero_matrix(R, K.lattice_dim())
+        sage: is_lyapunov_like_on(L,K)
         True
 
-    The Lyapunov rank of a proper polyhedral cone in `n` dimensions can
-    be any number between `1` and `n` inclusive, excluding `n-1`
-    [Gowda/Tao]_. By accident, the `n-1` restriction will hold for the
-    trivial cone in a trivial space as well. However, in zero dimensions,
-    the Lyapunov rank of the trivial cone will be zero::
+    Everything in ``K.lyapunov_like_basis()`` should be Lyapunov-like
+    on ``K``::
 
-        sage: K = random_cone(max_dim=10, strictly_convex=True, solid=True)
-        sage: b = lyapunov_rank(K)
-        sage: n = K.lattice_dim()
-        sage: (n == 0 or 1 <= b) and b <= n
-        True
-        sage: b == n-1
-        False
-
-    In fact [Orlitzky/Gowda]_, no closed convex polyhedral cone can have
-    Lyapunov rank `n-1` in `n` dimensions::
-
-        sage: K = random_cone(max_dim=10)
-        sage: b = lyapunov_rank(K)
-        sage: n = K.lattice_dim()
-        sage: b == n-1
-        False
-
-    The calculation of the Lyapunov rank of an improper cone can be
-    reduced to that of a proper cone [Orlitzky/Gowda]_::
-
-        sage: K = random_cone(max_dim=15, solid=False, strictly_convex=False)
-        sage: actual = lyapunov_rank(K)
-        sage: (phi1, phi1_inv) = span_iso(K)
-        sage: K_S = phi1(K)
-        sage: (phi2, phi2_inv) = span_iso(K_S.dual())
-        sage: J_T = phi2(K_S.dual()).dual()
-        sage: phi1_inv(phi2_inv(J_T)) == K
+        sage: K = random_cone(max_ambient_dim=5)
+        sage: all([ is_lyapunov_like_on(L,K)            # long time
+        ....:       for L in K.lyapunov_like_basis() ]) # long time
         True
-        sage: l = K.linear_subspace().dimension()
-        sage: codim = K.lattice_dim() - K.dim()
-        sage: expected = lyapunov_rank(J_T) + K.dim()*(l + codim) + codim**2
-        sage: actual == expected
+        sage: all([ is_lyapunov_like_on(L.change_ring(SR),K) # long time
+        ....:       for L in K.lyapunov_like_basis() ])      # long time
         True
 
+    Technically we could test this, but for now only closed convex cones
+    are supported as our ``K`` argument::
+
+        sage: L = identity_matrix(3)
+        sage: K = [ vector([2,2,-1]), vector([5,4,-3]) ]
+        sage: is_lyapunov_like_on(L,K)
+        Traceback (most recent call last):
+        ...
+        TypeError: K must be a Cone.
+
+    We can't give reliable answers over inexact rings::
+
+        sage: K = Cone([(1,2,3), (4,5,6)])
+        sage: L = identity_matrix(RR,3)
+        sage: is_lyapunov_like_on(L,K)
+        Traceback (most recent call last):
+        ...
+        ValueError: The base ring of L is neither SR nor exact.
+
     """
-    return len(LL(K))
+    if not is_Cone(K):
+        raise TypeError('K must be a Cone.')
+    if not L.base_ring().is_exact() and not L.base_ring() is SR:
+        raise ValueError('The base ring of L is neither SR nor exact.')
+
+    return all([ s*(L*x) == 0
+                 for (x,s) in K.discrete_complementarity_set() ])
+
+
+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)