Skip to content

Commit 5347528

Browse files
committed
using _an_element_ in algebras
1 parent 7888c42 commit 5347528

File tree

3 files changed

+84
-76
lines changed

3 files changed

+84
-76
lines changed

src/sage/algebras/askey_wilson.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ def __classcall_private__(cls, R, q=None):
234234
q = R(q)
235235
if q == 0:
236236
raise ValueError("q cannot be 0")
237-
if 1/q not in R:
237+
if 1 / q not in R:
238238
raise ValueError("q={} is not invertible in {}".format(q, R))
239239
if R not in Rings().Commutative():
240240
raise ValueError("{} is not a commutative ring".format(R))
241241
return super().__classcall__(cls, R, q)
242242

243-
def __init__(self, R, q):
243+
def __init__(self, R, q) -> None:
244244
r"""
245245
Initialize ``self``.
246246
@@ -258,7 +258,7 @@ def __init__(self, R, q):
258258
category=cat)
259259
self._assign_names('A,B,C,a,b,g')
260260

261-
def _repr_term(self, t):
261+
def _repr_term(self, t) -> str:
262262
r"""
263263
Return a string representation of the basis element indexed by ``t``.
264264
@@ -278,14 +278,14 @@ def exp(l, e):
278278
if e == 1:
279279
return '*' + l
280280
return '*' + l + '^{}'.format(e)
281-
ret = ''.join(exp(l, e) for l, e in zip(['A','B','C','a','b','g'], t))
281+
ret = ''.join(exp(l, e) for l, e in zip('ABCabg', t))
282282
if not ret:
283283
return '1'
284284
if ret[0] == '*':
285285
ret = ret[1:]
286286
return ret
287287

