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
def check_mem_compare(S): ReportGuard(False) with pytest.raises(RuntimeError): S.current_position([0, 0, 0, 0, 0, 0, 0, S.number_of_generators(), 1]) with pytest.raises(RuntimeError): S.current_position(S.number_of_generators()) S.run() assert all(S.contains(x) for x in S) assert [S.position(x) for x in S] == list(range(S.size())) # not implemented # self.assertEqual( # [S.position(S.factorisation(x)) for x in S], list(range(S.size())) # ) assert [S.current_position(S.factorisation(x)) for x in S] == list( range(S.size()) ) assert [S.current_position(x) for x in S] == list(range(S.size())) assert [ S.current_position(x) for x in range(S.number_of_generators()) ] == list(range(S.number_of_generators())) for x in S: assert S.sorted_position(x) == S.position_to_sorted_position( S.position(x) ) for x in S.idempotents(): w = S.factorisation(x) assert S.equal_to(w + w, w)
def check_prefix_suffix(S): ReportGuard(False) S.run() for i in range(S.number_of_generators(), S.size()): assert S.fast_product(S.prefix(i), S.final_letter(i)) == i assert S.fast_product(S.first_letter(i), S.suffix(i)) == i
def test_020(self): ReportGuard(False) tc = ToddCoxeter(congruence_type.twosided) tc.set_nr_generators(1) tc.strategy(strategy.hlt) self.assertTrue(tc.contains([0, 0], [0, 0])) self.assertFalse(tc.contains([0, 0], [0]))
def test_018(self): ReportGuard(False) twosided = congruence_kind.twosided S = FpSemigroup() S.set_alphabet(3) S.add_rule([0, 0], [0, 0]) S.add_rule([0, 1], [1, 0]) S.add_rule([0, 2], [2, 0]) S.add_rule([0, 0], [0]) S.add_rule([0, 2], [0]) S.add_rule([2, 0], [0]) S.add_rule([1, 0], [0, 1]) S.add_rule([1, 1], [1, 1]) S.add_rule([1, 2], [2, 1]) S.add_rule([1, 1, 1], [1]) S.add_rule([1, 2], [1]) S.add_rule([2, 1], [1]) self.assertTrue(S.is_obviously_infinite()) cong = Congruence(twosided, S) cong.add_pair([0], [1]) self.assertFalse(cong.finished()) self.assertEqual(cong.number_of_non_trivial_classes(), 1) self.assertTrue(cong.finished()) self.assertEqual(cong.non_trivial_classes(0), [[0], [1], [0, 1], [1, 1], [0, 1, 1]])
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"))
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_operators(self): ReportGuard(False) tc = ToddCoxeter(congruence_kind.left) tc.set_number_of_generators(2) tc.add_pair([0, 0, 0, 0], [1]) tc.add_pair([1, 1, 1, 1], [1]) tc.run() tc = ToddCoxeter(congruence_kind.left) tc.set_number_of_generators(1) tc.add_pair([0, 0, 0], [0]) tc.run_for(timedelta(microseconds=2)) tc = ToddCoxeter(congruence_kind.right) tc.set_number_of_generators(1) tc.add_pair([0, 0, 0, 0, 0, 0, 0, 0], [0]) tc.run_until(lambda: tc.const_contains([0, 0, 0, 0, 0, 0, 0, 0], [0]) == tril.true) self.assertTrue(tc.stopped_by_predicate()) self.assertFalse(tc.finished()) tc = ToddCoxeter(congruence_kind.left) tc.set_number_of_generators(2) tc.add_pair([0, 0, 0, 0], [1]) tc.add_pair([1, 0], [0, 1]) tc.add_pair([1, 1, 1, 1], [0]) tc.run_for(timedelta(microseconds=1)) # If this is run on an incredibly fast computer, this # test of timed_out() may not work. self.assertTrue(tc.timed_out()) tc.run() self.assertFalse(tc.timed_out())
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(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_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)
def check_cayley_graphs(S): ReportGuard(False) g = S.right_cayley_graph() assert len(g) == S.size() assert len(g[0]) == S.number_of_generators() g = S.left_cayley_graph() assert len(g) == S.size() assert len(g[0]) == S.number_of_generators()
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))
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))
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))
def check_settings(S): ReportGuard(False) assert not S.immutable() S.immutable(False) assert S.batch_size() == 8192 S.batch_size(S.batch_size()) assert S.concurrency_threshold() == 823543 S.concurrency_threshold(S.concurrency_threshold()) S.max_threads(2) assert S.max_threads() == 2 S.reserve(100)
def check_running_and_state(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") check_runner(x, timedelta(microseconds=1000))
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()
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))
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()))
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))
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()))
def test_033(self): ReportGuard(False) tc1 = ToddCoxeter(congruence_type.twosided) tc1.set_nr_generators(2) tc1.add_pair([0, 0, 0], [0]) tc1.add_pair([0], [1, 1]) self.assertEqual(tc1.nr_classes(), 5) tc2 = ToddCoxeter(congruence_type.left, tc1) tc2.next_lookahead(1) tc2.report_every(timedelta(microseconds=1)) self.assertFalse(tc2.empty()) tc2.add_pair([0], [0, 0]) self.assertEqual(tc2.nr_classes(), 3)
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))
def check_accessors(S): ReportGuard(False) # current_size assert S.current_size() == S.number_of_generators() S.run() # size assert S.current_size() == S.size() # at, sorted_at for i in range(S.size()): assert S.at(i) == S.sorted_at(S.position_to_sorted_position(i)) # __iter__, sorted assert sorted(list(S)) == list(S.sorted())
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))
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))
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))
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))
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_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)