]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/tests.py
Replace _rho with _restrict_to_space in cone/tests.py.
[sage.d.git] / mjo / cone / tests.py
1 """
2 Additional tests for the mjo.cone.cone module. These are extra
3 properties that we'd like to check, but which are overkill for inclusion
4 into Sage.
5 """
6
7 # Sage doesn't load ~/.sage/init.sage during testing (sage -t), so we
8 # have to explicitly mangle our sitedir here so that "mjo.cone"
9 # resolves.
10 from os.path import abspath
11 from site import addsitedir
12 addsitedir(abspath('../../'))
13
14 from sage.all import *
15
16 # The double-import is needed to get the underscore methods.
17 from mjo.cone.cone import *
18 from mjo.cone.cone import _basically_the_same, _restrict_to_space
19
20 #
21 # Tests for _restrict_to_space.
22 #
23 """
24 Apply _restrict_to_space according to our paper (to obtain our main
25 result). Test all four parameter combinations::
26
27 sage: set_random_seed()
28 sage: K = random_cone(max_ambient_dim = 8,
29 ....: strictly_convex=False,
30 ....: solid=False)
31 sage: K_S = _restrict_to_space(K, K.span())
32 sage: K_SP = _restrict_to_space(K_S.dual(), K_S.dual().span()).dual()
33 sage: K_SP.is_proper()
34 True
35 sage: K_SP = _restrict_to_space(K_S, K_S.dual().span())
36 sage: K_SP.is_proper()
37 True
38
39 ::
40
41 sage: set_random_seed()
42 sage: K = random_cone(max_ambient_dim = 8,
43 ....: strictly_convex=True,
44 ....: solid=False)
45 sage: K_S = _restrict_to_space(K, K.span())
46 sage: K_SP = _restrict_to_space(K_S.dual(), K_S.dual().span()).dual()
47 sage: K_SP.is_proper()
48 True
49 sage: K_SP = _restrict_to_space(K_S, K_S.dual().span())
50 sage: K_SP.is_proper()
51 True
52
53 ::
54
55 sage: set_random_seed()
56 sage: K = random_cone(max_ambient_dim = 8,
57 ....: strictly_convex=False,
58 ....: solid=True)
59 sage: K_S = _restrict_to_space(K, K.span())
60 sage: K_SP = _restrict_to_space(K_S.dual(), K_S.dual().span()).dual()
61 sage: K_SP.is_proper()
62 True
63 sage: K_SP = _restrict_to_space(K_S, K_S.dual().span())
64 sage: K_SP.is_proper()
65 True
66
67 ::
68
69 sage: set_random_seed()
70 sage: K = random_cone(max_ambient_dim = 8,
71 ....: strictly_convex=True,
72 ....: solid=True)
73 sage: K_S = _restrict_to_space(K, K.span())
74 sage: K_SP = _restrict_to_space(K_S.dual(), K_S.dual().span()).dual()
75 sage: K_SP.is_proper()
76 True
77 sage: K_SP = _restrict_to_space(K_S, K_S.dual().span())
78 sage: K_SP.is_proper()
79 True
80
81 Test the proposition in our paper concerning the duals and
82 restrictions. Generate a random cone, then create a subcone of
83 it. The operation of dual-taking should then commute with rho. Test
84 all parameter combinations::
85
86
87 sage: set_random_seed()
88 sage: J = random_cone(max_ambient_dim = 8,
89 ....: solid=False,
90 ....: strictly_convex=False)
91 sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
92 sage: K_W_star = _restrict_to_space(K, J.span()).dual()
93 sage: K_star_W = _restrict_to_space(K.dual(), J.span())
94 sage: _basically_the_same(K_W_star, K_star_W)
95 True
96
97 ::
98
99 sage: set_random_seed()
100 sage: J = random_cone(max_ambient_dim = 8,
101 ....: solid=True,
102 ....: strictly_convex=False)
103 sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
104 sage: K_W_star = _restrict_to_space(K, J.span()).dual()
105 sage: K_star_W = _restrict_to_space(K.dual(), J.span())
106 sage: _basically_the_same(K_W_star, K_star_W)
107 True
108
109 ::
110
111 sage: set_random_seed()
112 sage: J = random_cone(max_ambient_dim = 8,
113 ....: solid=False,
114 ....: strictly_convex=True)
115 sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
116 sage: K_W_star = _restrict_to_space(K, J.span()).dual()
117 sage: K_star_W = _restrict_to_space(K.dual(), J.span())
118 sage: _basically_the_same(K_W_star, K_star_W)
119 True
120
121 ::
122
123 sage: set_random_seed()
124 sage: J = random_cone(max_ambient_dim = 8,
125 ....: solid=True,
126 ....: strictly_convex=True)
127 sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
128 sage: K_W_star = _restrict_to_space(K, J.span()).dual()
129 sage: K_star_W = _restrict_to_space(K.dual(), J.span())
130 sage: _basically_the_same(K_W_star, K_star_W)
131 True
132
133 """
134
135
136 #
137 # Lyapunov rank tests
138 #
139 """
140
141 The Lyapunov rank is invariant under a linear isomorphism. Check all
142 combinations of parameters::
143
144 sage: K1 = random_cone(max_ambient_dim=8,
145 ....: strictly_convex=True,
146 ....: solid=True)
147 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
148 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
149 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
150 True
151
152 ::
153
154 sage: K1 = random_cone(max_ambient_dim=8,
155 ....: strictly_convex=True,
156 ....: solid=False)
157 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
158 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
159 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
160 True
161
162 ::
163
164 sage: K1 = random_cone(max_ambient_dim=8,
165 ....: strictly_convex=False,
166 ....: solid=True)
167 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
168 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
169 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
170 True
171
172 ::
173
174 sage: K1 = random_cone(max_ambient_dim=8,
175 ....: strictly_convex=False,
176 ....: solid=False)
177 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
178 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
179 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
180 True
181
182 The Lyapunov rank of a dual cone should be the same as the original
183 cone. Check all combinations of parameters::
184
185 sage: set_random_seed()
186 sage: K = random_cone(max_ambient_dim=8,
187 ....: strictly_convex=False,
188 ....: solid=False)
189 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
190 True
191
192 ::
193
194 sage: set_random_seed()
195 sage: K = random_cone(max_ambient_dim=8,
196 ....: strictly_convex=False,
197 ....: solid=True)
198 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
199 True
200
201 ::
202
203 sage: set_random_seed()
204 sage: K = random_cone(max_ambient_dim=8,
205 ....: strictly_convex=True,
206 ....: solid=False)
207 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
208 True
209
210 ::
211
212 sage: set_random_seed()
213 sage: K = random_cone(max_ambient_dim=8,
214 ....: strictly_convex=True,
215 ....: solid=True)
216 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
217 True
218
219 The Lyapunov rank of a cone ``K`` is the dimension of ``LL(K)``. Check
220 all combinations of parameters::
221
222 sage: set_random_seed()
223 sage: K = random_cone(max_ambient_dim=8,
224 ....: strictly_convex=True,
225 ....: solid=True)
226 sage: lyapunov_rank(K) == len(LL(K))
227 True
228
229 ::
230
231 sage: set_random_seed()
232 sage: K = random_cone(max_ambient_dim=8,
233 ....: strictly_convex=True,
234 ....: solid=False)
235 sage: lyapunov_rank(K) == len(LL(K))
236 True
237
238 ::
239
240 sage: set_random_seed()
241 sage: K = random_cone(max_ambient_dim=8,
242 ....: strictly_convex=False,
243 ....: solid=True)
244 sage: lyapunov_rank(K) == len(LL(K))
245 True
246
247 ::
248
249 sage: set_random_seed()
250 sage: K = random_cone(max_ambient_dim=8,
251 ....: strictly_convex=False,
252 ....: solid=False)
253 sage: lyapunov_rank(K) == len(LL(K))
254 True
255
256 """