43
43
# ****************************************************************************
44
44
import itertools
45
45
from copy import copy
46
+
46
47
from sage .combinat .combination import Combinations
47
48
from sage .combinat .permutation import Permutation
48
49
from sage .functions .generalized import sign
@@ -165,7 +166,7 @@ def sgn(x, y):
165
166
return B (braid )
166
167
167
168
168
- def discrim (pols ):
169
+ def discrim (pols ) -> tuple :
169
170
r"""
170
171
Return the points in the discriminant of the product of the polynomials
171
172
of a list or tuple ``pols``.
@@ -195,9 +196,8 @@ def discrim(pols):
195
196
0.2613789792873551? - 0.4527216721561923?*I,
196
197
0.2613789792873551? + 0.4527216721561923?*I)
197
198
"""
198
- flist = tuple (pols )
199
- x , y = flist [0 ].parent ().gens ()
200
- field = flist [0 ].base_ring ()
199
+ x , y = pols [0 ].parent ().gens ()
200
+ field = pols [0 ].base_ring ()
201
201
pol_ring = PolynomialRing (field , (x ,))
202
202
203
203
@parallel
@@ -206,7 +206,7 @@ def discrim_pairs(f, g):
206
206
return pol_ring (f .discriminant (y ))
207
207
return pol_ring (f .resultant (g , y ))
208
208
209
- pairs = [(f , None ) for f in flist ] + [( f , g ) for f , g in Combinations (flist , 2 )]
209
+ pairs = [(f , None ) for f in pols ] + [tuple ( t ) for t in Combinations (pols , 2 )]
210
210
fdiscrim = discrim_pairs (pairs )
211
211
rts = ()
212
212
poly = 1
@@ -464,7 +464,7 @@ def voronoi_cells(V):
464
464
return (G , E , p , EC , DG )
465
465
466
466
467
- def followstrand (f , factors , x0 , x1 , y0a , prec = 53 ):
467
+ def followstrand (f , factors , x0 , x1 , y0a , prec = 53 ) -> list :
468
468
r"""
469
469
Return a piecewise linear approximation of the homotopy continuation
470
470
of the root ``y0a`` from ``x0`` to ``x1``.
@@ -715,7 +715,7 @@ def roots_interval(f, x0):
715
715
envelop = IF (diam ) * IF ((- 1 , 1 ), (- 1 , 1 ))
716
716
qapr = QQ (CF (r ).real ()) + QQbar .gen () * QQ (CF (r ).imag ())
717
717
if qapr not in r + envelop :
718
- raise ValueError ("Could not approximate roots with exact values" )
718
+ raise ValueError ("could not approximate roots with exact values" )
719
719
result [qapr ] = r + envelop
720
720
return result
721
721
@@ -847,7 +847,7 @@ def braid_in_segment(glist, x0, x1, precision={}):
847
847
sage: B = braid_in_segment(glist, p1b, p2b); B # optional - sirocco
848
848
s5*s3^-1
849
849
"""
850
- precision1 = { _ : precision [ _ ] for _ in precision . keys ()}
850
+ precision1 = precision . copy ()
851
851
g = prod (glist )
852
852
F1 = g .base_ring ()
853
853
x , y = g .parent ().gens ()
@@ -908,7 +908,7 @@ def braid_in_segment(glist, x0, x1, precision={}):
908
908
return initialbraid * centralbraid * finalbraid
909
909
910
910
911
- def geometric_basis (G , E , EC0 , p , dual_graph ):
911
+ def geometric_basis (G , E , EC0 , p , dual_graph ) -> list :
912
912
r"""
913
913
Return a geometric basis, based on a vertex.
914
914
@@ -982,19 +982,20 @@ def geometric_basis(G, E, EC0, p, dual_graph):
982
982
if G .size () == E .size ():
983
983
if E .is_cycle ():
984
984
return [EC ]
985
- InternalEdges = [_ for _ in G .edges (sort = True ) if _ not in E .edges (sort = True )]
985
+ edges_E = E .edges (sort = True )
986
+ InternalEdges = [e for e in G .edges (sort = True ) if e not in edges_E ]
986
987
InternalVertices = [v for e in InternalEdges for v in e [:2 ]]
987
988
Internal = G .subgraph (vertices = InternalVertices , edges = InternalEdges )
988
989
for i , ECi in enumerate (EC ): # q and r are the points we will cut through
989
990
if ECi in Internal :
990
991
EI = [v for v in E if v in Internal .connected_component_containing_vertex (ECi , sort = True ) and v != ECi ]
991
- if len ( EI ) > 0 :
992
+ if EI :
992
993
q = ECi
993
994
connecting_path = list (EC [:i ])
994
995
break
995
996
if EC [- i ] in Internal :
996
997
EI = [v for v in E if v in Internal .connected_component_containing_vertex (EC [- i ], sort = True ) and v != EC [- i ]]
997
- if len ( EI ) > 0 :
998
+ if EI :
998
999
q = EC [- i ]
999
1000
connecting_path = list (reversed (EC [- i :]))
1000
1001
break
@@ -1125,7 +1126,7 @@ def strand_components(f, flist, p1):
1125
1126
h0 = h .subs ({x : p1 })
1126
1127
h1 = F [y ](h0 )
1127
1128
rt = h1 .roots (QQbar , multiplicities = False )
1128
- roots_base += [(_ , i ) for _ in rt ]
1129
+ roots_base += [(r , i ) for r in rt ]
1129
1130
roots_base .sort ()
1130
1131
strands = {i : par [1 ] for i , par in enumerate (roots_base )} # quitar +1 despues de revision
1131
1132
return (roots_base , strands )
@@ -1206,7 +1207,7 @@ def braid_monodromy(f, arrangement=()):
1206
1207
disc = discrim (glist )
1207
1208
else :
1208
1209
disc = []
1209
- if len ( disc ) == 0 :
1210
+ if not disc :
1210
1211
result = []
1211
1212
p1 = F (0 )
1212
1213
roots_base , strands = strand_components (g , arrangement1 , p1 )
@@ -1303,8 +1304,8 @@ def conjugate_positive_form(braid):
1303
1304
cuts = [j for j in range (d + 1 ) if j not in gns ]
1304
1305
blocks = []
1305
1306
for i in range (len (cuts ) - 1 ):
1306
- block = [j for j in L1 if j > cuts [i ] and j < cuts [i + 1 ]]
1307
- if len ( block ) > 0 :
1307
+ block = [j for j in L1 if cuts [i ] < j < cuts [i + 1 ]]
1308
+ if block :
1308
1309
blocks .append (block )
1309
1310
shorts = []
1310
1311
for a in blocks :
@@ -1315,7 +1316,7 @@ def conjugate_positive_form(braid):
1315
1316
A1 = rightnormalform (sg )
1316
1317
par = A1 [- 1 ][0 ] % 2
1317
1318
A1 = [B (a ) for a in A1 [:- 1 ]]
1318
- if len ( A1 ) == 0 :
1319
+ if not A1 :
1319
1320
b = B .one ()
1320
1321
else :
1321
1322
b = prod (A1 )
@@ -1378,8 +1379,8 @@ def braid2rels(L):
1378
1379
br1 = B0 .delta ()** r * B0 (prod (B0 (_ ) for _ in br0_left [1 :]))
1379
1380
cox = prod (F0 .gens ())
1380
1381
U0 = [cox ** q * (f0 * br1 ) / cox ** q / f0 for f0 in F0 .gens ()[:- 1 ]]
1381
- U = [tuple (sign (k1 )* (abs (k1 ) + k ) for k1 in _ .Tietze ()) for _ in U0 ]
1382
- pasos = [B .one ()] + [ _ for _ in reversed (L1 )]
1382
+ U = [tuple (sign (k1 ) * (abs (k1 ) + k ) for k1 in _ .Tietze ()) for _ in U0 ]
1383
+ pasos = [B .one ()] + list ( reversed (L1 ))
1383
1384
for C in pasos :
1384
1385
U = [(F (a ) * C .inverse ()).Tietze () for a in U ]
1385
1386
ga = F / U
@@ -1465,7 +1466,7 @@ def fundamental_group_from_braid_mon(bm, degree=None, simplified=True, projectiv
1465
1466
"""
1466
1467
vertical0 = sorted (vertical )
1467
1468
v = len (vertical0 )
1468
- if bm == [] :
1469
+ if not bm :
1469
1470
d = degree
1470
1471
else :
1471
1472
d = bm [0 ].parent ().strands ()
@@ -1605,7 +1606,7 @@ def fundamental_group(f, simplified=True, projective=False, puiseux=False):
1605
1606
while g .degree (y ) < g .degree ():
1606
1607
g = g .subs ({x : x + y })
1607
1608
bm = braid_monodromy (g )[0 ]
1608
- if bm == [] :
1609
+ if not bm :
1609
1610
d = g .degree (y )
1610
1611
else :
1611
1612
d = bm [0 ].parent ().strands ()
@@ -1691,15 +1692,15 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, puis
1691
1692
arrangements, even for hyperplane arrangements defined over a number
1692
1693
subfield of ``QQbar`` after applying a generic line section.
1693
1694
"""
1694
- if len ( flist ) > 0 :
1695
+ if flist :
1695
1696
f = prod (flist )
1696
1697
R = f .parent ()
1697
1698
else :
1698
1699
R = PolynomialRing (QQ , ('x' , 'y' ))
1699
1700
f = R (1 )
1700
1701
x , y = R .gens ()
1701
1702
F = R .base_ring ()
1702
- flist1 = [ _ for _ in flist ]
1703
+ flist1 = list ( flist )
1703
1704
d = f .degree (y )
1704
1705
while not f .coefficient (y ** d ) in F :
1705
1706
flist1 = [g .subs ({x : x + y }) for g in flist1 ]
@@ -1709,7 +1710,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, puis
1709
1710
while f .degree (y ) < f .degree ():
1710
1711
flist1 = [g .subs ({x : x + y }) for g in flist ]
1711
1712
f = prod (flist1 )
1712
- if len ( flist1 ) == 0 :
1713
+ if not flist1 :
1713
1714
bm = []
1714
1715
dic = {}
1715
1716
else :
@@ -1720,7 +1721,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, puis
1720
1721
else :
1721
1722
hom = g .hom (codomain = g , im_gens = list (g .gens ()), check = False )
1722
1723
g1 = hom .codomain ()
1723
- if len ( flist ) == 0 :
1724
+ if not flist :
1724
1725
return (g1 , {})
1725
1726
dic1 = {}
1726
1727
for i in range (len (flist1 )):
0 commit comments