Skip to content

Commit c4d98ca

Browse files
committed
refreshing the modified file
1 parent 3dd953c commit c4d98ca

File tree

1 file changed

+52
-57
lines changed

1 file changed

+52
-57
lines changed

src/sage/schemes/projective/projective_subscheme.py

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from sage.matrix.constructor import matrix
3030

3131
from sage.rings.integer_ring import ZZ
32-
from sage.rings.finite_rings.finite_field_base import FiniteField
3332
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
3433
from sage.rings.rational_field import is_RationalField
3534

@@ -111,7 +110,7 @@ def point(self, v, check=True):
111110
"""
112111
from sage.rings.infinity import infinity
113112
if v is infinity or\
114-
(isinstance(v, (list,tuple)) and len(v) == 1 and v[0] is infinity):
113+
(isinstance(v, (list, tuple)) and len(v) == 1 and v[0] is infinity):
115114
if self.ambient_space().dimension_relative() > 1:
116115
raise ValueError("%s not well defined in dimension > 1" % v)
117116
v = [1, 0]
@@ -209,10 +208,10 @@ def affine_patch(self, i, AA=None):
209208
210209
INPUT:
211210
212-
- ``i`` -- integer between 0 and dimension of self, inclusive.
211+
- ``i`` -- integer between 0 and dimension of ``self``, inclusive.
213212
214-
- ``AA`` -- (default: None) ambient affine space, this is constructed
215-
if it is not given.
213+
- ``AA`` -- (default: ``None``) ambient affine space, this
214+
is constructed if it is not given.
216215
217216
OUTPUT:
218217
@@ -260,11 +259,11 @@ def affine_patch(self, i, AA=None):
260259
PP = self.ambient_space()
261260
n = PP.dimension_relative()
262261
if i < 0 or i > n:
263-
raise ValueError("Argument i (= %s) must be between 0 and %s." % (i, n))
262+
raise ValueError(f"Argument i (= {i}) must be between 0 and {n}.")
264263
try:
265264
A = self.__affine_patches[i]
266-
#assume that if you've passed in a new ambient affine space
267-
#you want to override the existing patch
265+
# assume that if you've passed in a new ambient affine space
266+
# you want to override the existing patch
268267
if AA is None or A.ambient_space() == AA:
269268
return self.__affine_patches[i]
270269
except AttributeError:
@@ -318,14 +317,14 @@ def _best_affine_patch(self, point):
318317
"""
319318
point = list(point)
320319
try:
321-
abs_point = [abs(_) for _ in point]
320+
abs_point = [abs(c) for c in point]
322321
except ArithmeticError:
323322
# our base ring does not know abs
324323
abs_point = point
325324
# find best patch
326325
i_max = 0
327326
p_max = abs_point[i_max]
328-
for i in range(1,len(point)):
327+
for i in range(1, len(point)):
329328
if abs_point[i] > p_max:
330329
i_max = i
331330
p_max = abs_point[i_max]
@@ -385,16 +384,17 @@ def neighborhood(self, point):
385384
R = patch_cover.coordinate_ring()
386385

387386
phi = list(point)
388-
for j in range(0,i):
389-
phi[j] = phi[j] + R.gen(j)
390-
for j in range(i,n):
391-
phi[j+1] = phi[j+1] + R.gen(j)
387+
for j in range(i):
388+
phi[j] += R.gen(j)
389+
for j in range(i, n):
390+
phi[j + 1] += R.gen(j)
392391

393392
pullback_polys = [f(phi) for f in self.defining_polynomials()]
394-
return patch_cover.subscheme(pullback_polys, embedding_center=[0]*n,
395-
embedding_codomain=self, embedding_images=phi)
393+
return patch_cover.subscheme(pullback_polys, embedding_center=[0] * n,
394+
embedding_codomain=self,
395+
embedding_images=phi)
396396

397-
def is_smooth(self, point=None):
397+
def is_smooth(self, point=None) -> bool:
398398
r"""
399399
Test whether the algebraic subscheme is smooth.
400400
@@ -450,7 +450,7 @@ def is_smooth(self, point=None):
450450
self._smooth = (sing_dim <= 0)
451451
return self._smooth
452452

453-
def orbit(self, f, N):
453+
def orbit(self, f, N) -> list:
454454
r"""
455455
Return the orbit of this scheme by ``f``.
456456
@@ -512,8 +512,8 @@ def orbit(self, f, N):
512512
from sage.dynamics.arithmetic_dynamics.generic_ds import DynamicalSystem
513513
if not isinstance(f, DynamicalSystem):
514514
raise TypeError("map must be a dynamical system for iteration")
515-
if not isinstance(N,(list,tuple)):
516-
N = [0,N]
515+
if not isinstance(N, (list, tuple)):
516+
N = [0, N]
517517
N[0] = ZZ(N[0])
518518
N[1] = ZZ(N[1])
519519
if N[0] < 0 or N[1] < 0:
@@ -522,11 +522,11 @@ def orbit(self, f, N):
522522
return []
523523

