libsemigroups  v3.0.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.hpp" // for WordGraph
42#include "word-range.hpp" // for ToString
43
44#include "detail/fmt.hpp" // for format
45#include "detail/knuth-bendix-nf.hpp" // for KnuthBendix, KnuthBe...
46#include "detail/rewriters.hpp" // for internal_string_type
47
48namespace libsemigroups {
49
50 namespace congruence_common {
52 // Interface helpers - normal_forms
54
78 template <typename Word, typename Rewriter, typename ReductionOrder>
79 [[nodiscard]] auto
80 normal_forms(KnuthBendix<Word, Rewriter, ReductionOrder>& kb) {
81 return detail::KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>(
82 kb);
83 }
84
86 // Interface helpers - non_trivial_classes
88
129 template <typename Word, typename Rewriter, typename ReductionOrder>
130 [[nodiscard]] std::vector<std::vector<Word>>
131 non_trivial_classes(KnuthBendix<Word, Rewriter, ReductionOrder>& kb1,
132 KnuthBendix<Word, Rewriter, ReductionOrder>& kb2);
133
134 } // namespace congruence_common
135
151
155 namespace knuth_bendix {
156
158 // KnuthBendix specific helpers
160
189 template <typename Word, typename Rewriter, typename ReductionOrder>
190 void by_overlap_length(KnuthBendix<Word, Rewriter, ReductionOrder>& kb);
191
210#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
211 template <typename Rewriter, typename ReductionOrder>
212 [[nodiscard]] bool
213 is_reduced(detail::KnuthBendixImpl<Rewriter, ReductionOrder>& kb);
214#else
215 template <typename Word, typename Rewriter, typename ReductionOrder>
216 [[nodiscard]] bool
217 is_reduced(KnuthBendix<Word, Rewriter, ReductionOrder>& kb);
218#endif
219
221 // Interface helpers - add_generating_pair
223
226
228 // Interface helpers - contains
230
235
237 // Interface helpers - reduce
239
244
246 // Interface helpers - normal_forms
248
249 using congruence_common::normal_forms;
250
252 // Interface helpers - partition
254
256
258 // Interface helpers - non_trivial_classes
260
262
264 // Possible future interface helpers - redundant_rule
266
298 template <typename Word, typename Time>
299 [[nodiscard]] typename std::vector<Word>::const_iterator
301
302 } // namespace knuth_bendix
303} // namespace libsemigroups
304
305#include "knuth-bendix-helpers.tpp"
306#endif // LIBSEMIGROUPS_KNUTH_BENDIX_HELPERS_HPP_
For an implementation of presentations for semigroups or monoids.
Definition presentation.hpp:102
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:155
Namespace for everything in the libsemigroups library.
Definition action.hpp:44