Skip to content

Commit

Permalink
sagemathgh-37947: various ruff suggestions fixed in schemes
Browse files Browse the repository at this point in the history
    
This is fixing some details, as suggested by `ruff` in the `schemes`
folder.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#37947
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed May 11, 2024
2 parents c2484f5 + 604d6a4 commit 5906b63
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 64 deletions.
14 changes: 7 additions & 7 deletions src/sage/schemes/curves/plane_curve_arrangement.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ def _repr_(self):
Arrangement of 5 curves in Projective Space of dimension 2 over Rational Field
"""
if not self:
return 'Empty curve arrangement in {0}'.format(self.parent().ambient_space())
return 'Empty curve arrangement in {}'.format(self.parent().ambient_space())
elif len(self) < 5:
curves = ', '.join(h.defining_polynomial()._repr_()
for h in self._curves)
return 'Arrangement ({0}) in {1}'.format(curves,
return 'Arrangement ({}) in {}'.format(curves,
self.parent().ambient_space())
return 'Arrangement of {0} curves in {1}'.format(len(self),
return 'Arrangement of {} curves in {}'.format(len(self),
self.parent().ambient_space())

def _richcmp_(self, other, op):
Expand Down Expand Up @@ -574,7 +574,7 @@ def fundamental_group(self, simplified=True, vertical=True,
if not vertical:
st = self._strands_nonvertical
d1 = prod(L).degree()
bd = (bm, st, dict(), d1)
bd = (bm, st, {}, d1)
else:
st = self._strands_vertical
d1 = prod(L).degree(R.gen(1))
Expand Down Expand Up @@ -920,7 +920,7 @@ def fundamental_group(self, simplified=True):
projective=proj)
dic = C_affine.meridians(simplified=simplified, vertical=True)
if infinity_in_C:
dic1 = dict()
dic1 = {}
for k in range(j):
dic1[k] = dic[k]
dic1[j] = dic[n - 1]
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def __classcall__(cls, base, names=()):
names = normalize_names(len(names), names)
return super().__classcall__(cls, base, names)

def __init__(self, base_ring, names=tuple()):
def __init__(self, base_ring, names=()):
"""
Initialize ``self``.
Expand Down Expand Up @@ -1115,7 +1115,7 @@ def _repr_(self):
sage: L.<x, y> = AffinePlaneCurveArrangements(QQ); L
Curve arrangements in Affine Space of dimension 2 over Rational Field
"""
return 'Curve arrangements in {0}'.format(self.ambient_space())
return 'Curve arrangements in {}'.format(self.ambient_space())

def _element_constructor_(self, *args, **kwds):
"""
Expand Down
17 changes: 9 additions & 8 deletions src/sage/schemes/curves/zariski_vankampen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,14 +1524,15 @@ def braid2rels(L):
k = min(T1) - 1
B0 = BraidGroup(m)
F0 = FreeGroup(m)
br0 = B0([j-k for j in T])
br0 = B0([j - k for j in T])
br0_left = leftnormalform(br0)
q, r = ZZ(br0_left[0][0]).quo_rem(2)
br1 = B0.delta()**r * prod(map(B0, br0_left[1:]), B0.one())
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 br.Tietze()) for br in U0]
pasos = [B.one()] + list(reversed(L1))
pasos = [B.one()]
pasos.extend(reversed(L1))
for C in pasos:
U = [(F(a) * C.inverse()).Tietze() for a in U]
ga = F / U
Expand Down Expand Up @@ -1884,13 +1885,13 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False,
x, y = R.gens()
flist1 = tuple(flist)
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])
infinity = all(Curve(g).is_vertical_line() or
g.degree(y) == g.degree() for g in flist1)
else:
infinity = any([Curve(g).has_vertical_asymptote() or
Curve(g).is_vertical_line() for g in flist1])
infinity = any(Curve(g).has_vertical_asymptote() or
Curve(g).is_vertical_line() for g in flist1)
if not infinity:
infinity = all([g.degree(y) == g.degree() for g in flist1])
infinity = all(g.degree(y) == g.degree() for g in flist1)
if braid_data:
bm, dic, dv, d1 = braid_data
elif not flist:
Expand Down Expand Up @@ -1925,5 +1926,5 @@ def fundamental_group_arrangement(flist, simplified=True, projective=False,
n = g1.ngens()
rels = [rel.Tietze() for rel in g1.relations()]
g1 = FreeGroup(n) / rels
dic1 = {i: list(set([g1(el.Tietze()) for el in dic1[i]])) for i in dic1}
dic1 = {i: list({g1(el.Tietze()) for el in dic1[i]}) for i in dic1}
return (g1, dic1)
11 changes: 5 additions & 6 deletions src/sage/schemes/elliptic_curves/ell_rational_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -5823,8 +5823,8 @@ def height(self, precision=None):
c4 = self.c4()
c6 = self.c6()
j = self.j_invariant()
log_g2 = R((c4/12)).abs().log()
log_g3 = R((c6/216)).abs().log()
log_g2 = R(c4/12).abs().log()
log_g3 = R(c6/216).abs().log()

if j == 0:
h_j = R(1)
Expand Down Expand Up @@ -6348,7 +6348,7 @@ def point_preprocessing(free,tor):
#new bound according to low_bound and upper bound
#[c_5 exp((-c_2*H_q^2)/2)] provided by Corollary 8.7.3
if low_bound != 0:
H_q_new = R((log(low_bound/c5)/(-c2/2))).sqrt()
H_q_new = R(log(low_bound/c5)/(-c2/2)).sqrt()
H_q_new = H_q_new.ceil()
if H_q_new == 1:
break_cond = 1 # stops reduction
Expand Down Expand Up @@ -7025,9 +7025,8 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound):
else:
bound_list.append(H_q)

