Skip to content

Commit f7e36b4

Browse files
author
Release Manager
committed
gh-35218: reduce exponents of AbelianGroup elements modulo the respective orders <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> Fixes #35216 <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. URL: #35218 Reported by: Peter Bruin Reviewer(s): Alex J Best
2 parents 81e2b34 + a2929b0 commit f7e36b4

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/sage/groups/abelian_gps/element_base.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,25 @@ def __init__(self, parent, exponents):
6565
sage: A,B,C = Fd.gens()
6666
sage: A*B^-1 in Fd
6767
True
68+
69+
Check that :issue:`35216` is fixed::
70+
71+
sage: M = AbelianGroup([3])
72+
sage: M([5]) == M([2])
73+
True
74+
sage: M([3]).is_trivial()
75+
True
6876
"""
6977
MultiplicativeGroupElement.__init__(self, parent)
7078
n = parent.ngens()
7179
if exponents == 1:
72-
self._exponents = tuple( ZZ.zero() for i in range(n) )
80+
self._exponents = tuple(ZZ.zero() for i in range(n))
7381
else:
74-
self._exponents = tuple( ZZ(e) for e in exponents )
75-
if len(self._exponents) != n:
76-
raise IndexError('argument length (= %s) must be %s.'%(len(exponents), n))
82+
if len(exponents) != n:
83+
raise IndexError('argument length (= %s) must be %s'
84+
% (len(exponents), n))
85+
self._exponents = tuple(ZZ(e % o if o else e) for e, o in
86+
zip(exponents, parent.gens_orders()))
7787

7888
def __hash__(self):
7989
r"""
@@ -257,9 +267,8 @@ def _div_(left, right):
257267
"""
258268
G = left.parent()
259269
assert G is right.parent()
260-
exponents = [ (x-y)%order if order!=0 else x-y
261-
for x, y, order in
262-
zip(left._exponents, right._exponents, G.gens_orders()) ]
270+
exponents = [x - y for x, y in
271+
zip(left._exponents, right._exponents)]
263272
return G.element_class(G, exponents)
264273

265274
def _mul_(left, right):
@@ -276,9 +285,8 @@ def _mul_(left, right):
276285
"""
277286
G = left.parent()
278287
assert G is right.parent()
279-
exponents = [ (x+y)%order if order!=0 else x+y
280-
for x, y, order in
281-
zip(left._exponents, right._exponents, G.gens_orders()) ]
288+
exponents = [x + y for x, y in
289+
zip(left._exponents, right._exponents)]
282290
return G.element_class(G, exponents)
283291

284292
def __pow__(self, n):
@@ -295,8 +303,7 @@ def __pow__(self, n):
295303
if n != m:
296304
raise TypeError('argument n (= '+str(n)+') must be an integer.')
297305
G = self.parent()
298-
exponents = [ (m*e) % order if order!=0 else m*e
299-
for e,order in zip(self._exponents, G.gens_orders()) ]
306+
exponents = [m * e for e in self._exponents]
300307
return G.element_class(G, exponents)
301308

302309
def __invert__(self):
@@ -320,8 +327,7 @@ def __invert__(self):
320327
(-1, 4)
321328
"""
322329
G = self.parent()
323-
exponents = [(-e) % order if order != 0 else -e
324-
for e, order in zip(self._exponents, G.gens_orders())]
330+
exponents = [-e for e in self._exponents]
325331
return G.element_class(G, exponents)
326332

327333
def is_trivial(self):

0 commit comments

Comments
 (0)