Skip to content

Commit 9a1a964

Browse files
author
Release Manager
committed
gh-37281: details in Zariski-Van-Kampen Small changes in the modified files, about pep8 and ruff warnings about code ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #37281 Reported by: Frédéric Chapoton Reviewer(s): grhkm21, Martin Rubey
2 parents c02dfc4 + bdf89ec commit 9a1a964

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/sage/schemes/curves/zariski_vankampen.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
# ****************************************************************************
4444
import itertools
4545
from copy import copy
46+
4647
from sage.combinat.combination import Combinations
4748
from sage.combinat.permutation import Permutation
4849
from sage.functions.generalized import sign
@@ -165,7 +166,7 @@ def sgn(x, y):
165166
return B(braid)
166167

167168

168-
def discrim(pols):
169+
def discrim(pols) -> tuple:
169170
r"""
170171
Return the points in the discriminant of the product of the polynomials
171172
of a list or tuple ``pols``.
@@ -195,9 +196,8 @@ def discrim(pols):
195196
0.2613789792873551? - 0.4527216721561923?*I,
196197
0.2613789792873551? + 0.4527216721561923?*I)
197198
"""
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()
201201
pol_ring = PolynomialRing(field, (x,))
202202

203203
@parallel
@@ -206,7 +206,7 @@ def discrim_pairs(f, g):
206206
return pol_ring(f.discriminant(y))
207207
return pol_ring(f.resultant(g, y))
208208

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)]
210210
fdiscrim = discrim_pairs(pairs)
211211
rts = ()
212212
poly = 1
@@ -464,7 +464,7 @@ def voronoi_cells(V):
464464
return (G, E, p, EC, DG)
465465

466466

467-
def followstrand(f, factors, x0, x1, y0a, prec=53):
467+
def followstrand(f, factors, x0, x1, y0a, prec=53) -> list:
468468
r"""
469469
Return a piecewise linear approximation of the homotopy continuation
470470
of the root ``y0a`` from ``x0`` to ``x1``.
@@ -715,7 +715,7 @@ def roots_interval(f, x0):
715715
envelop = IF(diam) * IF((-1, 1), (-1, 1))
716716
qapr = QQ(CF(r).real()) + QQbar.gen() * QQ(CF(r).imag())
717717
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")
719719
result[qapr] = r + envelop
720720
return result
721721

@@ -847,7 +847,7 @@ def braid_in_segment(glist, x0, x1, precision={}):
847847
sage: B = braid_in_segment(glist, p1b, p2b); B # optional - sirocco
848848
s5*s3^-1
849849
"""
850-
precision1 = {_: precision[_] for _ in precision.keys()}
850+
precision1 = precision.copy()
851851
g = prod(glist)
852852
F1 = g.base_ring()
853853
x, y = g.parent().gens()
@@ -908,7 +908,7 @@ def braid_in_segment(glist, x0, x1, precision={}):
908908
return initialbraid * centralbraid * finalbraid
909909

910910