288-
def _latex_term(self, t):
288+
def _latex_term(self, t) -> str:
289289
r"""
290290
Return a latex representation of the basis element indexed by ``t``.
291291
@@ -389,7 +389,7 @@ def q(self):
389389
return self._q
390390

391391
@cached_method
392-
def an_element(self):
392+
def _an_element_(self):
393393
r"""
394394
Return an element of ``self``.
395395
@@ -451,13 +451,13 @@ def casimir_element(self):
451451
"""
452452
q = self._q
453453
I = self._indices
454-
d = {I((1,1,1,0,0,0)): q, # q ABC
455-
I((2,0,0,0,0,0)): q**2, # q^2 A^2
456-
I((0,2,0,0,0,0)): q**-2, # q^-2 B^2
457-
I((0,0,2,0,0,0)): q**2, # q^2 C^2
458-
I((1,0,0,1,0,0)): -q, # -q A\alpha
459-
I((0,1,0,0,1,0)): -q**-1, # -q^-1 B\beta
460-
I((0,0,1,0,0,1)): -q} # -q C\gamma
454+
d = {I((1, 1, 1, 0, 0, 0)): q, # q ABC
455+
I((2, 0, 0, 0, 0, 0)): q**2, # q^2 A^2
456+
I((0, 2, 0, 0, 0, 0)): q**-2, # q^-2 B^2
457+
I((0, 0, 2, 0, 0, 0)): q**2, # q^2 C^2
458+
I((1, 0, 0, 1, 0, 0)): -q, # -q A\alpha
459+
I((0, 1, 0, 0, 1, 0)): -q**-1, # -q^-1 B\beta
460+
I((0, 0, 1, 0, 0, 1)): -q} # -q C\gamma
461461
return self.element_class(self, d)
462462

463463
@cached_method
@@ -505,7 +505,7 @@ def product_on_basis(self, x, y):
505505
# Commute the central parts to the right
506506
lhs = list(x[:3])
507507
rhs = list(y)
508-
for i in range(3,6):
508+
for i in range(3, 6):
509509
rhs[i] += x[i]
510510

511511
# No ABC variables on the RHS to move past
@@ -515,44 +515,44 @@ def product_on_basis(self, x, y):
515515
# We recurse using the PBW-type basis property:
516516
# that YX = XY + lower order terms (see Theorem 4.1 in Terwilliger).
517517
q = self._q
518-
if lhs[2] > 0: # lhs has a C
519-
if rhs[0] > 0: # rhs has an A to commute with C
518+
if lhs[2] > 0: # lhs has a C
519+
if rhs[0] > 0: # rhs has an A to commute with C
520520
lhs[2] -= 1
521521
rhs[0] -= 1
522-
rel = {I((1,0,1,0,0,0)): q**-2, # q^2 AC
523-
I((0,1,0,0,0,0)): q**-3 - q**1, # q^-1(q^-2-q^2) B
524-
I((0,0,0,0,1,0)): 1 - q**-2} # -q^-1(q^-1-q) b
522+
rel = {I((1, 0, 1, 0, 0, 0)): q**-2, # q^2 AC
523+
I((0, 1, 0, 0, 0, 0)): q**-3 - q**1, # q^-1(q^-2-q^2) B
524+
I((0, 0, 0, 0, 1, 0)): 1 - q**-2} # -q^-1(q^-1-q) b
525525
rel = self.element_class(self, rel)
526526
return self.monomial(I(lhs+[0]*3)) * (rel * self.monomial(I(rhs)))
527-
elif rhs[1] > 0: # rhs has a B to commute with C
527+
elif rhs[1] > 0: # rhs has a B to commute with C
528528
lhs[2] -= 1
529529
rhs[1] -= 1
530-
rel = {I((0,1,1,0,0,0)): q**2, # q^2 BC
531-
I((1,0,0,0,0,0)): q**3 - q**-1, # q(q^2-q^-2) A
532-
I((0,0,0,1,0,0)): -q**2 + 1} # -q(q-q^-1) a
530+
rel = {I((0, 1, 1, 0, 0, 0)): q**2, # q^2 BC
531+
I((1, 0, 0, 0, 0, 0)): q**3 - q**-1, # q(q^2-q^-2) A
532+
I((0, 0, 0, 1, 0, 0)): -q**2 + 1} # -q(q-q^-1) a
533533
rel = self.element_class(self, rel)
534534
return self.monomial(I(lhs+[0]*3)) * (rel * self.monomial(I(rhs)))
535-
else: # nothing to commute as rhs has no A nor B
535+
else: # nothing to commute as rhs has no A nor B
536536
rhs[2] += lhs[2]
537537
rhs[1] = lhs[1]
538538
rhs[0] = lhs[0]
539539
return self.monomial(I(rhs))
540540

541-
elif lhs[1] > 0: # lhs has a B
542-
if rhs[0] > 0: # rhs has an A to commute with B
541+
elif lhs[1] > 0: # lhs has a B
542+
if rhs[0] > 0: # rhs has an A to commute with B
543543
lhs[1] -= 1
544544
rhs[0] -= 1
545-
rel = {I((1,1,0,0,0,0)): q**2, # q^2 AB
546-
I((0,0,1,0,0,0)): q**3 - q**-1, # q(q^2-q^-2) C
547-
I((0,0,0,0,0,1)): -q**2 + 1} # -q(q-q^-1) g
545+
rel = {I((1, 1, 0, 0, 0, 0)): q**2, # q^2 AB
546+
I((0, 0, 1, 0, 0, 0)): q**3 - q**-1, # q(q^2-q^-2) C
547+
I((0, 0, 0, 0, 0, 1)): -q**2 + 1} # -q(q-q^-1) g
548548
rel = self.element_class(self, rel)
549549
return self.monomial(I(lhs+[0]*3)) * (rel * self.monomial(I(rhs)))
550-
else: # nothing to commute as rhs has no A
550+
else: # nothing to commute as rhs has no A
551551
rhs[1] += lhs[1]
552552
rhs[0] = lhs[0]
553553
return self.monomial(I(rhs))
554554

555-
elif lhs[0] > 0: # lhs has an A
555+
elif lhs[0] > 0: # lhs has an A
556556
rhs[0] += lhs[0]
557557
return self.monomial(I(rhs))
558558

@@ -905,7 +905,7 @@ def _on_basis(self, c):
905905
+ (3-3*q^2)*g^2 - q^2*C + q*g
906906
"""
907907
return self.codomain().prod(self._on_generators[i]**exp
908-
for i,exp in enumerate(c))
908+
for i, exp in enumerate(c))
909909

