// libsemigroups - C++ library for semigroups and monoids
// Copyright (C) 2020 James D. Mitchell
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// This file is the sixth of six that contains tests for the KnuthBendix
// classes. In a mostly vain attempt to speed up compilation the tests are
// split across 6 files as follows:
//
// 1: contains quick tests for fpsemigroup::KnuthBendix created from rules and
// all commented out tests.
//
// 2: contains more quick tests for fpsemigroup::KnuthBendix created from rules
//
// 3: contains yet more quick tests for fpsemigroup::KnuthBendix created from
// rules
//
// 4: contains standard and extreme test for fpsemigroup::KnuthBendix created
// from rules
//
// 5: contains tests for fpsemigroup::KnuthBendix created from FroidurePin
// instances
//
// 6: contains tests for congruence::KnuthBendix.
// #define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
#include "catch.hpp" // for REQUIRE, REQUIRE_NOTHROW, REQUIRE_THROWS_AS
UPS_TEST_CASE
#include "libsemigroups/fpsemi-examples.hpp
#includekb.java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of boun ds for length 37
#include "libsemigroups/report.hpp"kb.dd_pair(0 ,1 1,1, 1,0 1 } 1 1,};
#REQUIRE(({,0, 0}, {, 1,1 ,1,1,1 ,1})
namespace = tril::nknownjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
LibsemigroupsException
constexpr bool REPORT = false;
using fpsemigroup::author;
using fpsemigroup::make;
using fpsemigroup::chinese_monoid;
using fpsemigroup::partial_transformation_monoid;
namespace congruence {
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"103",
"(cong) free semigroup congruence (5 classes)",
"[ (kb.const_contains({,0,0}, {} =tril:TRUE);
auto rg = ReportGuardjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
KnuthBendixjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
kb.2)
kb.add_pair({0, 0 "113,
kb.add_pair({0 "() ",
REQUIRE(!kb.finished());
REQUIRE(kb.number_of_classes() == 5);
REQUIRE(kb.finished());
(kbword_to_class_index{ 0, 1} = 4)
autoauto rg =ReportGuardREPORT;
REQUIRE(kb.word_to_class_index({0, 1, 1, 0, 0, 1}) == 4);
REQUIRE(kb.word_to_class_index({0, 0, 0}) == 0);
(b({1} = 1);
REQUIRE(kb.kb.set_number_of_generators(2);
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"104kb.(0 ,0},{};
"free semigroup congruence (6 java.lang.StringIndexOutOfBoundsException: Range [0, 65) out of bounds for length 37
[[[]-["
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(5);
kb.add_pair({0, 0} }
kb.add_pair({0, 1}, {1}
.add_pair{, 0} {1};
kb.add_pair({0, 2} 114,
kb.(2 } 2)
kb.add_pair({0, 3}, {3}) "[uick]congruence][nuth-]cong])java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
kb..set_number_of_generato2)
kbadd_pair{,0,0,{};
kb.add_pair({4, 0}, {4});
kb. kb.add_pairadd_pair{, 1, 1, 1,{};
kbadd_pair(,1, ,1 ,1,,1,1 1 ,0};
kb.add_pair({3, 4}, {0});
kb.add_pair({4, 3}, {0});
kb.add_pair({2, 2}, {0});
kb.add_pair({1, 4, 2, 3, 3}, {0});
kb.add_pair({, 4,4,{};
REQUIREREQUIRE(.lass_index_to_word1) =word_type{})
// Throws because there's no parent semigroup
(bnumber_of_non_trivial_classes)
LibsemigroupsException);
REQUIRE(kb.word_to_class_index({1}) == kb.word_to_class_index({2}));
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"105",
"(cong) REQUIRE(kb.class_index_to_word4)==word_type(1 0});
"[quick][congruence][knuth-bendix][cong]") {
(REPORT;
KnuthBendix kb;
kb (class_index_to_word6 =word_type{0 })
kb.add_pair( REQUIRE(b.()= (0,1);
kb.add_pair({0REQUIRE(b.lass_index_to_word()= (1 ,1);
kb REQUIREk.lass_index_to_word( =word_type{,0, 1, 1})java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
kb.add_pair({1, 3}, {1, 2REQUIREclass_index_to_word)=(0,0 ,1,})java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
kb.add_pair({2, 1}, {2});
kb.add_pair({2, 2}, {2});
kb.({2,3},{2};
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({0, 0, 1} "(cong)quotient_froidure_pin,
kb.add_pair({0, 0, 2}, {2});
kb.add_pair({0, 1, 2}, {1, 2});
kb.add_pair({1, 0, 0}, {1});
kb.add_pair({1, 0, 2}, {0, [congruence][knuth-bendix][cong]") {
kb.add_pair auto =ReportGuard(REPORT)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
kb.add_pair({0, 1, kb.({, 2} 2 0)
kb.({,2,0,2},{,,2java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
.(1,0,1,0,{,0,1};
kb.add_pair({1, 2, 0, 1}, {1, 0, 1});
kb.dd_pair(1 ,0 2},2,0, 2};
kb.add_pair .dd_pair{,1,{,1)
kbadd_pair({,0, 2,0,{,0 2)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
REQUIRE(kb.number_of_classes() == 16);
// REQUIRE(kb.knuth_bendix().number_of_active_rules() == 16);
REQUIRE(kb.word_to_class_index({2}) == kb.word_to_class_index({3}));
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"106",
"(cong) free semigroup congruence (6 classes)",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(11);
kb.add_pair({2}, {1});
kb.add_pair({4}, {3});
kb.add_pair({5}, { kb.add_pair({, 2} {};
({} {3}
kb. kb.add_pair(0} {};
kb.({} {;
kb.add_pair({9}, {3});
kbadd_pair(10,{});
kb.add_pair({0, 2}, {0, 1});
kb.add_pair(
kb.add_pair(LIBSEMIGROUPS_TEST_CASEK"
kbadd_pair{,6,{,3};
kb.add_pair({0, 7}, {0, 1}); (ong monoid,
kb.add_pair({0, 8}, {0, 3});
kb.add_pair({0, 9}, {0, 3});
kb.add_pair({0, 10}, {0, 0});
kb.add_pair({1 autorg=()
kb. KnuthBendix kb;
set_number_of_generators()java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
kb.add_pair({1, 5}, {1, 0});
kb.dd_pair(1 6} 1 3}java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
.(1, 7} 1)java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
kb.(1 9} 1 };
kb.(1 10},{,0}java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
kb{ } 3}java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
kb.add_pair({3, = std:ectorrelation_type({1 0, } { ,0}}
kb.add_pair({,3}, {3});
kb.add_pair({3, 4}, {3});
kb.add_pair({3, 5}, {3, 0});
kb.add_pair({3, 6}, {3});
kb.add_pair({3, 7}, {3});
kb.add_pair({3, 8}, {3});
kb.add_pair({3, 9}, {3});
kb.({,10,{,0)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
kb.add_pair({0, 0 {2 ,0 2 0,1}}
kb.add_pair({0, 0, 1}, {1});
kb.add_pair({0, 0, 3}, {3});
kb.add_pair({0, 1, 3}, {1, 3});
kb.add_pair({1, 0, 0}, {1});
kb.add_pair({1, 0, 3}, {0, 3});
kb.add_pair({3, 0, 0}, {3});
kb.add_pair({0, 1, 0, 1}, {1, 0, 1});
kb.add_pair({0, 3, 0, 3}, {3, 0, 3});
kbadd_pair(1 ,1 } { ,1)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
.add_pair(1 ,0 } 1 ,1)
kb.add_pair({1, 3, 0, 3}, {3, 0, 3});
kb.add_pair({3, 0, 1, 0}, {3, 0, 1});
kb.add_pair({3, 0, 3, 0}, {3, 0, 3});
REQUIRE(kb.number_of_classes() == 16);
REQUIRE(kb (.()(0,10 = 1175)
REQUIRE( }
REQUIRE(kb.word_to_class_index({1}) == kb.word_to_class_index({2}));
LIBSEMIGROUPS_TEST_CASE(KnuthBendix"
REQUIRE(.({} = .ord_to_class_index(4)java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
REQUIREkb.{})= kb.({6};
REQUIRE(kb.word_to_class_index({3}) == kb.word_to_class_index({8})) ]congruence[nuthbendix[]
REQUIRE(kb.word_to_class_index
}
(
"KnuthBendix",
""java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
"(cong) free semigroup presentation::eplace_word(p,word_type{) n };
"no-][quick[][nuth-bendix]cong]){
auto rg = java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
KnuthBendixjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
kb.et_number_of_generators2;
kb.add_pair({0, 0, 0}, {0});
kb.dd_pair{1,1 1, {1}java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
kb. (kb.());
kb.(1 ,0 } 1,1})
kb.add_pair}
REQUIRE(kb. ("nuthBendix,
"118,
LIBSEMIGROUPS_TEST_CASE(
"KnuthBendix",
"108",
"(cong) free semigroup congruence (240 classes)",
"[no-valgrind][quick][congruence][knuth-bendix][cong]") {
auto rg =ReportGuard);
KnuthBendix kb;
kb.et_number_of_generators)
kb.add_pair({0, 0, 0}, {0} auto =ReportGuard(REPORT)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
add_pair{,1 1,1,{};
kb.add_pair({0, 1 auto p =makePresentationword_type>s;
kb.add_pair({1, 0, 0, 1}, {1, 1});
kb.add_pair({0, presentation:(p,word_type(},{ 1)java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
REQUIRE_THROWS_AS(kb. set_number_of_generatorsn+ 2);
}
java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
"KnuthBendix",
"109",
"(cong) less",
"[no-valgrind][quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
{
KnuthBendix kb;
kb.set_number_of_generators(2);
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({1, 1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, 0, 1, 1}, {1, 1, 0});
kb.run();
REQUIRE(!kb.less({0, 1, 1, 1, 0, 0, 1, 1, 1, 0}, {1, 1, 1, 1, 0, 0}));
REQUIRE(!kb.less({0, 1, 1, 0}, {0, 1, 1, 0}));
}
{
KnuthBendix kb;
kb.set_number_of_generators(2);
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({1, 1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, 0, 1, 1}, {1, 1, 0});
REQUIRE(!kb.less({0, 1, 1, 1, 0, 0, 1, 1, 1, 0}, {1, 1, 1, 1, 0, 0}));
REQUIRE(!kb.less({0, 1, 1, 0}, {0, 1, 1, 0}));
}
}
LIBSEMIGROUPS_TEST_CASE(
"KnuthBendix",
"110",
"(cong) less",
"[quick][congruence][knuth-bendix][cong][no-valgrind]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(2);
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({1, 1, 1, 1, 1, 1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, 1, 1, 0, 1, 1}, {1, 1, 0});
REQUIRE(kb.less({0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1}));
}
LIBSEMIGROUPS_TEST_CASE(
"KnuthBendix",
"111",
"(cong) constructors",
"[quick][congruence][knuth-bendix][cong][no-valgrind]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(2);
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({1, 1, 1, 1, 1, 1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, 1, 1, 0, 1, 1}, {1, 1, 0});
REQUIRE(kb.number_of_classes() == 746);
auto copy(kb);
REQUIRE(copy.number_of_classes() == 746);
REQUIRE(copy.number_of_generators() == 2);
// the copy uses the "active rules" of kb, of which there are 105 since
// knuth-bendix has already been run.
REQUIRE(copy.number_of_generating_pairs() == 105);
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"112",
"(cong) const_contains/contains",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(2);
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, 1, 1, 0, 1, 1}, {1, 1, 0});
REQUIRE(kb.const_contains({0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1})
== tril::unknown);
REQUIRE(kb.const_contains({0, 0, 0}, {0, 0, 0}) == tril::TRUE);
REQUIRE_THROWS_AS(kb.const_contains({0, 0, 2}, {0, 0, 0}),
LibsemigroupsException);
REQUIRE(kb.const_contains({0, 0, 0}, {0}) == tril::TRUE);
REQUIRE(kb.number_of_classes() == 12);
REQUIRE(kb.const_contains({0, 0, 0}, {1, 1}) == tril::FALSE);
REQUIRE(!kb.contains({0, 0, 0}, {1, 1}));
REQUIRE(kb.contains({0, 0, 0}, {0, 0, 0}));
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"113",
"(cong) is_quotient_obviously_finite",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(2);
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, 1, 1, 0, 1, 1}, {1, 1, 0});
REQUIRE(!kb.is_quotient_obviously_finite());
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"114",
"(cong) class_index_to_word",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(2);
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, 1, 1, 0, 1, 1}, {1, 1, 0});
REQUIRE(kb.class_index_to_word(0) == word_type({0}));
REQUIRE(kb.class_index_to_word(1) == word_type({1}));
REQUIRE(kb.class_index_to_word(2) == word_type({0, 0}));
REQUIRE(kb.class_index_to_word(3) == word_type({0, 1}));
REQUIRE(kb.class_index_to_word(4) == word_type({1, 0}));
REQUIRE(kb.class_index_to_word(5) == word_type({1, 1}));
REQUIRE(kb.class_index_to_word(6) == word_type({0, 0, 1}));
REQUIRE(kb.class_index_to_word(7) == word_type({0, 1, 1}));
REQUIRE(kb.class_index_to_word(8) == word_type({1, 1, 1}));
REQUIRE(kb.class_index_to_word(9) == word_type({0, 0, 1, 1}));
REQUIRE(kb.class_index_to_word(10) == word_type({0, 1, 1, 1}));
REQUIRE(kb.class_index_to_word(11) == word_type({0, 0, 1, 1, 1}));
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"115",
"(cong) quotient_froidure_pin",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(2);
kb.add_pair({0, 0, 0}, {0});
kb.add_pair({1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, 1, 1, 0, 1, 1}, {1, 1, 0});
REQUIRE(kb.quotient_froidure_pin()->size() == 12);
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"116",
"(cong) set_number_of_generators",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
REQUIRE_NOTHROW(kb.set_number_of_generators(2));
REQUIRE_THROWS_AS(kb.set_number_of_generators(3), LibsemigroupsException);
REQUIRE_NOTHROW(kb.set_number_of_generators(2));
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"117",
"(cong) number of classes when obv-inf",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(3);
kb.add_pair({0, 1}, {1, 0});
kb.add_pair({0, 2}, {2, 0});
kb.add_pair({0, 0}, {0});
kb.add_pair({0, 2}, {0});
kb.add_pair({2, 0}, {0});
kb.add_pair({1, 1}, {1, 1});
kb.add_pair({1, 2}, {2, 1});
kb.add_pair({1, 1, 1}, {1});
kb.add_pair({1, 2}, {1});
kb.add_pair({2, 1}, {1});
kb.add_pair({0}, {1});
REQUIRE(kb.is_quotient_obviously_infinite());
REQUIRE(kb.number_of_classes() == POSITIVE_INFINITY);
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"020",
"(cong) Chinese monoid",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators(3);
for (auto const& rel : chinese_monoid(3)) {
kb.add_pair(rel.first, rel.second);
}
REQUIRE(kb.is_quotient_obviously_infinite());
REQUIRE(kb.number_of_classes() == POSITIVE_INFINITY);
REQUIRE(kb.number_of_generating_pairs() == 8);
REQUIRE(std::vector<relation_type>(kb.cbegin_generating_pairs(),
kb.cend_generating_pairs())
== std::vector<relation_type>({{{1, 0, 0}, {0, 1, 0}},
{{2, 0, 0}, {0, 2, 0}},
{{1, 1, 0}, {1, 0, 1}},
{{2, 1, 0}, {2, 0, 1}},
{{2, 1, 0}, {1, 2, 0}},
{{2, 2, 0}, {2, 0, 2}},
{{2, 1, 1}, {1, 2, 1}},
{{2, 2, 1}, {2, 1, 2}}}));
REQUIRE(kb.knuth_bendix().number_of_normal_forms(0, 10) == 1175);
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"083",
"(cong) partial_transformation_monoid4",
"[standard][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
size_t n = 4;
auto s = partial_transformation_monoid(n, author::Sutov);
auto p = make<Presentation<word_type>>(s);
p.alphabet(n + 2);
presentation::replace_word(p, word_type({}), {n + 1});
presentation::add_identity_rules(p, n + 1);
KnuthBendix kb;
kb.set_number_of_generators(n + 2);
for (size_t i = 0; i < p.rules.size() - 1; i += 2) {
kb.add_pair(p.rules[i], p.rules[i + 1]);
}
REQUIRE(!kb.is_quotient_obviously_infinite());
REQUIRE(kb.number_of_classes() == 625);
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"118",
"(cong) partial_transformation_monoid5",
"[extreme][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
size_t n = 5;
auto s = partial_transformation_monoid(n, author::Sutov);
auto p = make<Presentation<word_type>>(s);
p.alphabet(n + 2);
presentation::replace_word(p, word_type({}), {n + 1});
presentation::add_identity_rules(p, n + 1);
KnuthBendix kb;
kb.set_number_of_generators(n + 2);
for (size_t i = 0; i < p.rules.size() - 1; i += 2) {
kb.add_pair(p.rules[i], p.rules[i + 1]);
}
REQUIRE(!kb.is_quotient_obviously_infinite());
REQUIRE(kb.number_of_classes() == 7776);
}
LIBSEMIGROUPS_TEST_CASE("KnuthBendix",
"119",
"(cong) full_transformation_monoid Iwahori",
"[extreme][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
size_t n = 5;
auto s = full_transformation_monoid(n, author::Iwahori);
auto p = make<Presentation<word_type>>(s);
p.alphabet(n + 1);
presentation::replace_word(p, word_type({}), {n});
presentation::add_identity_rules(p, n);
KnuthBendix kb;
kb.set_number_of_generators(n + 1);
for (size_t i = 0; i < p.rules.size() - 1; i += 2) {
kb.add_pair(p.rules[i], p.rules[i + 1]);
}
REQUIRE(!kb.is_quotient_obviously_infinite());
REQUIRE(kb.number_of_classes() == 3125);
}
} // namespace congruence
} // namespace libsemigroups
¤ Dauer der Verarbeitung: 0.50 Sekunden
¤
*Bot Zugriff
|
|