@@ -32,33 +32,33 @@ from sage.modules.free_module import FreeModule
32
32
# full-dimensional case, the Smith normal form takes care of that for
33
33
# you.
34
34
#
35
- # # def parallelotope_points(spanning_points, lattice):
36
- # # # compute points in the open parallelotope, see [BK2001]
37
- # # R = matrix(spanning_points).transpose()
38
- # # D,U,V = R.smith_form()
39
- # # e = D.diagonal() # the elementary divisors
40
- # # d = prod(e) # the determinant
41
- # # u = U.inverse().columns() # generators for gp(semigroup)
42
- # #
43
- # # # "inverse" of the ray matrix as far as possible over ZZ
44
- # # # R*Rinv == diagonal_matrix([d]*D.ncols() + [0]*(D.nrows()-D.ncols()))
45
- # # # If R is full rank, this is Rinv = matrix(ZZ, R.inverse() * d)
46
- # # Dinv = D.transpose()
47
- # # for i in range(D.ncols()):
48
- # # Dinv[i,i] = d/D[i,i]
49
- # # Rinv = V * Dinv * U
50
- # #
51
- # # gens = []
52
- # # for b in CartesianProduct(*[ range(i) for i in e ]):
53
- # # # this is our generator modulo the lattice spanned by the rays
54
- # # gen_mod_rays = sum( b_i*u_i for b_i, u_i in zip(b,u) )
55
- # # q_times_d = Rinv * gen_mod_rays
56
- # # q_times_d = vector(ZZ,[ q_i % d for q_i in q_times_d ])
57
- # # gen = lattice(R*q_times_d / d)
58
- # # gen.set_immutable()
59
- # # gens.append(gen)
60
- # # assert(len(gens) == d)
61
- # # return tuple(gens)
35
+ # def parallelotope_points(spanning_points, lattice):
36
+ # # compute points in the open parallelotope, see [BK2001]
37
+ # R = matrix(spanning_points).transpose()
38
+ # D,U,V = R.smith_form()
39
+ # e = D.diagonal() # the elementary divisors
40
+ # d = prod(e) # the determinant
41
+ # u = U.inverse().columns() # generators for gp(semigroup)
42
+ #
43
+ # # "inverse" of the ray matrix as far as possible over ZZ
44
+ # # R*Rinv == diagonal_matrix([d]*D.ncols() + [0]*(D.nrows()-D.ncols()))
45
+ # # If R is full rank, this is Rinv = matrix(ZZ, R.inverse() * d)
46
+ # Dinv = D.transpose()
47
+ # for i in range(D.ncols()):
48
+ # Dinv[i,i] = d/D[i,i]
49
+ # Rinv = V * Dinv * U
50
+ #
51
+ # gens = []
52
+ # for b in CartesianProduct(*[range(i) for i in e]):
53
+ # # this is our generator modulo the lattice spanned by the rays
54
+ # gen_mod_rays = sum(b_i*u_i for b_i, u_i in zip(b,u))
55
+ # q_times_d = Rinv * gen_mod_rays
56
+ # q_times_d = vector(ZZ, [ q_i % d for q_i in q_times_d])
57
+ # gen = lattice(R*q_times_d / d)
58
+ # gen.set_immutable()
59
+ # gens.append(gen)
60
+ # assert(len(gens) == d)
61
+ # return tuple(gens)
62
62
#
63
63
# The problem with the naive implementation is that it is slow:
64
64
#
@@ -115,7 +115,7 @@ cpdef tuple parallelotope_points(spanning_points, lattice):
115
115
116
116
A non-smooth cone::
117
117
118
- sage: c = Cone( [ (1,0), (1,2) ])
118
+ sage: c = Cone( [(1,0), (1,2) ])
119
119
sage: parallelotope_points( c. rays( ) , c. lattice( ))
120
120
( N( 0, 0) , N( 1, 1))
121
121
@@ -162,13 +162,13 @@ cpdef tuple ray_matrix_normal_form(R):
162
162
sage: ray_matrix_normal_form( R)
163
163
( [3 ], 3, [1 ])
164
164
"""
165
- D,U, V = R.smith_form()
165
+ D, U, V = R.smith_form()
166
166
e = D.diagonal() # the elementary divisors
167
167
cdef Integer d = prod(e) # the determinant
168
168
if d == ZZ.zero():
169
169
raise ValueError (' The spanning points are not linearly independent!' )
170
170
cdef int i
171
- Dinv = diagonal_matrix(ZZ, [ d // e[i] for i in range (D.ncols()) ])
171
+ Dinv = diagonal_matrix(ZZ, [d // e[i] for i in range (D.ncols())])
172
172
VDinv = V * Dinv
173
173
return (e, d, VDinv)
174
174
@@ -212,20 +212,20 @@ cpdef tuple loop_over_parallelotope_points(e, d, MatrixClass VDinv,
212
212
cdef int i, j
213
213
cdef int dim = VDinv.nrows()
214
214
cdef int ambient_dim = R.nrows()
215
- s = ZZ.zero() # summation variable
215
+ s = ZZ.zero() # summation variable
216
216
cdef list gens = []
217
217
gen = lattice(ZZ.zero())
218
218
cdef VectorClass q_times_d = vector(ZZ, dim)
219
- for base in itertools.product(* [ range (i) for i in e ]):
219
+ for base in itertools.product(* [range (i) for i in e]):
220
220
for i in range (dim):
221
221
s = ZZ.zero()
222
222
for j in range (dim):
223
- s += VDinv.get_unsafe(i,j) * base[j]
223
+ s += VDinv.get_unsafe(i, j) * base[j]
224
224
q_times_d.set_unsafe(i, s % d)
225
225
for i in range (ambient_dim):
226
226
s = ZZ.zero()
227
227
for j in range (dim):
228
- s += R.get_unsafe(i,j) * q_times_d.get_unsafe(j)
228
+ s += R.get_unsafe(i, j) * q_times_d.get_unsafe(j)
229
229
gen[i] = s / d
230
230
if A is not None :
231
231
s = ZZ.zero()
@@ -572,7 +572,7 @@ cpdef rectangular_box_points(list box_min, list box_max,
572
572
v.set_unsafe(i, Integer(p[orig_perm[i]]))
573
573
v_copy = copy.copy(v)
574
574
v_copy.set_immutable()
575
- points.append( (v_copy, saturated) )
575
+ points.append((v_copy, saturated))
576
576
577
577
return tuple (points)
578
578
@@ -694,7 +694,7 @@ cdef loop_over_rectangular_box_points_saturated(list box_min, list box_max,
694
694
while i <= i_max:
695
695
p[0 ] = i
696
696
saturated = inequalities.satisfied_as_equalities(i)
697
- points.append( (tuple (p), saturated) )
697
+ points.append((tuple (p), saturated))
698
698
i += 1
699
699
# finally increment the other entries in p to move on to next inner loop
700
700
inc = 1
@@ -917,8 +917,8 @@ cdef class Inequality_int:
917
917
if self .dim > 0 :
918
918
self .coeff_next = self .A[1 ]
919
919
# finally, make sure that there cannot be any overflow during the enumeration
920
- self ._to_int(abs (ZZ(b)) + sum ( abs (ZZ(A[i])) * ZZ(max_abs_coordinates[i])
921
- for i in range (self .dim) ))
920
+ self ._to_int(abs (ZZ(b)) + sum (abs (ZZ(A[i])) * ZZ(max_abs_coordinates[i])
921
+ for i in range (self .dim)))
922
922
923
923
def __repr__ (self ):
924
924
"""
@@ -1131,7 +1131,7 @@ cdef class InequalityCollection:
1131
1131
"""
1132
1132
cdef list A
1133
1133
cdef int index
1134
- for index,c in enumerate (polyhedron.minimized_constraints()):
1134
+ for index, c in enumerate (polyhedron.minimized_constraints()):
1135
1135
A = perm_action(permutation, [Integer(mpz) for mpz in c.coefficients()])
1136
1136
b = Integer(c.inhomogeneous_term())
1137
1137
try :
@@ -1141,7 +1141,7 @@ cdef class InequalityCollection:
1141
1141
H = Inequality_generic(A, b, index)
1142
1142
self .ineqs_generic.append(H)
1143
1143
if c.is_equality():
1144
- A = [ - a for a in A ]
1144
+ A = [- a for a in A]
1145
1145
b = - b
1146
1146
try :
1147
1147
H = Inequality_int(A, b, max_abs_coordinates, index)
@@ -1194,7 +1194,7 @@ cdef class InequalityCollection:
1194
1194
H = Inequality_generic(A, b, Hrep_obj.index())
1195
1195
self .ineqs_generic.append(H)
1196
1196
# add sign-reversed inequality
1197
- A = [ - a for a in A ]
1197
+ A = [- a for a in A]
1198
1198
b = - b
1199
1199
try :
1200
1200
H = Inequality_int(A, b, max_abs_coordinates, Hrep_obj.index())
@@ -1310,7 +1310,7 @@ cdef class InequalityCollection:
1310
1310
"""
1311
1311
i_th_entry = self .ineqs_int[i]
1312
1312
cdef int j
1313
- for j in range (i- 1 ,- 1 ,- 1 ):
1313
+ for j in range (i- 1 , - 1 , - 1 ):
1314
1314
self .ineqs_int[j+ 1 ] = self .ineqs_int[j]
1315
1315
self .ineqs_int[0 ] = i_th_entry
1316
1316
@@ -1389,12 +1389,12 @@ cdef class InequalityCollection:
1389
1389
sig_check()
1390
1390
ineq = self .ineqs_int[i]
1391
1391
if (< Inequality_int> ineq).is_equality(inner_loop_variable):
1392
- result.append( (< Inequality_int> ineq).index )
1392
+ result.append((< Inequality_int> ineq).index)
1393
1393
for i in range (len (self .ineqs_generic)):
1394
1394
sig_check()
1395
1395
ineq = self .ineqs_generic[i]
1396
1396
if (< Inequality_generic> ineq).is_equality(inner_loop_variable):
1397
- result.append( (< Inequality_generic> ineq).index )
1397
+ result.append((< Inequality_generic> ineq).index)
1398
1398
return frozenset (result)
1399
1399
1400
1400
0 commit comments