Ejemplo n.º 1
0
    def test_attributes(self):
        # Check FpSemigroupInterface general attributes
        check_attributes(self, KnuthBendix)
        # Check KnuthBendix specific attributes
        ReportGuard(False)
        kb = KnuthBendix()
        kb.set_alphabet("abB")
        kb.set_identity("")
        kb.set_inverses("aBb")

        kb.add_rule("bb", "B")
        kb.add_rule("BaBa", "abab")

        self.assertFalse(kb.confluent())
        kb.run()
        self.assertTrue(kb.confluent())

        self.assertEqual(
            kb.active_rules(),
            [
                ["BB", "b"],
                ["Bb", ""],
                ["aa", ""],
                ["bB", ""],
                ["bb", "B"],
                ["BaBa", "abab"],
                ["baba", "aBaB"],
                ["BabaB", "baBab"],
                ["Babab", "baBa"],
                ["baBaB", "Baba"],
                ["baBaba", "abaBab"],
            ],
        )
        self.assertEqual(kb.nr_active_rules(), 11)
Ejemplo n.º 2
0
 def test_right(self):
     ReportGuard(False)
     x = PartialPerm(range(16))
     o = RightAction(type(x), type(x))
     o.add_seed(x)
     o.add_generator(
         PartialPerm(
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0],
             16,
         ))
     o.add_generator(
         PartialPerm(
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             [1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             16,
         ))
     o.add_generator(
         PartialPerm(
             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
             16,
         ))
     o.add_generator(
         PartialPerm(
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
             16,
         ))
     self.assertEqual(o.size(), 65536)
     self.assertEqual(o.digraph().nr_scc(), 17)
Ejemplo n.º 3
0
 def test_congruence_by_pairs1(self):
     ReportGuard(False)
     S = FroidurePin(Transformation([1, 0, 1]), Transformation([0, 0, 0]))
     C = CongruenceByPairs("left", S)
     C.add_pair([0], [1])
     self.assertEqual(C.nr_classes(), 1)
     self.assertEqual(S.size(), 4)
Ejemplo n.º 4
0
    def test_running_and_state(self):
        ReportGuard(False)
        kb = KnuthBendix()
        kb.set_alphabet("abc")
        kb.add_rule("aa", "")
        kb.add_rule("bc", "")
        kb.add_rule("bbb", "")
        kb.add_rule("ababababababab", "")
        kb.add_rule("abacabacabacabacabacabacabacabac", "")
        kb.run_for(milliseconds(500))

        self.assertTrue(kb.stopped())
        self.assertFalse(kb.finished())
        self.assertFalse(kb.running())
        self.assertTrue(kb.started())
        self.assertFalse(kb.stopped_by_predicate())
        self.assertTrue(kb.timed_out())

        kb = KnuthBendix()
        kb.set_alphabet("abc")
        kb.add_rule("aa", "")
        kb.add_rule("bc", "")
        kb.add_rule("bbb", "")
        kb.add_rule("ababababababab", "")
        kb.add_rule("abacabacabacabacabacabacabacabac", "")

        kb.run_until(lambda: kb.nr_active_rules() > 100)

        self.assertTrue(kb.stopped())
        self.assertFalse(kb.finished())
        self.assertFalse(kb.running())
        self.assertTrue(kb.started())
        self.assertTrue(kb.stopped_by_predicate())
        self.assertFalse(kb.timed_out())
Ejemplo n.º 5
0
    def test_all(self):
        ReportGuard(False)
        S = FpSemigroup()
        S.set_alphabet("abcde")
        S.set_identity("e")
        S.add_rule("cacac", "aacaa")
        S.add_rule("acaca", "ccacc")
        S.add_rule("ada", "bbcbb")
        S.add_rule("bcb", "aadaa")
        S.add_rule("aaaa", "e")
        S.add_rule("ab", "e")
        S.add_rule("ba", "e")
        S.add_rule("cd", "e")
        S.add_rule("dc", "e")
        S.run()

        self.assertEqual(S.nr_rules(), 18)
        # self.assertEqual()
        self.assertTrue(
            S.equal_to(
                "abbbbbbbbbbbadddddddddddddddacccccccccccc",
                "aaccccccccccccccccccccccccccc",
            ))

        self.assertFalse(
            S.equal_to("abbbbbbbbbbbadddddddddddddddacccccccccccc", "a"))
Ejemplo n.º 6
0
def check_initialisation(self, t):
    ReportGuard(False)
    x = t()
    x.set_alphabet("ba")
    x.add_rule([0, 1], [1, 0])

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

    S = FroidurePin(Transformation([1, 2, 0]), Transformation([1, 0, 2]))
    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)
 def test_cayley_graphs(self):
     ReportGuard(False)
     S = FroidurePin(Transformation(list(range(1, 10)) + [0]))
     S.run()
     for i in range(S.size()):
         self.assertEqual(S.left(i, 0), S.right(i, 0))
     for i in range(S.size()):
         self.assertEqual(S.left_cayley_graph().get(i, 0), S.left(i, 0))
         self.assertEqual(S.right_cayley_graph().get(i, 0), S.right(i, 0))
 def test_state(self):
     ReportGuard(False)
     S = FroidurePin(Transformation([1, 0] + list(range(2, 10))))
     S.add_generator(Transformation(list(range(1, 10)) + [0]))
     self.assertFalse(S.started())
     S.run_for(milliseconds(10))
     self.assertTrue(S.started())
     self.assertTrue(S.timed_out())
     self.assertTrue(S.stopped())
     self.assertFalse(S.finished())
 def test_run_until(self):
     if compare_version_numbers(libsemigroups_version(), "1.0.8"):
         ReportGuard(False)
         S = FroidurePin(Transformation([1, 0] + list(range(2, 10))))
         S.add_generator(Transformation(list(range(1, 10)) + [0]))
         S.run_until(lambda: S.current_size() > 10)
         self.assertFalse(S.finished())
         self.assertTrue(S.current_size() > 10)
         S.run_until(lambda: S.current_nr_rules() > 100)
         self.assertFalse(S.finished())
         self.assertTrue(S.current_nr_rules() > 100)
    def test_init(self):
        ReportGuard(False)
        FroidurePin(Transformation([1, 0, 1]), Transformation([0, 0, 0]))

        with self.assertRaises(KeyError):
            FroidurePin()

        with self.assertRaises(ValueError):
            FroidurePin(PartialPerm([1, 2], [0, 1], 3), Transformation([0, 1]))

        with self.assertRaises(TypeError):
            FroidurePin({2, 3})
