本文整理汇总了Python中sympy.combinatorics.permutations.Permutation类的典型用法代码示例。如果您正苦于以下问题:Python Permutation类的具体用法?Python Permutation怎么用?Python Permutation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Permutation类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_unrank_lex
def test_unrank_lex():
assert Permutation.unrank_lex(5, 10).rank == 10
assert Permutation.unrank_lex(15, 225).rank == 225
assert Permutation.unrank_lex(10, 0).is_Identity
p = Permutation.unrank_lex(4, 23)
assert p.rank == 23
assert p.array_form == [3, 2, 1, 0]
开发者ID:Ingwar,项目名称:sympy,代码行数:7,代码来源:test_permutations.py
示例2: test_coset_factor
def test_coset_factor():
a = Permutation([0, 2, 1])
G = PermutationGroup([a])
c = Permutation([2, 1, 0])
assert not G.coset_factor(c)
assert G.coset_rank(c) is None
a = Permutation([2, 0, 1, 3, 4, 5])
b = Permutation([2, 1, 3, 4, 5, 0])
g = PermutationGroup([a, b])
assert g.order() == 360
d = Permutation([1, 0, 2, 3, 4, 5])
assert not g.coset_factor(d.array_form)
assert not g.contains(d)
assert Permutation(2) in G
c = Permutation([1, 0, 2, 3, 5, 4])
v = g.coset_factor(c, True)
tr = g.basic_transversals
p = Permutation.rmul(*[tr[i][v[i]] for i in range(len(g.base))])
assert p == c
v = g.coset_factor(c)
p = Permutation.rmul(*v)
assert p == c
assert g.contains(c)
G = PermutationGroup([Permutation([2, 1, 0])])
p = Permutation([1, 0, 2])
assert G.coset_factor(p) == []
开发者ID:sixpearls,项目名称:sympy,代码行数:27,代码来源:test_perm_groups.py
示例3: test_muln
def test_muln():
n = 6
m = 8
a = [Permutation.unrank_nonlex(n, i).array_form for i in range(m)]
h = range(n)
for i in range(m):
h = perm_af_mul(h, a[i])
h2 = perm_af_muln(*a[:i+1])
assert h == h2
开发者ID:StefenYin,项目名称:sympy,代码行数:9,代码来源:test_permutations.py
示例4: test_mul
def test_mul():
a, b = [0, 2, 1, 3], [0, 1, 3, 2]
assert _af_rmul(a, b) == [0, 2, 3, 1]
assert _af_rmuln(a, b, range(4)) == [0, 2, 3, 1]
assert rmul(Permutation(a), Permutation(b)).array_form == [0, 2, 3, 1]
a = Permutation([0, 2, 1, 3])
b = (0, 1, 3, 2)
c = (3, 1, 2, 0)
assert Permutation.rmul(a, b, c) == Permutation([1, 2, 3, 0])
assert Permutation.rmul(a, c) == Permutation([3, 2, 1, 0])
raises(TypeError, lambda: Permutation.rmul(b, c))
n = 6
m = 8
a = [Permutation.unrank_nonlex(n, i).array_form for i in range(m)]
h = range(n)
for i in range(m):
h = _af_rmul(h, a[i])
h2 = _af_rmuln(*a[:i + 1])
assert h == h2
开发者ID:jenshnielsen,项目名称:sympy,代码行数:21,代码来源:test_permutations.py
示例5: test_Permutation
def test_Permutation():
# don't auto fill 0
raises(ValueError, lambda: Permutation([1]))
p = Permutation([0, 1, 2, 3])
# call as bijective
assert [p(i) for i in range(p.size)] == list(p)
# call as operator
assert p(range(p.size)) == list(p)
# call as function
assert list(p(1, 2)) == [0, 2, 1, 3]
# conversion to list
assert list(p) == range(4)
# cycle form with size
assert Permutation([[1, 2]], size=4) == Permutation([[1, 2], [0], [3]])
# random generation
assert Permutation.random(2) in (Permutation([1, 0]), Permutation([0, 1]))
p = Permutation([2, 5, 1, 6, 3, 0, 4])
q = Permutation([[1], [0, 3, 5, 6, 2, 4]])
assert len(set([p, p])) == 1
r = Permutation([1, 3, 2, 0, 4, 6, 5])
ans = Permutation(_af_rmuln(*[w.array_form for w in (p, q, r)])).array_form
assert rmul(p, q, r).array_form == ans
# make sure no other permutation of p, q, r could have given
# that answer
for a, b, c in permutations((p, q, r)):
if (a, b, c) == (p, q, r):
continue
assert rmul(a, b, c).array_form != ans
assert p.support() == range(7)
assert q.support() == [0, 2, 3, 4, 5, 6]
assert Permutation(p.cyclic_form).array_form == p.array_form
assert p.cardinality == 5040
assert q.cardinality == 5040
assert q.cycles == 2
assert rmul(q, p) == Permutation([4, 6, 1, 2, 5, 3, 0])
assert rmul(p, q) == Permutation([6, 5, 3, 0, 2, 4, 1])
assert _af_rmul(p.array_form, q.array_form) == \
[6, 5, 3, 0, 2, 4, 1]
assert rmul(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]
assert q.cyclic_form == [[0, 3, 5, 6, 2, 4]]
assert q.full_cyclic_form == [[0, 3, 5, 6, 2, 4], [1]]
assert p.cyclic_form == [[0, 2, 1, 5], [3, 6, 4]]
t = p.transpositions()
assert t == [(0, 5), (0, 1), (0, 2), (3, 4), (3, 6)]
assert Permutation.rmul(*[Permutation(Cycle(*ti)) for ti in (t)])
assert Permutation([1, 0]).transpositions() == [(0, 1)]
assert p**13 == p
assert q**0 == Permutation(range(q.size))
assert q**-2 == ~q**2
assert q**2 == Permutation([5, 1, 0, 6, 3, 2, 4])
assert q**3 == q**2*q
assert q**4 == q**2*q**2
a = Permutation(1, 3)
b = Permutation(2, 0, 3)
I = Permutation(3)
assert ~a == a**-1
assert a*~a == I
assert a*b**-1 == a*~b
ans = Permutation(0, 5, 3, 1, 6)(2, 4)
assert (p + q.rank()).rank() == ans.rank()
assert (p + q.rank())._rank == ans.rank()
assert (q + p.rank()).rank() == ans.rank()
raises(TypeError, lambda: p + Permutation(range(10)))
assert (p - q.rank()).rank() == Permutation(0, 6, 3, 1, 2, 5, 4).rank()
assert p.rank() - q.rank() < 0 # for coverage: make sure mod is used
assert (q - p.rank()).rank() == Permutation(1, 4, 6, 2)(3, 5).rank()
assert p*q == Permutation(_af_rmuln(*[list(w) for w in (q, p)]))
assert p*Permutation([]) == p
assert Permutation([])*p == p
assert p*Permutation([[0, 1]]) == Permutation([2, 5, 0, 6, 3, 1, 4])
assert Permutation([[0, 1]])*p == Permutation([5, 2, 1, 6, 3, 0, 4])
pq = p^q
assert pq == Permutation([5, 6, 0, 4, 1, 2, 3])
assert pq == rmul(q, p, ~q)
qp = q^p
assert qp == Permutation([4, 3, 6, 2, 1, 5, 0])
assert qp == rmul(p, q, ~p)
raises(ValueError, lambda: p^Permutation([]))
assert p.commutator(q) == Permutation(0, 1, 3, 4, 6, 5, 2)
assert q.commutator(p) == Permutation(0, 2, 5, 6, 4, 3, 1)
assert p.commutator(q) == ~q.commutator(p)
raises(ValueError, lambda: p.commutator(Permutation([])))
assert len(p.atoms()) == 7
assert q.atoms() == set([0, 1, 2, 3, 4, 5, 6])
assert p.inversion_vector() == [2, 4, 1, 3, 1, 0]
#.........这里部分代码省略.........
开发者ID:jenshnielsen,项目名称:sympy,代码行数:101,代码来源:test_permutations.py
示例6: test_from_sequence
def test_from_sequence():
assert Permutation.from_sequence('SymPy') == Permutation(4)(0, 1, 3)
assert Permutation.from_sequence('SymPy', key=lambda x: x.lower()) == \
Permutation(4)(0, 2)(1, 3)
开发者ID:jenshnielsen,项目名称:sympy,代码行数:4,代码来源:test_permutations.py
示例7: test_ranking
def test_ranking():
assert Permutation.unrank_lex(5, 10).rank() == 10
p = Permutation.unrank_lex(15, 225)
assert p.rank() == 225
p1 = p.next_lex()
assert p1.rank() == 226
assert Permutation.unrank_lex(15, 225).rank() == 225
assert Permutation.unrank_lex(10, 0).is_Identity
p = Permutation.unrank_lex(4, 23)
assert p.rank() == 23
assert p.array_form == [3, 2, 1, 0]
assert p.next_lex() is None
p = Permutation([1, 5, 2, 0, 3, 6, 4])
q = Permutation([[1, 2, 3, 5, 6], [0, 4]])
a = [Permutation.unrank_trotterjohnson(4, i).array_form for i in range(5)]
assert a == [[0, 1, 2, 3], [0, 1, 3, 2], [0, 3, 1, 2], [3, 0, 1,
2], [3, 0, 2, 1] ]
assert [Permutation(pa).rank_trotterjohnson() for pa in a] == range(5)
assert Permutation([0, 1, 2, 3]).next_trotterjohnson() == \
Permutation([0, 1, 3, 2])
assert q.rank_trotterjohnson() == 2283
assert p.rank_trotterjohnson() == 3389
assert Permutation([1, 0]).rank_trotterjohnson() == 1
a = Permutation(range(3))
b = a
l = []
tj = []
for i in range(6):
l.append(a)
tj.append(b)
a = a.next_lex()
b = b.next_trotterjohnson()
assert a == b is None
assert set([tuple(a) for a in l]) == set([tuple(a) for a in tj])
p = Permutation([2, 5, 1, 6, 3, 0, 4])
q = Permutation([[6], [5], [0, 1, 2, 3, 4]])
assert p.rank() == 1964
assert q.rank() == 870
assert Permutation([]).rank_nonlex() == 0
prank = p.rank_nonlex()
assert prank == 1600
assert Permutation.unrank_nonlex(7, 1600) == p
qrank = q.rank_nonlex()
assert qrank == 41
assert Permutation.unrank_nonlex(7, 41) == Permutation(q.array_form)
a = [Permutation.unrank_nonlex(4, i).array_form for i in range(24)]
assert a == [
[1, 2, 3, 0], [3, 2, 0, 1], [1, 3, 0, 2], [1, 2, 0, 3], [2, 3, 1, 0],
[2, 0, 3, 1], [3, 0, 1, 2], [2, 0, 1, 3], [1, 3, 2, 0], [3, 0, 2, 1],
[1, 0, 3, 2], [1, 0, 2, 3], [2, 1, 3, 0], [2, 3, 0, 1], [3, 1, 0, 2],
[2, 1, 0, 3], [3, 2, 1, 0], [0, 2, 3, 1], [0, 3, 1, 2], [0, 2, 1, 3],
[3, 1, 2, 0], [0, 3, 2, 1], [0, 1, 3, 2], [0, 1, 2, 3]]
ok = []
p = Permutation([1, 0])
for i in range(3):
ok.append(p.array_form)
p = p.next_nonlex()
if p is None:
ok.append(None)
break
assert ok == [[1, 0], [0, 1], None]
assert Permutation([3, 2, 0, 1]).next_nonlex() == Permutation([1, 3, 0, 2])
assert [Permutation(pa).rank_nonlex() for pa in a] == range(24)
开发者ID:jenshnielsen,项目名称:sympy,代码行数:68,代码来源:test_permutations.py
示例8: test_josephus
def test_josephus():
assert Permutation.josephus(4, 6, 1) == Permutation([3, 1, 0, 2, 5, 4])
assert Permutation.josephus(1, 5, 1).is_Identity
开发者ID:jenshnielsen,项目名称:sympy,代码行数:3,代码来源:test_permutations.py
示例9: test_Permutation
def test_Permutation():
p = Permutation([2, 5, 1, 6, 3, 0, 4])
q = Permutation([[1], [0, 3, 5, 6, 2, 4]])
assert Permutation(p.cyclic_form).array_form == p.array_form
assert p.cardinality == 5040
assert q.cardinality == 5040
assert q.cycles == 2
assert q*p == Permutation([4, 6, 1, 2, 5, 3, 0])
assert p*q == Permutation([6, 5, 3, 0, 2, 4, 1])
assert perm_af_mul([2, 5, 1, 6, 3, 0, 4], [3, 1, 4, 5, 0, 6, 2]) == \
[6, 5, 3, 0, 2, 4, 1]
assert cyclic([(2,3,5)], 5) == [[1, 2, 4], [0], [3]]
assert (Permutation([[1,2,3],[0,4]])*Permutation([[1,2,4],[0],[3]])).cyclic_form == \
[[1, 3], [0, 4, 2]]
assert q.array_form == [3, 1, 4, 5, 0, 6, 2]
assert p.cyclic_form == [[3, 6, 4], [0, 2, 1, 5]]
assert p.transpositions() == [(3, 4), (3, 6), (0, 5), (0, 1), (0, 2)]
assert p**13 == p
assert q**2 == Permutation([5, 1, 0, 6, 3, 2, 4])
assert p+q == Permutation([5, 6, 3, 1, 2, 4, 0])
assert q+p == p+q
assert p-q == Permutation([6, 3, 5, 1, 2, 4, 0])
assert q-p == Permutation([1, 4, 2, 6, 5, 3, 0])
a = p-q
b = q-p
assert (a+b).is_Identity
assert p.conjugate(q) == Permutation([5, 3, 0, 4, 6, 2, 1])
assert p.conjugate(q) == ~q*p*q == p**q
assert q.conjugate(p) == Permutation([6, 3, 2, 0, 1, 4, 5])
assert q.conjugate(p) == ~p*q*p == q**p
assert p.commutator(q) == Permutation([1, 4, 5, 6, 3, 0, 2])
assert q.commutator(p) == Permutation([5, 0, 6, 4, 1, 2, 3])
assert p.commutator(q) == ~ q.commutator(p)
assert len(p.atoms()) == 7
assert q.atoms() == set([0, 1, 2, 3, 4, 5, 6])
assert p.inversion_vector() == [2, 4, 1, 3, 1, 0]
assert q.inversion_vector() == [3, 1, 2, 2, 0, 1]
assert Permutation.from_inversion_vector(p.inversion_vector()) == p
assert Permutation.from_inversion_vector(q.inversion_vector()).array_form\
== q.array_form
assert Permutation([i for i in range(500,-1,-1)]).inversions() == 125250
assert Permutation([0, 4, 1, 3, 2]).parity() == 0
assert Permutation([0, 1, 4, 3, 2]).parity() == 1
assert perm_af_parity([0, 4, 1, 3, 2]) == 0
assert perm_af_parity([0, 1, 4, 3, 2]) == 1
s = Permutation([0])
assert s.is_Singleton
r = Permutation([3, 2, 1, 0])
assert (r**2).is_Identity
assert (p*(~p)).is_Identity
assert (~p)**13 == Permutation([5, 2, 0, 4, 6, 1, 3])
assert ~(r**2).is_Identity
assert p.max() == 6
assert p.min() == 0
q = Permutation([[6], [5], [0, 1, 2, 3, 4]])
assert q.max() == 4
assert q.min() == 0
p = Permutation([1, 5, 2, 0, 3, 6, 4])
q = Permutation([[1, 2, 3, 5, 6], [0, 4]])
assert p.ascents() == [0, 3, 4]
assert q.ascents() == [1, 2, 4]
assert r.ascents() == []
assert p.descents() == [1, 2, 5]
assert q.descents() == [0, 3, 5]
assert Permutation(r.descents()).is_Identity
assert p.inversions() == 7
assert p.signature() == -1
assert q.inversions() == 11
assert q.signature() == -1
assert (p*(~p)).inversions() == 0
assert (p*(~p)).signature() == 1
assert p.order() == 6
assert q.order() == 10
assert (p**(p.order())).is_Identity
assert p.length() == 6
assert q.length() == 7
#.........这里部分代码省略.........
开发者ID:StefenYin,项目名称:sympy,代码行数:101,代码来源:test_permutations.py
示例10: test_ranking
def test_ranking():
assert Permutation.unrank_lex(5, 10).rank() == 10
p = Permutation.unrank_lex(15, 225)
assert p.rank() == 225
p1 = p.next_lex()
assert p1.rank() == 226
assert Permutation.unrank_lex(15, 225).rank() == 225
assert Permutation.unrank_lex(10, 0).is_Identity
p = Permutation.unrank_lex(4, 23)
assert p.rank() == 23
assert p.array_form == [3, 2, 1, 0]
assert p.next_lex() == None
p = Permutation([1, 5, 2, 0, 3, 6, 4])
q = Permutation([[1, 2, 3, 5, 6], [0, 4]])
a = [Permutation.unrank_trotterjohnson(4, i).array_form for i in range(5)]
assert a == [[0,1,2,3], [0,1,3,2], [0,3,1,2], [3,0,1,2], [3,0,2,1] ]
assert [Permutation(pa).rank_trotterjohnson() for pa in a] == range(5)
assert Permutation([0,1,2,3]).next_trotterjohnson() == \
Permutation([0,1,3,2])
assert q.rank_trotterjohnson() == 2283
assert p.rank_trotterjohnson() == 3389
p = Permutation([2, 5, 1, 6, 3, 0, 4])
q = Permutation([[6], [5], [0, 1, 2, 3, 4]])
assert p.rank() == 1964
assert q.rank() == 870
assert Permutation([]).rank_nonlex() == 0
prank = p.rank_nonlex()
assert prank == 1600
assert Permutation.unrank_nonlex(7, 1600) == p
qrank = q.rank_nonlex()
assert qrank == 41
assert Permutation.unrank_nonlex(7, 41) == Permutation(q.array_form)
a = [Permutation.unrank_nonlex(4, i).array_form for i in range(24)]
assert a == \
[[1, 2, 3, 0], [3, 2, 0, 1], [1, 3, 0, 2], [1, 2, 0, 3], [2, 3, 1, 0], \
[2, 0, 3, 1], [3, 0, 1, 2], [2, 0, 1, 3], [1, 3, 2, 0], [3, 0, 2, 1], \
[1, 0, 3, 2], [1, 0, 2, 3], [2, 1, 3, 0], [2, 3, 0, 1], [3, 1, 0, 2], \
[2, 1, 0, 3], [3, 2, 1, 0], [0, 2, 3, 1], [0, 3, 1, 2], [0, 2, 1, 3], \
[3, 1, 2, 0], [0, 3, 2, 1], [0, 1, 3, 2], [0, 1, 2, 3]]
assert Permutation([3, 2, 0, 1]).next_nonlex() == Permutation([1, 3, 0, 2])
assert [Permutation(pa).rank_nonlex() for pa in a] == range(24)
开发者ID:StefenYin,项目名称:sympy,代码行数:46,代码来源:test_permutations.py
示例11: test_Permutation
def test_Permutation():
p = Permutation([2,5,1,6,3,0,4])
q = Permutation([[1,4,5],[2,0,6],[3]])
assert q.cycles == 3
assert p*q == Permutation([4, 6, 1, 2, 5, 3, 0])
assert q*p == Permutation([6, 5, 3, 0, 2, 4, 1])
assert q.array_form == [3, 1, 4, 5, 0, 6, 2]
assert p.cyclic_form == [[3, 6, 4], [0, 2, 1, 5]]
assert p**13 == p
assert q**2 == Permutation([5, 1, 0, 6, 3, 2, 4])
assert p+q == Permutation([5, 6, 3, 1, 2, 4, 0])
assert q+p == p+q
assert p-q == Permutation([6, 3, 5, 1, 2, 4, 0])
assert q-p == Permutation([1, 4, 2, 6, 5, 3, 0])
a = p-q
b = q-p
assert (a+b).is_Identity
assert len(p.atoms()) == 7
assert q.atoms() == set([0, 1, 2, 3, 4, 5, 6])
assert p.inversion_vector == [2, 4, 1, 3, 1, 0]
assert q.inversion_vector == [3, 1, 2, 2, 0, 1]
assert Permutation.from_inversion_vector(p.inversion_vector) == p
assert Permutation.from_inversion_vector(q.inversion_vector).array_form\
== q.array_form
s = Permutation([0])
assert s.is_Singleton
r = Permutation([3,2,1,0])
assert (r**2).is_Identity
assert (p*(~p)).is_Identity
assert (~p)**13 == Permutation([5, 2, 0, 4, 6, 1, 3])
assert ~(r**2).is_Identity
assert p.max == 6
assert p.min == 0
q = Permutation([[4,1,2,3],[0,5,6]])
assert q.max == 4
assert q.min == 0
assert p.rank_nonlex() == 14830
assert q.rank_nonlex() == 8441
assert Permutation.unrank_nonlex(7, 41) == Permutation([4, 2, 3, 5, 1, 0, 6])
assert q.rank == 870
assert p.rank == 1964
p = Permutation([1,5,2,0,3,6,4])
q = Permutation([[2,3,5],[1,0,6],[4]])
assert p.ascents == [0, 3, 4]
assert q.ascents == [1, 2, 4]
assert r.ascents == []
assert p.descents == [1, 2, 5]
assert q.descents == [0, 3, 5]
assert Permutation(r.descents).is_Identity
assert p.inversions == 7
assert p.signature == -1
assert q.inversions == 11
assert q.signature == -1
assert (p*(~p)).inversions == 0
assert (p*(~p)).signature == 1
assert p.order == 6
assert q.order == 3
assert (p**(p.order)).is_Identity
assert p.length == 6
assert q.length == 7
assert r.length == 4
assert not p.is_Positive
assert p.is_Negative
assert not q.is_Positive
assert q.is_Negative
assert r.is_Positive
assert not r.is_Negative
assert p.runs() == [[1, 5], [2], [0, 3, 6], [4]]
assert q.runs() == [[4], [2, 3, 5], [0, 6], [1]]
assert r.runs() == [[3], [2], [1], [0]]
assert p.index == 8
assert q.index == 8
assert r.index == 3
#.........这里部分代码省略.........
开发者ID:Ingwar,项目名称:sympy,代码行数:101,代码来源:test_permutations.py
示例12: test_Permutation
def test_Permutation():
p = Permutation([2, 5, 1, 6, 3, 0, 4])
q = Permutation([[1], [0, 3, 5, 6, 2, 4]])
assert Permutation(p.cyclic_form).array_form == p.array_form
assert p.cardinality == 5040
assert q.cardinality == 5040
assert q.cycles == 2
assert q*p == Permutation([4, 6, 1, 2, 5, 3, 0])
assert p*q == Permutation([6, 5, 3, 0, 2, 4, 1])
assert (Permutation([[1,2,3],[0,4]])*Permutation([[1,2,4],[0],[3]])).cyclic_form == \
[[1, 3], [0, 4, 2]]
assert q.array_form == [3, 1, 4, 5, 0, 6, 2]
assert p.cyclic_form == [[3, 6, 4], [0, 2, 1, 5]]
assert p**13 == p
assert q**2 == Permutation([5, 1, 0, 6, 3, 2, 4])
assert p+q == Permutation([5, 6, 3, 1, 2, 4, 0])
assert q+p == p+q
assert p-q == Permutation([6, 3, 5, 1, 2, 4, 0])
assert q-p == Permutation([1, 4, 2, 6, 5, 3, 0])
a = p-q
b = q-p
assert (a+b).is_Identity
assert len(p.atoms()) == 7
assert q.atoms() == set([0, 1, 2, 3, 4, 5, 6])
assert p.inversion_vector() == [2, 4, 1, 3, 1, 0]
assert q.inversion_vector() == [3, 1, 2, 2, 0, 1]
assert Permutation.from_inversion_vector(p.inversion_vector()) == p
assert Permutation.from_inversion_vector(q.inversion_vector()).array_form\
== q.array_form
assert Permutation([0, 4, 1, 3, 2]).parity() == 0
assert Permutation([0, 1, 4, 3, 2]).parity() == 1
s = Permutation([0])
assert s.is_Singleton
r = Permutation([3, 2, 1, 0])
assert (r**2).is_Identity
assert (p*(~p)).is_Identity
assert (~p)**13 == Permutation([5, 2, 0, 4, 6, 1, 3])
assert ~(r**2).is_Identity
assert p.max() == 6
assert p.min() == 0
q = Permutation([[6], [5], [0, 1, 2, 3, 4]])
assert q.max() == 4
assert q.min() == 0
assert Permutation([]).rank_nonlex() == 0
prank = p.rank_nonlex()
assert prank == 1600
assert Permutation.unrank_nonlex(7, 1600) == p
qrank = q.rank_nonlex()
assert qrank == 41
assert Permutation.unrank_nonlex(7, 41) == Permutation(q.array_form)
a = [Permutation.unrank_nonlex(4, i).array_form for i in range(24)]
assert a == \
[[1, 2, 3, 0], [3, 2, 0, 1], [1, 3, 0, 2], [1, 2, 0, 3], [2, 3, 1, 0], \
[2, 0, 3, 1], [3, 0, 1, 2], [2, 0, 1, 3], [1, 3, 2, 0], [3, 0, 2, 1], \
[1, 0, 3, 2], [1, 0, 2, 3], [2, 1, 3, 0], [2, 3, 0, 1], [3, 1, 0, 2], \
[2, 1, 0, 3], [3, 2, 1, 0], [0, 2, 3, 1], [0, 3, 1, 2], [0, 2, 1, 3], \
[3, 1, 2, 0], [0, 3, 2, 1], [0, 1, 3, 2], [0, 1, 2, 3]]
assert [Permutation(pa).rank_nonlex() for pa in a] == range(24)
assert q.rank() == 870
assert p.rank() == 1964
p = Permutation([1, 5, 2, 0, 3, 6, 4])
q = Permutation([[1, 2, 3, 5, 6], [0, 4]])
assert p.ascents() == [0, 3, 4]
assert q.ascents() == [1, 2, 4]
assert r.ascents() == []
assert p.descents() == [1, 2, 5]
assert q.descents() == [0, 3, 5]
assert Permutation(r.descents()).is_Identity
assert p.inversions() == 7
assert p.signature() == -1
assert q.inversions() == 11
assert q.signature() == -1
assert (p*(~p)).inversions() == 0
assert (p*(~p)).signature() == 1
assert p.order() == 6
assert q.order() == 10
#.........这里部分代码省略.........
开发者ID:ArchKaine,项目名称:sympy,代码行数:101,代码来源:test_permutations.py
注:本文中的sympy.combinatorics.permutations.Permutation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论