Skip to content

Commit ad3fd44

Browse files
author
Release Manager
committed
sagemathgh-41198: some typing in vankampen so mostly trivial, but some code is changed too ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: sagemath#41198 Reported by: Frédéric Chapoton Reviewer(s): Chenxin Zhong
2 parents eeaa444 + b085cd5 commit ad3fd44

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

src/sage/schemes/curves/zariski_vankampen.py

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@
4141
# (at your option) any later version.
4242
# https://www.gnu.org/licenses/
4343
# ****************************************************************************
44-
import itertools
45-
4644
from copy import copy
4745
from itertools import combinations
46+
from typing import Any
4847

4948
from sage.combinat.permutation import Permutation
5049
from sage.functions.generalized import sign
@@ -71,7 +70,7 @@
7170

7271
lazy_import('sage.libs.braiding', ['leftnormalform', 'rightnormalform'])
7372

74-
roots_interval_cache = {}
73+
roots_interval_cache: dict[tuple, Any] = {}
7574

7675

7776
def braid_from_piecewise(strands):
@@ -109,8 +108,8 @@ def braid_from_piecewise(strands):
109108
yauxi = val[indices[j]][2]
110109
aaux = val[indices[j] - 1][0]
111110
baux = val[indices[j]][0]
112-
interpolar = xauxr + (yauxr - xauxr)*(i - aaux) / (baux - aaux)
113-
interpolai = xauxi + (yauxi - xauxi)*(i - aaux) / (baux - aaux)
111+
interpolar = xauxr + (yauxr - xauxr) * (i - aaux) / (baux - aaux)
112+
interpolai = xauxi + (yauxi - xauxi) * (i - aaux) / (baux - aaux)
114113
totalpoints[j].append([interpolar, interpolai])
115114
else:
116115
totalpoints[j].append([val[indices[j]][1],
@@ -219,9 +218,10 @@ def discrim_pairs(f, g):
219218

220219

221220
@cached_function
222-
def corrected_voronoi_diagram(points):
221+
def corrected_voronoi_diagram(points) -> VoronoiDiagram:
223222
r"""
224223
Compute a Voronoi diagram of a set of points with rational coordinates.
224+
225225
The given points are granted to lie one in each bounded region.
226226
227227
INPUT:
@@ -276,7 +276,7 @@ def corrected_voronoi_diagram(points):
276276
return V
277277

278278

279-
def orient_circuit(circuit, convex=False, precision=53, verbose=False):
279+
def orient_circuit(circuit, convex=False, precision=53, verbose=False) -> tuple:
280280
r"""
281281
Reverse a circuit if it goes clockwise; otherwise leave it unchanged.
282282
@@ -331,7 +331,7 @@ def orient_circuit(circuit, convex=False, precision=53, verbose=False):
331331
sage: cir_oriented == orient_circuit(cir, convex=True)
332332
True
333333
sage: P0=[(1,1/2),(0,1),(1,1)]; P1=[(0,3/2),(-1,0)]
334-
sage: Q=Polyhedron(P0).vertices()
334+
sage: Q = Polyhedron(P0).vertices()
335335
sage: Q = [Q[2], Q[0], Q[1]] + [_ for _ in reversed(Polyhedron(P1).vertices())]
336336
sage: Q
337337
[A vertex at (1, 1/2), A vertex at (0, 1), A vertex at (1, 1),
@@ -369,7 +369,7 @@ def orient_circuit(circuit, convex=False, precision=53, verbose=False):
369369
print(prec)
370370

371371

372-
def voronoi_cells(V, vertical_lines=frozenset()):
372+
def voronoi_cells(V, vertical_lines=frozenset()) -> tuple:
373373
r"""
374374
Compute the graph, the boundary graph, a base point, a positive orientation
375375
of the boundary graph, and the dual graph of a corrected Voronoi diagram.
@@ -480,7 +480,7 @@ def voronoi_cells(V, vertical_lines=frozenset()):
480480
return (G, E, p, EC, DG, vertical_regions)
481481

482482

483-
def followstrand(f, factors, x0, x1, y0a, prec=53) -> list:
483+
def followstrand(f, factors, x0, x1, y0a, prec=53) -> list[tuple]:
484484
r"""
485485
Return a piecewise linear approximation of the homotopy continuation
486486
of the root ``y0a`` from ``x0`` to ``x1``.
@@ -564,18 +564,18 @@ def followstrand(f, factors, x0, x1, y0a, prec=53) -> list:
564564
ci = c.imag()
565565
coefsfactors += list(cr.endpoints())
566566
coefsfactors += list(ci.endpoints())
567-
from sage.libs.sirocco import (contpath, contpath_mp, contpath_comps, contpath_mp_comps)
567+
from sage.libs.sirocco import (contpath, contpath_mp,
568+
contpath_comps, contpath_mp_comps)
568569
try:
569570
if prec == 53:
570571
if factors:
571572
points = contpath_comps(deg, coefs, yr, yi, degsfactors, coefsfactors)
572573
else:
573574
points = contpath(deg, coefs, yr, yi)
575+
elif factors:
576+
points = contpath_mp_comps(deg, coefs, yr, yi, prec, degsfactors, coefsfactors)
574577
else:
575-
if factors:
576-
points = contpath_mp_comps(deg, coefs, yr, yi, prec, degsfactors, coefsfactors)
577-
else:
578-
points = contpath_mp(deg, coefs, yr, yi, prec)
578+
points = contpath_mp(deg, coefs, yr, yi, prec)
579579
return points
580580
except Exception:
581581
return followstrand(f, factors, x0, x1, y0a, 2 * prec)
@@ -613,7 +613,7 @@ def newton(f, x0, i0):
613613
return x0 - f(x0) / f.derivative()(i0)
614614

615615

616-
def fieldI(field):
616+
def fieldI(field: NumberField) -> NumberField:
617617
r"""
618618
Return the (either double or trivial) extension of a number field which contains ``I``.
619619
@@ -675,7 +675,7 @@ def fieldI(field):
675675

676676

677677
@parallel
678-
def roots_interval(f, x0):
678+
def roots_interval(f, x0) -> dict:
679679
"""
680680
Find disjoint intervals that isolate the roots of a polynomial for a fixed
681681
value of the first variable.
@@ -747,7 +747,7 @@ def roots_interval(f, x0):
747747
return result
748748

749749

750-
def roots_interval_cached(f, x0):
750+
def roots_interval_cached(f, x0) -> dict:
751751
r"""
752752
Cached version of :func:`roots_interval`.
753753
@@ -777,7 +777,7 @@ def roots_interval_cached(f, x0):
777777
return result
778778

779779

780-
def populate_roots_interval_cache(inputs):
780+
def populate_roots_interval_cache(inputs) -> None:
781781
r"""
782782
Call :func:`roots_interval` to the inputs that have not been
783783
computed previously, and cache them.
@@ -889,7 +889,7 @@ def braid_in_segment(glist, x0, x1, precision={}):
889889
CIFp = ComplexIntervalField(precision1[f])
890890
intervals[f] = [r.interval(CIFp) for r in y0sf]
891891
if not any(a.overlaps(b) for a, b in
892-
itertools.combinations(intervals[f], 2)):
892+
combinations(intervals[f], 2)):
893893
break
894894
precision1[f] *= 2
895895
strands = []
@@ -934,7 +934,8 @@ def braid_in_segment(glist, x0, x1, precision={}):
934934
return initialbraid * centralbraid * finalbraid
935935

936936

937-
def geometric_basis(G, E, EC0, p, dual_graph, vertical_regions={}) -> list:
937+
def geometric_basis(G, E, EC0, p, dual_graph,
938+
vertical_regions={}) -> tuple[list, dict]:
938939
r"""
939940
Return a geometric basis, based on a vertex.
940941
@@ -1122,7 +1123,7 @@ def geometric_basis(G, E, EC0, p, dual_graph, vertical_regions={}) -> list:
11221123
return (resul, vd)
11231124

11241125

1125-
def vertical_lines_in_braidmon(pols) -> list:
1126+
def vertical_lines_in_braidmon(pols) -> list[int]:
11261127
r"""
11271128
Return the vertical lines in ``pols``, unless
11281129
one of the other components has a vertical asymptote.
@@ -1164,7 +1165,7 @@ def vertical_lines_in_braidmon(pols) -> list:
11641165
return res
11651166

11661167

1167-
def strand_components(f, pols, p1):
1168+
def strand_components(f, pols, p1) -> tuple[list, dict]:
11681169
r"""
11691170
Compute only the assignment from strands to elements of ``flist``.
11701171
@@ -1210,7 +1211,7 @@ def strand_components(f, pols, p1):
12101211
return (roots_base, strands)
12111212

12121213

1213-
def braid_monodromy(f, arrangement=(), vertical=False):
1214+
def braid_monodromy(f, arrangement=(), vertical=False) -> tuple:
12141215
r"""
12151216
Compute the braid monodromy of a projection of the curve defined by
12161217
a polynomial.
@@ -1308,22 +1309,19 @@ def braid_monodromy(f, arrangement=(), vertical=False):
13081309
arrangement_h = tuple(f1.subs({x: x + y}) for f1 in arrangement_h)
13091310
arrangement1 = arrangement_h
13101311
glist = tuple(f1.subs({x: x + y}) for f1 in glist)
1311-
if d > 0:
1312-
disc = discrim(glist)
1313-
else:
1314-
disc = []
1312+
disc = discrim(glist) if d > 0 else []
13151313
vertical_braid = {}
13161314
transversal = {}
1317-
vl = []
1315+
vl_list = []
13181316
for f0 in arrangement_v:
13191317
pt = [j for j, t in enumerate(disc) if f0.subs({x: t}) == 0]
13201318
if pt:
13211319
vertical_braid[f0] = (pt[0], arrangement1.index(f0))
1322-
vl.append(pt[0])
1320+
vl_list.append(pt[0])
13231321
else:
13241322
transversal[f0] = arrangement1.index(f0)
1325-
vl.sort()
1326-
vl = frozenset(vl)
1323+
vl_list.sort()
1324+
vl = frozenset(vl_list)
13271325
if not disc:
13281326
vertical_braids = {i: transversal[f0]
13291327
for i, f0 in enumerate(transversal)}
@@ -1354,13 +1352,13 @@ def braid_monodromy(f, arrangement=(), vertical=False):
13541352
k = arrangement1.index(arrangement_h[i])
13551353
strands1[j] = k
13561354
geombasis, vd = geometric_basis(G, E, EC, p, DG, vertical_regions=VR)
1357-
segs = set()
1355+
segs_set = set()
13581356
for p in geombasis:
1359-
for s in zip(p[:-1], p[1:]):
1360-
if (s[1], s[0]) not in segs:
1361-
segs.add((s[0], s[1]))
1357+
for s0, s1 in zip(p[:-1], p[1:]):
1358+
if (s1, s0) not in segs_set:
1359+
segs_set.add((s0, s1))
13621360
I0 = QQbar.gen()
1363-
segs = [(a[0] + I0 * a[1], b[0] + I0 * b[1]) for a, b in segs]
1361+
segs = [(a[0] + I0 * a[1], b[0] + I0 * b[1]) for a, b in segs_set]
13641362
vertices = list(set(flatten(segs)))
13651363
tocacheverts = tuple([(g, v) for v in vertices])
13661364
populate_roots_interval_cache(tocacheverts)
@@ -1403,7 +1401,7 @@ def braid_monodromy(f, arrangement=(), vertical=False):
14031401
return (result, strands1, vertical_braids, d)
14041402

14051403

1406-
def conjugate_positive_form(braid):
1404+
def conjugate_positive_form(braid) -> list[list]:
14071405
r"""
14081406
For a ``braid`` which is conjugate to a product of *disjoint* positive
14091407
braids a list of such decompositions is given.
@@ -1485,13 +1483,14 @@ def conjugate_positive_form_p(braid):
14851483
return conjugate_positive_form(braid)
14861484

14871485

1488-
def braid2rels(L):
1486+
def braid2rels(L) -> list:
14891487
r"""
14901488
Return a minimal set of relations of the group
14911489
``F / [(b * F([j])) / F([j]) for j in (1..d)]`` where ``F = FreeGroup(d)``
1492-
and ``b`` is a conjugate of a positive braid . One starts from the
1493-
non-trivial relations determined by the positive braid and transform
1494-
them in relations determined by ``b``.
1490+
and ``b`` is a conjugate of a positive braid.
1491+
1492+
One starts from the non-trivial relations determined by the
1493+
positive braid and transform them in relations determined by ``b``.
14951494
14961495
INPUT:
14971496
@@ -1813,7 +1812,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False,
18131812
OUTPUT:
18141813
18151814
- A list of braids. The braids correspond to paths based in the same point;
1816-
each of this paths is the conjugated of a loop around one of the points
1815+
each of these paths is the conjugated of a loop around one of the points
18171816
in the discriminant of the projection of ``f``.
18181817
18191818
- A dictionary attaching to ``j`` a tuple a list of elements
@@ -1880,7 +1879,7 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False,
18801879
R = f.parent()
18811880
else:
18821881
R = PolynomialRing(QQ, ('x', 'y'))
1883-
f = R(1)
1882+
f = R.one()
18841883
x, y = R.gens()
18851884
flist1 = tuple(flist)
18861885
if vertical and vertical_lines_in_braidmon(flist1):

0 commit comments

Comments
 (0)