Skip to content

Commit

Permalink
Rename _k to _arity globally
Browse files Browse the repository at this point in the history
  • Loading branch information
Newtech66 committed Aug 30, 2024
1 parent 56beab2 commit bf87e50
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions src/sage/rings/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def __eq__(self, other):
return False
# If they do, construct the mapping between the groups
selflist, otherlist = [], []
for i in range(self.parent()._k):
for i in range(self.parent()._arity):
if len(self._dompart[i]) != len(other._dompart[i]):
return False
selflist.extend(sorted(list(self._dompart[i])))
Expand All @@ -471,7 +471,7 @@ def _repr_(self):
sage: A = At(G, {2: [1,2,3,4,5,6,7,8,9,10]}); A
{((1,2,3,4)(5,6)(7,8)(9,10),): ({}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})}
"""
if self.parent()._k == 1:
if self.parent()._arity == 1:
return "{" + f"{self._dis}" + "}"
dompart = ', '.join("{" + repr(sorted(b))[1:-1] + "}"
for b in self._dompart)
Expand Down Expand Up @@ -517,8 +517,8 @@ def __init__(self, names):
category = SetsWithGrading().Infinite()
Parent.__init__(self, names=names, category=category)
ElementCache.__init__(self)
self._k = len(names)
self._grading_set = IntegerVectors(length=self._k)
self._arity = len(names)
self._grading_set = IntegerVectors(length=self._arity)
self._renamed = set() # the degrees that have been renamed already

@cached_method
Expand All @@ -535,8 +535,8 @@ def an_element(self):
sage: At2.an_element()
{((1,2)(3,4),): ({1, 2}, {3, 4})}
"""
G = PermutationGroup([[(2 * i - 1, 2 * i) for i in range(1, self._k + 1)]])
m = {i: [2 * i - 1, 2 * i] for i in range(1, self._k + 1)}
G = PermutationGroup([[(2 * i - 1, 2 * i) for i in range(1, self._arity + 1)]])
m = {i: [2 * i - 1, 2 * i] for i in range(1, self._arity + 1)}
return self._element_constructor_(G, m)

def _element_constructor_(self, G, pi=None):
Expand All @@ -557,12 +557,12 @@ def _element_constructor_(self, G, pi=None):
if not isinstance(G, PermutationGroup_generic):
raise ValueError(f"{G} must be a permutation group")
if pi is None:
if self._k == 1:
if self._arity == 1:
pi = {1: G.domain()}
else:
raise ValueError("the assignment of sorts to the domain elements must be provided")
if not set(pi.keys()).issubset(range(1, self._k + 1)):
raise ValueError(f"keys of pi (={pi.keys()}) must be in the range [1, {self._k}]")
if not set(pi.keys()).issubset(range(1, self._arity + 1)):
raise ValueError(f"keys of pi (={pi.keys()}) must be in the range [1, {self._arity}]")
if sum(len(p) for p in pi.values()) != len(G.domain()) or set(chain.from_iterable(pi.values())) != set(G.domain()):
raise ValueError(f"values of pi (={pi.values()}) must partition the domain of G (={G.domain()})")
for orbit in G.orbits():
Expand All @@ -572,7 +572,7 @@ def _element_constructor_(self, G, pi=None):
mapping = {v: i for i, v in enumerate(G.domain(), 1)}
mapping2 = PermutationGroupElement([mapping[e] for o in sorted(G.orbits(), key=len, reverse=True)
for e in o]).inverse()
dpart = [frozenset() for _ in range(self._k)]
dpart = [frozenset() for _ in range(self._arity)]
for k, v in pi.items():
dpart[k - 1] = frozenset(mapping2(mapping[x]) for x in v)
elm = self._cache_get(self.element_class(self, dis_elm, tuple(dpart)))
Expand Down Expand Up @@ -612,11 +612,11 @@ def _rename(self, n):

# prevent infinite recursion in self._element_constructor_
self._renamed.add(n)
for i in range(self._k):
for i in range(self._arity):
if n == 1:
self(SymmetricGroup(1), {i+1: [1]}).rename(self._names[i])

