libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
knuth-bendix-nf.hpp
1//
2// libsemigroups - C++ library for semigroups and monoids
3// Copyright (C) 2024-2025 James D. Mitchell
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 an implementation of a range object for producing normal
20// forms for a KnuthBendixImpl object.
21
22#ifndef LIBSEMIGROUPS_DETAIL_KNUTH_BENDIX_NF_HPP_
23#define LIBSEMIGROUPS_DETAIL_KNUTH_BENDIX_NF_HPP_
24
25#include <cstdint> // for uint32_t
26
27#include "libsemigroups/paths.hpp" // for Paths
28#include "libsemigroups/to-froidure-pin.hpp" // for to_froidure_pin
29#include "libsemigroups/types.hpp" // for word_type
30
31namespace libsemigroups {
32
33 template <typename Word, typename Rewriter, typename ReductionOrder>
34 class KnuthBendix;
35
36 namespace detail {
37
38 template <typename Word, typename Rewriter, typename ReductionOrder>
39 class KnuthBendixNormalFormRange : public Paths<uint32_t> {
40 using Paths_ = Paths<uint32_t>;
41
42 mutable Word _current;
43 KnuthBendix<Word, Rewriter, ReductionOrder>* _kb;
44
45 public:
46 using size_type = typename Paths_::size_type;
47 using output_type = Word const&;
48
49 explicit KnuthBendixNormalFormRange(
50 KnuthBendix<Word, Rewriter, ReductionOrder>& kb)
51 : Paths(kb.gilman_graph()), _current(), _kb(&kb) {
52 // It's possible that the gilman graph is empty, so the call to
53 // source_no_checks(0) is technically invalid, but nothing goes wrong,
54 // so we just go with it. This is slightly smelly.
56 if (!kb.presentation().contains_empty_word()) {
58 }
59 }
60
61 KnuthBendixNormalFormRange();
62 KnuthBendixNormalFormRange(KnuthBendixNormalFormRange const&);
63 KnuthBendixNormalFormRange(KnuthBendixNormalFormRange&&);
64 KnuthBendixNormalFormRange& operator=(KnuthBendixNormalFormRange const&);
65 KnuthBendixNormalFormRange& operator=(KnuthBendixNormalFormRange&&);
66
67 ~KnuthBendixNormalFormRange();
68
69 output_type get() const {
70 word_type const& w = Paths_::get();
71 _current.clear();
72 for (auto c : w) {
73 _current.push_back(_kb->presentation().letter_no_checks(c));
74 }
75 return _current;
76 }
77
78 KnuthBendixNormalFormRange& min(size_type val) noexcept {
79 Paths_::min(val);
80 return *this;
81 }
82
83 KnuthBendixNormalFormRange& max(size_type val) noexcept {
84 Paths_::max(val);
85 return *this;
86 }
87
88 using Paths_::at_end;
89 using Paths_::count;
90 using Paths_::max;
91 using Paths_::min;
92 using Paths_::next;
94
95 static constexpr bool is_finite = true; // this isn't always true!
96 static constexpr bool is_idempotent = true;
97 }; // class KnuthBendixNormalFormRange
98
99 template <typename Word, typename Rewriter, typename ReductionOrder>
100 KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>::
101 KnuthBendixNormalFormRange()
102 = default;
103
104 template <typename Word, typename Rewriter, typename ReductionOrder>
105 KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>::
106 KnuthBendixNormalFormRange(KnuthBendixNormalFormRange const&)
107 = default;
108
109 template <typename Word, typename Rewriter, typename ReductionOrder>
110 KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>::
111 KnuthBendixNormalFormRange(KnuthBendixNormalFormRange&&)
112 = default;
113
114 template <typename Word, typename Rewriter, typename ReductionOrder>
115 KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>&
116 KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>::operator=(
117 KnuthBendixNormalFormRange const&)
118 = default;
119
120 template <typename Word, typename Rewriter, typename ReductionOrder>
121 KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>&
122 KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>::operator=(
123 KnuthBendixNormalFormRange&&)
124 = default;
125
126 template <typename Word, typename Rewriter, typename ReductionOrder>
127 KnuthBendixNormalFormRange<Word, Rewriter, ReductionOrder>::
128 ~KnuthBendixNormalFormRange()
129 = default;
130 } // namespace detail
131} // namespace libsemigroups
132#endif // LIBSEMIGROUPS_DETAIL_KNUTH_BENDIX_NF_HPP_
void next()
Definition paths.hpp:751
typename WordGraph< uint32_t >::size_type size_type
Definition paths.hpp:613
size_type min() const noexcept
Definition paths.hpp:970
Paths(WordGraph< Node > const &) -> Paths< Node >
Paths & min(size_type val) noexcept
Definition paths.hpp:957
Paths & max(size_type val) noexcept
Definition paths.hpp:986
size_type max() const noexcept
Definition paths.hpp:999
bool at_end() const
Definition paths.hpp:767
output_type get() const
Definition paths.hpp:738
uint64_t count() const
Definition paths.hpp:800
Paths & source_no_checks(node_type n) noexcept
Definition paths.hpp:831
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:101
Namespace for everything in the libsemigroups library.
Definition action.hpp:44