##reduction for finite places in S
for p in S:
bound_list.append(reduction_at(p))
# reduction for finite places in S
bound_list.extend(reduction_at(p) for p in S)

if verbose:
print('bound_list', bound_list)
Expand Down
4 changes: 1 addition & 3 deletions src/sage/schemes/elliptic_curves/gal_reps_number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,7 @@ def _exceptionals(E, L, patience=1000):
if (not D) or (patience == 0):
break

for l in D:
output.append(l)

output.extend(D)
output.sort()
return output

Expand Down
7 changes: 3 additions & 4 deletions src/sage/schemes/elliptic_curves/heegner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7055,7 +7055,7 @@ def _heegner_index_in_EK(self, D):
basis = [G(z) for z in E.gens()] + [G(phi(z)) for z in F.gens()]
# Make a list of the 2-power order torsion points in E(K), including 0.
T = [G(z) for z in G.torsion_subgroup().list() if z.order() == 1 or
((z.order() % 2 == 0 and len(z.order().factor()) == 1))]
(z.order() % 2 == 0 and len(z.order().factor()) == 1)]

r = len(basis) # rank
V = QQ**r
Expand All @@ -7066,9 +7066,8 @@ def _heegner_index_in_EK(self, D):
if not v:
continue
P = sum([basis[i] for i in range(r) if v[i]])
for t in T:
if (P+t).is_divisible_by(2):
B.append(V(v)/2)
w = V(v) / 2
B.extend(w for t in T if (P + t).is_divisible_by(2))

