Skip to content

Commit

Permalink
Added default argument strict to is_transitive`
Browse files Browse the repository at this point in the history
  • Loading branch information
pernici committed Sep 16, 2012
1 parent 6a4830a commit 8df042c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
41 changes: 31 additions & 10 deletions sympy/combinatorics/perm_groups.py
Expand Up @@ -1804,7 +1804,7 @@ def is_alt_sym(self, eps=0.05, _random_prec=None):
n = self.degree
if n < 8:
return False
if not self.is_transitive:
if not self.is_transitive():
return False
if n < 17:
c_n = 0.34
Expand Down Expand Up @@ -2050,12 +2050,14 @@ def is_subgroup(self, G, strict=True):
return False
return all(G.contains(g) for g in gens)

@property
def is_transitive(self):
def is_transitive(self, strict=True):
"""Test if the group is transitive.
A group is transitive if it has a single orbit.
If ``strict`` is False the group is transitive if it has
a single orbit of length different from 1.
Examples
========
Expand All @@ -2064,20 +2066,39 @@ def is_transitive(self):
>>> a = Permutation([0, 2, 1, 3])
>>> b = Permutation([2, 0, 1, 3])
>>> G1 = PermutationGroup([a, b])
>>> G1.is_transitive
>>> G1.is_transitive()
False
>>> G1.is_transitive(strict=False)
True
>>> c = Permutation([2, 3, 0, 1])
>>> G2 = PermutationGroup([a, c])
>>> G2.is_transitive
True
>>> d = Permutation([1,0,2,3])
>>> e = Permutation([0,1,3,2])
>>> G3 = PermutationGroup([d, e])
>>> G3.is_transitive() or G3.is_transitive(strict=False)
False
"""
if self._is_transitive is not None:
if self._is_transitive:
return self._is_transitive
if strict:
if self._is_transitive is not None:
return self._is_transitive

ans = len(self.orbit(0)) == self.degree
self._is_transitive = ans
return ans
orbits = self.orbits()
n_orbs = 0
for x in orbits:
if len(x) > 1:
n_orbs += 1
if n_orbs > 1:
return False
return True


ans = len(self.orbit(0)) == self.degree
self._is_transitive = ans
return ans

@property
def is_trivial(self):
Expand Down Expand Up @@ -2221,7 +2242,7 @@ def minimal_block(self, points):
_union_find_rep, _union_find_merge, is_transitive, is_primitive
"""
if not self.is_transitive:
if not self.is_transitive():
return False
n = self.degree
gens = self.generators
Expand Down
6 changes: 4 additions & 2 deletions sympy/combinatorics/tests/test_perm_groups.py
Expand Up @@ -203,7 +203,7 @@ def test_orbits():
g = PermutationGroup([a, b])
assert g.orbit(0) == set([0, 1, 2])
assert g.orbits() == [set([0, 1, 2])]
assert g.is_transitive
assert g.is_transitive() and g.is_transitive(strict=False)
assert g.orbits(rep=True) == [0]
assert g.orbit_transversal(0) == \
[Permutation([0, 1, 2]), Permutation([2, 0, 1]), Permutation([1, 2, 0])]
Expand All @@ -216,7 +216,9 @@ def test_orbits():
assert G.orbits(rep=True) == [0]
G = PermutationGroup(rubik_cube_generators())
assert G.orbits(rep=True) == [0, 1]
assert not G.is_transitive
assert not G.is_transitive() and not G.is_transitive(strict=False)
G = PermutationGroup([Permutation(0, 1, 3), Permutation(3)(0, 1)])
assert not G.is_transitive() and G.is_transitive(strict=False)

def test_is_normal():
gens_s5 = [Permutation(p) for p in [[1,2,3,4,0], [2,1,4,0,3]]]
Expand Down

0 comments on commit 8df042c

Please sign in to comment.