16
16
# ****************************************************************************
17
17
18
18
from sage .geometry .polyhedron .constructor import Polyhedron
19
- from sage .matrix .constructor import matrix , identity_matrix
19
+ from sage .matrix .constructor import matrix
20
20
from sage .modules .free_module_element import vector
21
21
22
22
from math import sqrt , floor , ceil
23
23
24
24
25
- def plane_inequality (v ):
25
+ def plane_inequality (v ) -> list :
26
26
"""
27
27
Return the inequality for points on the same side as the origin
28
28
with respect to the plane through ``v`` normal to ``v``.
@@ -124,7 +124,7 @@ def jacobi(M):
124
124
return matrix (q )
125
125
126
126
127
- def diamond_cut (V , GM , C , verbose = False ):
127
+ def diamond_cut (V , GM , C , verbose = False ) -> Polyhedron :
128
128
r"""
129
129
Perform diamond cutting on polyhedron ``V`` with basis matrix ``GM``
130
130
and squared radius ``C``.
@@ -137,7 +137,8 @@ def diamond_cut(V, GM, C, verbose=False):
137
137
138
138
- ``C`` -- square of the radius to use in cutting algorithm
139
139
140
- - ``verbose`` -- boolean (default: ``False``); whether to print debug information
140
+ - ``verbose`` -- boolean (default: ``False``); whether to print
141
+ debug information
141
142
142
143
OUTPUT: a :class:`Polyhedron` instance
143
144
@@ -199,7 +200,7 @@ def diamond_cut(V, GM, C, verbose=False):
199
200
inequalities = []
200
201
while True :
201
202
if verbose :
202
- print ("Dimension: {}" . format ( i ) )
203
+ print (f "Dimension: { i } " )
203
204
if new_dimension :
204
205
Z = sqrt (T [i ] / q [i ][i ])
205
206
if verbose :
@@ -212,7 +213,7 @@ def diamond_cut(V, GM, C, verbose=False):
212
213
213
214
x [i ] += 1
214
215
if verbose :
215
- print ("x: {}" . format ( x ) )
216
+ print (f "x: { x } " )
216
217
if x [i ] > L [i ]:
217
218
i += 1
218
219
elif i > 0 :
@@ -249,7 +250,7 @@ def diamond_cut(V, GM, C, verbose=False):
249
250
return V
250
251
251
252
252
- def calculate_voronoi_cell (basis , radius = None , verbose = False ):
253
+ def calculate_voronoi_cell (basis , radius = None , verbose = False ) -> Polyhedron :
253
254
"""
254
255
Calculate the Voronoi cell of the lattice defined by basis.
255
256
@@ -289,7 +290,8 @@ def calculate_voronoi_cell(basis, radius=None, verbose=False):
289
290
sage: L = IntegerLattice([v])
290
291
sage: C = L.voronoi_cell()
291
292
sage: C.Hrepresentation()
292
- (An inequality (-2, -2, 2) x + 3 >= 0, An inequality (2, 2, -2) x + 3 >= 0)
293
+ (An inequality (-2, -2, 2) x + 3 >= 0,
294
+ An inequality (2, 2, -2) x + 3 >= 0)
293
295
sage: C.Vrepresentation()
294
296
(A line in the direction (0, 1, 1),
295
297
A line in the direction (1, 0, 1),
@@ -299,7 +301,8 @@ def calculate_voronoi_cell(basis, radius=None, verbose=False):
299
301
Verify that :issue:`37086` is fixed::
300
302
301
303
sage: from sage.modules.free_module_integer import IntegerLattice
302
- sage: l = [7, 0, -1, -2, -1, -2, 7, -2, 0, 0, -2, 0, 7, -2, 0, -1, -2, -1, 7, 0 , -1, -1, 0, -2, 7]
304
+ sage: l = [7, 0, -1, -2, -1, -2, 7, -2, 0, 0, -2,
305
+ ....: 0, 7, -2, 0, -1, -2, -1, 7, 0 , -1, -1, 0, -2, 7]
303
306
sage: M = matrix(5, 5, l)
304
307
sage: C = IntegerLattice(M).voronoi_cell()
305
308
sage: C
@@ -313,15 +316,15 @@ def calculate_voronoi_cell(basis, radius=None, verbose=False):
313
316
# Convert the basis matrix to use RDF numbers for efficiency when we
314
317
# calculate the triangular matrix of the QR decomposition.
315
318
from sage .rings .real_double import RDF
316
- tranposed_RDF_matrix = (basis .transpose ()).change_ring (RDF )
317
- R = tranposed_RDF_matrix .QR ()[1 ]
319
+ transposed_RDF_matrix = (basis .transpose ()).change_ring (RDF )
320
+ R = transposed_RDF_matrix .QR ()[1 ]
318
321
# The length of the vector formed by the diagonal entries of R is an
319
322
# upper bound for twice the covering radius, so it is an upper bound
320
323
# on the length of the lattice vectors that need to be considered for
321
324
# diamond cutting. However, the value of the `radius` keyword is
322
325
# actually a squared length, so there is no square root in the
323
326
# following formula.
324
- radius = sum (R [i ,i ]** 2 for i in range (dim [0 ]))
327
+ radius = sum (R [i , i ]** 2 for i in range (dim [0 ]))
325
328
# We then divide by 4 as we will divide the basis by 2 later on.
326
329
radius = ceil (radius / 4 )
327
330
artificial_length = None
@@ -336,13 +339,14 @@ def calculate_voronoi_cell(basis, radius=None, verbose=False):
336
339
from sage .rings .real_double import RDF
337
340
# Convert the basis matrix to use RDF numbers for efficiency when we
338
341
# perform the QR decomposition.
339
- tranposed_RDF_matrix = ( additional_vectors .transpose () ).change_ring (RDF )
340
- R = tranposed_RDF_matrix .QR ()[1 ]
342
+ transposed_RDF_matrix = additional_vectors .transpose ().change_ring (RDF )
343
+ R = transposed_RDF_matrix .QR ()[1 ]
341
344
# Since R is triangular, its smallest diagonal entry provides a
342
345
# lower bound on the length of the shortest nonzero vector in the
343
346
# lattice spanned by the artificial points. We square it because
344
347
# value of `radius` is a squared length.
345
- shortest_vector_lower_bound = min (R [i ,i ]** 2 for i in range (dim [1 ] - dim [0 ]))
348
+ shortest_vector_lower_bound = min (R [i , i ]** 2
349
+ for i in range (dim [1 ] - dim [0 ]))
346
350
# We will multiply our artificial points by the following scalar in
347
351
# order to make sure the squared length of the shortest
348
352
# nonzero vector is greater than radius, even after the vectors
0 commit comments