From 805b61b3751065f9c7d36280ce22d961d207553c Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 12 Oct 2015 11:59:22 -0400 Subject: [PATCH] Move basically_the_same() into tests.py and call it _look_isomorphic(). --- mjo/cone/tests.py | 89 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/mjo/cone/tests.py b/mjo/cone/tests.py index 1758f8b..550beb3 100644 --- a/mjo/cone/tests.py +++ b/mjo/cone/tests.py @@ -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 """ -- 2.44.2