if self._k == 1:
if self._arity == 1:
sort = ""
else:
sort = f"({self._names[i]})"
Expand Down Expand Up @@ -661,7 +661,7 @@ def __contains__(self, x):
return True
G, pi = None, None
if isinstance(x, PermutationGroup_generic):
if self._k == 1:
if self._arity == 1:
G = x
pi = {1: G.domain()}
else:
Expand All @@ -670,8 +670,8 @@ def __contains__(self, x):
G, pi = x
if not isinstance(G, PermutationGroup_generic):
raise ValueError(f"{G} must be a permutation group")
if not set(pi.keys()).issubset(range(1, self._k + 1)):
raise ValueError(f"keys of pi (={pi.keys()}) must be in the range [1, {self._k}]")
if not set(pi.keys()).issubset(range(1, self._arity + 1)):
raise ValueError(f"keys of pi (={pi.keys()}) must be in the range [1, {self._arity}]")
if sum(len(p) for p in pi.values()) != len(G.domain()) or set(chain.from_iterable(pi.values())) != set(G.domain()):
raise ValueError(f"values of pi (={pi.values()}) must partition the domain of G (={G.domain()})")
for orbit in G.orbits():
Expand Down Expand Up @@ -720,7 +720,7 @@ def __init__(self, indices, prefix=None, **kwds):
category = Monoids() & SetsWithGrading().Infinite()
IndexedFreeAbelianMonoid.__init__(self, indices, prefix=prefix, category=category, **kwds)
ElementCache.__init__(self)
self._k = indices._k
self._arity = indices._arity

def _project(self, G, pi, part):
r"""
Expand Down Expand Up @@ -783,7 +783,7 @@ def _element_constructor_(self, G, pi=None):
return G
if isinstance(G, PermutationGroup_generic):
if pi is None:
if self._k == 1:
if self._arity == 1:
pi = {1: G.domain()}
else:
raise ValueError("the assignment of sorts to the domain elements must be provided")
Expand All @@ -795,11 +795,11 @@ def _element_constructor_(self, G, pi=None):
# Assume G is a tuple (X, a)
X, a = G
if pi is None:
if self._k == 1:
if self._arity == 1:
pi = {1: X}
else:
raise ValueError("the assignment of sorts to the domain elements must be provided")
L = [None for _ in range(self._k)]
L = [None for _ in range(self._arity)]
for k, v in pi.items():
L[k - 1] = list(v)
# Create group
Expand All @@ -826,7 +826,7 @@ def one(self):
elm = super().one()
elm._group = SymmetricGroup(0)
elm._dompart = tuple()
elm._mc = tuple(0 for _ in range(self._k))
elm._mc = tuple(0 for _ in range(self._arity))
elm._tc = 0
return elm

Expand Down Expand Up @@ -929,7 +929,7 @@ def _elmmul(self, elm1, elm2):
if elm2._tc == 0:
self._assign_group_info(elm1)
return
self._mc = tuple(elm1._mc[i] + elm2._mc[i] for i in range(self.parent()._k))
self._mc = tuple(elm1._mc[i] + elm2._mc[i] for i in range(self.parent()._arity))
self._tc = elm1._tc + elm2._tc
gens1 = elm1._group.gens()
# Try to avoid gens_small unless necessary
Expand All @@ -947,7 +947,7 @@ def _elmmul(self, elm1, elm2):
gens.append([tuple(elm1._tc + k for k in cyc) for cyc in gen.cycle_tuples()])
self._group = PermutationGroup(gens, domain=range(1, elm1._tc + elm2._tc + 1))
self._dompart = list(elm1._dompart)
for i in range(elm2.parent()._k):
for i in range(elm2.parent()._arity):
self._dompart[i] = frozenset(list(self._dompart[i]) + [elm1._tc + e for e in elm2._dompart[i]])
self._dompart = tuple(self._dompart)

Expand Down Expand Up @@ -1201,11 +1201,11 @@ def __call__(self, *args):
sage: C3(X*Y)
{((1,2,3)(4,5,6),): ({1, 2, 3}, {4, 5, 6})}
"""
if len(args) != self.parent()._k:
if len(args) != self.parent()._arity:
raise ValueError("number of args must match arity of self")
if not all(isinstance(arg, MolecularSpecies.Element) for arg in args):
raise ValueError("all args must be molecular species")
if len(set(arg.parent()._k for arg in args)) > 1:
if len(set(arg.parent()._arity for arg in args)) > 1:
raise ValueError("all args must have same arity")

