Skip to content

Commit

Permalink
gh-35459: pep8 and code details in weyl_characters.py
Browse files Browse the repository at this point in the history
    
<!-- Please provide a concise, informative and self-explanatory title.
-->
<!-- Don't put issue numbers in the title. Put it in the Description
below. -->
<!-- For example, instead of "Fixes #12345", use "Add a new method to
multiply two integers" -->

### 📚 Description

Partial pep8 cleanup of the wile `weyl_characters.py`

also simplifying some dictionary constructions

and renaming `adams_operation` to `adams_operator`

<!-- Describe your changes here in detail. -->
<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes #12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x
]`. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- #12345: short description why this is a dependency
- #34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: #35459
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Apr 12, 2023
2 parents 91949e3 + e33815f commit a6e2c32
Showing 1 changed file with 55 additions and 56 deletions.
111 changes: 55 additions & 56 deletions src/sage/combinat/root_system/weyl_characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(self, ct, base_ring=ZZ, prefix=None, style="lattice", k=None, conju
self._origin = self._space.zero()
if prefix is None:
if ct.is_atomic():
prefix = ct[0]+str(ct[1])
prefix = ct[0] + str(ct[1])
else:
prefix = repr(ct)
self._prefix = prefix
Expand Down Expand Up @@ -510,7 +510,7 @@ def product_on_basis(self, a, b):
# smaller character is the one that is decomposed
# into weights.
if sum(a.coefficients()) > sum(b.coefficients()):
a,b = b,a
a, b = b, a
return self._product_helper(self._irr_weights(a), b)

def _product_helper(self, d1, b):
Expand All @@ -535,11 +535,11 @@ def _product_helper(self, d1, b):
"""
d = {}
for k in d1:
[epsilon,g] = self.dot_reduce(b+k)
[epsilon, g] = self.dot_reduce(b + k)
if epsilon == 1:
d[g] = d.get(g,0) + d1[k]
d[g] = d.get(g, 0) + d1[k]
elif epsilon == -1:
d[g] = d.get(g,0) - d1[k]
d[g] = d.get(g, 0) - d1[k]
return self._from_dict(d, coerce=True)

def dot_reduce(self, a):
Expand Down Expand Up @@ -576,31 +576,32 @@ def dot_reduce(self, a):
return [0, self._space.zero()]
elif c < -1:
epsilon = -epsilon
ret -= (1+c)*alpha[i]
ret -= (1 + c) * alpha[i]
done = False
break
if self._k is not None:
l = self.level(ret)
k = self._k
if l > k:
if l == k+1:
if l == k + 1:
return [0, self._space.zero()]
else:
epsilon = -epsilon
ret = self.affine_reflect(ret,k+1)
ret = self.affine_reflect(ret, k + 1)
done = False
return [epsilon, ret]

def affine_reflect(self, wt, k=0):
r"""
Return the reflection of wt in the hyperplane `\theta`.
Optionally, this also shifts by a multiple `k` of `\theta`.
INPUT:
- ``wt`` -- a weight
- ``k`` -- (optional) a positive integer
Returns the reflection of wt in the hyperplane
`\theta`. Optionally shifts by a multiple `k`of `\theta`.
EXAMPLES::
sage: B22 = FusionRing("B2",2)
Expand All @@ -609,8 +610,8 @@ def affine_reflect(self, wt, k=0):
sage: [B22.affine_reflect(x,2) for x in fw]
[(2, 1), (3/2, 3/2)]
"""
coef = ZZ(2*wt.inner_product(self._highest)/self._hip)
return wt+(k-coef)*self._highest
coef = ZZ(2 * wt.inner_product(self._highest) / self._hip)
return wt + (k - coef) * self._highest

def some_elements(self):
"""
Expand Down Expand Up @@ -722,7 +723,7 @@ def _demazure_helper(self, dd, word="long", debug=False):
for i in index_set:
temp = []
cm[i] = [0] * r
for ind,j in enumerate(index_set):
for ind, j in enumerate(index_set):
cm[i][ind] = int(alpha[i].inner_product(alphacheck[j]))
if cm[i][ind]:
temp.append(ind)
Expand All @@ -737,27 +738,27 @@ def _demazure_helper(self, dd, word="long", debug=False):
print("i=%s" % i)
next = {}
for v in accum:
coroot = v[i-1]
coroot = v[i - 1]
if debug:
print(" v=%s, coroot=%s" % (v, coroot))
if coroot >= 0:
mu = v
for j in range(coroot+1):
next[mu] = next.get(mu,0) + accum[v]
for j in range(coroot + 1):
next[mu] = next.get(mu, 0) + accum[v]
if debug:
print(" mu=%s, next[mu]=%s" % (mu, next[mu]))
mu = list(mu)
for k in supp[i-1]:
for k in supp[i - 1]:
mu[k] -= cm[i][k]
mu = tuple(mu)
else:
mu = v
for j in range(-1-coroot):
for j in range(-1 - coroot):
mu = list(mu)
for k in supp[i-1]:
for k in supp[i - 1]:
mu[k] += cm[i][k]
mu = tuple(mu)
next[mu] = next.get(mu,0) - accum[v]
next[mu] = next.get(mu, 0) - accum[v]
if debug:
print(" mu=%s, next[mu]=%s" % (mu, next[mu]))
accum = {}
Expand Down Expand Up @@ -789,9 +790,9 @@ def _weight_multiplicities(self, x):
d1 = self._irr_weights(k)
for l in d1:
if l in d:
d[l] += c*d1[l]
d[l] += c * d1[l]
else:
d[l] = c*d1[l]
d[l] = c * d1[l]
for k in list(d):
if d[k] == 0:
del d[k]
Expand Down Expand Up @@ -824,7 +825,7 @@ def irr_repr(self, hwv):
sage: [B3.irr_repr(v) for v in B3.fundamental_weights()]
['B3(1,0,0)', 'B3(0,1,0)', 'B3(0,0,1)']
"""
return self._prefix+self._wt_repr(hwv)
return self._prefix + self._wt_repr(hwv)

def level(self, wt):
"""
Expand All @@ -838,7 +839,7 @@ def level(self, wt):
sage: [CartanType("F4~").dual().a()[x] for x in [1..4]]
[2, 3, 2, 1]
"""
return ZZ(2*wt.inner_product(self._highest)/self._hip)
return ZZ(2 * wt.inner_product(self._highest) / self._hip)

def _dual_helper(self, wt):
"""
Expand All @@ -857,7 +858,7 @@ def _dual_helper(self, wt):
alphacheck = self._space.simple_coroots()
fw = self._space.fundamental_weights()
for i in self._space.index_set():
ret += wt.inner_product(alphacheck[i])*fw[self._opposition[i]]
ret += wt.inner_product(alphacheck[i]) * fw[self._opposition[i]]
return ret

def _wt_repr(self, wt):
Expand Down Expand Up @@ -1078,7 +1079,7 @@ def _char_from_weights(self, mdict):
hdict = {}
ddict = mdict.copy()
while ddict:
highest = max((x.inner_product(self._space.rho()),x) for x in ddict)[1]
highest = max((x.inner_product(self._space.rho()), x) for x in ddict)[1]
if not highest.is_dominant():
raise ValueError("multiplicity dictionary may not be Weyl group invariant")
sdict = self._irr_weights(highest)
Expand Down Expand Up @@ -1279,8 +1280,10 @@ def dual(self):

def highest_weight(self):
"""
This method is only available for basis elements. Returns the
parametrizing dominant weight of an irreducible character.
Return the parametrizing dominant weight
of an irreducible character.
This method is only available for basis elements.
EXAMPLES::
Expand Down Expand Up @@ -1323,7 +1326,7 @@ def __pow__(self, n):
n = -n

res = self
for i in range(n-1):
for i in range(n - 1):
res = self * res
return res

Expand Down Expand Up @@ -1371,13 +1374,12 @@ def symmetric_power(self, k):
if k == 1:
return self
ret = par.zero()
for r in range(1, k+1):
adam_r = self._adams_operation_helper(r)
ret += par.linear_combination((par._product_helper(adam_r, l), c) for (l, c) in self.symmetric_power(k-r))
dd = {}
for r in range(1, k + 1):
adam_r = self._adams_operator_helper(r)
ret += par.linear_combination((par._product_helper(adam_r, l), c)
for l, c in self.symmetric_power(k - r))
m = ret.weight_multiplicities()
for l in m:
dd[l] = m[l]/k
dd = {key: val / k for key, val in m.items()}
return self.parent().char_from_weights(dd)

@cached_method
Expand Down Expand Up @@ -1410,8 +1412,8 @@ def exterior_power(self, k):
if k == 1:
return self
ret = par.zero()
for r in range(1,k+1):
adam_r = self._adams_operation_helper(r)
for r in range(1, k + 1):
adam_r = self._adams_operator_helper(r)
if is_even(r):
ret -= par.linear_combination((par._product_helper(adam_r, l), c) for (l, c) in self.exterior_power(k-r))
else:
Expand All @@ -1422,7 +1424,7 @@ def exterior_power(self, k):
dd[l] = m[l]/k
return self.parent().char_from_weights(dd)

def adams_operation(self, r):
def adams_operator(self, r):
"""
Return the `r`-th Adams operation of ``self``.
Expand All @@ -1436,12 +1438,14 @@ def adams_operation(self, r):
EXAMPLES::
sage: A2 = WeylCharacterRing("A2")
sage: A2(1,1,0).adams_operation(3)
sage: A2(1,1,0).adams_operator(3)
A2(2,2,2) - A2(3,2,1) + A2(3,3,0)
"""
return self.parent().char_from_weights(self._adams_operation_helper(r))
return self.parent().char_from_weights(self._adams_operator_helper(r))

def _adams_operation_helper(self, r):
adams_operation = adams_operator

def _adams_operator_helper(self, r):
"""
Helper function for Adams operations.
Expand All @@ -1455,14 +1459,11 @@ def _adams_operation_helper(self, r):
EXAMPLES::
sage: A2 = WeylCharacterRing("A2")
sage: A2(1,1,0)._adams_operation_helper(3)
sage: A2(1,1,0)._adams_operator_helper(3)
{(3, 3, 0): 1, (3, 0, 3): 1, (0, 3, 3): 1}
"""
d = self.weight_multiplicities()
dd = {}
for k in d:
dd[r*k] = d[k]
return dd
return {r * key: val for key, val in d.items()}

def symmetric_square(self):
"""
Expand Down Expand Up @@ -1701,14 +1702,14 @@ def irreducible_character_freudenthal(hwv, debug=False):
for alpha in positive_roots:
mu_plus_i_alpha = mu + alpha
while mu_plus_i_alpha in mdict:
accum += mdict[mu_plus_i_alpha]*(mu_plus_i_alpha).inner_product(alpha)
accum += mdict[mu_plus_i_alpha] * (mu_plus_i_alpha).inner_product(alpha)
mu_plus_i_alpha += alpha
if accum == 0:
next_layer[mu] = 0
else:
hwv_plus_rho = hwv + rho
mu_plus_rho = mu + rho
next_layer[mu] = ZZ(2*accum)/ZZ((hwv_plus_rho).inner_product(hwv_plus_rho)-(mu_plus_rho).inner_product(mu_plus_rho))
next_layer[mu] = ZZ(2 * accum) / ZZ((hwv_plus_rho).inner_product(hwv_plus_rho) - (mu_plus_rho).inner_product(mu_plus_rho))
current_layer = next_layer
return mdict

Expand Down Expand Up @@ -1786,7 +1787,7 @@ def __init__(self, parent, prefix):
self._base_ring = parent._base_ring
if prefix is None:
# TODO: refactor this fragile logic into CartanType's
if self._parent._prefix.replace('x','_').isupper():
if self._parent._prefix.replace('x', '_').isupper():
# The 'x' workaround above is to support reducible Cartan types like 'A1xB2'
prefix = self._parent._prefix.lower()
elif self._parent._prefix.islower():
Expand Down Expand Up @@ -1878,7 +1879,7 @@ def product_on_basis(self, a, b):
sage: a2(1,0,0) * a2(0,1,0) # indirect doctest
a2(1,1,0)
"""
return self(a+b)
return self(a + b)

def some_elements(self):
"""
Expand Down Expand Up @@ -2012,7 +2013,7 @@ def wt_repr(self, wt):
sage: [G2.ambient().wt_repr(x) for x in G2.fundamental_weights()]
['g2(1,0)', 'g2(0,1)']
"""
return self._prefix+self.parent()._wt_repr(wt)
return self._prefix + self.parent()._wt_repr(wt)

def _repr_term(self, t):
"""
Expand Down Expand Up @@ -2118,9 +2119,7 @@ def shift(self, mu):
[g2(2,2), g2(1,3)]
"""
d1 = self.monomial_coefficients()
d2 = {}
for nu in d1:
d2[mu + nu] = d1[nu]
d2 = {mu + nu: val for nu, val in d1.items()}
return self.parent()._from_dict(d2)

def demazure(self, w, debug=False):
Expand Down Expand Up @@ -2228,7 +2227,7 @@ def demazure_lusztig(self, i, v):
if i in self.parent().space().index_set():
rho = self.parent().space().from_vector_notation(self.parent().space().rho(), style="coroots")
inv = self.scale(-1)
return (-inv.shift(-rho).demazure([i]).shift(rho)+v * inv.demazure([i])).scale(-1)
return (-inv.shift(-rho).demazure([i]).shift(rho) + v * inv.demazure([i])).scale(-1)
elif isinstance(i, list):
if not i:
return self
Expand Down

0 comments on commit a6e2c32

Please sign in to comment.