524524
Q = self
525-
for i in range(1, N[0]+1):
525+
for i in range(1, N[0] + 1):
526526
Q = f(Q)
527527
Orb = [Q]
528528

529-
for i in range(N[0]+1, N[1]+1):
529+
for i in range(N[0] + 1, N[1] + 1):
530530
Q = f(Q)
531531
Orb.append(Q)
532532
return Orb
@@ -590,7 +590,7 @@ def nth_iterate(self, f, n):
590590
n = ZZ(n)
591591
if n < 0:
592592
raise TypeError("must be a forward orbit")
593-
return self.orbit(f,[n,n+1])[0]
593+
return self.orbit(f, [n, n + 1])[0]
594594

595595
def _forward_image(self, f, check=True):
596596
r"""
@@ -764,15 +764,15 @@ def _forward_image(self, f, check=True):
764764
CR_codom = codom.coordinate_ring()
765765
n = CR_dom.ngens()
766766
m = CR_codom.ngens()
767-
#can't call eliminate if the base ring is polynomial so we do it ourselves
768-
#with a lex ordering
767+
# can't call eliminate if the base ring is polynomial so we do it ourselves
768+
# with a lex ordering
769769
R = PolynomialRing(f.base_ring(), n + m, 'tempvar', order='lex')
770-
Rvars = R.gens()[0 : n]
770+
Rvars = R.gens()[0:n]
771771
phi = CR_dom.hom(Rvars, R)
772-
zero = n*[0]
772+
zero = n * [0]
773773
psi = R.hom(zero + list(CR_codom.gens()), CR_codom)
774-
#set up ideal
775-
L = R.ideal([phi(t) for t in self.defining_polynomials()] + [R.gen(n+i) - phi(f[i]) for i in range(m)])
774+
# set up ideal
775+
L = R.ideal([phi(t) for t in self.defining_polynomials()] + [R.gen(n + i) - phi(f[i]) for i in range(m)])
776776
G = L.groebner_basis() # eliminate
777777
newL = []
778778
# get only the elimination ideal portion
@@ -897,12 +897,9 @@ def preimage(self, f, k=1, check=True):
897897
if k > 1 and not f.is_endomorphism():
898898
raise TypeError("map must be an endomorphism")
899899
R = codom.coordinate_ring()
900-
if k > 1:
901-
F = f.as_dynamical_system().nth_iterate_map(k)
902-
else:
903-
F = f
904-
dict = {R.gen(i): F[i] for i in range(codom.dimension_relative()+1)}
905-
return dom.subscheme([t.subs(dict) for t in self.defining_polynomials()])
900+
F = f.as_dynamical_system().nth_iterate_map(k) if k > 1 else f
901+
dic = {R.gen(i): F[i] for i in range(codom.dimension_relative() + 1)}
902+
return dom.subscheme([t.subs(dic) for t in self.defining_polynomials()])
906903

907904
def dual(self):
908905
r"""
@@ -978,13 +975,13 @@ def dual(self):
978975
from sage.libs.singular.function_factory import ff
979976