Ejemplo n.º 11
0
 def test_aaa_bug(self):
     ReportGuard(False)
     S = FroidurePin(Transformation([1, 0, 1]), Transformation([0, 0, 0]))
     S.run()
     self.assertEqual(std.distance(S.cbegin(), S.cend()), 4)
     self.assertEqual(
         list(S),
         [
             Transformation([1, 0, 1]),
             Transformation([0, 0, 0]),
             Transformation([0, 1, 0]),
             Transformation([1, 1, 1]),
         ],
     )
Ejemplo n.º 12
0
def check_running_and_state(self, t):
    ReportGuard(False)
    x = t()
    x.set_alphabet("abce")
    x.set_identity("e")
    x.add_rule("aa", "e")
    x.add_rule("bc", "e")
    x.add_rule("bbb", "e")
    x.add_rule("ababababababab", "e")
    x.add_rule("abacabacabacabacabacabacabacabac", "e")
    x.run_for(microseconds(1))

    if t != FpSemigroup or compare_version_numbers(libsemigroups_version(),
                                                   "1.1.0"):
        # FpSemigroup doesn't behave correctly wrt run_until or run_for in
        # versions less than 1.1.0
        self.assertTrue(x.stopped())
        self.assertFalse(x.finished())
        self.assertFalse(x.running())
        self.assertTrue(x.started())
        self.assertFalse(x.stopped_by_predicate())
        self.assertTrue(x.timed_out())

    x = t()
    x.set_alphabet("abce")
    x.set_identity("e")
    x.add_rule("aa", "e")
    x.add_rule("bc", "e")
    x.add_rule("bbb", "e")
    x.add_rule("ababababababab", "e")
    x.add_rule("abacabacabacabacabacabacabacabac", "e")

    n = 0

    def func():
        nonlocal n
        n += 1
        return n == 2

    x.run_until(func)

    if t != FpSemigroup or compare_version_numbers(libsemigroups_version(),
                                                   "1.1.0"):
        self.assertTrue(x.stopped())
        self.assertFalse(x.finished())
        self.assertFalse(x.running())
        self.assertTrue(x.started())
        self.assertTrue(x.stopped_by_predicate())
        self.assertFalse(x.timed_out())
