Skip to content

Commit

Permalink
permutations: add one_based
Browse files Browse the repository at this point in the history
  • Loading branch information
smichr committed Sep 11, 2012
1 parent 995a56e commit 9221943
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions sympy/combinatorics/permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ def cyclic(cyclic_form1, n):
rv.extend([[i] for i in sorted(need)])
return rv

def one_based(cyclic_form0, singletons=True):
"""Return a cyclic form in 1-based cyclic form, omitting cycles
smaller than ``smallest``.
>>> from sympy.combinatorics.permutations import one_based
>>> one_based([[0, 1], [2]])
[[1, 2], [3]]
>>> one_based([[0, 1], [2]], singletons=False)
[[1, 2]]
"""
min = 1 + (not bool(singletons))
return [[e + 1 for e in c] for c in cyclic_form0 if len(c) >= min]

def _af_parity(pi):
"""
Computes the parity of a permutation in array form.
Expand Down
4 changes: 3 additions & 1 deletion sympy/combinatorics/tests/test_permutations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sympy.core import FiniteSet
from sympy.combinatorics.permutations import (Permutation, _af_parity,
_af_mul, _af_mul, cyclic)
_af_mul, _af_mul, cyclic, one_based)

from sympy.utilities.pytest import raises

Expand All @@ -21,6 +21,8 @@ def test_Permutation():

assert cyclic([(2,3,5)], 5) == [[1, 2, 4], [0], [3]]
assert cyclic([(2,3,5)], 3) == [[1, 2, 4], [0]]
assert one_based([[0, 1], [2]]) == [[1, 2], [3]]
assert one_based([[0, 1], [2]], singletons=False) == [[1, 2]]
assert (Permutation([[1,2,3],[0,4]])*Permutation([[1,2,4],[0],[3]])).cyclic_form == \
[[0, 4, 2], [1, 3]]
assert q.array_form == [3, 1, 4, 5, 0, 6, 2]
Expand Down

0 comments on commit 9221943

Please sign in to comment.