911-
def geometric_basis(G, E, EC0, p, dual_graph):
911+
def geometric_basis(G, E, EC0, p, dual_graph) -> list:
912912
r"""
913913
Return a geometric basis, based on a vertex.
914914
@@ -982,19 +982,20 @@ def geometric_basis(G, E, EC0, p, dual_graph):
982982
if G.size() == E.size():
983983
if E.is_cycle():
984984
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]
986987
InternalVertices = [v for e in InternalEdges for v in e[:2]]
987988
Internal = G.subgraph(vertices=InternalVertices, edges=InternalEdges)
988989
for i, ECi in enumerate(EC): # q and r are the points we will cut through
989990
if ECi in Internal:
990991
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:
992993
q = ECi
993994
connecting_path = list(EC[:i])
994995
break
995996
if EC[-i] in Internal:
996997
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:
998999
q = EC[-i]
9991000
connecting_path = list(reversed(EC[-i:]))
10001001
break
@@ -1125,7 +1126,7 @@ def strand_components(f, flist, p1):
11251126
h0 = h.subs({x: p1})
11261127
h1 = F[y](h0)
11271128
rt = h1.roots(QQbar, multiplicities=False)
1128-
roots_base += [(_, i) for _ in rt]
1129+
roots_base += [(r, i) for r in rt]
11291130
roots_base.sort()
11301131
strands = {i: par[1] for i, par in enumerate(roots_base)} # quitar +1 despues de revision
11311132
return (roots_base, strands)
@@ -1206,7 +1207,7 @@ def braid_monodromy(f, arrangement=()):
12061207
disc = discrim(glist)
12071208
else:
12081209
disc = []
1209-
if len(disc) == 0:
1210+
if not disc:
12101211
result = []
12111212
p1 = F(0)
12121213
roots_base, strands = strand_components(g, arrangement1, p1)
@@ -1303,8 +1304,8 @@ def conjugate_positive_form(braid):
13031304
cuts = [j for j in range(d + 1) if j not in gns]
13041305
blocks = []
13051306
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:
13081309
blocks.append(block)
13091310
shorts = []
13101311
for a in blocks:
@@ -1315,7 +1316,7 @@ def conjugate_positive_form(braid):
13151316
A1 = rightnormalform(sg)
13161317
par = A1[-1][0] % 2
13171318
A1 = [B(a) for a in A1[:-1]]
1318-
if len(A1) == 0:
1319+
if not A1:
13191320
b = B.one()
13201321
else:
13211322
b = prod(A1)
@@ -1378,8 +1379,8 @@ def braid2rels(L):
13781379
br1 = B0.delta()**r * B0(prod(B0(_) for _ in br0_left[1:]))
13791380
cox = prod(F0.gens())
13801381
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))
13831384
for C in pasos:
13841385
U = [(F(a) * C.inverse()).Tietze() for a in U]
13851386
ga = F / U
@@ -1465,7 +1466,7 @@ def fundamental_group_from_braid_mon(bm, degree=None, simplified=True, projectiv
14651466
"""
14661467
vertical0 = sorted(vertical)
14671468
v = len(vertical0)
1468-
if bm == []:
1469+
if not bm:
14691470
d = degree
14701471
else:
14711472
d = bm[0].parent().strands()
@@ -1605,7 +1606,7 @@ def fundamental_group(f, simplified=True, projective=False, puiseux=False):
16051606
while g.degree(y) < g.degree():
16061607
g = g.subs({x: x + y})
16071608
bm = braid_monodromy(g)[0]
1608-
if bm == []:
1609+
if not bm:
16091610
d = g.degree(y)
16101611
else:
16111612
d = bm[0].parent().strands()
@@ -1691,15 +1692,15 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, puis
16911692
arrangements, even for hyperplane arrangements defined over a number
16921693
subfield of ``QQbar`` after applying a generic line section.
16931694
"""
1694-
if len(flist) > 0:
1695+
if flist:
16951696
f = prod(flist)
16961697
R = f.parent()
16971698
else:
16981699
R = PolynomialRing(QQ, ('x', 'y'))
16991700
f = R(1)
17001701
x, y = R.gens()
17011702
F = R.base_ring()
1702-
flist1 = [_ for _ in flist]
1703+
flist1 = list(flist)
17031704
d = f.degree(y)
17041705
while not f.coefficient(y**d) in F:
17051706
flist1 = [g.subs({x: x + y}) for g in flist1]
@@ -1709,7 +1710,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, puis
17091710
while f.degree(y) < f.degree():
17101711
flist1 = [g.subs({x: x + y}) for g in flist]
17111712
f = prod(flist1)
1712-
if len(flist1) == 0:
1713+
if not flist1:
17131714
bm = []
17141715
dic = {}
17151716
else:
@@ -1720,7 +1721,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, puis
17201721
else:
17211722
hom = g.hom(codomain=g, im_gens=list(g.gens()), check=False)
17221723
g1 = hom.codomain()
1723-
if len(flist) == 0:
1724+
if not flist:
17241725
return (g1, {})
17251726
dic1 = {}
17261727
for i in range(len(flist1)):

0 commit comments

Comments
 (0)