// 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
#include "test-main.hpp" // for LIBSEMIGROUPS_TEST_CASE
#include "libsemigroups/fpsemi-examples.hpp" // for chinese_monoid
#include "libsemigroups/knuth-bendix.hpp" // for KnuthBendix, operator<<
#include "libsemigroups/report.hpp" // for ReportGuard
#include "libsemigroups/types.hpp" // for word_type
namespace libsemigroups {
struct 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)",
"[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({ 0}, { 1, 1});
REQUIRE(!kb.finished());
REQUIRE(kb.number_of_classes() == 5);
REQUIRE(kb.finished());
REQUIRE(kb.word_to_class_index({ 0, 0, 1}) == 4);
REQUIRE(kb.word_to_class_index({ 0, 0, 0, 0, 1}) == 4);
REQUIRE(kb.word_to_class_index({ 0, 1, 1, 0, 0, 1}) == 4);
REQUIRE(kb.word_to_class_index({ 0, 0, 0}) == 0);
REQUIRE(kb.word_to_class_index({ 1}) == 1);
REQUIRE(kb.word_to_class_index({ 0, 0, 0, 0}) == 2);
}
LIBSEMIGROUPS_TEST_CASE( "KnuthBendix",
"104",
"free semigroup congruence (6 classes)",
"[quick][cong][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators( 5);
kb.add_pair({ 0, 0}, { 0});
kb.add_pair({ 0, 1}, { 1});
kb.add_pair({ 1, 0}, { 1});
kb.add_pair({ 0, 2}, { 2});
kb.add_pair({ 2, 0}, { 2});
kb.add_pair({ 0, 3}, { 3});
kb.add_pair({ 3, 0}, { 3});
kb.add_pair({ 0, 4}, { 4});
kb.add_pair({ 4, 0}, { 4});
kb.add_pair({ 1, 2}, { 0});
kb.add_pair({ 2, 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, 4}, { 0});
REQUIRE(kb.number_of_classes() == 6);
// Throws because there's no parent semigroup
REQUIRE_THROWS_AS(kb.number_of_non_trivial_classes(),
LibsemigroupsException);
REQUIRE(kb.word_to_class_index({ 1}) == kb.word_to_class_index({ 2}));
}
LIBSEMIGROUPS_TEST_CASE( "KnuthBendix",
"105",
"(cong) free semigroup congruence (16 classes)",
"[quick][congruence][knuth-bendix][cong]") {
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kb.set_number_of_generators( 4);
kb.add_pair({ 3}, { 2});
kb.add_pair({ 0, 3}, { 0, 2});
kb.add_pair({ 1, 1}, { 1});
kb.add_pair({ 1, 3}, { 1, 2});
kb.add_pair({ 2, 1}, { 2});
kb.add_pair({ 2, 2}, { 2});
kb.add_pair({ 2, 3}, { 2});
kb.add_pair({ 0, 0, 0}, { 0});
kb.add_pair({ 0, 0, 1}, { 1});
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, 2});
kb.add_pair({ 2, 0, 0}, { 2});
kb.add_pair({ 0, 1, 0, 1}, { 1, 0, 1});
kb.add_pair({ 0, 2, 0, 2}, { 2, 0, 2});
kb.add_pair({ 1, 0, 1, 0}, { 1, 0, 1});
kb.add_pair({ 1, 2, 0, 1}, { 1, 0, 1});
kb.add_pair({ 1, 2, 0, 2}, { 2, 0, 2});
kb.add_pair({ 2, 0, 1, 0}, { 2, 0, 1});
kb.add_pair({ 2, 0, 2, 0}, { 2, 0, 2});
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}, { 0});
kb.add_pair({ 6}, { 3});
kb.add_pair({ 7}, { 1});
kb.add_pair({ 8}, { 3});
kb.add_pair({ 9}, { 3});
kb.add_pair({ 10}, { 0});
kb.add_pair({ 0, 2}, { 0, 1});
kb.add_pair({ 0, 4}, { 0, 3});
kb.add_pair({ 0, 5}, { 0, 0});
kb.add_pair({ 0, 6}, { 0, 3});
kb.add_pair({ 0, 7}, { 0, 1});
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, 1}, { 1});
kb.add_pair({ 1, 2}, { 1});
kb.add_pair({ 1, 4}, { 1, 3});
kb.add_pair({ 1, 5}, { 1, 0});
kb.add_pair({ 1, 6}, { 1, 3});
kb.add_pair({ 1, 7}, { 1});
kb.add_pair({ 1, 8}, { 1, 3});
kb.add_pair({ 1, 9}, { 1, 3});
kb.add_pair({ 1, 10}, { 1, 0});
kb.add_pair({ 3, 1}, { 3});
kb.add_pair({ 3, 2}, { 3});
kb.add_pair({ 3, 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.add_pair({ 3, 10}, { 3, 0});
kb.add_pair({ 0, 0, 0}, { 0});
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});
kb.add_pair({ 1, 0, 1, 0}, { 1, 0, 1});
kb.add_pair({ 1, 3, 0, 1}, { 1, 0, 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.word_to_class_index({ 0}) == kb.word_to_class_index({ 5}));
REQUIRE(kb.word_to_class_index({ 0}) == kb.word_to_class_index({ 10}));
REQUIRE(kb.word_to_class_index({ 1}) == kb.word_to_class_index({ 2}));
REQUIRE(kb.word_to_class_index({ 1}) == kb.word_to_class_index({ 7}));
REQUIRE(kb.word_to_class_index({ 3}) == kb.word_to_class_index({ 4}));
REQUIRE(kb.word_to_class_index({ 3}) == kb.word_to_class_index({ 6}));
REQUIRE(kb.word_to_class_index({ 3}) == kb.word_to_class_index({ 8}));
REQUIRE(kb.word_to_class_index({ 3}) == kb.word_to_class_index({ 9}));
}
LIBSEMIGROUPS_TEST_CASE(
"KnuthBendix",
"107",
"(cong) free semigroup congruence (240 classes)",
"[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});
kb.add_pair({ 0, 1, 1, 1, 0}, { 0, 0});
kb.add_pair({ 1, 0, 0, 1}, { 1, 1});
kb.add_pair({ 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}, { 0, 0});
REQUIRE(kb.number_of_classes() == 240);
}
LIBSEMIGROUPS_TEST_CASE(
"KnuthBendix",
"108",
"(cong) free semigroup congruence (240 classes)",
"[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});
kb.add_pair({ 0, 1, 1, 1, 0}, { 0, 0});
kb.add_pair({ 1, 0, 0, 1}, { 1, 1});
kb.add_pair({ 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}, { 0, 0});
REQUIRE_NOTHROW(kb.knuth_bendix().froidure_pin());
REQUIRE_THROWS_AS(kb.add_pair({ 0}, { 1}), LibsemigroupsException);
}
LIBSEMIGROUPS_TEST_CASE(
"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 // it under the terms of the GNU General Public License as published by
}
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 2
//
"(cong) const_contains// rules//
"[java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 15
auto rg = ReportGuard(#include "test-main.hpp" // for LIBSEMIGRO
set_number_of_generators( 2);
kb.add_pair({ 0, 0, 0}, { 0});
kb.add_pair({ 1, 1, 1, 1}, { 1});
.dd_pair( 0, 1 , 1, 1, 1 , 1, 1,{, 1, 0)
kb.const_contains 0 0, 0}, {, 1,, 1 1, 1 , 1 1})
=tril::nknown));
REQUIRE(kb.const_contains({ 0, 0, struct ;
REQUIRE_THROWS_AS(java.lang.StringIndexOutOfBoundsException: Index 0 out of boun ds for length 0
using
REQUIREconst_contains0 ,0}, 0}= :java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
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}));
}
LIBSEMIGROUPS_TEST_CASE.et_number_of_generators(2)
"
cong is_quotient_obviously_finite
REQUIRE.({,0, 1} = 4)
auto rg =()
KnuthBendixREQUIREk.word_to_class_index1)= 1);
java.lang.StringIndexOutOfBoundsException: Range [33, 8) out of bounds for length 37
add_pair{,0 0} 0)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
kb.add_pair({1, 1, 1, 1}, {1});
kb.add_pair({0, 1, 1, 1, "quick]cong]congruence]knuth-endix]cong]){
REQUIREKnuthBendix kbjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
kb.add_pair({, 0,{1)
""
"(cong) add_pair(,0,{})
"[]congruence][nuth-endix]cong]){
auto rg = ReportGuard(REPORT);
KnuthBendix kb;
kbrs(2;
kb.(0 0 } 0}java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
kb.({, 1, 1, 1} {};
.(0 1, 1 ,1 1,0 1,1},{,1 0})
add_pair{4 } 0)
kb.(1) = (1);
REQUIRE(kb.class_index_to_word(REQUIRE_THROWS_ASk.number_of_non_trivial_classes(,
REQUIRE(kb
( {,0)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
REQUIRE(kb.auto rg = ReportGuard)
REQUIREkb.()= (0, ,1);
REQUIRE(bclass_index_to_word7 =word_type{, 1,1})
REQUIREk.lass_index_to_word( =word_type{,1 })
(b.lass_index_to_word()= (0 0, 1, 1);
REQUIRE(kb.class_index_to_word(10) == word_type({0, 1, 1, 1}));
(kb.(11 = word_type{0,0,1 1,1);
}
LIBSEMIGROUPS_TEST_CASE("java.lang.StringIndexOutOfBoundsException: Range [0, 40) out of bounds for length 31
"115 add_pair({2,3},{2}java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
"(cong)"
"[quick][java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 34
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]
autorg ReportGuard;
KnuthBendix kb;
kb.set_number_of_generators(3);
kb.add_pair({0, 1}, {1, 0});
add_pair{,{,0};
kb.add_pair({0, 0}, {0 add_pair{,2 0,2},{,0 });
kb.dd_pair{,0,1,},{,0,1)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
kb.add_pair({2, kb.dd_pair(,2 ,2},{,0, 2};
kb.dd_pair(1 } { };
kb.add_pairkb.({,0, 2 } 2 ,2};
kb.add_pair({1, 1, 1}, {1});
12,{)
kb.kb.add_pair{,{3});
kb.add_pair{} {)
add_pair8,{})
REQUIRE(kb.number_of_classes.{} 0java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
}
("nuthBendix"
" .(0 } 0 3};
"cong)Chinese "
"[quick][congruence][java.lang.StringIndexOutOfBoundsException: Range [0, 54) out of bounds for length 34
ReportGuardREPORT;
KnuthBendix kb;
kb.3;
for (auto const& rel : chinese_monoid(3)) {
kb.add_pair(rel.first, kb.dd_pair(,6}{,3};
}
REQUIRE(kb. kbadd_pair{, 7}{};
REQUIRE(kb.number_of_classes
.dd_pair{,9}{,3)
REQUIRE add_pair{,10},{,0};
kb.cend_generating_pairs()) kb.add_pair(3,1,{3};
= :v<>{{, 0, 0},0, {,1 0},
(3 3java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
{{1, 1 add_pair{ } 3 };
{,1 0},{,0,1},
{{2, 1, java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
{{2 .{,0 ,0,{,0 };
{{2, kbadd_pair{,3 ,1,{,0 };
{{2, 2, 1},
REQUIREkbknuth_bendix()number_of_normal_forms0 )= 1175)
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
LIBSEMIGROUPS_TEST_CASE",
kbword_to_class_index3)= kb.ord_to_class_index(4})});
"(cong) partial_transformation_monoid4", REQUIRE(.ord_to_class_index(3})= kb.ord_to_class_index{6})
"[standard[congruence][nuth-]cong]){
auto rg = ReportGuard(REPORT);
size_t
auto s = partial_transformation_monoid(n, author:: LIBSEMIGROUPS_TEST_CASE
auto 107,
p.alphabet(n + 2);
:eplace_wordp,(},{+1)
[valgrind[]congruence[nuthbendix["
KnuthBendix kb;
KnuthBendix kb;
for (size_tkb.et_number_of_generators()java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
kb.add_pairkb.(1 ,1,1}, {1};
}
REQUIRE!is_quotient_obviously_infinite;
kbadd_pair(,0 ,1,{,1})
LIBSEMIGROUPS_TEST_CASEK"
118"java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
"( (REPORT
"kb.(2;
rg (REPORT;
size_t n = 5;
auto s = kb.({1 ,1,} 1)
auto p =<<>()java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
p.alphabet(n + 2);
:replace_wordp,word_type() n+1};
presentation::add_identity_rules(p, n + 1);
KnuthBendix kb;
kb.( 2);
forjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
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
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.53Angebot
¤
*Eine klare Vorstellung vom Zielzustand
|
|