How to use the permuta.Permutation 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 / oldtests / test_mesh_pattern.py View on Github external
def test_contained_in(self):
        self.assertTrue(Permutation([1,2,3]).contains(MeshPattern([1,2], set([(1,0),(1,1),(1,2)]))))
        self.assertTrue(self.mesh_pattern.contained_in(self.perm1))
        self.assertTrue(self.mesh_pattern.contained_in(self.perm2))
        self.assertFalse(self.mesh_pattern.contained_in(self.perm3))
        self.assertTrue(self.mesh_pattern.contained_in(self.perm1, self.perm2))
        self.assertFalse(self.mesh_pattern.contained_in(self.perm1, self.perm3))
github PermutaTriangle / Permuta / oldtests / test_permutations.py View on Github external
ts = [
            ([[]], [0,0,0,0,0,0,0,0,0,0]),
            ([[1,2]], [1,1,1,1,1,1,1,1,1,1]),
            ([[2,1]], [1,1,1,1,1,1,1,1,1,1]),
            ([[1,2,3]], [ catalan(i) for i in range(8) ]),
            ([[1,3,2]], [ catalan(i) for i in range(8) ]),
            ([[2,1,3]], [ catalan(i) for i in range(8) ]),
            ([[2,3,1]], [ catalan(i) for i in range(8) ]),
            ([[3,1,2]], [ catalan(i) for i in range(8) ]),
            ([[3,2,1]], [ catalan(i) for i in range(8) ]),
            ([[1,2,3], [1,4,3,2]], [1, 1, 2, 5, 13, 34, 89, 233, 610]),
        ]

        for (patts, enum) in ts:
            patts = [ Permutation(patt) for patt in patts ]
            for (n,cnt) in enumerate(enum):
                inst = Permutations(n, avoiding=patts)
                gen = list(inst)
                self.assertEqual(len(gen), cnt)
                self.assertEqual(len(gen), len(set(gen)))
                for p in gen:
                    self.assertTrue(p.avoids(*patts))

            mx = len(enum)-1
            cnt = [ 0 for _ in range(mx+1) ]
            inst = Permutations(mx, avoiding=patts, upto=True)
            gen = list(inst)
            for p in gen:
                self.assertTrue(p.avoids(*patts))
                cnt[len(p)] += 1
github PermutaTriangle / Permuta / oldtests / test_permutations.py View on Github external
def test_avoiders(self):
        ts = [
            (PermutationsAvoiding12, [1,2], [1,1,1,1,1,1,1,1,1,1]),
            (PermutationsAvoiding21, [2,1], [1,1,1,1,1,1,1,1,1,1]),
            (PermutationsAvoiding123, [1,2,3], [ catalan(i) for i in range(8) ]),
            (PermutationsAvoiding132, [1,3,2], [ catalan(i) for i in range(8) ]),
            (PermutationsAvoiding213, [2,1,3], [ catalan(i) for i in range(8) ]),
            (PermutationsAvoiding231, [2,3,1], [ catalan(i) for i in range(8) ]),
            (PermutationsAvoiding312, [3,1,2], [ catalan(i) for i in range(8) ]),
            (PermutationsAvoiding321, [3,2,1], [ catalan(i) for i in range(8) ]),
        ]

        for (cl, patt, enum) in ts:
            ginst = Permutations(5, avoiding=Permutation(patt))
            self.assertTrue(type(ginst) is cl)

            for (n,cnt) in enumerate(enum):
                inst = cl(n)
                gen = list(inst)
                self.assertEqual(len(gen), cnt)
                self.assertEqual(len(gen), len(set(gen)))
                for p in gen:
                    self.assertTrue(p.avoids(Permutation(patt)))
github PermutaTriangle / Permuta / oldtests / test_permutations.py View on Github external
def test_is_polynomial(self):
        self.assertEqual(Permutations(8, [Permutation([])]).is_polynomial(), True)
        self.assertEqual(Permutations(8, [Permutation([1])]).is_polynomial(),True)
        self.assertEqual(Permutations(8, [Permutation([1,2])]).is_polynomial(),True)
        self.assertEqual(Permutations(8, [Permutation([1,3,2,4])]).is_polynomial(),False)
        self.assertEqual(Permutations(8, [Permutation([3,2,1]), Permutation([1,2,3])]).is_polynomial(),True)
        self.assertEqual(Permutations(8, [Permutation([1,2,3]), Permutation([2,3,1])]).is_polynomial(), True)
        self.assertEqual(Permutations(8, [Permutation([1,2,3]), Permutation([1,3,2])]).is_polynomial(), False)
        self.assertEqual(Permutations(8, [Permutation([1,3,2]), Permutation([3,1,2])]).is_polynomial(), False)
        self.assertEqual(Permutations(8, [Permutation([2,3,1]), Permutation([3,1,2])]).is_polynomial(), False)
github PermutaTriangle / Permuta / oldtests / test_mesh_pattern.py View on Github external
def setUp(self):
        pattern = [2,4,3,1]
        shading = set([(0,0),(4,0),(2,1),(4,1),(2,2),(4,2),(3,3),(0,4)])
        self.mesh_pattern = MeshPattern(pattern, shading)
        self.perm1 = Permutation([6,3,9,7,8,10,5,4,2,1])  # Occurrence: E.g., [1,3,6,9]
        self.perm2 = Permutation([2,3,9,7,6,10,5,4,8,1])  # Occurrence: E.g., [1,6,7,9]
        self.perm3 = Permutation([10,9,8,7,3,6,4,5,1,2])  # Occurrence: None (avoids)
        self.perm4 = Permutation([1,2,3,4,5])  # Avoids as well
        self.perm5 = Permutation([2,3,5,4,1])  # Two occurrences
        self.patt1 = self.perm4
        self.patt2 = self.perm5
        self.patt3 = Permutation((3,4,1,2))
        self.shad1 = frozenset([(5,0),(5,1),(5,2),(3,2),(2,1),(3,3),(0,0),(1,0),(2,0)])
        self.shad2 = frozenset([(3,3),(2,2),(1,1),(0,2)])
        self.shad3 = frozenset([(1,3),(4,4),(2,1),(2,2),(0,4),(4,0)])
        self.mesh1 = MeshPattern(self.patt1, self.shad1)
        self.mesh2 = MeshPattern(self.patt2, self.shad2)
        self.mesh3 = MeshPattern(self.patt3, self.shad3)
github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
def __new__(cls, pattern=Permutation(), shading=frozenset(), check=False):
        # TODO: Tests, took into having shading be a sorted tuple of coordinates
        if not isinstance(pattern, Permutation):
            pattern = Permutation(pattern, check=check)
        if not isinstance(shading, frozenset):
            shading = frozenset(shading)
        return super(MeshPattern, cls).__new__(cls, pattern, shading)
github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
    def __new__(cls, pattern=Permutation(), shading=frozenset(), check=False):
        # TODO: Tests, took into having shading be a sorted tuple of coordinates
        if not isinstance(pattern, Permutation):
            pattern = Permutation(pattern, check=check)
        if not isinstance(shading, frozenset):
            shading = frozenset(shading)
        return super(MeshPattern, cls).__new__(cls, pattern, shading)