A = ZZ**r
# Take span of our vectors in (1/2)*ZZ^r, along with ZZ^r. This is E(K)/tor.
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/elliptic_curves/isogeny_small_degree.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def _sporadic_Q_data(j):
w = w1 # real period
if j in [-121, -24729001, -162677523113838677, QQ(-882216989)/131072]:
w = 2*w2-w1 # imaginary period
kerpol = prod(([X-L.elliptic_exponential(n*w/ell)[0] for n in range(1,(ell+1)//2)]))
kerpol = prod([X-L.elliptic_exponential(n*w/ell)[0] for n in range(1,(ell+1)//2)])
if j == -162677523113838677:
kerpolcoeffs = [(37*c.real()).round()/37 for c in list(kerpol)]
else:
Expand Down Expand Up @@ -2110,7 +2110,7 @@ def isogenies_prime_degree_genus_plus_0_j0(E, l, minimal_models=True):
raise ValueError("%s must be one of %s." % (l,hyperelliptic_primes))
F = E.base_field()
if E.j_invariant() != 0:
raise ValueError(("j-invariant must be 0."))
raise ValueError("j-invariant must be 0.")
if F.characteristic() in [2,3,l]:
raise NotImplementedError("Not implemented in characteristic 2, 3 or l.")

Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/padic_lseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ def __phi_bpr(self, prec=0):
if prec > 10:
print("Warning: Very large value for the precision.")
if prec == 0:
prec = floor((log(10000)/log(p)))
prec = floor(log(10000)/log(p))
verbose("prec set to %s" % prec)
eh = E.formal()
om = eh.differential(prec=p**prec+3)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/weierstrass_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from sage.rings.integer import Integer
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

class baseWI():
class baseWI:
r"""
This class implements the basic arithmetic of isomorphisms between
Weierstrass models of elliptic curves.
Expand Down
10 changes: 4 additions & 6 deletions src/sage/schemes/product_projective/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _repr_(self):
Product of projective spaces P^1 x P^1 x P^1 over Integer Ring
"""
return ''.join(['Product of projective spaces ',
' x '.join('P^{0}'.format(d) for d in self._dims),
' x '.join('P^{}'.format(d) for d in self._dims),
' over ', str(self.base_ring())])

def _repr_generic_point(self, v=None):
Expand Down Expand Up @@ -1197,8 +1197,8 @@ def points_of_bounded_height(self, **kwds):
P = []
for i in range(m):
pt = next(iters[i])
for j in range(dim[i]):
P.append(pt[j]) # initial value of P
P.extend(pt[j] for j in range(dim[i]))
# initial value of P
yield self(P)

i = 0
Expand Down Expand Up @@ -1248,9 +1248,7 @@ def __iter__(self):
(1 : 0 : 0 , 1 : 0)]
"""
iters = [iter(T) for T in self._components]
L = []
for x in iters:
L.append(next(x)) # put at zero
L = [next(x) for x in iters] # put at zero
yield self(L)
j = 0
while j < self.num_components():
Expand Down
26 changes: 10 additions & 16 deletions src/sage/schemes/projective/projective_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,9 +1233,8 @@ def dehomogenize(self, n):
G = phi(self._polys[ind[1]])
# ind[1] is relative to codomain
M = self.codomain().ambient_space().dimension_relative()
for i in range(0, M + 1):
if i != ind[1]:
F.append(phi(self._polys[i]) / G)
F.extend(phi(self._polys[i]) / G
for i in range(M + 1) if i != ind[1])
H = Hom(Aff_domain, self.codomain().affine_patch(ind[1]))
# since often you dehomogenize at the same coordinate in domain
# and codomain it should be stored appropriately.
Expand Down Expand Up @@ -1720,17 +1719,13 @@ def rational_preimages(self, Q, k=1):
L2 = []
for P in L:
I = list(self.domain().defining_polynomials())
for i in range(N+1):
for j in range(i+1, N+1):
I.append(P[i]*self[j] - P[j]*self[i])
I.extend(P[i] * self[j] - P[j] * self[i]
for i in range(N + 1) for j in range(i + 1, N + 1))
X = PS.subscheme(I)
if X.dimension() > 0:
return X
preimages = []
for T in X.rational_points():
if not all(g(tuple(T)) == 0 for g in self):
preimages.append(PS(T))
L2 = L2 + preimages
L2.extend(PS(T) for T in X.rational_points()
if not all(g(tuple(T)) == 0 for g in self))
L = L2
return L

Expand Down Expand Up @@ -2224,8 +2219,8 @@ def reduce_base_field(self):
# find the right subfield and it's embedding
if M.degree() == da:
break
c = M((str(c).replace(c.as_finite_field_element()[0].variable_name(),
M.variable_name())))
c = M(str(c).replace(c.as_finite_field_element()[0].variable_name(),
M.variable_name()))
new_c.append(M_to_L(c))
# reconstruct as a poly in the new domain
new_f.append(sum([new_c[i] * prod(new_R.gen(j)**mon_deg[i][j]
Expand Down Expand Up @@ -2613,9 +2608,8 @@ def self_with_domain(C):
polys = list(X.defining_polynomials())

for r in self.representatives():
r_proj = r if emb is None else emb*r
for p in r_proj:
polys.append(p)
r_proj = r if emb is None else emb * r
polys.extend(r_proj)

return Amb.subscheme(polys).reduce()

Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/riemann_surfaces/riemann_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def reparameterize_differential_minpoly(minpoly, z0):
return mt


class RiemannSurface():
class RiemannSurface:
r"""
Construct a Riemann Surface. This is specified by the zeroes of a bivariate
polynomial with rational coefficients `f(z,w) = 0`.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/toric/divisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def ToricDivisor(toric_variety, arg=None, ring=None, check=True, reduce=True):
except (AssertionError, TypeError):
n_rays = toric_variety.fan().nrays()
assert len(arg) == n_rays, \
'Argument list {0} is not of the required length {1}!' \
'Argument list {} is not of the required length {}!' \
.format(arg, n_rays)
arg = list(zip(arg, toric_variety.gens()))
reduce = False
Expand Down
7 changes: 3 additions & 4 deletions src/sage/schemes/toric/morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,12 +1537,11 @@ def fiber_dimension(self, codomain_cone):
dim = []
fm = self.fan_morphism()
base_dim = codomain_cone.dim()
for c in fm.primitive_preimage_cones(codomain_cone):
dim.append(base_dim - c.dim())
dim.extend(base_dim - c.dim()
for c in fm.primitive_preimage_cones(codomain_cone))
if dim:
return max(dim) + self.domain().dimension() - self.codomain().dimension()
else:
return ZZ(-1)
return ZZ(-1)

def fiber_graph(self, codomain_cone):
r"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/schemes/toric/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from sage.parallel.decorate import Parallel


class InfinitePointEnumerator():
class InfinitePointEnumerator:

def __init__(self, fan, ring):
"""
Expand Down Expand Up @@ -105,7 +105,7 @@ def __iter__(self):
yield tuple(p)


class NaiveFinitePointEnumerator():
class NaiveFinitePointEnumerator:

def __init__(self, fan, ring):
"""
Expand Down Expand Up @@ -756,7 +756,7 @@ def cardinality(self):
return n


class NaiveSubschemePointEnumerator():
class NaiveSubschemePointEnumerator:

def __init__(self, polynomials, ambient):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/toric/sheaf/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def LineBundle(X, D):
return klyachko.Bundle(X, filtrations, check=True)


class SheafLibrary():
class SheafLibrary:

def __init__(self, toric_variety):
"""
Expand Down

0 comments on commit 5906b63

Please sign in to comment.