980977
K = self.base_ring()
981-
if not (is_RationalField(K) or isinstance(K, FiniteField)):
978+
if not (is_RationalField(K) or K in Fields().Finite()):
982979
raise NotImplementedError("base ring must be QQ or a finite field")
983980
I = self.defining_ideal()
984981
m = I.ngens()
985982
n = I.ring().ngens() - 1
986983
if (m != 1 or (n < 1) or I.is_zero()
987-
or I.is_trivial() or not I.is_prime()):
984+
or I.is_trivial() or not I.is_prime()):
988985
raise NotImplementedError("At the present, the method is only"
989986
" implemented for irreducible and"
990987
" reduced hypersurfaces and the given"
@@ -1108,7 +1105,7 @@ def intersection_multiplicity(self, X, P):
11081105
try:
11091106
self.ambient_space()(P)
11101107
except TypeError:
1111-
raise TypeError("(=%s) must be a point in the ambient space of this subscheme and (=%s)" % (P,X))
1108+
raise TypeError("(={}) must be a point in the ambient space of this subscheme and (={})".format(P, X))
11121109
# find an affine chart of the ambient space of this curve that contains P
11131110
n = self.ambient_space().dimension_relative()
11141111
for i in range(n + 1):
@@ -1173,7 +1170,7 @@ def multiplicity(self, P):
11731170
try:
11741171
P = self(P)
11751172
except TypeError:
1176-
raise TypeError("(=%s) is not a point on (=%s)" % (P,self))
1173+
raise TypeError(f"(={P}) is not a point on (={self})")
11771174

11781175
# find an affine chart of the ambient space of self that contains P
11791176
i = 0
@@ -1347,24 +1344,24 @@ def Chow_form(self):
13471344
I = self.defining_ideal()
13481345
P = self.ambient_space()
13491346
R = P.coordinate_ring()
1350-
N = P.dimension()+1
1347+
N = P.dimension() + 1
13511348
d = self.dimension()
13521349
# create the ring for the generic linear hyperplanes
13531350
# u0x0 + u1x1 + ...
1354-
SS = PolynomialRing(R.base_ring(), 'u', N*(d+1), order='lex')
1351+
SS = PolynomialRing(R.base_ring(), 'u', N * (d + 1), order='lex')
13551352
vars = SS.variable_names() + R.variable_names()
13561353
S = PolynomialRing(R.base_ring(), vars, order='lex')
13571354
n = S.ngens()
1358-
newcoords = [S.gen(n-N+t) for t in range(N)]
1355+
newcoords = [S.gen(n - N + t) for t in range(N)]
13591356
# map the generators of the subscheme into the ring with the hyperplane variables
1360-
phi = R.hom(newcoords,S)
1357+
phi = R.hom(newcoords, S)
13611358
phi(self.defining_polynomials()[0])
13621359
# create the dim(X)+1 linear hyperplanes
13631360
l = []
1364-
for i in range(d+1):
1361+
for i in range(d + 1):
13651362
t = 0
13661363
for j in range(N):
1367-
t += S.gen(N*i + j)*newcoords[j]
1364+
t += S.gen(N * i + j) * newcoords[j]
13681365
l.append(t)
13691366
# intersect the hyperplanes with X
13701367
J = phi(I) + S.ideal(l)
@@ -1373,15 +1370,15 @@ def Chow_form(self):
13731370
# eliminate the original variables to be left with the hyperplane coefficients 'u'
13741371
E = J2.elimination_ideal(newcoords)
13751372
# create the plucker coordinates
1376-
D = binomial(N,N-d-1) #number of plucker coordinates
1377-
tvars = [str('t') + str(i) for i in range(D)] #plucker coordinates
1378-
T = PolynomialRing(R.base_ring(), tvars+list(S.variable_names()), order='lex')
1373+
D = binomial(N, N - d - 1) # number of plucker coordinates
1374+
tvars = [f't{i}' for i in range(D)] # plucker coordinates
1375+
T = PolynomialRing(R.base_ring(), tvars + list(S.variable_names()), order='lex')
13791376
L = []
1380-
coeffs = [T.gen(i) for i in range(0+len(tvars), N*(d+1)+len(tvars))]
1381-
M = matrix(T,d+1,N,coeffs)
1377+
coeffs = [T.gen(i) for i in range(len(tvars), N * (d + 1) + len(tvars))]
1378+
M = matrix(T, d + 1, N, coeffs)
13821379
i = 0
1383-
for c in M.minors(d+1):
1384-
L.append(T.gen(i)-c)
1380+
for c in M.minors(d + 1):
1381+
L.append(T.gen(i) - c)
13851382
i += 1
13861383
# create the ideal that we can use for eliminating to get a polynomial
13871384
# in the plucker coordinates (brackets)
@@ -1398,14 +1395,12 @@ def Chow_form(self):
13981395
# get the relations among the plucker coordinates
13991396
rel = br.elimination_ideal(coeffs)
14001397
# reduce CH with respect to the relations
1401-
reduced = []
1402-
for f in CH.gens():
1403-
reduced.append(f.reduce(rel))
1398+
reduced = [f.reduce(rel) for f in CH.gens()]
14041399
# find the principal generator
14051400

14061401
# polynomial ring in just the plucker coordinates
14071402
T2 = PolynomialRing(R.base_ring(), tvars)
1408-
alp = T.hom(tvars + (N*(d+1) + N)*[0], T2)
1403+
alp = T.hom(tvars + (N * (d + 1) + N) * [0], T2)
14091404
# get the degrees of the reduced generators of CH
14101405
degs = [u.degree() for u in reduced]
14111406
mind = max(degs)
@@ -1414,7 +1409,7 @@ def Chow_form(self):
14141409
if d < mind and d > 0:
14151410
mind = d
14161411
ind = degs.index(mind)
1417-
CF = reduced[ind] #this should be the Chow form of X
1412+
CF = reduced[ind] # this should be the Chow form of X
14181413
# check that it is correct (i.e., it is a principal generator for CH + the relations)
14191414
rel2 = rel + [CF]
14201415
assert all(f in rel2 for f in CH.gens()), "did not find a principal generator"

0 commit comments

Comments
 (0)