]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/cone/tests.py
Move basically_the_same() into tests.py and call it _look_isomorphic().
[sage.d.git] / mjo / cone / tests.py
index e059d94528c749f3d366b1ed2b00b9c610d775cc..550beb38744f1d399f492aa5d3ef2f7fcc23febb 100644 (file)
@@ -15,11 +15,90 @@ from sage.all import *
 
 # The double-import is needed to get the underscore methods.
 from mjo.cone.cone import *
-from mjo.cone.cone import _basically_the_same, _restrict_to_space
+from mjo.cone.cone import _restrict_to_space
 
 #
 # Tests for _restrict_to_space.
 #
+def _look_isomorphic(K1, K2):
+    r"""
+    Test whether or not ``K1`` and ``K2`` look linearly isomorphic.
+
+    This is a hack to get around the fact that it's difficult to tell
+    when two cones are linearly isomorphic. Instead, we check a list of
+    properties that should be preserved under linear isomorphism.
+
+    OUTPUT:
+
+    ``True`` if ``K1`` and ``K2`` look isomorphic, or ``False``
+    if we can prove that they are not isomorphic.
+
+    EXAMPLES:
+
+    Any proper cone with three generators in `\mathbb{R}^{3}` is
+    isomorphic to the nonnegative orthant::
+
+        sage: K1 = Cone([(1,0,0), (0,1,0), (0,0,1)])
+        sage: K2 = Cone([(1,2,3), (3, 18, 4), (66, 51, 0)])
+        sage: _look_isomorphic(K1, K2)
+        True
+
+    Negating a cone gives you an isomorphic cone::
+
+        sage: K = Cone([(0,2,-5), (-6, 2, 4), (0, 51, 0)])
+        sage: _look_isomorphic(K, -K)
+        True
+
+    TESTS:
+
+    Any cone is isomorphic to itself::
+
+        sage: K = random_cone(max_ambient_dim = 8)
+        sage: _look_isomorphic(K, K)
+        True
+
+    After applying an invertible matrix to the rows of a cone, the
+    result should is isomorphic to the cone we started with::
+
+        sage: K1 = random_cone(max_ambient_dim = 8)
+        sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
+        sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
+        sage: _look_isomorphic(K1, K2)
+        True
+
+    """
+    if K1.lattice_dim() != K2.lattice_dim():
+        return False
+
+    if K1.nrays() != K2.nrays():
+        return False
+
+    if K1.dim() != K2.dim():
+        return False
+
+    if K1.lineality() != K2.lineality():
+        return False
+
+    if K1.is_solid() != K2.is_solid():
+        return False
+
+    if K1.is_strictly_convex() != K2.is_strictly_convex():
+        return False
+
+    if len(K1.lyapunov_like_basis()) != len(K2.lyapunov_like_basis()):
+        return False
+
+    C_of_K1 = K1.discrete_complementarity_set()
+    C_of_K2 = K2.discrete_complementarity_set()
+    if len(C_of_K1) != len(C_of_K2):
+        return False
+
+    if len(K1.facets()) != len(K2.facets()):
+        return False
+
+    return True
+
+
 """
 Apply _restrict_to_space according to our paper (to obtain our main
 result). Test all four parameter combinations::
@@ -91,7 +170,7 @@ all parameter combinations::
     sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
     sage: K_W_star = _restrict_to_space(K, J.span()).dual()
     sage: K_star_W = _restrict_to_space(K.dual(), J.span())
-    sage: _basically_the_same(K_W_star, K_star_W)
+    sage: _look_isomorphic(K_W_star, K_star_W)
     True
 
 ::
@@ -103,7 +182,7 @@ all parameter combinations::
     sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
     sage: K_W_star = _restrict_to_space(K, J.span()).dual()
     sage: K_star_W = _restrict_to_space(K.dual(), J.span())
-    sage: _basically_the_same(K_W_star, K_star_W)
+    sage: _look_isomorphic(K_W_star, K_star_W)
     True
 
 ::
@@ -115,7 +194,7 @@ all parameter combinations::
     sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
     sage: K_W_star = _restrict_to_space(K, J.span()).dual()
     sage: K_star_W = _restrict_to_space(K.dual(), J.span())
-    sage: _basically_the_same(K_W_star, K_star_W)
+    sage: _look_isomorphic(K_W_star, K_star_W)
     True
 
 ::
@@ -127,7 +206,7 @@ all parameter combinations::
     sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
     sage: K_W_star = _restrict_to_space(K, J.span()).dual()
     sage: K_star_W = _restrict_to_space(K.dual(), J.span())
-    sage: _basically_the_same(K_W_star, K_star_W)
+    sage: _look_isomorphic(K_W_star, K_star_W)
     True
 
 """
@@ -216,14 +295,14 @@ cone. Check all combinations of parameters::
     sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
     True
 
-The Lyapunov rank of a cone ``K`` is the dimension of ``LL(K)``. Check
-all combinations of parameters::
+The Lyapunov rank of a cone ``K`` is the dimension of
+``K.lyapunov_like_basis()``. Check all combinations of parameters::
 
     sage: set_random_seed()
     sage: K = random_cone(max_ambient_dim=8,
     ....:                 strictly_convex=True,
     ....:                 solid=True)
-    sage: lyapunov_rank(K) == len(LL(K))
+    sage: lyapunov_rank(K) == len(K.lyapunov_like_basis())
     True
 
 ::
@@ -232,7 +311,7 @@ all combinations of parameters::
     sage: K = random_cone(max_ambient_dim=8,
     ....:                 strictly_convex=True,
     ....:                 solid=False)
-    sage: lyapunov_rank(K) == len(LL(K))
+    sage: lyapunov_rank(K) == len(K.lyapunov_like_basis())
     True
 
 ::
@@ -241,7 +320,7 @@ all combinations of parameters::
     sage: K = random_cone(max_ambient_dim=8,
     ....:                 strictly_convex=False,
     ....:                 solid=True)
-    sage: lyapunov_rank(K) == len(LL(K))
+    sage: lyapunov_rank(K) == len(K.lyapunov_like_basis())
     True
 
 ::
@@ -250,7 +329,7 @@ all combinations of parameters::
     sage: K = random_cone(max_ambient_dim=8,
     ....:                 strictly_convex=False,
     ....:                 solid=False)
-    sage: lyapunov_rank(K) == len(LL(K))
+    sage: lyapunov_rank(K) == len(K.lyapunov_like_basis())
     True
 
 """