diff --git a/src/sage/schemes/curves/plane_curve_arrangement.py b/src/sage/schemes/curves/plane_curve_arrangement.py index 718c0bbadfc..724f7f607d4 100644 --- a/src/sage/schemes/curves/plane_curve_arrangement.py +++ b/src/sage/schemes/curves/plane_curve_arrangement.py @@ -534,7 +534,7 @@ def fundamental_group(self, simplified=True, vertical=True, bm = self._braid_monodromy_vertical else: bm = self._braid_monodromy_non_vertical - if bm is not None: + if bm is not None: # bm could be [] if not vertical: st = self._strands_nonvertical d1 = prod(L).degree() @@ -601,7 +601,7 @@ def meridians(self, simplified=True, vertical=True): computed = self._meridians_nonsimpl_nonvertical if computed: return computed - _ = self.fundamental_group(simplified=simplified, vertical=vertical) + self.fundamental_group(simplified=simplified, vertical=vertical) if simplified and vertical: return self._meridians_simpl_vertical elif simplified and not vertical: diff --git a/src/sage/schemes/curves/zariski_vankampen.py b/src/sage/schemes/curves/zariski_vankampen.py index c2912f517da..265209dec40 100644 --- a/src/sage/schemes/curves/zariski_vankampen.py +++ b/src/sage/schemes/curves/zariski_vankampen.py @@ -166,7 +166,7 @@ def sgn(x, y): return B(braid) -def discrim(pols): +def discrim(pols) -> tuple: r""" Return the points in the discriminant of the product of the polynomials of a list or tuple ``pols``. @@ -198,9 +198,8 @@ def discrim(pols): 0.2613789792873551? + 0.4527216721561923?*I, 1] """ - flist = tuple(pols) - x, y = flist[0].parent().gens() - field = flist[0].base_ring() + x, y = pols[0].parent().gens() + field = pols[0].base_ring() pol_ring = PolynomialRing(field, (x,)) @parallel @@ -209,8 +208,8 @@ def discrim_pairs(f, g): return pol_ring(f.discriminant(y)) return pol_ring(f.resultant(g, y)) - pairs = [(f, None) for f in flist] + [(f, g) for f, g - in Combinations(flist, 2)] + pairs = [(f, None) for f in pols] + [tuple(t) for t + in Combinations(pols, 2)] fdiscrim = discrim_pairs(pairs) rts = () poly = 1 @@ -484,7 +483,7 @@ def voronoi_cells(V, vertical_lines=frozenset()): return (G, E, p, EC, DG, vertical_regions) -def followstrand(f, factors, x0, x1, y0a, prec=53): +def followstrand(f, factors, x0, x1, y0a, prec=53) -> list: r""" Return a piecewise linear approximation of the homotopy continuation of the root ``y0a`` from ``x0`` to ``x1``. @@ -751,7 +750,7 @@ def roots_interval(f, x0): envelop = IF(diam) * IF((-1, 1), (-1, 1)) qapr = QQ(CF(r).real()) + QQbar.gen() * QQ(CF(r).imag()) if qapr not in r + envelop: - raise ValueError("Could not approximate roots with exact values") + raise ValueError("could not approximate roots with exact values") result[qapr] = r + envelop return result @@ -839,7 +838,7 @@ def braid_in_segment(glist, x0, x1, precision={}): - ``glist`` -- a tuple of polynomials in two variables - ``x0`` -- a Gauss rational - ``x1`` -- a Gauss rational - - ``precision`` -- a dictionary (default: `dict()`) which assigns a number + - ``precision`` -- a dictionary (default: `{}`) which assigns a number precision bits to each element of ``glist`` OUTPUT: @@ -882,7 +881,7 @@ def braid_in_segment(glist, x0, x1, precision={}): sage: B = braid_in_segment(glist, p1b, p2b); B # needs sirocco s5*s3^-1 """ - precision1 = {_: precision[_] for _ in precision.keys()} + precision1 = precision.copy() g = prod(glist) F1 = g.base_ring() x, y = g.parent().gens() @@ -946,7 +945,7 @@ def braid_in_segment(glist, x0, x1, precision={}): return initialbraid * centralbraid * finalbraid -def geometric_basis(G, E, EC0, p, dual_graph, vertical_regions={}): +def geometric_basis(G, E, EC0, p, dual_graph, vertical_regions={}) -> list: r""" Return a geometric basis, based on a vertex. @@ -1016,10 +1015,10 @@ def geometric_basis(G, E, EC0, p, dual_graph, vertical_regions={}): if j in vertical_regions: vd = {j: 0} else: - vd = dict() + vd = {} return [EC], vd - InternalEdges = [_ for _ in G.edges(sort=True) if _ not in - E.edges(sort=True)] + edges_E = E.edges(sort=True) + InternalEdges = [e for e in G.edges(sort=True) if e not in edges_E] InternalVertices = [v for e in InternalEdges for v in e[:2]] Internal = G.subgraph(vertices=InternalVertices, edges=InternalEdges) for i, ECi in enumerate(EC): # q and r are the points we will cut through @@ -1027,7 +1026,7 @@ def geometric_basis(G, E, EC0, p, dual_graph, vertical_regions={}): EI = [v for v in E if v in Internal.connected_component_containing_vertex(ECi, sort=True) and v != ECi] - if len(EI) > 0: + if EI: q = ECi connecting_path = list(EC[:i]) break @@ -1036,7 +1035,7 @@ def geometric_basis(G, E, EC0, p, dual_graph, vertical_regions={}): Internal.connected_component_containing_vertex(EC[-i], sort=True) and v != EC[-i]] - if len(EI) > 0: + if EI: q = EC[-i] connecting_path = list(reversed(EC[-i:])) break @@ -1135,14 +1134,14 @@ def geometric_basis(G, E, EC0, p, dual_graph, vertical_regions={}): return (resul, vd) -def vertical_lines_in_braidmon(flist): +def vertical_lines_in_braidmon(pols) -> list: r""" - Returns the vertical lines in ``flist``, unless + Returns the vertical lines in ``pols``, unless one of the other components has a vertical asymptote. INPUT: - - ``flist`` -- a list of polynomials with two variables whose + - ``pols`` -- a list of polynomials with two variables whose product equals ``f`` OUTPUT: @@ -1164,10 +1163,10 @@ def vertical_lines_in_braidmon(flist): sage: vertical_lines_in_braidmon([]) [] """ - if not flist: + if not pols: return [] res = [] - for j, f in enumerate(flist): + for j, f in enumerate(pols): C = Curve(f) vertical_asymptote = C.has_vertical_asymptote() if vertical_asymptote: @@ -1177,7 +1176,7 @@ def vertical_lines_in_braidmon(flist): return res -def strand_components(f, flist, p1): +def strand_components(f, pols, p1): r""" Compute only the assignment from strands to elements of ``flist``. @@ -1186,7 +1185,7 @@ def strand_components(f, flist, p1): - ``f`` -- a reduced polynomial with two variables, over a number field with an embedding in the complex numbers - - ``flist`` -- a list of polynomials with two variables whose + - ``pols`` -- a list of polynomials with two variables whose product equals ``f`` - ``p1`` -- a Gauss rational @@ -1211,14 +1210,14 @@ def strand_components(f, flist, p1): (1, 0), (1.333333333333334?, 1)], {0: 0, 1: 0, 2: 0, 3: 1}) """ x, y = f.parent().gens() - F = flist[0].base_ring() + F = pols[0].base_ring() strands = {} roots_base = [] - for i, h in enumerate(flist): + for i, h in enumerate(pols): h0 = h.subs({x: p1}) h1 = F[y](h0) rt = h1.roots(QQbar, multiplicities=False) - roots_base += [(_, i) for _ in rt] + roots_base += [(r, i) for r in rt] roots_base.sort() strands = {i: par[1] for i, par in enumerate(roots_base)} return (roots_base, strands) @@ -1299,10 +1298,10 @@ def braid_monodromy(f, arrangement=(), vertical=False): F = fieldI(f.base_ring()) I1 = F(QQbar.gen()) f = f.change_ring(F) - if arrangement == (): + if not arrangement: arrangement1 = (f,) else: - arrangement1 = tuple(_.change_ring(F) for _ in arrangement) + arrangement1 = tuple(g.change_ring(F) for g in arrangement) x, y = f.parent().gens() if vertical: indices_v = vertical_lines_in_braidmon(arrangement1) @@ -1312,7 +1311,7 @@ def braid_monodromy(f, arrangement=(), vertical=False): if j not in indices_v) arrangement_v = tuple(f0 for j, f0 in enumerate(arrangement1) if j in indices_v) - glist = tuple(_[0] for f0 in arrangement_h for _ in f0.factor()) + glist = tuple(fc[0] for f0 in arrangement_h for fc in f0.factor()) g = f.parent()(prod(glist)) d = g.degree(y) if not arrangement_v: # change of coordinates only if indices_v is empty @@ -1326,8 +1325,8 @@ def braid_monodromy(f, arrangement=(), vertical=False): disc = discrim(glist) else: disc = [] - vertical_braid = dict() - transversal = dict() + vertical_braid = {} + transversal = {} vl = [] for f0 in arrangement_v: pt = [j for j, t in enumerate(disc) if f0.subs({x: t}) == 0] @@ -1349,20 +1348,20 @@ def braid_monodromy(f, arrangement=(), vertical=False): p1 = F(0) if d > 0: roots_base, strands = strand_components(g, arrangement_h, p1) - strands1 = dict() + strands1 = {} for j in range(d): i = strands[j] k = arrangement1.index(arrangement_h[i]) strands1[j] = k else: - strands1 = dict() + strands1 = {} return (result, strands1, vertical_braids, d) V = corrected_voronoi_diagram(tuple(disc)) G, E, p, EC, DG, VR = voronoi_cells(V, vertical_lines=vl) p0 = (p[0], p[1]) p1 = p0[0] + I1 * p0[1] roots_base, strands = strand_components(g, arrangement_h, p1) - strands1 = dict() + strands1 = {} for j in range(d): i = strands[j] k = arrangement1.index(arrangement_h[i]) @@ -1403,7 +1402,7 @@ def braid_monodromy(f, arrangement=(), vertical=False): x1 = tuple(path[i + 1].vector()) braidpath = braidpath * segsbraids[(x0, x1)] result.append(braidpath) - vertical_braids = dict() + vertical_braids = {} r = len(result) t = 0 for f0 in arrangement_v: @@ -1465,8 +1464,8 @@ def conjugate_positive_form(braid): cuts = [j for j in range(d + 1) if j not in gns] blocks = [] for i in range(len(cuts) - 1): - block = [j for j in L1 if j > cuts[i] and j < cuts[i + 1]] - if len(block) > 0: + block = [j for j in L1 if cuts[i] < j < cuts[i + 1]] + if block: blocks.append(block) shorts = [] for a in blocks: @@ -1477,7 +1476,7 @@ def conjugate_positive_form(braid): A1 = rightnormalform(sg) par = A1[-1][0] % 2 A1 = [B(a) for a in A1[:-1]] - if len(A1) == 0: + if not A1: b = B.one() else: b = prod(A1) @@ -1540,8 +1539,8 @@ def braid2rels(L): br1 = B0.delta()**r * B0(prod(B0(_) for _ in br0_left[1:])) cox = prod(F0.gens()) U0 = [cox**q * (f0 * br1) / cox**q / f0 for f0 in F0.gens()[:-1]] - U = [tuple(sign(k1)*(abs(k1) + k) for k1 in _.Tietze()) for _ in U0] - pasos = [B.one()] + [_ for _ in reversed(L1)] + U = [tuple(sign(k1) * (abs(k1) + k) for k1 in _.Tietze()) for _ in U0] + pasos = [B.one()] + list(reversed(L1)) for C in pasos: U = [(F(a) * C.inverse()).Tietze() for a in U] ga = F / U @@ -1632,7 +1631,7 @@ def fundamental_group_from_braid_mon(bm, degree=None, """ vertical0 = sorted(vertical) v = len(vertical0) - if bm == []: + if not bm: d = degree elif bm[0].parent().order() == 1: d = 1 @@ -1776,7 +1775,7 @@ def fundamental_group(f, simplified=True, projective=False, puiseux=True): while g.degree(y) < g.degree(): g = g.subs({x: x + y}) bm = braid_monodromy(g)[0] - if bm == []: + if not bm: d = g.degree(y) else: d = bm[0].parent().strands() @@ -1886,14 +1885,14 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, x1*x2*x0*x1^-1*x0^-1*x2^-1 >, {0: [x2], 1: [x0], 2: [x3], 3: [x1], 4: [x3^-1*x2^-1*x1^-1*x0^-1]}) """ - if len(flist) > 0: + if flist: f = prod(flist) R = f.parent() else: R = PolynomialRing(QQ, ('x', 'y')) f = R(1) x, y = R.gens() - flist1 = [_ for _ in flist] + flist1 = tuple(list(flist).copy()) if vertical and vertical_lines_in_braidmon(flist1): infinity = all([Curve(g).is_vertical_line() or g.degree(y) == g.degree() for g in flist1]) @@ -1904,7 +1903,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, infinity = all([g.degree(y) == g.degree() for g in flist1]) if braid_data: bm, dic, dv, d1 = braid_data - elif len(flist1) == 0: + elif not flist: bm = [] dic = {} dv = {j: j for j, f in flist1} @@ -1924,7 +1923,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False, else: hom = g.hom(codomain=g, im_gens=list(g.gens()), check=False) g1 = hom.codomain() - if len(flist) == 0: + if not flist: return (g1, {}) dic1 = {} for i in range(len(flist1)):