@@ -17,7 +17,6 @@ AUTHORS:
17
17
# https://www.gnu.org/licenses/
18
18
# ****************************************************************************
19
19
20
- from copy import copy
21
20
from cpython.object cimport Py_EQ, Py_NE, Py_GT, Py_GE
22
21
23
22
from sage.misc.repr import repr_lincomb
@@ -119,9 +118,11 @@ cdef class LieAlgebraElement(IndexedFreeModuleElement):
119
118
return s
120
119
names = self .parent().variable_names()
121
120
if base_map is None :
122
- base_map = lambda x : x
121
+ def base_map (x ):
122
+ return x
123
+
123
124
return codomain.sum(base_map(c) * t._im_gens_(codomain, im_gens, names)
124
- for t, c in self ._monomial_coefficients.iteritems ())
125
+ for t, c in self ._monomial_coefficients.items ())
125
126
126
127
cpdef lift(self ):
127
128
"""
@@ -166,10 +167,10 @@ cdef class LieAlgebraElement(IndexedFreeModuleElement):
166
167
# does not match the generators index set of the UEA.
167
168
if hasattr (self ._parent, ' _UEA_names_map' ):
168
169
names_map = self ._parent._UEA_names_map
169
- for t, c in self ._monomial_coefficients.iteritems ():
170
+ for t, c in self ._monomial_coefficients.items ():
170
171
s += c * gen_dict[names_map[t]]
171
172
else :
172
- for t, c in self ._monomial_coefficients.iteritems ():
173
+ for t, c in self ._monomial_coefficients.items ():
173
174
s += c * gen_dict[t]
174
175
return s
175
176
@@ -459,7 +460,7 @@ cdef class LieAlgebraElementWrapper(ElementWrapper):
459
460
((1,3,2), 1), ((1,3), 1)]
460
461
"""
461
462
cdef dict d = self .value.monomial_coefficients(copy = False )
462
- yield from d.iteritems ()
463
+ yield from d.items ()
463
464
464
465
465
466
# TODO: Also used for vectors, find a better name
@@ -598,7 +599,8 @@ cdef class LieSubalgebraElementWrapper(LieAlgebraElementWrapper):
598
599
if self ._monomial_coefficients is None :
599
600
sm = self .parent().module()
600
601
v = sm.coordinate_vector(self .to_vector())
601
- self ._monomial_coefficients = {k: v[k] for k in range (len (v)) if v[k]}
602
+ self ._monomial_coefficients = {k: v[k] for k in range (len (v))
603
+ if v[k]}
602
604
if copy:
603
605
return dict (self ._monomial_coefficients)
604
606
return self ._monomial_coefficients
@@ -861,7 +863,7 @@ cdef class StructureCoefficientsElement(LieAlgebraMatrixWrapper):
861
863
"""
862
864
UEA = self ._parent.universal_enveloping_algebra()
863
865
gens = UEA.gens()
864
- return UEA.sum(c * gens[i] for i, c in self .value.iteritems ())
866
+ return UEA.sum(c * gens[i] for i, c in self .value.items ())
865
867
866
868
cpdef dict monomial_coefficients(self , bint copy = True ):
867
869
"""
@@ -878,7 +880,7 @@ cdef class StructureCoefficientsElement(LieAlgebraMatrixWrapper):
878
880
{'x': 2, 'z': -3/2}
879
881
"""
880
882
I = self ._parent._indices
881
- return {I[i]: v for i, v in self .value.iteritems ()}
883
+ return {I[i]: v for i, v in self .value.items ()}
882
884
883
885
def __getitem__ (self , i ):
884
886
"""
@@ -1066,7 +1068,8 @@ cdef class UntwistedAffineLieAlgebraElement(Element):
1066
1068
( alpha[1 ] - alphacheck[1 ] + 2·-alpha[1 ] ) ⊗t⁰ + ( -alpha[1 ] ) ⊗t¹ + 3⋅c + -2⋅d
1067
1069
"""
1068
1070
from sage.typeset.unicode_art import unicode_art, unicode_superscript
1069
- return self ._repr_generic(unicode_art, unicode_art, lambda t : " t" + unicode_superscript(t),
1071
+ return self ._repr_generic(unicode_art, unicode_art,
1072
+ lambda t : " t" + unicode_superscript(t),
1070
1073
unicode_art(' ⋅' ), unicode_art(' ⊗' ))
1071
1074
1072
1075
cpdef dict t_dict(self ):
@@ -1269,7 +1272,7 @@ cdef class UntwistedAffineLieAlgebraElement(Element):
1269
1272
"""
1270
1273
cdef dict d = {}
1271
1274
for t, g in self ._t_dict.items():
1272
- for k, c in g.monomial_coefficients(copy = False ).iteritems ():
1275
+ for k, c in g.monomial_coefficients(copy = False ).items ():
1273
1276
d[k, t] = c
1274
1277
if self ._c_coeff:
1275
1278
d[' c' ] = self ._c_coeff
@@ -1437,7 +1440,7 @@ class FreeLieAlgebraElement(LieAlgebraElement):
1437
1440
if not self :
1438
1441
return s
1439
1442
gen_dict = UEA.gens_dict()
1440
- for t, c in self ._monomial_coefficients.iteritems ():
1443
+ for t, c in self ._monomial_coefficients.items ():
1441
1444
s += c * t.lift(gen_dict)
1442
1445
return s
1443
1446
@@ -1446,6 +1449,7 @@ class FreeLieAlgebraElement(LieAlgebraElement):
1446
1449
Return ``self`` as a list of pairs ``(m, c)`` where ``m`` is a
1447
1450
basis key (i.e., a key of one of the basis elements)
1448
1451
and ``c`` is its coefficient.
1452
+
1449
1453
This list is sorted from highest to lowest degree.
1450
1454
1451
1455
EXAMPLES::
@@ -1455,8 +1459,10 @@ class FreeLieAlgebraElement(LieAlgebraElement):
1455
1459
sage: elt.list()
1456
1460
[([x, y], -1), (x, 1)]
1457
1461
"""
1458
- k = lambda x : (- x[0 ]._grade, x[0 ]) if isinstance (x[0 ], GradedLieBracket) else (- 1 , x[0 ])
1459
- return sorted ((< dict > self ._monomial_coefficients).iteritems(), key = k)
1462
+ def k (x ):
1463
+ y = x[0 ]
1464
+ return (- y._grade, y) if isinstance (y, GradedLieBracket) else (- 1 , y)
1465
+ return sorted ((< dict > self ._monomial_coefficients).items(), key = k)
1460
1466
1461
1467
def _bracket_ (self , y ):
1462
1468
"""
@@ -1479,16 +1485,16 @@ class FreeLieAlgebraElement(LieAlgebraElement):
1479
1485
1480
1486
cdef dict d = {}
1481
1487
zero = self .base_ring().zero()
1482
- for ml, cl in self ._monomial_coefficients.iteritems (): # The left monomials
1483
- for mr, cr in y._monomial_coefficients.iteritems (): # The right monomials
1488
+ for ml, cl in self ._monomial_coefficients.items (): # The left monomials
1489
+ for mr, cr in y._monomial_coefficients.items (): # The right monomials
1484
1490
if ml == mr:
1485
1491
continue
1486
1492
if ml < mr: # Make sure ml < mr
1487
1493
a, b = ml, mr
1488
1494
else :
1489
1495
a, b = mr, ml
1490
1496
cr = - cr
1491
- for b_elt, coeff in self .parent()._rewrite_bracket(a, b).iteritems ():
1497
+ for b_elt, coeff in self .parent()._rewrite_bracket(a, b).items ():
1492
1498
d[b_elt] = d.get(b_elt, zero) + cl * cr * coeff
1493
1499
if d[b_elt] == zero:
1494
1500
del d[b_elt]
0 commit comments