Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combinatorics: improved the FpGroups.index() method #26458

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ Tom Fryers <61272761+TomFryers@users.noreply.github.com>
Tom Gijselinck <tomgijselinck@gmail.com>
Tomasz Buchert <thinred@gmail.com>
Tomasz Pytel <tompytel@gmail.com>
Tommy Ford <tommyford28@googlemail.com>
Tommy Olofsson <tommy.olofsson.90@gmail.com>
Tomo Lazovich <lazovich@gmail.com>
Tomáš Bambas <tomas.bambas@gmail.com>
Expand Down
6 changes: 4 additions & 2 deletions sympy/combinatorics/fp_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,10 @@ def index(self, H, strategy="relator_based"):
# TODO: use |G:H| = |G|/|H| (currently H can't be made into a group)
# when we know |G| and |H|

if H == []:
return self.order()
# Lagrange's Theorem applies for finite groups, this should solve the above task and give a small optimisation
# for finite groups
if self.order(strategy) is not S.Infinity:
return self.order(strategy) / self.subgroup(H).order(strategy)
else:
C = self.coset_enumeration(H, strategy)
return len(C.table)
Expand Down
20 changes: 20 additions & 0 deletions sympy/combinatorics/tests/test_fp_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,23 @@ def test_abelian_invariants():
assert f.abelian_invariants() == [2]
f = FpGroup(F, [x**4, y**2, x*y*x**-1*y])
assert f.abelian_invariants() == [2, 4]


def test_index():
F, x = free_group("x")
f = FpGroup(F, [x**8])
H1 = [[x**i] for i in range(1, 9)]
I1 = [1, 2, 1, 4, 1, 2, 1, 8]
for H, I in zip(H1, I1):
assert f.index(H) == I

F, x, y = free_group("x, y")
f = FpGroup(F, [x**3, y**2, (x*y)**4])
H2 = [f.identity, x, x**-1, y, x*y, x**2*y, y*x, y*x**2, x*y*x, x*y*x**2, x**2*y*x, x**2*y*x**2, y*x*y, y*x**2*y,
x*y*x*y, x*y*x**2*y, x**2*y*x*y, y*x*y*x, y*x*y*x**2, y*x**2*y*x, x*y*x**2*y*x, y*x*y*x**2*y, y*x**2*y*x*y,
x*y*x**2*y*x*y]
I2 = [24, 8, 8, 12, 6, 6, 6, 6, 6, 12, 12, 6, 8, 8, 12, 8, 8, 12, 8, 8, 12, 12, 12, 12]
for H, I in zip(H2, I2):
assert f.index([H]) == I

assert f.index(f.elements) == 1