-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Added function to check if a group is Cyclic or not #16522
Conversation
✅ Hi, I am the SymPy bot (v145). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
@jksuom please review! |
Codecov Report
@@ Coverage Diff @@
## master #16522 +/- ##
=============================================
+ Coverage 73.677% 73.757% +0.079%
=============================================
Files 618 619 +1
Lines 158567 158656 +89
Branches 37224 37185 -39
=============================================
+ Hits 116828 117020 +192
+ Misses 36322 36217 -105
- Partials 5417 5419 +2 |
sympy/combinatorics/fp_groups.py
Outdated
False | ||
|
||
""" | ||
if len(self.generators) == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the trivial case (no generators)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll include that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like that will also have length of 1 for permutation group but I have added for Fp group.
>>> g=PermutationGroup()
>>> g.generators
[Permutation()]
>>> len(g.generators)
1
>>> g=PermutationGroup([Permutation(1,2,3)])
>>> len(g.generators)
1
sympy/combinatorics/fp_groups.py
Outdated
return True | ||
if not self.is_abelian: | ||
return False | ||
for p in primefactors(self.order()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order should probably be finite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for the current implementation order is finite, For infinite order we probably have to implement Abelian Invariants
which I have included in my GSoC proposal!
Would it be possible to implement |
@jksuom I'll look into it. |
sympy/combinatorics/fp_groups.py
Outdated
pgens = [] | ||
for g in self.generators: | ||
pgens.append(g**p) | ||
K, T = self.subgroup(pgens, homomorphism=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually both the is_cyclic
methods are not completely same there is a slight difference so, I doubt it if a single method would be suffice or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that is_cyclic
has different meanings for permutation groups and finitely presented groups?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we are using the method .subgroup
which has been defined separately for both the permutation groups and fp groups also we are keeping homomorphism=True
in the subgroup method so that we can have a list of generators which can be passed to the index
method below. Otherwise the generators will simply produce the free variables and we will not be able to compute the index
below.
But this is not the case in permutation group where the subgroup method directly returns a group via which index can be calculated easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess is_cyclic
is same for both but it actually depends on the implementation of subgroup method which works differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to apply PermutationGroup.is_cyclic
also for an instance of FpGroup
by transforming it to a permutation group using _to_perm_group
? One could first check the 0-1 generator cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we can do this.
>>> F, x, y = free_group("x, y")
>>> f = FpGroup(F, [x*y*x**-1*y**-1, y**5, x**4])
>>> g, t = f._to_perm_group()
>>> g.is_cyclic()
True
>>> g
PermutationGroup([
(0 1 5 2)(3 6 12 8)(4 7 13 9)(10 14 18 16)(11 15 19 17),
(0 3 10 11 4)(1 6 14 15 7)(2 8 16 17 9)(5 12 18 19 13)])
@jksuom can this be merged. |
sympy/combinatorics/fp_groups.py
Outdated
False | ||
|
||
""" | ||
if self.order() == S.Infinity: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An infinite group could be cyclic if there is only one generator.
A finite group can handled in two ways. Which method is more efficient, |
|
|
That is what I expected. Therefore I suggested that the FpGroup method would apply |
@jksuom thanks, for pointing it out, you were right we can easily use Should I convert |
It seems that |
sympy/combinatorics/fp_groups.py
Outdated
Return ``True`` if group is Cyclic. | ||
|
||
""" | ||
if len(self.generators) == 0 or len(self.generators) == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be len(self.generators) <= 1
sympy/combinatorics/fp_groups.py
Outdated
""" | ||
if len(self.generators) == 0 or len(self.generators) == 1: | ||
return True | ||
P, T = self._to_perm_group() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_to_perm_group
will raise NotImplementedError
if the group is infinite. That can be raised also here but the error message should probably be changed. Maybe something like this:
try:
P, _ = self._to_perm_group()
except NotImplementedError:
raise NotImplementedError("suitable message")
@jksuom I've done the above changes please have a look. |
The purpose of |
@jksuom can this be merged now! |
It looks good otherwise but I am not sure about |
Okay I'll remove it for this PR. |
sympy/combinatorics/fp_groups.py
Outdated
@@ -1,6 +1,8 @@ | |||
"""Finitely Presented Groups and its algorithms. """ | |||
|
|||
from __future__ import print_function, division | |||
from sympy.ntheory import primefactors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not needed.
sympy/combinatorics/perm_groups.py
Outdated
@@ -2,6 +2,8 @@ | |||
|
|||
from random import randrange, choice | |||
from math import log | |||
from sympy.ntheory import primefactors | |||
from sympy.polys import lcm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I forget to remove it!
@jksuom I think now this can be merged. |
Thanks. |
Brief description of what is fixed or changed
Added method
is_cyclic
for bothPermutationGroup
and FpGroup. Also, added a method to compute the exponent of a PermutationGroup.Other comments
Release Notes