910910
def _composition_(self, right, homset):
911911
"""

src/sage/algebras/rational_cherednik_algebra.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __classcall_private__(cls, ct, c=1, t=None, base_ring=None, prefix=('a', 's'
117117

118118
return super().__classcall__(cls, ct, c, t, base_ring, tuple(prefix))
119119

120-
def __init__(self, ct, c, t, base_ring, prefix):
120+
def __init__(self, ct, c, t, base_ring, prefix) -> None:
121121
r"""
122122
Initialize ``self``.
123123
@@ -161,7 +161,7 @@ def _genkey(self, t):
161161
return (self.degree_on_basis(t), t[1].length(), t[1], str(t[0]), str(t[2]))
162162

163163
@lazy_attribute
164-
def _reflections(self):
164+
def _reflections(self) -> dict:
165165
"""
166166
A dictionary of reflections to a pair of the associated root
167167
and coroot.
@@ -205,7 +205,7 @@ def _repr_(self) -> str:
205205
ret += "c_L={} and c_S={}".format(*self._c)
206206
return ret + " and t={} over {}".format(self._t, self.base_ring())
207207

208-
def _repr_term(self, t):
208+
def _repr_term(self, t) -> str:
209209
"""
210210
Return a string representation of the term indexed by ``t``.
211211
@@ -238,26 +238,26 @@ def algebra_generators(self):
238238
sage: list(R.algebra_generators())
239239
[a1, a2, s1, s2, ac1, ac2]
240240
"""
241-
keys = ['a'+str(i) for i in self._cartan_type.index_set()]
242-
keys += ['s'+str(i) for i in self._cartan_type.index_set()]
243-
keys += ['ac'+str(i) for i in self._cartan_type.index_set()]
241+
keys = ['a' + str(i) for i in self._cartan_type.index_set()]
242+
keys += ['s' + str(i) for i in self._cartan_type.index_set()]
243+
keys += ['ac' + str(i) for i in self._cartan_type.index_set()]
244244

245245
def gen_map(k):
246246
if k[0] == 's':
247247
i = int(k[1:])
248248
return self.monomial((self._hd.one(),
249-
self._weyl.group_generators()[i],
250-
self._h.one()))
249+
self._weyl.group_generators()[i],
250+
self._h.one()))
251251
if k[1] == 'c':
252252
i = int(k[2:])
253253
return self.monomial((self._hd.one(),
254-
self._weyl.one(),
255-
self._h.monoid_generators()[i]))
254+
self._weyl.one(),
255+
self._h.monoid_generators()[i]))
256256

257257
i = int(k[1:])
258258
return self.monomial((self._hd.monoid_generators()[i],
259-
self._weyl.one(),
260-
self._h.one()))
259+
self._weyl.one(),
260+
self._h.one()))
261261
return Family(keys, gen_map)
262262

263263
@cached_method
@@ -320,12 +320,12 @@ def product_on_basis(self, left, right):
320320
I = self._cartan_type.index_set()
321321
P = PolynomialRing(R, 'x', len(I))
322322
G = P.gens()
323-
gens_dict = {a:G[i] for i,a in enumerate(I)}
323+
gens_dict = {a: G[i] for i, a in enumerate(I)}
324324
Q = RootSystem(self._cartan_type).root_lattice()
325325
alpha = Q.simple_roots()
326326
alphacheck = Q.simple_coroots()
327327

328-
def commute_w_hd(w, al): # al is given as a dictionary
328+
def commute_w_hd(w, al): # al is given as a dictionary
329329
ret = P.one()
330330
for k in al:
331331
x = sum(c * gens_dict[i] for i, c in alpha[k].weyl_action(w))
@@ -351,15 +351,15 @@ def commute_w_hd(w, al): # al is given as a dictionary
351351
del dr[ir]
352352

353353
# We now commute right roots past the left reflections: s Ra = Ra' s
354-
cur = self._from_dict({(hd, s*right[1], right[2]): c * cc
355-
for s,c in terms
356-
for hd, cc in commute_w_hd(s, dr)})
354+
cur = self._from_dict({(hd, s * right[1], right[2]): c * cc
355+
for s, c in terms
356+
for hd, cc in commute_w_hd(s, dr)})
357357
cur = self.monomial((left[0], left[1], self._h(dl))) * cur
358358

359359
# Add back in the commuted h and hd elements
360360
rem = self.monomial((left[0], left[1], self._h(dl)))
361-
rem = rem * self.monomial((self._hd({ir:1}), self._weyl.one(),
362-
self._h({il:1})))
361+
rem = rem * self.monomial((self._hd({ir: 1}), self._weyl.one(),
362+
self._h({il: 1})))
363363
rem = rem * self.monomial((self._hd(dr), right[1], right[2]))
364364

365365
return cur + rem
@@ -385,9 +385,9 @@ def commute_w_hd(w, al): # al is given as a dictionary
385385

386386
# Otherwise dr is non-trivial and we have La Ls Ra Rs Rac,
387387
# so we must commute Ls Ra = Ra' Ls
388-
w = left[1]*right[1]
388+
w = left[1] * right[1]
389389
return self._from_dict({(left[0] * hd, w, right[2]): c
390-
for hd, c in commute_w_hd(left[1], dr)})
390+
for hd, c in commute_w_hd(left[1], dr)})
391391

392392
@cached_method
393393
def _product_coroot_root(self, i, j):
@@ -435,7 +435,7 @@ def _product_coroot_root(self, i, j):
435435
# p[0] is the root, p[1] is the coroot, p[2] the value c_s
436436
pr, pc, c = self._reflections[s]
437437
terms.append((s, c * R(ac.scalar(pr) * pc.scalar(al)
438-
/ pc.scalar(pr))))
438+
/ pc.scalar(pr))))
439439
return tuple(terms)
440440

441441
def degree_on_basis(self, m):
@@ -468,8 +468,8 @@ def trivial_idempotent(self):
468468
1/6*I + 1/6*s1 + 1/6*s2 + 1/6*s2*s1 + 1/6*s1*s2 + 1/6*s1*s2*s1
469469
"""
470470
coeff = self.base_ring()(~self._weyl.cardinality())
471-
hd_one = self._hd.one() # root - a
472-
h_one = self._h.one() # coroot - ac
471+
hd_one = self._hd.one() # root - a
472+
h_one = self._h.one() # coroot - ac
473473
return self._from_dict({(hd_one, w, h_one): coeff for w in self._weyl},
474474
remove_zeros=False)
475475

@@ -489,12 +489,13 @@ def deformed_euler(self):
489489
G = self.algebra_generators()
490490
cm = ~CartanMatrix(self._cartan_type)
491491
n = len(I)
492-
ac = [G['ac'+str(i)] for i in I]
493-
la = [sum(cm[i,j]*G['a'+str(I[i])] for i in range(n)) for j in range(n)]
494-
return self.sum(ac[i]*la[i] for i in range(n))
492+
ac = [G['ac' + str(i)] for i in I]
493+
la = [sum(cm[i, j] * G['a' + str(I[i])]
494+
for i in range(n)) for j in range(n)]
495+
return self.sum(ac[i] * la[i] for i in range(n))
495496

496497
@cached_method
497-
def an_element(self):
498+
def _an_element_(self):
498499
"""
499500
Return an element of ``self``.
500501
@@ -506,7 +507,7 @@ def an_element(self):
506507
"""
507508
G = self.algebra_generators()
508509
i = str(self._cartan_type.index_set()[0])
509-
return G['a'+i] + 2*G['s'+i] + 3*G['ac'+i]
510+
return G['a' + i] + 2 * G['s' + i] + 3 * G['ac' + i]
510511

511512
def some_elements(self):
512513
"""

0 commit comments

Comments
 (0)