当前位置: 首页>>代码示例>>Python>>正文


Python Permutation.get_precedence_distance方法代码示例

本文整理汇总了Python中sympy.combinatorics.permutations.Permutation.get_precedence_distance方法的典型用法代码示例。如果您正苦于以下问题:Python Permutation.get_precedence_distance方法的具体用法?Python Permutation.get_precedence_distance怎么用?Python Permutation.get_precedence_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.combinatorics.permutations.Permutation的用法示例。


在下文中一共展示了Permutation.get_precedence_distance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_Permutation

# 需要导入模块: from sympy.combinatorics.permutations import Permutation [as 别名]
# 或者: from sympy.combinatorics.permutations.Permutation import get_precedence_distance [as 别名]

#.........这里部分代码省略.........
    assert Permutation.from_inversion_vector(q.inversion_vector()).array_form\
           == q.array_form
    raises(ValueError, lambda: Permutation.from_inversion_vector([0, 2]))
    assert Permutation([i for i in range(500, -1, -1)]).inversions() == 125250

    s = Permutation([0, 4, 1, 3, 2])
    assert s.parity() == 0
    _ = s.cyclic_form  # needed to create a value for _cyclic_form
    assert len(s._cyclic_form) != s.size and s.parity() == 0
    assert not s.is_odd
    assert s.is_even
    assert Permutation([0, 1, 4, 3, 2]).parity() == 1
    assert _af_parity([0, 4, 1, 3, 2]) == 0
    assert _af_parity([0, 1, 4, 3, 2]) == 1

    s = Permutation([0])

    assert s.is_Singleton
    assert Permutation([]).is_Empty

    r = Permutation([3, 2, 1, 0])
    assert (r**2).is_Identity

    assert rmul(~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
    # test the merge-sort with a longer permutation
    big = list(p) + list(range(p.max() + 1, p.max() + 130))
    assert Permutation(big).inversions() == 7
    assert p.signature() == -1
    assert q.inversions() == 11
    assert q.signature() == -1
    assert rmul(p, ~p).inversions() == 0
    assert rmul(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
    assert r.length() == 4

    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

    assert p.get_precedence_distance(q) == q.get_precedence_distance(p)
    assert p.get_adjacency_distance(q) == p.get_adjacency_distance(q)
    assert p.get_positional_distance(q) == p.get_positional_distance(q)
    p = Permutation([0, 1, 2, 3])
    q = Permutation([3, 2, 1, 0])
    assert p.get_precedence_distance(q) == 6
    assert p.get_adjacency_distance(q) == 3
    assert p.get_positional_distance(q) == 8
    p = Permutation([0, 3, 1, 2, 4])
    q = Permutation.josephus(4, 5, 2)
    assert p.get_adjacency_distance(q) == 3
    raises(ValueError, lambda: p.get_adjacency_distance(Permutation([])))
    raises(ValueError, lambda: p.get_positional_distance(Permutation([])))
    raises(ValueError, lambda: p.get_precedence_distance(Permutation([])))

    a = [Permutation.unrank_nonlex(4, i) for i in range(5)]
    iden = Permutation([0, 1, 2, 3])
    for i in range(5):
        for j in range(i + 1, 5):
            assert a[i].commutes_with(a[j]) == \
                (rmul(a[i], a[j]) == rmul(a[j], a[i]))
            if a[i].commutes_with(a[j]):
                assert a[i].commutator(a[j]) == iden
                assert a[j].commutator(a[i]) == iden

    a = Permutation(3)
    b = Permutation(0, 6, 3)(1, 2)
    assert a.cycle_structure == {1: 4}
    assert b.cycle_structure == {2: 1, 3: 1, 1: 2}
开发者ID:jenshnielsen,项目名称:sympy,代码行数:104,代码来源:test_permutations.py

示例2: test_Permutation

# 需要导入模块: from sympy.combinatorics.permutations import Permutation [as 别名]
# 或者: from sympy.combinatorics.permutations.Permutation import get_precedence_distance [as 别名]

#.........这里部分代码省略.........
    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

    assert q.rank_trotterjohnson == 259
    assert p.rank_trotterjohnson == 1087

    assert p.get_precedence_distance(q) == q.get_precedence_distance(p)
    assert p.get_adjacency_distance(q) == p.get_adjacency_distance(q)
    assert p.get_positional_distance(q) == p.get_positional_distance(q)
    p = Permutation([0, 1, 2, 3])
    q = Permutation([3, 2, 1, 0])
    assert p.get_precedence_distance(q) == 6
    assert p.get_adjacency_distance(q) == 3
    assert p.get_positional_distance(q) == 8
开发者ID:Ingwar,项目名称:sympy,代码行数:104,代码来源:test_permutations.py

示例3: test_Permutation

# 需要导入模块: from sympy.combinatorics.permutations import Permutation [as 别名]
# 或者: from sympy.combinatorics.permutations.Permutation import get_precedence_distance [as 别名]

#.........这里部分代码省略.........
    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
    assert r.length() == 4

    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

    assert p.get_precedence_distance(q) == q.get_precedence_distance(p)
    assert p.get_adjacency_distance(q) == p.get_adjacency_distance(q)
    assert p.get_positional_distance(q) == p.get_positional_distance(q)
    p = Permutation([0, 1, 2, 3])
    q = Permutation([3, 2, 1, 0])
    assert p.get_precedence_distance(q) == 6
    assert p.get_adjacency_distance(q) == 3
    assert p.get_positional_distance(q) == 8

    a = [Permutation.unrank_nonlex(4, i) for i in range(5)]
    iden = Permutation([0, 1, 2, 3])
    for i in range(5):
        for j in range(i+1, 5):
            assert a[i].commutes_with(a[j]) == (a[i]*a[j] == a[j]*a[i])
            if a[i].commutes_with(a[j]):
                assert a[i].commutator(a[j]) == iden
                assert a[j].commutator(a[i]) == iden
开发者ID:StefenYin,项目名称:sympy,代码行数:104,代码来源:test_permutations.py

示例4: test_Permutation

# 需要导入模块: from sympy.combinatorics.permutations import Permutation [as 别名]
# 或者: from sympy.combinatorics.permutations.Permutation import get_precedence_distance [as 别名]

#.........这里部分代码省略.........
    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
    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

    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 q.rank_trotterjohnson() == 2283
    assert p.rank_trotterjohnson() == 3389

    assert p.get_precedence_distance(q) == q.get_precedence_distance(p)
    assert p.get_adjacency_distance(q) == p.get_adjacency_distance(q)
    assert p.get_positional_distance(q) == p.get_positional_distance(q)
    p = Permutation([0, 1, 2, 3])
    q = Permutation([3, 2, 1, 0])
    assert p.get_precedence_distance(q) == 6
    assert p.get_adjacency_distance(q) == 3
    assert p.get_positional_distance(q) == 8
开发者ID:ArchKaine,项目名称:sympy,代码行数:104,代码来源:test_permutations.py


注:本文中的sympy.combinatorics.permutations.Permutation.get_precedence_distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。