Ejemplo n.º 13
0
    def test_two(self):
        ReportGuard(False)
        kb = KnuthBendix()
        kb.set_alphabet("ab")
        kb.add_rule("aaa", "a")
        kb.add_rule("bbbb", "b")
        kb.add_rule("ba", "aab")

        self.assertEqual(kb.froidure_pin().size(), 11)
        # work around change in libsemigroups
        try:
            self.assertEqual(kb.froidure_pin()[10].string(kb), "babb")
        except:
            self.assertEqual(
                ll.static_cast["std::string"](kb.froidure_pin()[10]), "babb")
Ejemplo n.º 14
0
        def test_init(self):
            ReportGuard(False)
            S = Konieczny(Transformation([1, 0, 1]), Transformation([0, 0, 0]))
            self.assertEqual(S.size(), 4)
            self.assertEqual(S.number_of_generators(), 2)

            with self.assertRaises(KeyError):
                Konieczny()

            with self.assertRaises(ValueError):
                Konieczny(PartialPerm([1, 2], [0, 1], 3),
                          Transformation([0, 1]))

            with self.assertRaises(TypeError):
                Konieczny({2, 3})
Ejemplo n.º 15
0
    def test_bug1_works_yes(self):
        ReportGuard(False)
        # S = FpSemigroup()
        # S.set_alphabet("01")

        # S.add_rule("000", "0")
        # S.add_rule("1111", "1")
        # S.add_rule("01110", "00")
        # S.add_rule("1001", "11")
        # S.add_rule("001010101010", "00")
        # S.run()
        # S.rules()

        S = FroidurePin(Transformation([1, 0, 1]), Transformation([0, 0, 0]))
        S.run()
        self.assertEqual(std.distance(S.cbegin(), S.cend()), S.size())
    def test_attributes(self):
        ReportGuard(False)
        S = FroidurePin(Transformation(list(range(1, 10)) + [0]))
        self.assertEqual(S.current_nr_rules(), 0)
        self.assertEqual(S.current_size(), 1)
        self.assertEqual(S.degree(), 10)

        self.assertEqual(S.size(), 10)

        self.assertTrue(S.is_idempotent(9))
        for i in range(8):
            self.assertFalse(S.is_idempotent(i))

        with self.assertRaises(LibsemigroupsException):
            S.is_idempotent(10)

        self.assertTrue(S.is_monoid())
        self.assertEqual(S.nr_generators(), 1)
        self.assertEqual(S.nr_idempotents(), 1)
