Ejemplo n.º 1
0
def check_froidure_pin_transf2(T):
    add = list(range(3, 16)) if T is Transf16 else []
    gens = [
        T.make([1, 0, 2] + add),
        T.make([1, 2, 0] + add),
    ]
    S = FroidurePin(gens)
    S.run()
    assert list(S) == [
        T.make([1, 0, 2] + add),
        T.make([1, 2, 0] + add),
        T.make([0, 1, 2] + add),
        T.make([2, 1, 0] + add),
        T.make([0, 2, 1] + add),
        T.make([2, 0, 1] + add),
    ]

    assert list(S.sorted()) == [
        T.make([0, 1, 2] + add),
        T.make([0, 2, 1] + add),
        T.make([1, 0, 2] + add),
        T.make([1, 2, 0] + add),
        T.make([2, 0, 1] + add),
        T.make([2, 1, 0] + add),
    ]
def check_initialisation(self, t):
    ReportGuard(False)
    x = t()
    x.set_alphabet("ba")
    x.add_rule([0, 1], [1, 0])

    with self.assertRaises(RuntimeError):
        x.add_rule([0, 1], [2])

    S = FroidurePin([Transf([1, 2, 0]), Transf([1, 0, 2])])
    S.run()
    x.add_rules(S)
    self.assertEqual(x.size(), 2)

    x = t()
    x.set_alphabet("abBe")
    x.set_identity("e")

    x.set_inverses("aBbe")

    x.add_rule("bb", "B")
    x.add_rule("BaBa", "abab")
    self.assertEqual(x.size(), 24)

    x = t()
    x.set_alphabet(1)
    x.set_identity(0)
    self.assertEqual(x.size(), 1)
