How to use the permuta.perm_sets.Av 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 / perm_sets / test_av.py View on Github external
def test_generators():
    assert list(Av(Basis(Perm((0, 1)), Perm((1, 0)))).first(500)) == [
        Perm(),
        Perm((0,)),
    ]
    assert sorted(Av(Basis(Perm((0, 2, 1)), Perm((1, 2, 0)))).of_length(3)) == sorted(
        set(Perm.of_length(3)) - {Perm((0, 2, 1)), Perm((1, 2, 0))}
    )
    assert sorted(
        Av(Basis(Perm((0, 2, 1)), Perm((1, 2, 0)))).up_to_length(3)
    ) == sorted(set(Perm.up_to_length(3)) - {Perm((0, 2, 1)), Perm((1, 2, 0))})
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
def test_class_variable_cache():
    Av.clear_cache()
    assert len(Av._CLASS_CACHE) == 0
    assert Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))) is Av(
        Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))
    )
    av = Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0))))
    assert av is Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0))))
    assert av is Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)), Perm((1, 2, 0, 3))))
    assert len(Av._CLASS_CACHE) == 1
    av2 = Av(Basis(Perm((0, 1, 3, 2)), Perm((0, 2, 1))))
    assert len(Av._CLASS_CACHE) == 2
    assert av is not av2
    assert av2 is Av(Basis(Perm((0, 2, 1))))
    assert Av.from_string("132") is av2
    assert Basis(Perm((0, 2, 1))) in Av._CLASS_CACHE
    assert (
        Av._CLASS_CACHE[Basis(Perm((0, 2, 1)))]
        is Av._CLASS_CACHE[Basis(Perm((0, 1, 3, 2)), Perm((0, 2, 1)))]
    )
    assert Av((Perm((2, 0, 1)),)) is Av(Basis(Perm((2, 0, 1))))
    Av.clear_cache()
    assert len(Av._CLASS_CACHE) == 0
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
def test_av_perm():
    p = Perm((0, 1))
    av = Av([p])
    for length in range(10):
        assert len(set(av.of_length(length))) == 1
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
def test_avoiding_generic_finite_class():
    ts = [
        ([[0]], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
        ([[0, 1], [3, 2, 1, 0]], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]),
        ([[0, 1, 2], [3, 2, 1, 0]], [1, 1, 2, 5, 13, 25, 25, 0, 0, 0, 0, 0]),
    ]

    for (patts, enum) in ts:
        patts = [Perm(patt) for patt in patts]
        basis = Basis(*patts)
        for (n, cnt) in enumerate(enum):
            inst = Av(basis).of_length(n)
            gen = list(inst)
            assert len(gen) == cnt
            assert len(gen) == len(set(gen))
            for perm in gen:
                assert perm.avoids(*patts)

        mx = len(enum) - 1
        cnt = [0 for _ in range(mx + 1)]
        for perm in Av(basis).up_to_length(mx):
            assert perm.avoids(*patts)
            cnt[len(perm)] += 1

        assert enum == cnt
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
list(av2.of_length(10))
    assert len(av.cache) == 11
    assert len(av2.cache) == 11
    assert len(Av.from_string("12").cache) == 11
    assert len(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))).cache) == 1
    list(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))).of_length(5))
    assert len(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))).cache) == 6
    assert (
        len(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)), Perm((1, 2, 0, 3)))).cache) == 6
    )
    assert len(Av(Basis(Perm((1, 2, 0)), Perm((2, 0, 1)))).cache) == 6
    for p in Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)), Perm((1, 2, 0, 3)))).of_length(
        10
    ):
        pass
    assert len(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))).cache) == 11
    Av.clear_cache()
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
)
    assert (
        Av.from_string("1243 1342 3241 3241").enumeration(8)
        == Av(
            Basis(
                Perm((0, 1, 3, 2)),
                Perm((0, 2, 3, 1)),
                Perm((2, 1, 3, 0)),
                Perm((2, 1, 3, 0)),
            )
        ).enumeration(8)
        == [1, 1, 2, 6, 21, 75, 262, 891, 2964]
    )
    assert (
        Av.from_string("Av(1342, 3124, 1432, 4312)").enumeration(8)
        == Av(
            Basis(
                Perm((0, 2, 3, 1)),
                Perm((2, 0, 1, 3)),
                Perm((0, 3, 2, 1)),
                Perm((3, 2, 0, 1)),
            )
        ).enumeration(8)
        == [1, 1, 2, 6, 20, 61, 169, 442, 1120]
    )
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
def test_generators():
    assert list(Av(Basis(Perm((0, 1)), Perm((1, 0)))).first(500)) == [
        Perm(),
        Perm((0,)),
    ]
    assert sorted(Av(Basis(Perm((0, 2, 1)), Perm((1, 2, 0)))).of_length(3)) == sorted(
        set(Perm.of_length(3)) - {Perm((0, 2, 1)), Perm((1, 2, 0))}
    )
    assert sorted(
        Av(Basis(Perm((0, 2, 1)), Perm((1, 2, 0)))).up_to_length(3)
    ) == sorted(set(Perm.up_to_length(3)) - {Perm((0, 2, 1)), Perm((1, 2, 0))})
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
def test_enumeration():
    assert (
        Av.from_string("132").enumeration(8)
        == Av(Basis(Perm((0, 2, 1)))).enumeration(8)
        == [1, 1, 2, 5, 14, 42, 132, 429, 1430]
    )
    assert (
        Av.from_string("Av(123,231)").enumeration(8)
        == Av(Basis(Perm((0, 1, 2)), Perm((1, 2, 0)))).enumeration(8)
        == [1, 1, 2, 4, 7, 11, 16, 22, 29]
    )
    assert Av(
        (Perm((0, 1, 2)), MeshPatt(Perm((2, 0, 1)), [(0, 1), (1, 1), (2, 1), (3, 1)]))
    ).enumeration(7) == [1, 1, 2, 4, 8, 16, 32, 64]
    assert (
        Av.from_string("0123_2013_1023").enumeration(8)
        == Av(
            Basis(Perm((0, 1, 2, 3)), Perm((2, 0, 1, 3)), Perm((1, 0, 2, 3)))
        ).enumeration(8)
        == [1, 1, 2, 6, 21, 79, 309, 1237, 5026]
    )
    assert (
        Av.from_string("1243 1342 3241 3241").enumeration(8)
        == Av(
            Basis(
                Perm((0, 1, 3, 2)),
                Perm((0, 2, 3, 1)),
                Perm((2, 1, 3, 0)),
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
def test_valid_error_in_construction():
    with pytest.raises(ValueError):
        Av(Basis())
    with pytest.raises(ValueError):
        Av(Basis(Perm()))
github PermutaTriangle / Permuta / tests / perm_sets / test_av.py View on Github external
def test_instance_variable_cache():
    Av.clear_cache()
    basis = Basis(Perm((0, 1)))
    av = Av(basis)
    assert basis in Av._CLASS_CACHE
    list(av.of_length(5))
    assert len(av.cache) == 6
    assert len(Av(Basis(Perm((0, 1)))).cache) == 6
    av2 = Av(Basis(Perm((0, 1))))
    assert len(av2.cache) == 6
    list(av2.of_length(10))
    assert len(av.cache) == 11
    assert len(av2.cache) == 11
    assert len(Av.from_string("12").cache) == 11
    assert len(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))).cache) == 1
    list(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))).of_length(5))
    assert len(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)))).cache) == 6
    assert (
        len(Av(Basis(Perm((2, 0, 1)), Perm((1, 2, 0)), Perm((1, 2, 0, 3)))).cache) == 6
    )