29
29
from sage .matrix .constructor import matrix
30
30
31
31
from sage .rings .integer_ring import ZZ
32
- from sage .rings .finite_rings .finite_field_base import FiniteField
33
32
from sage .rings .polynomial .polynomial_ring_constructor import PolynomialRing
34
33
from sage .rings .rational_field import is_RationalField
35
34
@@ -111,7 +110,7 @@ def point(self, v, check=True):
111
110
"""
112
111
from sage .rings .infinity import infinity
113
112
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 ):
115
114
if self .ambient_space ().dimension_relative () > 1 :
116
115
raise ValueError ("%s not well defined in dimension > 1" % v )
117
116
v = [1 , 0 ]
@@ -209,10 +208,10 @@ def affine_patch(self, i, AA=None):
209
208
210
209
INPUT:
211
210
212
- - ``i`` -- integer between 0 and dimension of self, inclusive.
211
+ - ``i`` -- integer between 0 and dimension of `` self`` , inclusive.
213
212
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.
216
215
217
216
OUTPUT:
218
217
@@ -260,11 +259,11 @@ def affine_patch(self, i, AA=None):
260
259
PP = self .ambient_space ()
261
260
n = PP .dimension_relative ()
262
261
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 } ." )
264
263
try :
265
264
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
268
267
if AA is None or A .ambient_space () == AA :
269
268
return self .__affine_patches [i ]
270
269
except AttributeError :
@@ -318,14 +317,14 @@ def _best_affine_patch(self, point):
318
317
"""
319
318
point = list (point )
320
319
try :
321
- abs_point = [abs (_ ) for _ in point ]
320
+ abs_point = [abs (c ) for c in point ]
322
321
except ArithmeticError :
323
322
# our base ring does not know abs
324
323
abs_point = point
325
324
# find best patch
326
325
i_max = 0
327
326
p_max = abs_point [i_max ]
328
- for i in range (1 ,len (point )):
327
+ for i in range (1 , len (point )):
329
328
if abs_point [i ] > p_max :
330
329
i_max = i
331
330
p_max = abs_point [i_max ]
@@ -385,16 +384,17 @@ def neighborhood(self, point):
385
384
R = patch_cover .coordinate_ring ()
386
385
387
386
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 )
392
391
393
392
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 )
396
396
397
- def is_smooth (self , point = None ):
397
+ def is_smooth (self , point = None ) -> bool :
398
398
r"""
399
399
Test whether the algebraic subscheme is smooth.
400
400
@@ -450,7 +450,7 @@ def is_smooth(self, point=None):
450
450
self ._smooth = (sing_dim <= 0 )
451
451
return self ._smooth
452
452
453
- def orbit (self , f , N ):
453
+ def orbit (self , f , N ) -> list :
454
454
r"""
455
455
Return the orbit of this scheme by ``f``.
456
456
@@ -512,8 +512,8 @@ def orbit(self, f, N):
512
512
from sage .dynamics .arithmetic_dynamics .generic_ds import DynamicalSystem
513
513
if not isinstance (f , DynamicalSystem ):
514
514
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 ]
517
517
N [0 ] = ZZ (N [0 ])
518
518
N [1 ] = ZZ (N [1 ])
519
519
if N [0 ] < 0 or N [1 ] < 0 :
@@ -522,11 +522,11 @@ def orbit(self, f, N):
522
522
return []
523
523
524
524
Q = self
525
- for i in range (1 , N [0 ]+ 1 ):
525
+ for i in range (1 , N [0 ] + 1 ):
526
526
Q = f (Q )
527
527
Orb = [Q ]
528
528
529
- for i in range (N [0 ]+ 1 , N [1 ]+ 1 ):
529
+ for i in range (N [0 ] + 1 , N [1 ] + 1 ):
530
530
Q = f (Q )
531
531
Orb .append (Q )
532
532
return Orb
@@ -590,7 +590,7 @@ def nth_iterate(self, f, n):
590
590
n = ZZ (n )
591
591
if n < 0 :
592
592
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 ]
594
594
595
595
def _forward_image (self , f , check = True ):
596
596
r"""
@@ -764,15 +764,15 @@ def _forward_image(self, f, check=True):
764
764
CR_codom = codom .coordinate_ring ()
765
765
n = CR_dom .ngens ()
766
766
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
769
769
R = PolynomialRing (f .base_ring (), n + m , 'tempvar' , order = 'lex' )
770
- Rvars = R .gens ()[0 : n ]
770
+ Rvars = R .gens ()[0 : n ]
771
771
phi = CR_dom .hom (Rvars , R )
772
- zero = n * [0 ]
772
+ zero = n * [0 ]
773
773
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 )])
776
776
G = L .groebner_basis () # eliminate
777
777
newL = []
778
778
# get only the elimination ideal portion
@@ -897,12 +897,9 @@ def preimage(self, f, k=1, check=True):
897
897
if k > 1 and not f .is_endomorphism ():
898
898
raise TypeError ("map must be an endomorphism" )
899
899
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 ()])
906
903
907
904
def dual (self ):
908
905
r"""
@@ -978,13 +975,13 @@ def dual(self):
978
975
from sage .libs .singular .function_factory import ff
979
976
980
977
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 ( )):
982
979
raise NotImplementedError ("base ring must be QQ or a finite field" )
983
980
I = self .defining_ideal ()
984
981
m = I .ngens ()
985
982
n = I .ring ().ngens () - 1
986
983
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 ()):
988
985
raise NotImplementedError ("At the present, the method is only"
989
986
" implemented for irreducible and"
990
987
" reduced hypersurfaces and the given"
@@ -1108,7 +1105,7 @@ def intersection_multiplicity(self, X, P):
1108
1105
try :
1109
1106
self .ambient_space ()(P )
1110
1107
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 ))
1112
1109
# find an affine chart of the ambient space of this curve that contains P
1113
1110
n = self .ambient_space ().dimension_relative ()
1114
1111
for i in range (n + 1 ):
@@ -1173,7 +1170,7 @@ def multiplicity(self, P):
1173
1170
try :
1174
1171
P = self (P )
1175
1172
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 } )" )
1177
1174
1178
1175
# find an affine chart of the ambient space of self that contains P
1179
1176
i = 0
@@ -1347,24 +1344,24 @@ def Chow_form(self):
1347
1344
I = self .defining_ideal ()
1348
1345
P = self .ambient_space ()
1349
1346
R = P .coordinate_ring ()
1350
- N = P .dimension ()+ 1
1347
+ N = P .dimension () + 1
1351
1348
d = self .dimension ()
1352
1349
# create the ring for the generic linear hyperplanes
1353
1350
# 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' )
1355
1352
vars = SS .variable_names () + R .variable_names ()
1356
1353
S = PolynomialRing (R .base_ring (), vars , order = 'lex' )
1357
1354
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 )]
1359
1356
# 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 )
1361
1358
phi (self .defining_polynomials ()[0 ])
1362
1359
# create the dim(X)+1 linear hyperplanes
1363
1360
l = []
1364
- for i in range (d + 1 ):
1361
+ for i in range (d + 1 ):
1365
1362
t = 0
1366
1363
for j in range (N ):
1367
- t += S .gen (N * i + j )* newcoords [j ]
1364
+ t += S .gen (N * i + j ) * newcoords [j ]
1368
1365
l .append (t )
1369
1366
# intersect the hyperplanes with X
1370
1367
J = phi (I ) + S .ideal (l )
@@ -1373,15 +1370,15 @@ def Chow_form(self):
1373
1370
# eliminate the original variables to be left with the hyperplane coefficients 'u'
1374
1371
E = J2 .elimination_ideal (newcoords )
1375
1372
# 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' )
1379
1376
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 )
1382
1379
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 )
1385
1382
i += 1
1386
1383
# create the ideal that we can use for eliminating to get a polynomial
1387
1384
# in the plucker coordinates (brackets)
@@ -1398,14 +1395,12 @@ def Chow_form(self):
1398
1395
# get the relations among the plucker coordinates
1399
1396
rel = br .elimination_ideal (coeffs )
1400
1397
# 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 ()]
1404
1399
# find the principal generator
1405
1400
1406
1401
# polynomial ring in just the plucker coordinates
1407
1402
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 )
1409
1404
# get the degrees of the reduced generators of CH
1410
1405
degs = [u .degree () for u in reduced ]
1411
1406
mind = max (degs )
@@ -1414,7 +1409,7 @@ def Chow_form(self):
1414
1409
if d < mind and d > 0 :
1415
1410
mind = d
1416
1411
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
1418
1413
# check that it is correct (i.e., it is a principal generator for CH + the relations)
1419
1414
rel2 = rel + [CF ]
1420
1415
assert all (f in rel2 for f in CH .gens ()), "did not find a principal generator"
0 commit comments