Ejemplo n.º 3
0
def test_froidure_pin_max_plus(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    gens = [MaxPlusMat([[0, -3], [-2, -10]])]
    assert FroidurePin(gens).size() == 2

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 4
0
def test_froidure_pin_int_mat(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    gens = [IntMat([[0, -3], [-2, -10]])]
    assert FroidurePin(gens).size() == 64

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 5
0
def test_froidure_pin_ntp(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    gens = [Matrix(MatrixKind.NTP, 5, 7, [[1, 1], [1, 1]])]
    assert FroidurePin(gens).size() == 6

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 6
0
def test_froidure_pin_min_plus(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    x = MinPlusMat(2, 2)
    gens = [MinPlusMat([[1, 0], [0, x.zero()]])]
    assert FroidurePin(gens).size() == 3

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 7
0
def check_constructors(coll):
    ReportGuard(False)
    # default constructor
    S = FroidurePin(coll[0])
    S.add_generators(coll[1:])

    # copy constructor
    U = FroidurePin(S)
    assert S is not U
    assert S.number_of_generators() == U.number_of_generators()
    assert S.current_size() == U.current_size()
Ejemplo n.º 8
0
def test_froidure_pin_min_plus_trunc(
    checks_for_froidure_pin, checks_for_generators
):
    ReportGuard(False)
    gens = [Matrix(MatrixKind.MinPlusTrunc, 11, [[1, 0], [0, 1]])]
    assert FroidurePin(gens).size() == 2

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 9
0
def test_froidure_pin_proj_max_plus(
    checks_for_froidure_pin, checks_for_generators
):
    ReportGuard(False)
    x = Matrix(MatrixKind.ProjMaxPlus, 2, 2)
    gens = [Matrix(MatrixKind.ProjMaxPlus, [[1, 0], [0, x.zero()]])]
    assert FroidurePin(gens).size() == 2

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 10
0
def test_runner_transf():
    for T in (Transf16, Transf1, Transf2, Transf4):
        add = list(range(8, 16)) if T is Transf16 else []
        S = FroidurePin(T.make([1, 7, 2, 6, 0, 4, 1, 5] + add))

        S.add_generator(T.make([2, 4, 6, 1, 4, 5, 2, 7] + add))
        S.add_generator(T.make([3, 0, 7, 2, 4, 6, 2, 4] + add))
        S.add_generator(T.make([3, 2, 3, 4, 5, 3, 0, 1] + add))
        S.add_generator(T.make([4, 3, 7, 7, 4, 5, 0, 4] + add))
        S.add_generator(T.make([5, 6, 3, 0, 3, 0, 5, 1] + add))
        S.add_generator(T.make([6, 0, 1, 1, 1, 6, 3, 4] + add))
        S.add_generator(T.make([7, 7, 4, 0, 6, 4, 1, 7] + add))
        check_runner(S, timedelta(microseconds=1000))
Ejemplo n.º 11
0
def test_froidure_pin_bmat8(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    gens = [
        BMat8([[0, 1], [1, 0]]),
        BMat8([[1, 0], [1, 1]]),
        BMat8([[1, 0], [0, 0]]),
    ]
    assert FroidurePin(gens).size() == 16

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 12
0
def test_froidure_pin_bmat(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    gens = [
        Matrix(MatrixKind.Boolean, [[0, 1], [1, 0]]),
        Matrix(MatrixKind.Boolean, [[1, 0], [1, 1]]),
        Matrix(MatrixKind.Boolean, [[1, 0], [0, 0]]),
    ]
    assert FroidurePin(gens).size() == 16

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 13
0
def test_froidure_pin_bipart(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    T = Bipartition
    gens = [
        T.make([0, 1, 1, 0]),
        T.make([0, 1, 2, 1]),
        T.make([0, 0, 0, 0]),
    ]
    assert FroidurePin(gens).size() == 15

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
Ejemplo n.º 14
0
def test_froidure_pin_perm(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    for T in (Perm16, Perm1, Perm2, Perm4):
        add = list(range(4, 16)) if T is Perm16 else []
        gens = [
            T.make([1, 0] + list(range(2, 4)) + add),
            T.make(list(range(1, 4)) + [0] + add),
        ]
        assert FroidurePin(gens).size() == 24

        for check in checks_for_generators:
            check(gens)

        for check in checks_for_froidure_pin:
            check(FroidurePin(gens))
Ejemplo n.º 15
0
def test_froidure_pin_pbr(checks_for_froidure_pin, checks_for_generators):
    ReportGuard(False)
    T = PBR
    gens = [
        T.make([[], [0]]),
        T.make([[0, 1], [0]]),
        T.make([[1], []]),
        T.make([[1], [0, 1]]),
    ]
    assert FroidurePin(gens).size() == 15

    for check in checks_for_generators:
        check(gens)

    for check in checks_for_froidure_pin:
        check(FroidurePin(gens))
 def test_036(self):
     ReportGuard(False)
     S = FroidurePin(Transf([1, 3, 4, 2, 3]), Transf([3, 2, 1, 3, 3]))
     tc = ToddCoxeter(congruence_kind.twosided, S)
     tc.set_number_of_generators(2)
     tc.add_pair([0], [1])
     tc.add_pair([0, 0], [0])
     self.assertEqual(tc.number_of_classes(), 1)
Ejemplo n.º 17
0
def test_runner_perm():
    for T in (Perm16, Perm1, Perm2, Perm4):
        add = list(range(9, 16)) if T is Perm16 else []
        gens = [
            T.make([1, 0] + list(range(2, 9)) + add),
            T.make(list(range(1, 9)) + [0] + add),
        ]
        S = FroidurePin(gens)
        check_runner(S, timedelta(microseconds=1000))
Ejemplo n.º 18
0
def test_froidure_pin_kbe(checks_for_froidure_pin):
    ReportGuard(False)
    kb = KnuthBendix()
    kb.set_alphabet(2)
    kb.add_rule([0, 0, 0, 0], [0])
    kb.add_rule([1, 1, 1, 1], [1])
    kb.add_rule([0, 1], [1, 0])

    assert kb.size() == 15

    for check in checks_for_froidure_pin:
        check(FroidurePin(kb.froidure_pin()))
Ejemplo n.º 19
0
def test_froidure_pin_pperm(checks_for_froidure_pin, checks_for_generators):
    for T in (PPerm16, PPerm1, PPerm2, PPerm4):
        gens = [
            T.make([0, 1, 2], [1, 0, 2], 16),
            T.make([0, 1, 2], [1, 2, 0], 16),
            T.make([0, 1], [0, 1], 16),
        ]
        for check in checks_for_generators:
            check(gens)

        for check in checks_for_froidure_pin:
            check(FroidurePin(gens))
Ejemplo n.º 20
0
def test_froidure_pin_tce(checks_for_froidure_pin):
    ReportGuard(False)
    tc = ToddCoxeter(congruence_kind.twosided)
    tc.set_number_of_generators(2)
    tc.add_pair([0, 0, 0, 0], [0])
    tc.add_pair([1, 1, 1, 1], [1])
    tc.add_pair([0, 1], [1, 0])

    assert tc.number_of_classes() == 15

    for check in checks_for_froidure_pin:
        check(FroidurePin(tc.quotient_froidure_pin()))
Ejemplo n.º 21
0
def test_froidure_pin_transf(checks_for_froidure_pin, checks_for_generators):
    for T in (Transf16, Transf1, Transf2, Transf4):
        add = list(range(3, 16)) if T is Transf16 else []
        gens = [
            T.make([1, 0, 2] + add),
            T.make([1, 2, 0] + add),
            T.make([0, 0, 1] + add),
        ]
        for check in checks_for_generators:
            check(gens)

        for check in checks_for_froidure_pin:
            check(FroidurePin(gens))

        check_froidure_pin_transf1(T)
        check_froidure_pin_transf2(T)
    def test_settings(self):
        ReportGuard(False)
        tc = ToddCoxeter(congruence_kind.left)
        tc.set_number_of_generators(1)
        tc.add_pair([0, 0, 0, 0], [0, 0])
        tc.reserve(10)
        tc.run()

        self.assertFalse(tc.is_standardized())
        tc.standardize(order.lex)
        self.assertTrue(tc.is_standardized())
        tc.standardize(order.shortlex)
        tc.standardize(order.recursive)
        tc.standardize(True)
        tc.standardize(False)
        tc.standardize(1)
        with self.assertRaises(TypeError):
            tc.standardize("shooortlex")

        S = FroidurePin(Transf([3, 1, 2, 1, 2]), Transf([1, 1, 1, 2, 2]))
        tc = ToddCoxeter(congruence_kind.twosided, S)
        tc.froidure_pin_policy()
        tc.froidure_pin_policy(fpp.none)
        self.assertEqual(tc.froidure_pin_policy(), fpp.none)
        tc.froidure_pin_policy(fpp.use_relations)
        self.assertEqual(tc.froidure_pin_policy(), fpp.use_relations)
        tc.froidure_pin_policy(fpp.use_cayley_graph)
        self.assertEqual(tc.froidure_pin_policy(), fpp.use_cayley_graph)
        with self.assertRaises(TypeError):
            tc.froidure_pin_policy(1)
        with self.assertRaises(TypeError):
            tc.froidure_pin_policy("userelations")

        tc = ToddCoxeter(congruence_kind.left)
        tc.set_number_of_generators(2)
        tc.add_pair([0, 0, 0, 0], [0])
        tc.add_pair([1, 1, 1, 1], [0])
        with self.assertRaises(TypeError):
            tc.strategy("feelsch")
        with self.assertRaises(TypeError):
            tc.strategy(1)
        tc.strategy(strategy.felsch)
        self.assertEqual(tc.strategy(), strategy.felsch)
        tc.strategy(strategy.hlt)
        self.assertEqual(tc.strategy(), strategy.hlt)
        tc.strategy(strategy.random)
        self.assertEqual(tc.strategy(), strategy.random)
    def test_attributes(self):
        ReportGuard(False)
        tc = ToddCoxeter(congruence_kind.left)
        tc.set_number_of_generators(1)
        tc.add_pair([0, 0, 0, 0, 0, 0], [0, 0, 0])
        self.assertEqual(tc.number_of_classes(), 5)
        self.assertTrue(tc.contains([0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0]))
        self.assertFalse(tc.contains([0, 0, 0], [0, 0]))
        self.assertEqual(tc.const_contains([0, 0, 0], [0, 0]), tril.false)
        self.assertEqual(tc.kind(), congruence_kind.left)
        self.assertFalse(tc.empty())
        self.assertEqual(tc.class_index_to_word(1), [0, 0])
        self.assertEqual(tc.word_to_class_index([0, 0]), 1)
        self.assertFalse(tc.has_parent_froidure_pin())
        self.assertEqual(tc.number_of_generators(), 1)
        self.assertEqual(tc.number_of_generating_pairs(), 1)
        self.assertTrue(tc.less([0], [0, 0]))

        S = FroidurePin(Transf([1, 2, 2]), Transf([2, 0, 1]))
        tc = ToddCoxeter(congruence_kind.twosided, S)
        self.assertEqual(tc.number_of_classes(), 24)
        self.assertTrue(tc.has_parent_froidure_pin())
        self.assertEqual(tc.parent_froidure_pin().size(), 24)
        self.assertEqual(tc.quotient_froidure_pin().size(), 24)

        K = KnuthBendix()
        K.set_alphabet("a")
        K.add_rule("aaaa", "aa")
        tc = ToddCoxeter(congruence_kind.left, K)
        self.assertEqual(tc.number_of_classes(), 3)

        tc = ToddCoxeter(congruence_kind.twosided)
        tc.set_number_of_generators(1)
        self.assertTrue(tc.is_quotient_obviously_infinite())
        self.assertFalse(tc.is_quotient_obviously_finite())
        tc.add_pair([0, 0, 0], [0])
        self.assertFalse(tc.is_quotient_obviously_infinite())
        tc.run()
        self.assertTrue(tc.is_quotient_obviously_finite())
Ejemplo n.º 24
0
def check_generators(coll):
    ReportGuard(False)
    S = FroidurePin(coll[0])
    S.add_generators(coll[1:])
    for i, x in enumerate(coll):
        assert S.generator(i) == x

    with pytest.raises(RuntimeError):
        S.generator(len(coll))

    U = FroidurePin(coll[0])
    for x in coll[1:]:
        U.add_generator(x)
    assert S.number_of_generators() == U.number_of_generators()
    assert S.size() == U.size()

    S.closure(coll)
    assert S.number_of_generators() == len(coll)

    U = S.copy_closure(coll)
    assert U.number_of_generators() == S.number_of_generators()
    assert U.size() == S.size()
    assert U is not S

    U = S.copy_add_generators(coll)
    assert U.number_of_generators() == 2 * S.number_of_generators()
    assert U.size() == S.size()
    assert U is not S
 def test_000_iterators(self):
     ReportGuard(False)
     tc = ToddCoxeter(congruence_kind.left)
     tc.set_number_of_generators(2)
     tc.add_pair([0, 0, 0, 0], [0])
     tc.add_pair([1, 1, 1, 1], [1])
     tc.add_pair([0, 1], [1, 0])
     self.assertEqual(
         list(tc.generating_pairs()),
         [([0, 0, 0, 0], [0]), ([1, 1, 1, 1], [1]), ([0, 1], [1, 0])],
     )
     self.assertEqual(
         list(tc.normal_forms()),
         [
             [0],
             [1],
             [0, 0],
             [1, 0],
             [1, 1],
             [0, 0, 0],
             [1, 0, 0],
             [1, 1, 0],
             [1, 1, 1],
             [1, 0, 0, 0],
             [1, 1, 0, 0],
             [1, 1, 1, 0],
             [1, 1, 0, 0, 0],
             [1, 1, 1, 0, 0],
             [1, 1, 1, 0, 0, 0],
         ],
     )
     S = FroidurePin(Transf([1, 3, 4, 2, 3]), Transf([3, 2, 1, 3, 3]))
     tc = ToddCoxeter(congruence_kind.left, S)
     tc.add_pair(
         S.factorisation(Transf([3, 4, 4, 4, 4])),
         S.factorisation(Transf([3, 1, 3, 3, 3])),
     )
     self.assertEqual(
         list(tc.non_trivial_classes()),
         [[
             [0, 0, 1],
             [1, 0, 1],
             [0, 0, 0, 1],
             [0, 1, 0, 1],
             [1, 0, 0, 1],
             [0, 0, 0, 0, 1],
             [0, 0, 1, 0, 1],
             [1, 0, 0, 0, 1],
             [1, 0, 1, 0, 1],
             [0, 0, 0, 1, 0, 1],
             [0, 1, 0, 0, 0, 1],
             [0, 1, 0, 1, 0, 1],
             [1, 0, 0, 1, 0, 1],
             [0, 0, 0, 0, 1, 0, 1],
             [0, 0, 1, 0, 0, 0, 1],
             [1, 0, 0, 0, 1, 0, 1],
             [0, 1, 0, 0, 0, 1, 0, 1],
             [0, 0, 1, 0, 0, 0, 1, 0, 0],
             [0, 0, 1, 0, 0, 0, 1, 0, 1],
             [0, 1, 0, 0, 0, 1, 1, 0, 0],
         ]],
     )
    def test_constructors(self):
        # pylint: disable=too-many-statements
        ToddCoxeter(congruence_kind.left)
        ToddCoxeter(congruence_kind.right)
        ToddCoxeter(congruence_kind.twosided)

        with self.assertRaises(TypeError):
            ToddCoxeter(45)
        with self.assertRaises(TypeError):
            ToddCoxeter("lft")
        with self.assertRaises(TypeError):
            ToddCoxeter(
                congruence_kind.twosided,
                congruence_kind.left,
                congruence_kind.right,
            )

        S = FroidurePin(Transf([0, 0, 1, 2, 3]))
        with self.assertRaises(TypeError):
            ToddCoxeter(S)

        ToddCoxeter(congruence_kind.twosided, S)

        K = KnuthBendix()
        with self.assertRaises(RuntimeError):
            ToddCoxeter(congruence_kind.left, K)
        K.set_alphabet("a")
        ToddCoxeter(congruence_kind.left, K)

        T = ToddCoxeter(congruence_kind.left)
        if libsemigroups_version() == "2.0.3":
            with self.assertRaises(ValueError):
                ToddCoxeter(congruence_kind.left, T)
        else:
            ToddCoxeter(congruence_kind.left, T)

        T.set_number_of_generators(1)

        with self.assertRaises(RuntimeError):
            ToddCoxeter(congruence_kind.right, T)
        with self.assertRaises(RuntimeError):
            ToddCoxeter(congruence_kind.twosided, T)
        ToddCoxeter(congruence_kind.left, T)

        T = ToddCoxeter(congruence_kind.right)
        if libsemigroups_version() == "2.0.3":
            with self.assertRaises(ValueError):
                ToddCoxeter(congruence_kind.right, T)
        else:
            ToddCoxeter(congruence_kind.right, T)
        T.set_number_of_generators(1)
        with self.assertRaises(RuntimeError):
            ToddCoxeter(congruence_kind.left, T)
        with self.assertRaises(RuntimeError):
            ToddCoxeter(congruence_kind.twosided, T)

        ToddCoxeter(congruence_kind.right, T)

        T = ToddCoxeter(congruence_kind.twosided)
        if libsemigroups_version() == "2.0.3":
            with self.assertRaises(ValueError):
                ToddCoxeter(congruence_kind.twosided, T)
        else:
            ToddCoxeter(congruence_kind.twosided, T)
        T.set_number_of_generators(1)
        ToddCoxeter(congruence_kind.left, T)
        ToddCoxeter(congruence_kind.right, T)
        ToddCoxeter(congruence_kind.twosided, T)

        tc = ToddCoxeter(congruence_kind.left)
        tc.set_number_of_generators(2)
        with self.assertRaises(RuntimeError):
            tc.add_pair([0, 0, 1, 0], [1, 1, 2])
Ejemplo n.º 27
0
def check_froidure_pin_transf1(T):
    ReportGuard(False)
    if T is Transf16:
        add = list(range(8, 16))
    else:
        add = []

    S = FroidurePin(T.make([1, 7, 2, 6, 0, 4, 1, 5] + add))

    S.add_generator(T.make([2, 4, 6, 1, 4, 5, 2, 7] + add))
    S.add_generator(T.make([3, 0, 7, 2, 4, 6, 2, 4] + add))
    S.add_generator(T.make([3, 2, 3, 4, 5, 3, 0, 1] + add))
    S.add_generator(T.make([4, 3, 7, 7, 4, 5, 0, 4] + add))
    S.add_generator(T.make([5, 6, 3, 0, 3, 0, 5, 1] + add))
    S.add_generator(T.make([6, 0, 1, 1, 1, 6, 3, 4] + add))
    S.add_generator(T.make([7, 7, 4, 0, 6, 4, 1, 7] + add))
    S.reserve(600000)

    assert S.number_of_generators() == 8
    assert S.current_size() == 8
    assert S.current_number_of_rules() == 0
    S.enumerate(100)
    assert S.current_size() == 8200
    assert S.current_number_of_rules() == 1049

    if T == Transf16:
        assert S.degree() == 16
    else:
        assert S.degree() == 8
Ejemplo n.º 28
0
def test_runner_pperm():
    for T in (PPerm16, PPerm1, PPerm2, PPerm4):
        S = FroidurePin(T.make(list(range(9)), [1, 0] + list(range(2, 9)), 16))
        S.add_generator(T.make(list(range(9)), list(range(1, 9)) + [0], 16))
        S.add_generator(T.make([0, 1], [0, 1], 16))
        check_runner(S, timedelta(microseconds=1000))