Skip to content

Commit

Permalink
Merge pull request #24455 from skieffer/fix-is-cyclic
Browse files Browse the repository at this point in the history
Repair `PermutationGroup.is_cyclic`
  • Loading branch information
smichr committed Jan 6, 2023
2 parents 56e4708 + 495a6c3 commit 6f0fd47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
18 changes: 8 additions & 10 deletions sympy/combinatorics/perm_groups.py
Expand Up @@ -3219,17 +3219,15 @@ def is_cyclic(self):
self._is_abelian = True
return True

for p in factors:
pgens = []
for g in self.generators:
pgens.append(g**p)
if self.index(self.subgroup(pgens)) != p:
self._is_cyclic = False
return False
if not self.is_abelian:
self._is_cyclic = False
return False

self._is_cyclic = True
self._is_abelian = True
return True
self._is_cyclic = all(
any(g**(order//p) != self.identity for g in self.generators)
for p, e in factors.items() if e > 1
)
return self._is_cyclic

@property
def is_dihedral(self):
Expand Down
19 changes: 19 additions & 0 deletions sympy/combinatorics/tests/test_perm_groups.py
Expand Up @@ -1046,6 +1046,25 @@ def test_cyclic():
assert G.is_cyclic
assert G._is_abelian

# Non-abelian and therefore not cyclic
G = PermutationGroup(*SymmetricGroup(3).generators)
assert G.is_cyclic is False

# Abelian and cyclic
G = PermutationGroup(
Permutation(0, 1, 2, 3),
Permutation(4, 5, 6)
)
assert G.is_cyclic

# Abelian but not cyclic
G = PermutationGroup(
Permutation(0, 1),
Permutation(2, 3),
Permutation(4, 5, 6)
)
assert G.is_cyclic is False


def test_dihedral():
G = SymmetricGroup(2)
Expand Down

1 comment on commit 6f0fd47

@MohitKumar020291
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not how to update my code to see these changes in my local setup I have tried $ git pull and $ git push I actually do not know do they work for it ? Kindly give me some more git commands to do local code up to date.

Please sign in to comment.