Ejemplo n.º 17
0
def check_validation(self, t):
    ReportGuard(False)
    x = t()
    x.set_alphabet("ab")

    with self.assertRaises(TypeError):
        x.validate_letter("c")
    try:
        x.validate_letter("a")
    except Exception as e:
        self.fail(
            "unexpected exception raised for FpSemigroupInterface::validate_letter: "
            + e)

    with self.assertRaises(LibsemigroupsException):
        x.validate_letter(3)
    try:
        x.validate_letter(0)
    except Exception as e:
        self.fail(
            "unexpected exception raised for FpSemigroupInterface::validate_letter: "
            + e)
    with self.assertRaises(TypeError):
        x.validate_word("abc")
    try:
        x.validate_word("abab")
    except Exception as e:
        self.fail(
            "unexpected exception raised for FpSemigroupInterface::validate_letter: "
            + e)

    if compare_version_numbers(cppyy_version(), "1.7.1"):
        with self.assertRaises(LibsemigroupsException):
            x.validate_word([0, 1, 2])
    else:
        with self.assertRaises(TypeError):
            x.validate_word([0, 1, 2])
    try:
        x.validate_word([0, 1, 0, 1])
    except Exception as e:
        self.fail(
            "unexpected exception raised for FpSemigroupInterface::validate_letter: "
            + e)
    def test_basic(self):
        ReportGuard(False)
        s1 = PythonElement(1)
        s2 = PythonElement(2)
        s3 = PythonElement(3)
        self.assertEqual(s3.get_value(), 3)
        self.assertTrue(not s1 < s1)
        self.assertTrue(s1 < s2)

        s = s2 * s3
        self.assertEqual(s.get_value(), 6)  # Fails with Sage Integers

        S = FroidurePin([s1])
        self.assertEqual(S.size(), 1)

        S = FroidurePin([s1, s2, s3])
        S.enumerate(100)
        self.assertEqual(S.current_size(), 8195)
        self.assertEqual(S.current_nr_rules(), 6)
Ejemplo n.º 19
0
def check_converters(self, t):
    ReportGuard(False)
    x = t()
    x.set_alphabet("ba")
    self.assertEqual(x.char_to_uint(ord("a")), 1)
    self.assertEqual(x.char_to_uint(ord("b")), 0)

    self.assertEqual(x.string_to_word("ab"), [1, 0])
    self.assertEqual(x.string_to_word("aaaaaa"), [1] * 6)
    with self.assertRaises(LibsemigroupsCppyyException):
        x.string_to_word("c")

    self.assertEqual(x.uint_to_char(0), "b")
    self.assertEqual(x.uint_to_char(1), "a")
    with self.assertRaises(LibsemigroupsException):
        x.uint_to_char(2)

    self.assertEqual(x.word_to_string([1, 0]), "ab")
    self.assertEqual(x.word_to_string([1] * 6), "a" * 6)
    with self.assertRaises(LibsemigroupsException):
        x.word_to_string([2])
Ejemplo n.º 20
0
    def test_one(self):
        ReportGuard(False)
        kb = KnuthBendix()

        kb.set_alphabet("abcd")
        kb.add_rule("cacac", "aacaa")
        kb.add_rule("acaca", "ccacc")
        kb.add_rule("ada", "bbcbb")
        kb.add_rule("bcb", "aadaa")
        kb.add_rule("aaaa", "")
        kb.add_rule("ab", "")
        kb.add_rule("ba", "")
        kb.add_rule("cd", "")
        kb.add_rule("dc", "")
        kb.run()

        self.assertTrue(kb.confluent())
        self.assertEqual(kb.nr_active_rules(), 10)
        self.assertEqual(
            kb.active_rules(),
            [
                ["ab", ""],
                ["ba", ""],
                ["bb", "aa"],
                ["ca", "bd"],
                ["cb", "ad"],
                ["cd", ""],
                ["da", "bc"],
                ["db", "ac"],
                ["dc", ""],
                ["aaa", "b"],
            ],
        )
        self.assertEqual(
            kb.rewrite("abbbbbbbbbbbadddddddddddddddacccccccccccc"),
            "aaccccccccccccccccccccccccccc",
        )

        self.assertFalse(
            kb.equal_to("abbbbbbbbbbbadddddddddddddddacccccccccccc", "a"))