gens = []
Expand All @@ -1226,7 +1226,7 @@ def __call__(self, *args):
gens.append(newgen)

# gens from M_i and dompart
dpart = {i: [] for i in range(1, args[0].parent()._k + 1)}
dpart = {i: [] for i in range(1, args[0].parent()._arity + 1)}
for start, M in zip(starts, Mlist):
for i, v in enumerate(M._dompart, 1):
dpart[i].extend([start + k for k in v])
Expand Down Expand Up @@ -1275,7 +1275,7 @@ def __init__(self, base_ring, names):
category=category,
element_class=self.Element,
prefix='', bracket=False)
self._k = len(names)
self._arity = len(names)

def degree_on_basis(self, m):
r"""
Expand Down Expand Up @@ -1326,19 +1326,19 @@ def _element_constructor_(self, G, pi=None):
return G
if isinstance(G, PermutationGroup_generic):
if pi is None:
if self._k == 1:
if self._arity == 1:
return self._from_dict({self._indices(G): ZZ.one()})
raise ValueError("the assignment of sorts to the domain elements must be provided")
return self._from_dict({self._indices(G, pi): ZZ.one()})
# Assume G is a tuple (X, a)
X, a = G
if pi is None:
if self._k == 1:
if self._arity == 1:
pi = {1: X}
else:
raise ValueError("the assignment of sorts to the domain elements must be provided")
# Make iteration over values of pi deterministic
L = [None for _ in range(self._k)]
L = [None for _ in range(self._arity)]
for k, v in pi.items():
L[k - 1] = list(v)
# Create group
Expand Down Expand Up @@ -1497,8 +1497,8 @@ def factor(s, c, d):
* self.powersum(s, k) for k in mu)
for mu in Partitions(d))

return self.prod(factor(s+1, multiplicities[s], degrees[s])
for s in range(self._k))
return prod(factor(s+1, multiplicities[s], degrees[s])
for s in range(self._arity))

class Element(CombinatorialFreeModule.Element):
def is_constant(self):
Expand Down Expand Up @@ -1657,8 +1657,8 @@ def _compose_with_weighted_singletons(self, names, multiplicities, degrees):
-E_2 + X^2
sage: C4 = P(CyclicPermutationGroup(4))
sage: C4._compose_with_weighted_singletons(["X"], [-1], [[4]])
-C_4 + {((1,2)(3,4),): ({1, 2, 3, 4})}
sage: C4.compose_with_weighted_singletons(ZZ, ["X"], [-1], [[4]])
{((1,2)(3,4),)} - C_4
Exercise (2.5.17)::
Expand All @@ -1676,8 +1676,9 @@ def _compose_with_weighted_singletons(self, names, multiplicities, degrees):
TESTS::
sage: (C4+E2^2)._compose_with_weighted_singletons(["X"], [-1], [[4]])
-C_4 + {((1,2)(3,4),): ({1, 2, 3, 4})} + E_2^2 - 2*X^2*E_2 + X^4
sage: (C4+E2^2).compose_with_weighted_singletons(ZZ, ["X"], [-1], [[4]])
{((1,2)(3,4),)} - C_4 - 2*X^2*E_2 + E_2^2 + X^4
"""
P = self.parent()
if not self.support():
Expand Down Expand Up @@ -1705,10 +1706,10 @@ def __call__(self, *args):
sage: E2(-X)
-E_2 + X^2
sage: E2(X^2)
{((1,2)(3,4),): ({1, 2, 3, 4})}
{((1,2)(3,4),)}
sage: E2(X + X^2)
E_2 + X^3 + {((1,2)(3,4),): ({1, 2, 3, 4})}
E_2 + X^3 + {((1,2)(3,4),)}
sage: P2 = PolynomialSpecies(QQ, ["X", "Y"])
sage: X = P2(SymmetricGroup(1), {1:[1]})
Expand Down

0 comments on commit bf87e50

Please sign in to comment.