// libsemigroups - C++ library for semigroups and monoids // Copyright (C) 2019 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 one 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.
// TODO(later) // 1. The other examples from Sims' book (Chapters 5 and 6) which use // reduction orderings different from shortlex // 2. Examples from MAF
// #define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
#include <string> // for string #include <vector> // for vector
#include"catch.hpp"// for REQUIRE, REQUIRE_NOTHROW, REQUIRE_THROWS_AS #include"test-main.hpp"// for LIBSEMIGROUPS_TEST_CASE
#include"libsemigroups/config.hpp"// for LIBSEMIGROUPS_DEBUG #include"libsemigroups/constants.hpp"// for POSITIVE_INFINITY #include"libsemigroups/kbe.hpp"// for KBE #include"libsemigroups/knuth-bendix.hpp"// for KnuthBendix, operator<< #include"libsemigroups/report.hpp"// for ReportGuard #include"libsemigroups/types.hpp"// for word_type
LIBSEMIGROUPS_TEST_CASE("KnuthBendix", "004", "(fpsemi) Example 5.1 in Sims (infinite)", "[quick][knuth-bendix][fpsemigroup][fpsemi]") { auto rg = ReportGuard(REPORT);
LIBSEMIGROUPS_TEST_CASE("KnuthBendix", "005", "(fpsemi) Example 5.1 in Sims (infinite)", "[quick][knuth-bendix][fpsemigroup][fpsemi]") { auto rg = ReportGuard(REPORT);
REQUIRE(std::vector<std::string>(kb.cbegin_normal_forms(1, 5),
kb.cend_normal_forms())
== std::vector<std::string>(
{"a", "b", "c", "ab", "ac", "ba", "ca", "aba", "aca", "bab", "bac", "cab", "cac", "abab", "abac", "acab", "acac", "baba", "baca", "caba", "caca"})); using FroidurePinKBE = KnuthBendix::froidure_pin_type; auto& S = static_cast<FroidurePinKBE&>(*kb.froidure_pin());
REQUIRE(S.size() == 168);
REQUIRE(S.generator(2).string(kb) == "c"); // FIXME(later) the next line compiles but leaves T in an invalid state. // auto T = FroidurePinKBE({S.generator(2)});
// Uncommenting the following adds ~3 seconds to the compile time of this // file. // auto T = FroidurePinKBE(kb); // T.add_generator(S.generator(2)); // REQUIRE(T.size() == 3); // REQUIRE(get_strings(T) == std::vector<std::string>({"c", "b", ""}));
}
LIBSEMIGROUPS_TEST_CASE( "KnuthBendix", "009", "(fpsemi)", "[quick][knuth-bendix][fpsemigroup][fpsemi][no-valgrind]") { auto rg = ReportGuard(REPORT);
//////////////////////////////////////////////////////////////////////// // Commented out test cases ////////////////////////////////////////////////////////////////////////
// This example verifies the nilpotence of the group using the Sims // algorithm. The original presentation was <a,b| [b,a,b], [b,a,a,a,a], // [b,a,a,a,b,a,a] >. (where [] mean left-normed commutators). The // presentation here was derived by first applying the NQA to find the // maximal nilpotent quotient, and then introducing new generators for the // PCP generators. It is essential for success that reasonably low values of // the maxstoredlen parameter are given. // LIBSEMIGROUPS_TEST_CASE( // "KnuthBendix", // "013", // "(fpsemi) (from kbmag/standalone/kb_data/verifynilp)", // "[quick][knuth-bendix][fpsemigroup][fpsemi][kbmag][recursive]") {} // KnuthBendix kb(new RECURSIVE(), "hHgGfFyYdDcCbBaA"); // kb.add_rule("BAba", "c"); // kb.add_rule("CAca", "d"); // kb.add_rule("DAda", "y"); // kb.add_rule("YByb", "f"); // kb.add_rule("FAfa", "g"); // kb.add_rule("ga", "ag"); // kb.add_rule("GBgb", "h"); // kb.add_rule("cb", "bc"); // kb.add_rule("ya", "ay"); // auto rg = ReportGuard(REPORT); // // REQUIRE(kb.confluent()); // // kb.run(); // REQUIRE(kb.confluent()); // REQUIRE(kb.number_of_active_rules() == 9); // // REQUIRE(kb.equal_to("BAba", "c")); // REQUIRE(kb.equal_to("CAca", "d")); // REQUIRE(kb.equal_to("DAda", "y")); // REQUIRE(kb.equal_to("YByb", "f")); // REQUIRE(kb.equal_to("FAfa", "g")); // REQUIRE(kb.equal_to("ga", "ag")); // REQUIRE(kb.equal_to("GBgb", "h")); // REQUIRE(kb.equal_to("cb", "bc")); // REQUIRE(kb.equal_to("ya", "ay")); // REQUIRE(kb.active_rules() == std::vector<std::pair<std::string, // std::string>>({})); // }
// TODO(later): temporarily commented out to because of change to // FpSemigroupInterface that forbids adding rules after started(), and // because the copy constructors for KnuthBendix et al. don't currently work // LIBSEMIGROUPS_TEST_CASE("KnuthBendix", // "014", // "(cong) finite transformation semigroup " // "congruence (21 classes)", // "[quick][congruence][knuth-bendix][cong]") { // auto rg = ReportGuard(REPORT); // using Transf = LeastTransf<5>; // FroidurePin<Transf> S({Transf({1, 3, 4, 2, 3}), Transf({3, 2, 1, 3, // 3})});
// KnuthBendix kb(S); // auto& P = kb.quotient_froidure_pin(); // REQUIRE(P.size() == 88); // kb.add_pair(S.factorisation(Transf({3, 4, 4, 4, 4})), // S.factorisation(Transf({3, 1, 3, 3, 3}))); // // P is now invalid, it's a reference to something that was deleted in // // kb.
// TODO(later): temporarily commented out to because of change to // FpSemigroupInterface that forbids adding rules after started(), and // because the copy constructors for KnuthBendix et al. don't currently work // LIBSEMIGROUPS_TEST_CASE("KnuthBendix", // "017", // "add_rule after knuth_bendix", // "[quick][knuth-bendix][fpsemigroup]") { // auto rg = ReportGuard(REPORT); // KnuthBendix kb; // kb.set_alphabet("Bab"); // kb.add_rule("aa", ""); // kb.add_rule("bB", ""); // kb.add_rule("bbb", ""); // kb.add_rule("ababab", "");
// REQUIRE(!kb.confluent()); // kb.run_for(FOREVER); // REQUIRE(kb.finished()); // // The next line tests what happens when run_for is called when // finished. kb.run_for(FOREVER); REQUIRE(kb.number_of_active_rules() == // 11); REQUIRE(kb.confluent()); REQUIRE(kb.size() == 12);
// KnuthBendix kb2(&kb); // REQUIRE(kb2.number_of_active_rules() == 11); // kb2.add_rule("a", "b"); // REQUIRE(kb2.number_of_rules() == 5); // // Adding a rule does not change the number of active rules until // *after* // // kb.run() is called again. // REQUIRE(kb2.number_of_active_rules() == 11);
// monoid presentation of F(2,7) - should produce a monoid of length 30 // which is the same as the group, together with the empty word. This is a // very difficult calculation indeed, however. // // KBMAG does not terminate when SHORTLEX order is used. // LIBSEMIGROUPS_TEST_CASE("KnuthBendix", // "019", // "(from kbmag/standalone/kb_data/f27monoid)", // "[fail][knuth-bendix][kbmag][recursive]") { // KnuthBendix kb(new RECURSIVE(), "abcdefg"); // kb.add_rule("ab", "c"); // kb.add_rule("bc", "d"); // kb.add_rule("cd", "e"); // kb.add_rule("de", "f"); // kb.add_rule("ef", "g"); // kb.add_rule("fg", "a"); // kb.add_rule("ga", "b"); // auto rg = ReportGuard(REPORT);
// This example verifies the nilpotence of the group using the Sims // algorithm. The original presentation was <a,b| [b,a,a,a], [b^-1,a,a,a], // [a,b,b,b], [a^-1,b,b,b], [a,a*b,a*b,a*b], [a^-1,a*b,a*b,a*b] >. (where [] // mean left-normed commutators. The presentation here was derived by first // applying the NQA to find the maximal nilpotent quotient, and then // introducing new generators for the PCP generators. // LIBSEMIGROUPS_TEST_CASE( // "KnuthBendix", // "020", // "(fpsemi) (from kbmag/standalone/kb_data/heinnilp)", // "[fail][knuth-bendix][fpsemigroup][fpsemi][kbmag][recursive]") { // // TODO(later) fails because internal_rewrite expect rules to be length // reducing KnuthBendix kb(new RECURSIVE(), "fFyYdDcCbBaA"); // kb.add_rule("BAba", "c"); // kb.add_rule("CAca", "d"); // kb.add_rule("CBcb", "y"); // kb.add_rule("DBdb", "f"); // kb.add_rule("cBCb", "bcBC"); // kb.add_rule("babABaBA", "abABaBAb"); // kb.add_rule("cBACab", "abcBAC"); // kb.add_rule("BabABBAbab", "aabABBAb"); // auto rg = ReportGuard(REPORT);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.