Ejemplo n.º 21
0
    def test_constructors(self):
        ReportGuard(False)
        S = FroidurePin(Transformation([1, 0, 1]), Transformation([0, 0, 0]))
        T = FpSemigroup(S)
        self.assertFalse(T.has_froidure_pin())
        if compare_version_numbers(libsemigroups_version(), "1.1.0"):
            self.assertEqual(S.nr_rules(), T.nr_rules())
            self.assertEqual(
                S.rules(),
                [[[0, 1], [1]], [[1, 1], [1]], [[0, 0, 0], [0]], [[1, 0, 0], [1]]],
            )
            self.assertEqual(
                T.rules(),
                [
                    ["\x01\x02", "\x02"],
                    ["\x02\x02", "\x02"],
                    ["\x01\x01\x01", "\x01"],
                    ["\x02\x01\x01", "\x02"],
                ],
            )

        self.assertEqual(T.size(), S.size())
Ejemplo n.º 22
0
    def test_settings(self):
        ReportGuard(False)
        kb = KnuthBendix()
        kb.set_alphabet("abB")
        kb.set_identity("")
        kb.set_inverses("aBb")

        kb.add_rule("bb", "B")
        kb.add_rule("BaBa", "abab")
        self.assertEqual(kb.check_confluence_interval(10), kb)
        self.assertEqual(kb.max_overlap(10), kb)

        with self.assertRaises(ValueError):
            kb.max_overlap(-10)

        kb = KnuthBendix()
        kb.set_alphabet("abc")

        kb.add_rule("aa", "")
        kb.add_rule("bc", "")
        kb.add_rule("bbb", "")
        kb.add_rule("ababababababab", "")
        kb.add_rule("abacabacabacabacabacabacabacabac", "")

        kb.max_rules(100)
        kb.run()
        self.assertGreaterEqual(kb.nr_active_rules(), 100)
        self.assertEqual(kb.overlap_policy("ABC"), kb)
        self.assertEqual(kb.overlap_policy("AB_BC"), kb)
        self.assertEqual(kb.overlap_policy("MAX_AB_BC"), kb)

        with self.assertRaises(TypeError):
            kb.overlap_policy(-10)

        with self.assertRaises(ValueError):
            kb.overlap_policy("AVC")
    def test_factorisation_and_relations(self):
        ReportGuard(False)
        S = FroidurePin(Transformation(list(range(1, 10)) + [0]))
        self.assertEqual(S.length_const(0), 1)

        with self.assertRaises(LibsemigroupsException):
            S.length_const(1)

        self.assertEqual(S.current_max_word_length(), 1)
        S.run()
        self.assertEqual(S.current_max_word_length(), 10)

        self.assertTrue(S.equal_to([0, 0], [0, 0]))
        self.assertFalse(S.equal_to([0], [0, 0]))
        self.assertFalse(S.equal_to([0] * 10, [0]))

        with self.assertRaises(LibsemigroupsException):
            self.assertFalse(S.equal_to([0] * 10, [1]))
        with self.assertRaises(LibsemigroupsException):
            self.assertFalse(S.equal_to([1], [0] * 10))

        for i in range(S.size()):
            self.assertEqual(S.length_const(i), i + 1)
            self.assertEqual(S.length_non_const(i), i + 1)

        with self.assertRaises(LibsemigroupsException):
            S.length_non_const(10)

        self.assertEqual(S.letter_to_pos(0), 0)
        with self.assertRaises(LibsemigroupsException):
            S.letter_to_pos(1)

        S.add_generator(Transformation([1, 0] + list(range(2, 10))))
        self.assertEqual(S.letter_to_pos(1), 10)
        S.add_generator(Transformation(list(range(1, 10)) + [0]))
        self.assertEqual(S.letter_to_pos(2), 0)
        self.assertEqual(
            [S.minimal_factorisation(x) for x in range(10)],
            [
                [0],
                [0, 0],
                [0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0],
                [1, 1],
            ],
        )

        with self.assertRaises(LibsemigroupsCppyyException):
            S.next_relation()

        S = FroidurePin(Transformation(list(range(1, 5)) + [0]))
        S.add_generator(Transformation([1, 0] + list(range(2, 5))))
        self.assertEqual(S.current_nr_rules(), 0)
        self.assertEqual(S.word_to_pos([0, 1, 0, 1]), 18446744073709551615)

        self.assertEqual(S.nr_rules(), 25)
        self.assertEqual(S.word_to_element([0, 1, 0, 1]),
                         Transformation([0, 3, 4, 1, 2]))
        self.assertEqual(S.word_to_pos([0, 1, 0, 1]), 15)
 def test_add_generator(self):
     ReportGuard(False)
     S = FroidurePin(Transformation([1, 0, 1]), Transformation([0, 0, 0]))
     self.assertEqual(S.size(), 4)
     S.add_generator(Transformation([1, 2, 0]))
     self.assertEqual(S.size(), 24)
 def test_run_for(self):
     ReportGuard(False)
     S = FroidurePin(Transformation([1, 0] + list(range(2, 10))))
     S.add_generator(Transformation(list(range(1, 10)) + [0]))
     S.run_for(milliseconds(10))
