How to use the permuta.Perm.to_standard function in permuta

To help you get started, we’ve selected a few permuta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PermutaTriangle / Permuta / tests / patterns / test_perm.py View on Github external
def test_to_standard():
    def gen(perm):
        res = list(perm)
        add = 0
        for i in perm.inverse():
            add += random.randint(0, 10)
            res[i] += add
        return Perm(res)

    perm = Perm.to_standard(x for x in range(10))
    Perm.to_standard(x for x in range(3, 10))

    for _ in range(100):
        perm = Perm.random(random.randint(0, 20))
        assert perm == Perm.to_standard(perm)
        assert perm == Perm.to_standard(gen(perm))

    assert Perm.to_standard("aaa") == Perm((0, 1, 2))
    assert Perm.to_standard("cba") == Perm((2, 1, 0))
github PermutaTriangle / Permuta / tests / patterns / test_perm.py View on Github external
add = 0
        for i in perm.inverse():
            add += random.randint(0, 10)
            res[i] += add
        return Perm(res)

    perm = Perm.to_standard(x for x in range(10))
    Perm.to_standard(x for x in range(3, 10))

    for _ in range(100):
        perm = Perm.random(random.randint(0, 20))
        assert perm == Perm.to_standard(perm)
        assert perm == Perm.to_standard(gen(perm))

    assert Perm.to_standard("aaa") == Perm((0, 1, 2))
    assert Perm.to_standard("cba") == Perm((2, 1, 0))
github PermutaTriangle / Permuta / tests / test_PermSet.py View on Github external
def test_avoiders_generic():
    PermSet.avoiding(Perm.to_standard("your mom")).of_length(5)

    res = PermSet.avoiding([Perm((0, 1, 2, 3)), Perm((1, 0))])
    assert isinstance(res, PermSet)

    ts = [
        ([[]], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
        ([[0, 1]], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
        ([[1, 0]], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
        ([[0, 1, 2]], [catalan(i) for i in range(8)]),
        ([[0, 2, 1]], [catalan(i) for i in range(8)]),
        ([[1, 0, 2]], [catalan(i) for i in range(8)]),
        ([[1, 2, 0]], [catalan(i) for i in range(8)]),
        ([[2, 0, 1]], [catalan(i) for i in range(8)]),
        ([[2, 1, 0]], [catalan(i) for i in range(8)]),
        ([[0, 1, 2], [0, 3, 2, 1]], [1, 1, 2, 5, 13, 34, 89, 233, 610]),
    ]
github PermutaTriangle / Permuta / tests / patterns / test_perm.py View on Github external
def test_to_standard():
    def gen(perm):
        res = list(perm)
        add = 0
        for i in perm.inverse():
            add += random.randint(0, 10)
            res[i] += add
        return Perm(res)

    perm = Perm.to_standard(x for x in range(10))
    Perm.to_standard(x for x in range(3, 10))

    for _ in range(100):
        perm = Perm.random(random.randint(0, 20))
        assert perm == Perm.to_standard(perm)
        assert perm == Perm.to_standard(gen(perm))

    assert Perm.to_standard("aaa") == Perm((0, 1, 2))
    assert Perm.to_standard("cba") == Perm((2, 1, 0))
github PermutaTriangle / Permuta / tests / patterns / test_perm.py View on Github external
res = list(perm)
        add = 0
        for i in perm.inverse():
            add += random.randint(0, 10)
            res[i] += add
        return Perm(res)

    perm = Perm.to_standard(x for x in range(10))
    Perm.to_standard(x for x in range(3, 10))

    for _ in range(100):
        perm = Perm.random(random.randint(0, 20))
        assert perm == Perm.to_standard(perm)
        assert perm == Perm.to_standard(gen(perm))

    assert Perm.to_standard("aaa") == Perm((0, 1, 2))
    assert Perm.to_standard("cba") == Perm((2, 1, 0))
github PermutaTriangle / Permuta / tests / patterns / test_perm.py View on Github external
def test_to_standard():
    def gen(perm):
        res = list(perm)
        add = 0
        for i in perm.inverse():
            add += random.randint(0, 10)
            res[i] += add
        return Perm(res)

    perm = Perm.to_standard(x for x in range(10))
    Perm.to_standard(x for x in range(3, 10))

    for _ in range(100):
        perm = Perm.random(random.randint(0, 20))
        assert perm == Perm.to_standard(perm)
        assert perm == Perm.to_standard(gen(perm))

    assert Perm.to_standard("aaa") == Perm((0, 1, 2))
    assert Perm.to_standard("cba") == Perm((2, 1, 0))
github PermutaTriangle / Permuta / tests / patterns / test_perm.py View on Github external
def test_to_standard():
    def gen(perm):
        res = list(perm)
        add = 0
        for i in perm.inverse():
            add += random.randint(0, 10)
            res[i] += add
        return Perm(res)

    perm = Perm.to_standard(x for x in range(10))
    Perm.to_standard(x for x in range(3, 10))

    for _ in range(100):
        perm = Perm.random(random.randint(0, 20))
        assert perm == Perm.to_standard(perm)
        assert perm == Perm.to_standard(gen(perm))

    assert Perm.to_standard("aaa") == Perm((0, 1, 2))
    assert Perm.to_standard("cba") == Perm((2, 1, 0))
github PermutaTriangle / Permuta / permuta / enumeration_strategies / core_strategies.py View on Github external
def last_sum_component(p):
    """
    Return the last sum component of a permutation.
    """
    n = len(p)
    i = 1
    comp = set([p[n - i]])
    while comp != set(range(n - i, n)):
        i += 1
        comp.add(p[n - i])
    return Perm.to_standard(p[n - i : n])