Skip to content

Commit

Permalink
Add add_rules(p, q)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph-Edwards committed Jun 13, 2024
1 parent 0a17aa7 commit 0ddc999
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions include/libsemigroups/presentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Word>
void add_rules_no_checks(Presentation<Word>& p,
Presentation<Word> 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 <typename Word>
void add_rules(Presentation<Word>& p, Presentation<Word> 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
Expand Down
3 changes: 2 additions & 1 deletion tests/test-presentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<W>({{0, 1, 2, 1},
Expand All @@ -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<W>({{0, 1, 2, 1},
{0, 0},
Expand Down

0 comments on commit 0ddc999

Please sign in to comment.