Ejemplo n.º 26
0
def check_attributes(self, t):
    ReportGuard(False)
    x = t()
    x.set_alphabet("abBe")
    x.set_identity("e")
    x.set_inverses("aBbe")

    x.add_rule("bb", "B")
    x.add_rule("BaBa", "abab")
    x.run()

    if compare_version_numbers("1.1.0", libsemigroups_version()):
        self.assertEqual(
            x.rules(),
            [
                ["ae", "a"],
                ["ea", "a"],
                ["be", "b"],
                ["eb", "b"],
                ["Be", "B"],
                ["eB", "B"],
                ["ee", "e"],
                ["aa", "e"],
                ["aa", "e"],
                ["bB", "e"],
                ["Bb", "e"],
                ["Bb", "e"],
                ["bB", "e"],
                ["ee", "e"],
                ["ee", "e"],
                ["bb", "B"],
                ["BaBa", "abab"],
            ],
        )
        self.assertEqual(x.nr_rules(), 17)
    else:
        self.assertEqual(
            x.rules(),
            [
                ["ae", "a"],
                ["ea", "a"],
                ["be", "b"],
                ["eb", "b"],
                ["Be", "B"],
                ["eB", "B"],
                ["ee", "e"],
                ["aa", "e"],
                ["bB", "e"],
                ["Bb", "e"],
                ["bb", "B"],
                ["BaBa", "abab"],
            ],
        )
        self.assertEqual(x.nr_rules(), 12)

    self.assertEqual(x.alphabet(), "abBe")
    self.assertFalse(x.has_froidure_pin())
    self.assertEqual(x.froidure_pin().size(), 24)
    self.assertEqual(x.identity(), "e")
    self.assertEqual(x.inverses(), "aBbe")
    self.assertFalse(x.is_obviously_infinite())
    self.assertTrue(x.is_obviously_finite())
    self.assertEqual(x.size(), 24)
