libsemigroups  v3.3.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
knuth-bendix-helpers.hpp
1//
2// libsemigroups - C++ library for semigroups and monoids
3// Copyright (C) 2024-2025 James D. Mitchell + Maria Tsalakou
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17//
18
19// This file contains the helpers for the KnuthBendix class template.
20
21#ifndef LIBSEMIGROUPS_KNUTH_BENDIX_HELPERS_HPP_
22#define LIBSEMIGROUPS_KNUTH_BENDIX_HELPERS_HPP_
23
24#include <cstddef> // for size_t
25#include <iterator> // for distance
26#include <stack> // for stack
27#include <string> // for basic_string, string
28#include <type_traits> // for is_same_v
29#include <utility> // for move
30#include <vector> // for vector
31
32#include "cong-common-helpers.hpp" // for partition, add_gener...
33#include "constants.hpp" // for UNDEFINED, POSITIVE_...
34#include "debug.hpp" // for LIBSEMIGROUPS_ASSERT
35#include "exception.hpp" // for LIBSEMIGROUPS_EXCEPTION
36#include "knuth-bendix-class.hpp" // for KnuthBendix
37#include "paths.hpp" // for Paths
38#include "presentation.hpp" // for Presentation
39#include "ranges.hpp" // for seq, input_range_ite...
40#include "types.hpp" // for congruence_kind, wor...
41#include "word-graph-helpers.hpp" // for word_graph
42#include "word-graph.hpp" // for WordGraph
43#include "word-range.hpp" // for ToString
44
45#include "detail/fmt.hpp" // for format
46#include "detail/knuth-bendix-nf.hpp" // for KnuthBendix, KnuthBe...
47#include "detail/rewriters.hpp" // for internal_string_type
48
49namespace libsemigroups {
50
51 namespace congruence_common {
53 // Interface helpers - normal_forms
55
79 template <typename Word, typename Rewriter, typename ReductionOrder>
80 [[nodiscard]] auto
81 normal_forms(KnuthBendix<Word, Rewriter, ReductionOrder>& kb) {
82 return detail::KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>(
83 kb);
84 }
85
87 // Interface helpers - non_trivial_classes
89
130 template <typename Word, typename Rewriter, typename ReductionOrder>
131 [[nodiscard]] std::vector<std::vector<Word>>
132 non_trivial_classes(KnuthBendix<Word, Rewriter, ReductionOrder>& kb1,
133 KnuthBendix<Word, Rewriter, ReductionOrder>& kb2);
134
135 } // namespace congruence_common
136
152
156 namespace knuth_bendix {
157
159 // KnuthBendix specific helpers
161
190 template <typename Word, typename Rewriter, typename ReductionOrder>
191 void by_overlap_length(KnuthBendix<Word, Rewriter, ReductionOrder>& kb);
192
211#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
212 template <typename Rewriter, typename ReductionOrder>
213 [[nodiscard]] bool
214 is_reduced(detail::KnuthBendixImpl<Rewriter, ReductionOrder>& kb);
215#else
216 template <typename Word, typename Rewriter, typename ReductionOrder>
217 [[nodiscard]] bool
218 is_reduced(KnuthBendix<Word, Rewriter, ReductionOrder>& kb);
219#endif
220
222 // Interface helpers - add_generating_pair
224
227
229 // Interface helpers - contains
231
236
238 // Interface helpers - reduce
240
245
247 // Interface helpers - normal_forms
249
250 using congruence_common::normal_forms;
251
253 // Interface helpers - partition
255
257
259 // Interface helpers - non_trivial_classes
261
263
265 // Possible future interface helpers - redundant_rule
267
299 template <typename Word, typename Time>
300 [[nodiscard]] typename std::vector<Word>::const_iterator
302
303 } // namespace knuth_bendix
304} // namespace libsemigroups
305
306#include "knuth-bendix-helpers.tpp"
307#endif // LIBSEMIGROUPS_KNUTH_BENDIX_HELPERS_HPP_
For an implementation of presentations for semigroups or monoids.
Definition presentation.hpp:103
void add_generating_pair(Thing &thing, typename Thing::native_word_type const &u, typename Thing::native_word_type const &v)
Helper for adding a generating pair of words.
Definition cong-common-helpers.hpp:200
void add_generating_pair_no_checks(Thing &thing, typename Thing::native_word_type const &u, typename Thing::native_word_type const &v)
Helper for adding a generating pair of words.
Definition cong-common-helpers.hpp:112
bool contains_no_checks(Thing &thing, typename Thing::native_word_type const &u, typename Thing::native_word_type const &v)
Check containment of a pair of words.
Definition cong-common-helpers.hpp:513
bool contains(Thing &thing, typename Thing::native_word_type const &u, typename Thing::native_word_type const &v)
Check containment of a pair of words.
Definition cong-common-helpers.hpp:605
tril currently_contains(Thing const &thing, typename Thing::native_word_type const &u, typename Thing::native_word_type const &v)
Check containment of a pair of words.
Definition cong-common-helpers.hpp:425
tril currently_contains_no_checks(Thing const &thing, typename Thing::native_word_type const &u, typename Thing::native_word_type const &v)
Check containment of a pair of words.
Definition cong-common-helpers.hpp:322
std::vector< std::vector< typename Thing::native_word_type > > non_trivial_classes(Thing &thing, Range r)
Find the non-trivial classes in the partition of a range of words.
std::vector< std::vector< typename Thing::native_word_type > > partition(Thing &thing, Range r)
Partition a range of words.
Thing::native_word_type reduce(Thing const &thing, typename Thing::native_word_type const &w)
Reduce a word.
Thing::native_word_type reduce_no_run_no_checks(Thing const &thing, typename Thing::native_word_type const &w)
Reduce a word with no enumeration or checks.
Thing::native_word_type reduce_no_checks(Thing const &thing, typename Thing::native_word_type const &w)
Reduce a word with no checks.
Thing::native_word_type reduce_no_run(Thing const &thing, typename Thing::native_word_type const &w)
Reduce a word with no enumeration.
void by_overlap_length(KnuthBendix< Word, Rewriter, ReductionOrder > &kb)
Run the Knuth-Bendix algorithm by considering all overlaps of a given length.
bool is_reduced(KnuthBendix< Word, Rewriter, ReductionOrder > &kb)
Check if the all rules are reduced with respect to each other.
std::vector< Word >::const_iterator redundant_rule(Presentation< Word > const &p, Time t)
Return an iterator pointing at the left hand side of a redundant rule.
Definition knuth-bendix-helpers.hpp:156
Namespace for everything in the libsemigroups library.
Definition action.hpp:44