From 0ddc999186ea4fc29e482dfe88b773d048c8ea7b Mon Sep 17 00:00:00 2001 From: Joseph Edwards Date: Thu, 13 Jun 2024 17:14:39 +0100 Subject: [PATCH] Add add_rules(p, q) --- include/libsemigroups/presentation.hpp | 20 ++++++++++++++++++++ tests/test-presentation.cpp | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/libsemigroups/presentation.hpp b/include/libsemigroups/presentation.hpp index 019e2bb1d..b595b942a 100644 --- a/include/libsemigroups/presentation.hpp +++ b/include/libsemigroups/presentation.hpp @@ -827,12 +827,32 @@ namespace libsemigroups { //! //! \exceptions //! \no_libsemigroups_except + //! + //! \warning + //! No checks that the arguments describe words over the alphabet of the + //! presentation are performed. template void add_rules_no_checks(Presentation& p, Presentation const& q) { add_rules_no_checks(p, q.rules.cbegin(), q.rules.cend()); } + //! \brief Add a rule to the presentation from another presentation. + //! + //! Adds all the rules of the second argument to the first argument + //! which is modified in-place. + //! + //! \tparam Word the type of the words in the presentation + //! \param p the presentation to add rules to + //! \param q the presentation with the rules to add + //! + //! \throws LibsemigroupsException if any rule contains any letters not + //! belonging to `p.alphabet()`. + template + void add_rules(Presentation& p, Presentation const& q) { + add_rules(p, q.rules.cbegin(), q.rules.cend()); + } + //! \brief Check if a presentation contains a rule //! //! Checks if the rule with left-hand side \p lhs and right-hand side \p rhs diff --git a/tests/test-presentation.cpp b/tests/test-presentation.cpp index 0bd6ed1dd..63a2c37f8 100644 --- a/tests/test-presentation.cpp +++ b/tests/test-presentation.cpp @@ -157,6 +157,7 @@ namespace libsemigroups { presentation::add_rule_no_checks(q, {4, 1}, {0, 5}); presentation::add_rule_no_checks( q, {4, 1}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1}); + REQUIRE_THROWS_AS(presentation::add_rules(p, q), LibsemigroupsException); presentation::add_rules_no_checks(p, q); REQUIRE(p.rules == std::vector({{0, 1, 2, 1}, @@ -173,7 +174,7 @@ namespace libsemigroups { p.alphabet_from_rules(); q.alphabet_from_rules(); presentation::add_rule_no_checks(q, {0}, {1}); - presentation::add_rules(p, q.rules.cbegin(), q.rules.cend()); + presentation::add_rules(p, q); REQUIRE(p.rules == std::vector({{0, 1, 2, 1}, {0, 0},