22
22
from sage .misc .lazy_attribute import lazy_attribute
23
23
from sage .misc .misc_c import prod
24
24
from sage .structure .richcmp import richcmp
25
- from sage .structure .element import AlgebraElement
25
+ from sage .structure .element import Element
26
+ from sage .structure .parent import Parent
26
27
from sage .structure .unique_representation import UniqueRepresentation
27
28
from sage .categories .action import Action
28
29
from sage .categories .rings import Rings
36
37
from sage .structure .global_options import GlobalOptions
37
38
38
39
39
- def repr_from_monomials (monomials , term_repr , use_latex = False ):
40
+ def repr_from_monomials (monomials , term_repr , use_latex = False ) -> str :
40
41
r"""
41
42
Return a string representation of an element of a free module
42
43
from the dictionary ``monomials``.
@@ -161,7 +162,7 @@ def repr_from_monomials(monomials, term_repr, use_latex=False):
161
162
return ret
162
163
163
164
164
- def repr_factored (w , latex_output = False ):
165
+ def repr_factored (w , latex_output = False ) -> str :
165
166
r"""
166
167
Return a string representation of ``w`` with the `dx_i` generators
167
168
factored on the right.
@@ -231,11 +232,11 @@ def repr_dx(k):
231
232
return ret
232
233
233
234
234
- class DifferentialWeylAlgebraElement (AlgebraElement ):
235
+ class DifferentialWeylAlgebraElement (Element ):
235
236
"""
236
237
An element in a differential Weyl algebra.
237
238
"""
238
- def __init__ (self , parent , monomials ):
239
+ def __init__ (self , parent , monomials ) -> None :
239
240
"""
240
241
Initialize ``self``.
241
242
@@ -246,10 +247,10 @@ def __init__(self, parent, monomials):
246
247
sage: elt = ((x^3-z)*dx + dy)^2
247
248
sage: TestSuite(elt).run()
248
249
"""
249
- AlgebraElement .__init__ (self , parent )
250
+ Element .__init__ (self , parent )
250
251
self .__monomials = monomials
251
252
252
- def _repr_ (self ):
253
+ def _repr_ (self ) -> str :
253
254
r"""
254
255
Return a string representation of ``self``.
255
256
@@ -279,7 +280,7 @@ def term(m):
279
280
return ret
280
281
return repr_from_monomials (self .list (), term )
281
282
282
- def _latex_ (self ):
283
+ def _latex_ (self ) -> str :
283
284
r"""
284
285
Return a `\LaTeX` representation of ``self``.
285
286
@@ -319,15 +320,15 @@ def half_term(mon, polynomial):
319
320
return ret
320
321
p = half_term (m [0 ], True )
321
322
d = half_term (m [1 ], False )
322
- if p == '1' : # No polynomial part
323
+ if p == '1' : # No polynomial part
323
324
return d
324
- elif d == '1' : # No differential part
325
+ elif d == '1' : # No differential part
325
326
return p
326
327
else :
327
328
return p + ' ' + d
328
329
return repr_from_monomials (self .list (), term , True )
329
330
330
- def _richcmp_ (self , other , op ):
331
+ def _richcmp_ (self , other , op ) -> bool :
331
332
"""
332
333
Rich comparison for equal parents.
333
334
@@ -369,7 +370,7 @@ def __neg__(self):
369
370
dy + z*dx - 3*x*dx
370
371
"""
371
372
return self .__class__ (self .parent (),
372
- {m :- c for m , c in self .__monomials .items ()})
373
+ {m : - c for m , c in self .__monomials .items ()})
373
374
374
375
def _add_ (self , other ):
375
376
"""
@@ -399,28 +400,30 @@ def _mul_(self, other):
399
400
dx*dy*dz^2 + x^3*dx^2*dz^2 - z*dx^2*dz^2 - 10*x*dy - 10*x^4*dx
400
401
+ 10*x*z*dx - 10*x^3 + 10*z
401
402
"""
402
- add_tuples = lambda x ,y : tuple (a + y [i ] for i ,a in enumerate (x ))
403
+ def add_tuples (x , y ):
404
+ return tuple (a + y [i ] for i , a in enumerate (x ))
405
+
403
406
d = {}
404
407
n = self .parent ()._n
405
- t = tuple ([0 ]* n )
408
+ t = tuple ([0 ] * n )
406
409
zero = self .parent ().base_ring ().zero ()
407
410
for ml in self .__monomials :
408
411
cl = self .__monomials [ml ]
409
412
for mr in other .__monomials :
410
413
cr = other .__monomials [mr ]
411
- cur = [ ((mr [0 ], t ), cl * cr ) ]
414
+ cur = [((mr [0 ], t ), cl * cr )]
412
415
for i , p in enumerate (ml [1 ]):
413
416
for _ in range (p ):
414
417
next = []
415
418
for m , c in cur : # Distribute and apply the derivative
416
419
diff = list (m [1 ])
417
420
diff [i ] += 1
418
- next .append ( ((m [0 ], tuple (diff )), c ) )
421
+ next .append (((m [0 ], tuple (diff )), c ))
419
422
if m [0 ][i ] != 0 :
420
423
poly = list (m [0 ])
421
424
c *= poly [i ]
422
425
poly [i ] -= 1
423
- next .append ( ((tuple (poly ), m [1 ]), c ) )
426
+ next .append (((tuple (poly ), m [1 ]), c ))
424
427
cur = next
425
428
426
429
for m , c in cur :
@@ -446,7 +449,7 @@ def _rmul_(self, other):
446
449
if other == 0 :
447
450
return self .parent ().zero ()
448
451
M = self .__monomials
449
- return self .__class__ (self .parent (), {t : other * M [t ] for t in M })
452
+ return self .__class__ (self .parent (), {t : other * M [t ] for t in M })
450
453
451
454
def _lmul_ (self , other ):
452
455
"""
@@ -463,9 +466,9 @@ def _lmul_(self, other):
463
466
if other == 0 :
464
467
return self .parent ().zero ()
465
468
M = self .__monomials
466
- return self .__class__ (self .parent (), {t : M [t ]* other for t in M })
469
+ return self .__class__ (self .parent (), {t : M [t ] * other for t in M })
467
470
468
- def monomial_coefficients (self , copy = True ):
471
+ def monomial_coefficients (self , copy = True ) -> dict :
469
472
"""
470
473
Return a dictionary which has the basis keys in the support
471
474
of ``self`` as keys and their corresponding coefficients
@@ -509,7 +512,7 @@ def __iter__(self):
509
512
"""
510
513
return iter (self .list ())
511
514
512
- def list (self ):
515
+ def list (self ) -> list :
513
516
"""
514
517
Return ``self`` as a list.
515
518
@@ -529,9 +532,9 @@ def list(self):
529
532
(((1, 0, 0), (1, 0, 0)), -3)]
530
533
"""
531
534
return sorted (self .__monomials .items (),
532
- key = lambda x : (- sum (x [0 ][1 ]), x [0 ][1 ], - sum (x [0 ][0 ]), x [0 ][0 ]) )
535
+ key = lambda x : (- sum (x [0 ][1 ]), x [0 ][1 ], - sum (x [0 ][0 ]), x [0 ][0 ]))
533
536
534
- def support (self ):
537
+ def support (self ) -> list :
535
538
"""
536
539
Return the support of ``self``.
537
540
@@ -567,15 +570,15 @@ def __truediv__(self, x):
567
570
F = self .parent ()
568
571
D = self .__monomials
569
572
if F .base_ring ().is_field ():
570
- x = F .base_ring ()( x )
573
+ x = F .base_ring ()(x )
571
574
x_inv = x ** - 1
572
- D = blas .linear_combination ( [ ( D , x_inv ) ] )
575
+ D = blas .linear_combination ([( D , x_inv )] )
573
576
574
577
return self .__class__ (F , D )
575
578
576
579
return self .__class__ (F , {t : D [t ]._divide_if_possible (x ) for t in D })
577
580
578
- def factor_differentials (self ):
581
+ def factor_differentials (self ) -> dict :
579
582
"""
580
583
Return a dict representing ``self`` with the differentials
581
584
factored out.
@@ -617,7 +620,7 @@ def factor_differentials(self):
617
620
DW = self .parent ()
618
621
P = DW .polynomial_ring ()
619
622
gens = P .gens ()
620
- for m ,c in self :
623
+ for m , c in self :
621
624
x , dx = m
622
625
if dx not in ret :
623
626
ret [dx ] = P .zero ()
@@ -743,7 +746,7 @@ def __classcall__(cls, R, names=None):
743
746
raise TypeError ("argument R must be a commutative ring" )
744
747
return super ().__classcall__ (cls , R , names )
745
748
746
- def __init__ (self , R , names = None ):
749
+ def __init__ (self , R , names = None ) -> None :
747
750
r"""
748
751
Initialize ``self``.
749
752
@@ -765,9 +768,9 @@ def __init__(self, R, names=None):
765
768
cat = AlgebrasWithBasis (R ).NoZeroDivisors ().Super ()
766
769
else :
767
770
cat = AlgebrasWithBasis (R ).Super ()
768
- Algebra .__init__ (self , R , names , category = cat )
771
+ Parent .__init__ (self , base = R , names = names , category = cat )
769
772
770
- def _repr_ (self ):
773
+ def _repr_ (self ) -> str :
771
774
r"""
772
775
Return a string representation of ``self``.
773
776
@@ -779,7 +782,7 @@ def _repr_(self):
779
782
"""
780
783
poly_gens = ', ' .join (repr (x ) for x in self .gens ()[:self ._n ])
781
784
return "Differential Weyl algebra of polynomials in {} over {}" .format (
782
- poly_gens , self .base_ring ())
785
+ poly_gens , self .base_ring ())
783
786
784
787
# add options to class
785
788
class options (GlobalOptions ):
@@ -829,7 +832,7 @@ def _element_constructor_(self, x):
829
832
sage: W(x^2 - y*z)
830
833
-y*z + x^2
831
834
"""
832
- t = tuple ([0 ]* (self ._n ))
835
+ t = tuple ([0 ] * (self ._n ))
833
836
if x in self .base_ring ():
834
837
if x == self .base_ring ().zero ():
835
838
return self .zero ()
@@ -839,7 +842,7 @@ def _element_constructor_(self, x):
839
842
if x .parent ().base_ring () is R :
840
843
return self .element_class (self , dict (x ))
841
844
zero = R .zero ()
842
- return self .element_class (self , {i : R (c ) for i ,c in x if R (c ) != zero })
845
+ return self .element_class (self , {i : R (c ) for i , c in x if R (c ) != zero })
843
846
x = self ._poly_ring (x )
844
847
return self .element_class (self , {(tuple (m ), t ): c
845
848
for m , c in x .dict ().items ()})
@@ -888,8 +891,8 @@ def _coerce_map_from_(self, R):
888
891
if self ._poly_ring .has_coerce_map_from (R ):
889
892
return True
890
893
if isinstance (R , DifferentialWeylAlgebra ):
891
- return ( R .variable_names () == self .variable_names ()
892
- and self .base_ring ().has_coerce_map_from (R .base_ring ()) )
894
+ return (R .variable_names () == self .variable_names ()
895
+ and self .base_ring ().has_coerce_map_from (R .base_ring ()))
893
896
return super ()._coerce_map_from_ (R )
894
897
895
898
def degree_on_basis (self , i ):
@@ -952,10 +955,16 @@ def basis(self):
952
955
"""
953
956
n = self ._n
954
957
from sage .combinat .integer_lists .nn import IntegerListsNN
955
- elt_map = lambda u : (tuple (u [:n ]), tuple (u [n :]))
956
- I = IntegerListsNN (length = 2 * n , element_constructor = elt_map )
958
+
959
+ def elt_map (u ):
960
+ return (tuple (u [:n ]), tuple (u [n :]))
961
+
962
+ I = IntegerListsNN (length = 2 * n , element_constructor = elt_map )
957
963
one = self .base_ring ().one ()
958
- f = lambda x : self .element_class (self , {(x [0 ], x [1 ]): one })
964
+
965
+ def f (x ):
966
+ return self .element_class (self , {(x [0 ], x [1 ]): one })
967
+
959
968
return Family (I , f , name = "basis map" )
960
969
961
970
@cached_method
@@ -1012,7 +1021,7 @@ def differentials(self):
1012
1021
Finite family {'dx': dx, 'dy': dy, 'dz': dz}
1013
1022
"""
1014
1023
N = self .variable_names ()[self ._n :]
1015
- d = {x : self .gen (self ._n + i ) for i , x in enumerate (N )}
1024
+ d = {x : self .gen (self ._n + i ) for i , x in enumerate (N )}
1016
1025
return Family (N , lambda x : d [x ])
1017
1026
1018
1027
def gen (self , i ):
@@ -1035,8 +1044,8 @@ def gen(self, i):
1035
1044
if i < self ._n :
1036
1045
P [i ] = 1
1037
1046
else :
1038
- D [i - self ._n ] = 1
1039
- return self .element_class (self , {(tuple (P ), tuple (D )): self .base_ring ().one ()} )
1047
+ D [i - self ._n ] = 1
1048
+ return self .element_class (self , {(tuple (P ), tuple (D )): self .base_ring ().one ()})
1040
1049
1041
1050
def ngens (self ):
1042
1051
"""
@@ -1063,8 +1072,8 @@ def one(self):
1063
1072
sage: W.one()
1064
1073
1
1065
1074
"""
1066
- t = tuple ([0 ]* self ._n )
1067
- return self .element_class ( self , {(t , t ): self .base_ring ().one ()} )
1075
+ t = tuple ([0 ] * self ._n )
1076
+ return self .element_class (self , {(t , t ): self .base_ring ().one ()})
1068
1077
1069
1078
@cached_method
1070
1079
def zero (self ):
@@ -1140,7 +1149,7 @@ class DifferentialWeylAlgebraAction(Action):
1140
1149
True
1141
1150
"""
1142
1151
1143
- def __init__ (self , G ):
1152
+ def __init__ (self , G ) -> None :
1144
1153
"""
1145
1154
INPUT:
1146
1155
0 commit comments