Ejemplo n.º 27
0
    def test_settings(self):
        ReportGuard(False)
        tc = ToddCoxeter("left")
        tc.set_nr_generators(1)
        tc.add_pair([0, 0, 0, 0], [0, 0])
        try:
            tc.reserve(10)
        except:
            self.fail("unexpected exception thrown")
        tc.run()

        self.assertFalse(tc.is_standardized())
        try:
            tc.standardize("lex")
        except:
            self.fail("unexpected exception thrown")
        self.assertTrue(tc.is_standardized())
        try:
            tc.standardize("shortlex")
        except:
            self.fail("unexpected exception thrown")
        try:
            tc.standardize("recursive")
        except:
            self.fail("unexpected exception thrown")
        try:
            tc.standardize(True)
        except:
            self.fail("unexpected exception thrown")
        try:
            tc.standardize(False)
        except:
            self.fail("unexpected exception thrown")
        with self.assertRaises(TypeError):
            tc.standardize(1)
        with self.assertRaises(ValueError):
            tc.standardize("shooortlex")

        S = FroidurePin(Transformation([3, 1, 2, 1, 2]),
                        Transformation([1, 1, 1, 2, 2]))
        tc = ToddCoxeter("twosided", S)
        try:
            tc.froidure_pin_policy()
        except:
            self.fail("unexpected exception thrown")
        try:
            tc.froidure_pin_policy("none")
        except:
            self.fail("unexpected exception thrown")
        self.assertEqual(tc.froidure_pin_policy(), "none")
        try:
            tc.froidure_pin_policy("use_relations")
        except:
            self.fail("unexpected exception thrown")
        self.assertEqual(tc.froidure_pin_policy(), "use_relations")
        try:
            tc.froidure_pin_policy("use_cayley_graph")
        except:
            self.fail("unexpected exception thrown")
        self.assertEqual(tc.froidure_pin_policy(), "use_cayley_graph")
        with self.assertRaises(TypeError):
            tc.froidure_pin_policy(1)
        with self.assertRaises(ValueError):
            tc.froidure_pin_policy("userelations")

        tc = ToddCoxeter("left")
        tc.set_nr_generators(2)
        tc.add_pair([0, 0, 0, 0], [0])
        tc.add_pair([1, 1, 1, 1], [0])
        with self.assertRaises(ValueError):
            tc.strategy("feelsch")
        with self.assertRaises(TypeError):
            tc.strategy(1)
        try:
            tc.strategy("felsch")
        except:
            self.fail("unexpected exception thrown")
        self.assertEqual(tc.strategy(), "felsch")
        try:
            tc.strategy("hlt")
        except:
            self.fail("unexpected exception thrown")
        self.assertEqual(tc.strategy(), "hlt")
        try:
            tc.strategy("random")
        except:
            self.fail("unexpected exception thrown")
        self.assertEqual(tc.strategy(), "random")
Ejemplo n.º 28
0
    def test_related_algorithms(self):
        ReportGuard(False)
        S = FpSemigroup()
        S.set_alphabet("abcde")
        S.set_identity("e")
        S.add_rule("cacac", "aacaa")
        S.add_rule("acaca", "ccacc")
        S.add_rule("ada", "bbcbb")
        S.add_rule("bcb", "aadaa")
        S.add_rule("aaaa", "e")
        S.add_rule("ab", "e")
        S.add_rule("ba", "e")
        S.add_rule("cd", "e")
        S.add_rule("dc", "e")

        self.assertEqual(
            S.froidure_pin().__repr__()[:40], "<FroidurePin object with 5 generators at"
        )
        self.assertTrue(S.has_knuth_bendix())
        self.assertFalse(S.has_todd_coxeter())
        #  S is infinite and so it always has a KnuthBendix
        self.assertTrue(S.knuth_bendix().finished())
        self.assertEqual(
            S.knuth_bendix().active_rules(),
            [
                ["ab", "e"],
                ["ae", "a"],
                ["ba", "e"],
                ["bb", "aa"],
                ["be", "b"],
                ["ca", "bd"],
                ["cb", "ad"],
                ["cd", "e"],
                ["ce", "c"],
                ["da", "bc"],
                ["db", "ac"],
                ["dc", "e"],
                ["de", "d"],
                ["ea", "a"],
                ["eb", "b"],
                ["ec", "c"],
                ["ed", "d"],
                ["ee", "e"],
                ["aaa", "b"],
            ],
        )
        self.assertEqual(S.rules(), S.knuth_bendix().rules())

        S = FpSemigroup()
        S.set_alphabet("01")

        S.add_rule("000", "0")
        S.add_rule("1111", "1")
        S.add_rule("01110", "00")
        S.add_rule("1001", "11")
        S.add_rule("001010101010", "00")

        self.assertEqual(S.size(), 240)
        self.assertTrue(S.has_todd_coxeter())
        self.assertFalse(S.has_knuth_bendix())
        S.todd_coxeter()
        self.assertFalse(S.has_froidure_pin())