libvata2  [unstable] git snapshot
nfa.hh
Go to the documentation of this file.
1 /* nfa.hh -- nondeterministic finite automaton (over finite words)
2  *
3  * Copyright (c) 2018 Ondrej Lengal <ondra.lengal@gmail.com>
4  *
5  * This file is a part of libvata2.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  */
17 
18 #ifndef _VATA2_NFA_HH_
19 #define _VATA2_NFA_HH_
20 
21 #include <algorithm>
22 #include <cassert>
23 #include <cstdint>
24 #include <set>
25 #include <unordered_map>
26 #include <vector>
27 
28 // VATA2 headers
29 #include <vata2/parser.hh>
30 #include <vata2/util.hh>
31 
32 namespace Vata2
33 {
34 namespace Nfa
35 {
36 
37 // START OF THE DECLARATIONS
38 
39 using State = uintptr_t;
40 using Symbol = uintptr_t;
41 using StateSet = std::set<State>; /// set of states
42 using PostSymb = std::unordered_map<Symbol, StateSet>; /// post over a symbol
43 using StateToPostMap = std::unordered_map<State, PostSymb>; /// transitions
44 
45 using ProductMap = std::unordered_map<std::pair<State, State>, State>;
46 using SubsetMap = std::unordered_map<StateSet, State>;
47 using Path = std::vector<State>; /// a finite-length path through automaton
48 using Word = std::vector<Symbol>; /// a finite-length word
49 
50 using StringToStateMap = std::unordered_map<std::string, State>;
51 using StringToSymbolMap = std::unordered_map<std::string, Symbol>;
52 using StateToStringMap = std::unordered_map<State, std::string>;
53 using SymbolToStringMap = std::unordered_map<Symbol, std::string>;
54 
55 using StringDict = std::unordered_map<std::string, std::string>;
56 
58 
59 /// A transition
60 struct Trans
61 {
65 
66  Trans() : src(), symb(), tgt() { }
67  Trans(State src, Symbol symb, State tgt) : src(src), symb(symb), tgt(tgt) { }
68 
69  bool operator==(const Trans& rhs) const
70  { // {{{
71  return src == rhs.src && symb == rhs.symb && tgt == rhs.tgt;
72  } // operator== }}}
73  bool operator!=(const Trans& rhs) const { return !this->operator==(rhs); }
74 };
75 
76 // ALPHABET {{{
77 class Alphabet
78 {
79 public:
80 
81  /// translates a string into a symbol
82  virtual Symbol translate_symb(const std::string& symb) = 0;
83  /// also translates strings to symbols
84  Symbol operator[](const std::string& symb) {return this->translate_symb(symb);}
85  /// gets a list of symbols in the alphabet
86  virtual std::list<Symbol> get_symbols() const
87  { // {{{
88  throw std::runtime_error("Unimplemented");
89  } // }}}
90 
91  /// complement of a set of symbols wrt the alphabet
92  virtual std::list<Symbol> get_complement(const std::set<Symbol>& syms) const
93  { // {{{
94  (void)syms;
95  throw std::runtime_error("Unimplemented");
96  } // }}}
97 
98  virtual ~Alphabet() { }
99 };
100 
102 {
103 private:
104  StringToSymbolMap* symbol_map;
105  Symbol cnt_symbol;
106 
107 private:
109  OnTheFlyAlphabet& operator=(const OnTheFlyAlphabet& rhs);
110 
111 public:
112 
113  OnTheFlyAlphabet(StringToSymbolMap* str_sym_map, Symbol init_symbol = 0) :
114  symbol_map(str_sym_map), cnt_symbol(init_symbol)
115  {
116  assert(nullptr != symbol_map);
117  }
118 
119  virtual std::list<Symbol> get_symbols() const override;
120  virtual Symbol translate_symb(const std::string& str) override;
121  virtual std::list<Symbol> get_complement(
122  const std::set<Symbol>& syms) const override;
123 };
124 
125 class DirectAlphabet : public Alphabet
126 {
127  virtual Symbol translate_symb(const std::string& str) override
128  {
129  Symbol symb;
130  std::istringstream stream(str);
131  stream >> symb;
132  return symb;
133  }
134 };
135 
136 class CharAlphabet : public Alphabet
137 {
138 public:
139 
140  virtual Symbol translate_symb(const std::string& str) override
141  {
142  if (str.length() == 3 &&
143  ((str[0] == '\'' && str[2] == '\'') ||
144  (str[0] == '\"' && str[2] == '\"')
145  ))
146  { // direct occurence of a character
147  return str[1];
148  }
149 
150  Symbol symb;
151  std::istringstream stream(str);
152  stream >> symb;
153  return symb;
154  }
155 
156  virtual std::list<Symbol> get_symbols() const override;
157  virtual std::list<Symbol> get_complement(
158  const std::set<Symbol>& syms) const override;
159 };
160 
161 class EnumAlphabet : public Alphabet
162 {
163 private:
164  StringToSymbolMap symbol_map;
165 
166 private:
167  EnumAlphabet(const EnumAlphabet& rhs);
168  EnumAlphabet& operator=(const EnumAlphabet& rhs);
169 
170 public:
171 
172  EnumAlphabet() : symbol_map() { }
173 
174  template <class InputIt>
175  EnumAlphabet(InputIt first, InputIt last) : EnumAlphabet()
176  { // {{{
177  size_t cnt = 0;
178  for (; first != last; ++first)
179  {
180  bool inserted;
181  std::tie(std::ignore, inserted) = symbol_map.insert({*first, cnt++});
182  if (!inserted)
183  {
184  throw std::runtime_error("multiple occurrence of the same symbol");
185  }
186  }
187  } // }}}
188 
189  EnumAlphabet(std::initializer_list<std::string> l) :
190  EnumAlphabet(l.begin(), l.end())
191  { }
192 
193  virtual Symbol translate_symb(const std::string& str) override
194  {
195  auto it = symbol_map.find(str);
196  if (symbol_map.end() == it)
197  {
198  throw std::runtime_error("unknown symbol \'" + str + "\'");
199  }
200 
201  return it->second;
202  }
203 
204  virtual std::list<Symbol> get_symbols() const override;
205  virtual std::list<Symbol> get_complement(
206  const std::set<Symbol>& syms) const override;
207 };
208 // }}}
209 
210 
211 struct Nfa;
212 
213 /// serializes Nfa into a ParsedSection
215  const Nfa& aut,
216  const SymbolToStringMap* symbol_map = nullptr,
217  const StateToStringMap* state_map = nullptr);
218 
219 
220 /// An NFA
221 struct Nfa
222 { // {{{
223 private:
224 
225  // private transitions in order to avoid the use of transitions.size() which
226  // returns something else than expected (basically returns the number of
227  // states with outgoing edges in the NFA
228  StateToPostMap transitions = {};
229 
230 public:
231 
232  std::set<State> initialstates = {};
233  std::set<State> finalstates = {};
234 
235  void add_initial(State state) { this->initialstates.insert(state); }
236  void add_initial(const std::vector<State> vec)
237  { // {{{
238  for (const State& st : vec) { this->add_initial(st); }
239  } // }}}
240  bool has_initial(State state) const
241  { // {{{
242  return Vata2::util::haskey(this->initialstates, state);
243  } // }}}
244  void add_final(State state) { this->finalstates.insert(state); }
245  void add_final(const std::vector<State> vec)
246  { // {{{
247  for (const State& st : vec) { this->add_final(st); }
248  } // }}}
249 
250  bool has_final(State state) const
251  { // {{{
252  return Vata2::util::haskey(this->finalstates, state);
253  } // }}}
254 
255  void add_trans(const Trans& trans);
256  void add_trans(State src, Symbol symb, State tgt)
257  { // {{{
258  this->add_trans({src, symb, tgt});
259  } // }}}
260 
261  bool has_trans(const Trans& trans) const;
262  bool has_trans(State src, Symbol symb, State tgt) const
263  { // {{{
264  return this->has_trans({src, symb, tgt});
265  } // }}}
266 
267  bool trans_empty() const { return this->transitions.empty();};// no transitions
268  size_t trans_size() const;/// number of transitions; has linear time complexity
269 
271  { // {{{
272  const Nfa* nfa;
273  StateToPostMap::const_iterator stpmIt;
274  PostSymb::const_iterator psIt;
275  StateSet::const_iterator ssIt;
277  bool is_end = { false };
278 
279  const_iterator() : nfa(), stpmIt(), psIt(), ssIt(), trans() { };
280  static const_iterator for_begin(const Nfa* nfa);
281  static const_iterator for_end(const Nfa* nfa);
282 
284  { // {{{
285  this->trans = {this->stpmIt->first, this->psIt->first, *(this->ssIt)};
286  } // }}}
287 
288  const Trans& operator*() const { return this->trans; }
289 
290  bool operator==(const const_iterator& rhs) const
291  { // {{{
292  if (this->is_end && rhs.is_end) { return true; }
293  if ((this->is_end && !rhs.is_end) || (!this->is_end && rhs.is_end)) { return false; }
294  return ssIt == rhs.ssIt && psIt == rhs.psIt && stpmIt == rhs.stpmIt;
295  } // }}}
296  bool operator!=(const const_iterator& rhs) const { return !(*this == rhs);}
298  }; // }}}
299 
301  const_iterator end() const { return const_iterator::for_end(this); }
302 
303  const PostSymb& operator[](State state) const
304  { // {{{
305  const PostSymb* post_s = this->post(state);
306  if (nullptr == post_s)
307  {
308  return EMPTY_POST;
309  }
310 
311  return *post_s;
312  } // operator[] }}}
313 
314  const PostSymb* post(State state) const
315  { // {{{
316  auto it = transitions.find(state);
317  return (transitions.end() == it)? nullptr : &it->second;
318  } // post }}}
319 
320  /// gets a post of a set of states over a symbol
321  StateSet post(const StateSet& macrostate, Symbol sym) const;
322 }; // Nfa }}}
323 
324 /// Do the automata have disjoint sets of states?
325 bool are_state_disjoint(const Nfa& lhs, const Nfa& rhs);
326 /// Is the language of the automaton empty?
327 bool is_lang_empty(const Nfa& aut, Path* cex = nullptr);
328 bool is_lang_empty_cex(const Nfa& aut, Word* cex);
329 
330 
331 /// Is the language of the automaton universal?
332 bool is_universal(
333  const Nfa& aut,
334  const Alphabet& alphabet,
335  Word* cex = nullptr,
336  const StringDict& params = {});
337 
338 inline bool is_universal(
339  const Nfa& aut,
340  const Alphabet& alphabet,
341  const StringDict& params)
342 { // {{{
343  return is_universal(aut, alphabet, nullptr, params);
344 } // }}}
345 
346 /// Checks inclusion of languages of two automata (smaller <= bigger)?
347 bool is_incl(
348  const Nfa& smaller,
349  const Nfa& bigger,
350  const Alphabet& alphabet,
351  Word* cex = nullptr,
352  const StringDict& params = {});
353 
354 inline bool is_incl(
355  const Nfa& smaller,
356  const Nfa& bigger,
357  const Alphabet& alphabet,
358  const StringDict& params)
359 { // {{{
360  return is_incl(smaller, bigger, alphabet, nullptr, params);
361 } // }}}
362 
363 /// Compute union of a pair of automata
364 /// Assumes that sets of states of lhs, rhs, and result are disjoint
365 void union_norename(
366  Nfa* result,
367  const Nfa& lhs,
368  const Nfa& rhs);
369 
370 /// Compute union of a pair of automata
372  const Nfa& lhs,
373  const Nfa& rhs)
374 { // {{{
375  Nfa result;
376  union_norename(&result, lhs, rhs);
377  return result;
378 } // union_norename }}}
379 
380 /// Compute intersection of a pair of automata
381 void intersection(
382  Nfa* result,
383  const Nfa& lhs,
384  const Nfa& rhs,
385  ProductMap* prod_map = nullptr);
386 
388  const Nfa& lhs,
389  const Nfa& rhs,
390  ProductMap* prod_map = nullptr)
391 { // {{{
392  Nfa result;
393  intersection(&result, lhs, rhs, prod_map);
394  return result;
395 } // intersection }}}
396 
397 /// Determinize an automaton
398 void determinize(
399  Nfa* result,
400  const Nfa& aut,
401  SubsetMap* subset_map = nullptr,
402  State* last_state_num = nullptr);
403 
405  const Nfa& aut,
406  SubsetMap* subset_map = nullptr,
407  State* last_state_num = nullptr)
408 { // {{{
409  Nfa result;
410  determinize(&result, aut, subset_map, last_state_num);
411  return result;
412 } // determinize }}}
413 
414 /// makes the transition relation complete
415 void make_complete(
416  Nfa* aut,
417  const Alphabet& alphabet,
418  State sink_state);
419 
420 /// Complement
421 void complement(
422  Nfa* result,
423  const Nfa& aut,
424  const Alphabet& alphabet,
425  SubsetMap* subset_map = nullptr);
426 
428  const Nfa& aut,
429  const Alphabet& alphabet,
430  SubsetMap* subset_map = nullptr)
431 { // {{{
432  Nfa result;
433  complement(&result, aut, alphabet, subset_map);
434  return result;
435 } // complement }}}
436 
437 /// Reverting the automaton
438 void revert(Nfa* result, const Nfa& aut);
439 
440 inline Nfa revert(const Nfa& aut)
441 { // {{{
442  Nfa result;
443  revert(&result, aut);
444  return result;
445 } // revert }}}
446 
447 
448 /// Test whether an automaton is deterministic, i.e., whether it has exactly
449 /// one initial state and every state has at most one outgoing transition over
450 /// every symbol. Checks the whole automaton, not only the reachable part
451 bool is_deterministic(const Nfa& aut);
452 
453 /// Test for automaton completeness wrt an alphabet. An automaton is complete
454 /// if every reachable state has at least one outgoing transition over every
455 /// symbol.
456 bool is_complete(const Nfa& aut, const Alphabet& alphabet);
457 
458 /** Loads an automaton from Parsed object */
459 void construct(
460  Nfa* aut,
461  const Vata2::Parser::ParsedSection& parsec,
462  StringToSymbolMap* symbol_map = nullptr,
463  StringToStateMap* state_map = nullptr);
464 
465 /** Loads an automaton from Parsed object */
466 inline Nfa construct(
467  const Vata2::Parser::ParsedSection& parsec,
468  StringToSymbolMap* symbol_map = nullptr,
469  StringToStateMap* state_map = nullptr)
470 { // {{{
471  Nfa result;
472  construct(&result, parsec, symbol_map, state_map);
473  return result;
474 } // construct }}}
475 
476 /** Loads an automaton from Parsed object */
477 void construct(
478  Nfa* aut,
479  const Vata2::Parser::ParsedSection& parsec,
480  Alphabet* alphabet,
481  StringToStateMap* state_map = nullptr);
482 
483 /** Loads an automaton from Parsed object */
484 inline Nfa construct(
485  const Vata2::Parser::ParsedSection& parsec,
486  Alphabet* alphabet,
487  StringToStateMap* state_map = nullptr)
488 { // {{{
489  Nfa result;
490  construct(&result, parsec, alphabet, state_map);
491  return result;
492 } // construct(Alphabet) }}}
493 
494 /**
495  * @brief Obtains a word corresponding to a path in an automaton (or sets a flag)
496  *
497  * Returns a word that is consistent with @p path of states in automaton @p
498  * aut, or sets a flag to @p false if such a word does not exist. Note that
499  * there may be several words with the same path (in case some pair of states
500  * is connected by transitions over more than one symbol).
501  *
502  * @param[in] aut The automaton
503  * @param[in] path The path of states
504  *
505  * @returns A pair (word, bool) where if @p bool is @p true, then @p word is a
506  * word consistent with @p path, and if @p bool is @p false, this
507  * denotes that the path is invalid in @p aut
508  */
509 std::pair<Word, bool> get_word_for_path(const Nfa& aut, const Path& path);
510 
511 
512 /// Checks whether a string is in the language of an automaton
513 bool is_in_lang(const Nfa& aut, const Word& word);
514 
515 /// Checks whether the prefix of a string is in the language of an automaton
516 bool is_prfx_in_lang(const Nfa& aut, const Word& word);
517 
518 /** Encodes a vector of strings (each corresponding to one symbol) into a
519  * @c Word instance
520  */
522  const StringToSymbolMap& symbol_map,
523  const std::vector<std::string>& input)
524 { // {{{
525  Word result;
526  for (auto str : input) { result.push_back(symbol_map.at(str)); }
527  return result;
528 } // encode_word }}}
529 
530 /// operator<<
531 std::ostream& operator<<(std::ostream& strm, const Nfa& nfa);
532 
533 /// global constructor to be called at program startup (from vm-dispatch)
534 void init();
535 
536 // CLOSING NAMESPACES AND GUARDS
537 } /* Nfa */
538 } /* Vata2 */
539 
540 namespace std
541 { // {{{
542 template <>
543 struct hash<Vata2::Nfa::Trans>
544 {
545  inline size_t operator()(const Vata2::Nfa::Trans& trans) const
546  {
547  size_t accum = std::hash<Vata2::Nfa::State>{}(trans.src);
548  accum = Vata2::util::hash_combine(accum, trans.symb);
549  accum = Vata2::util::hash_combine(accum, trans.tgt);
550  return accum;
551  }
552 };
553 
554 std::ostream& operator<<(std::ostream& strm, const Vata2::Nfa::Trans& trans);
555 } // std }}}
556 
557 
558 #endif /* _VATA2_NFA_HH_ */
virtual Symbol translate_symb(const std::string &str) override
translates a string into a symbol
Definition: nfa.hh:193
bool haskey(const T &cont, const K &key)
checks whether a container with find contains a key
Definition: util.hh:96
State tgt
Definition: nfa.hh:64
std::vector< Symbol > Word
a finite-length path through automaton
Definition: nfa.hh:48
void add_final(State state)
Definition: nfa.hh:244
bool is_deterministic(const Nfa &aut)
Test whether an automaton is deterministic, i.e., whether it has exactly one initial state and every ...
bool is_in_lang(const Nfa &aut, const Word &word)
Checks whether a string is in the language of an automaton.
void determinize(Nfa *result, const Nfa &aut, SubsetMap *subset_map=nullptr, State *last_state_num=nullptr)
Determinize an automaton.
Parsed data (single section)
Definition: parser.hh:41
StateSet::const_iterator ssIt
Definition: nfa.hh:275
EnumAlphabet(InputIt first, InputIt last)
Definition: nfa.hh:175
bool is_incl(const Nfa &smaller, const Nfa &bigger, const Alphabet &alphabet, Word *cex=nullptr, const StringDict &params={})
Checks inclusion of languages of two automata (smaller <= bigger)?
std::unordered_map< std::string, Symbol > StringToSymbolMap
Definition: nfa.hh:51
std::unordered_map< std::string, std::string > StringDict
Definition: nfa.hh:55
bool are_state_disjoint(const Nfa &lhs, const Nfa &rhs)
Do the automata have disjoint sets of states?
bool is_universal(const Nfa &aut, const Alphabet &alphabet, Word *cex=nullptr, const StringDict &params={})
Is the language of the automaton universal?
virtual std::list< Symbol > get_complement(const std::set< Symbol > &syms) const
complement of a set of symbols wrt the alphabet
Definition: nfa.hh:92
bool operator!=(const Trans &rhs) const
Definition: nfa.hh:73
bool is_lang_empty_cex(const Nfa &aut, Word *cex)
std::unordered_map< StateSet, State > SubsetMap
Definition: nfa.hh:46
std::unordered_map< Symbol, std::string > SymbolToStringMap
Definition: nfa.hh:53
A transition.
Definition: nfa.hh:60
std::set< State > finalstates
Definition: nfa.hh:233
virtual Symbol translate_symb(const std::string &symb)=0
translates a string into a symbol
number of transitions; has linear time complexity
Definition: nfa.hh:270
virtual Symbol translate_symb(const std::string &str) override
translates a string into a symbol
virtual std::list< Symbol > get_symbols() const
gets a list of symbols in the alphabet
Definition: nfa.hh:86
size_t hash_combine(size_t lhs, const T &rhs)
Combine two hash values.
Definition: util.hh:67
EnumAlphabet(std::initializer_list< std::string > l)
Definition: nfa.hh:189
std::unordered_map< State, std::string > StateToStringMap
Definition: nfa.hh:52
virtual std::list< Symbol > get_complement(const std::set< Symbol > &syms) const override
complement of a set of symbols wrt the alphabet
size_t operator()(const Vata2::Nfa::Trans &trans) const
Definition: nfa.hh:545
void revert(Nfa *result, const Nfa &aut)
Reverting the automaton.
const PostSymb * post(State state) const
Definition: nfa.hh:314
bool operator==(const Trans &rhs) const
Definition: nfa.hh:69
static const_iterator for_end(const Nfa *nfa)
OnTheFlyAlphabet(StringToSymbolMap *str_sym_map, Symbol init_symbol=0)
Definition: nfa.hh:113
std::set< State > initialstates
Definition: nfa.hh:232
const_iterator & operator++()
void add_trans(State src, Symbol symb, State tgt)
Definition: nfa.hh:256
virtual std::list< Symbol > get_symbols() const override
gets a list of symbols in the alphabet
void init()
global constructor to be called at program startup (from vm-dispatch)
void add_trans(const Trans &trans)
std::pair< Word, bool > get_word_for_path(const Nfa &aut, const Path &path)
Obtains a word corresponding to a path in an automaton (or sets a flag)
Symbol operator[](const std::string &symb)
also translates strings to symbols
Definition: nfa.hh:84
std::unordered_map< State, PostSymb > StateToPostMap
post over a symbol
Definition: nfa.hh:43
bool trans_empty() const
Definition: nfa.hh:267
const PostSymb & operator[](State state) const
Definition: nfa.hh:303
virtual std::list< Symbol > get_complement(const std::set< Symbol > &syms) const override
complement of a set of symbols wrt the alphabet
virtual std::list< Symbol > get_complement(const std::set< Symbol > &syms) const override
complement of a set of symbols wrt the alphabet
virtual std::list< Symbol > get_symbols() const override
gets a list of symbols in the alphabet
const Trans & operator*() const
Definition: nfa.hh:288
const PostSymb EMPTY_POST
Definition: nfa.hh:57
void union_norename(Nfa *result, const Nfa &lhs, const Nfa &rhs)
Compute union of a pair of automata Assumes that sets of states of lhs, rhs, and result are disjoint...
std::vector< State > Path
Definition: nfa.hh:47
PostSymb::const_iterator psIt
Definition: nfa.hh:274
bool has_trans(State src, Symbol symb, State tgt) const
Definition: nfa.hh:262
const_iterator end() const
Definition: nfa.hh:301
std::unordered_map< Symbol, StateSet > PostSymb
set of states
Definition: nfa.hh:42
Vata2::Parser::ParsedSection serialize(const Nfa &aut, const SymbolToStringMap *symbol_map=nullptr, const StateToStringMap *state_map=nullptr)
serializes Nfa into a ParsedSection
Symbol symb
Definition: nfa.hh:63
static const_iterator for_begin(const Nfa *nfa)
bool is_complete(const Nfa &aut, const Alphabet &alphabet)
Test for automaton completeness wrt an alphabet. An automaton is complete if every reachable state ha...
void construct(Nfa *aut, const Vata2::Parser::ParsedSection &parsec, StringToSymbolMap *symbol_map=nullptr, StringToStateMap *state_map=nullptr)
Loads an automaton from Parsed object.
void add_final(const std::vector< State > vec)
Definition: nfa.hh:245
bool operator!=(const const_iterator &rhs) const
Definition: nfa.hh:296
std::ostream & operator<<(std::ostream &strm, const Nfa &nfa)
operator<<
const_iterator begin() const
Definition: nfa.hh:300
void make_complete(Nfa *aut, const Alphabet &alphabet, State sink_state)
makes the transition relation complete
size_t trans_size() const
bool has_trans(const Trans &trans) const
std::unordered_map< std::string, State > StringToStateMap
a finite-length word
Definition: nfa.hh:50
virtual ~Alphabet()
Definition: nfa.hh:98
virtual std::list< Symbol > get_symbols() const override
gets a list of symbols in the alphabet
void complement(Nfa *result, const Nfa &aut, const Alphabet &alphabet, SubsetMap *subset_map=nullptr)
Complement.
std::unordered_map< std::pair< State, State >, State > ProductMap
transitions
Definition: nfa.hh:45
uintptr_t State
Definition: nfa.hh:39
virtual Symbol translate_symb(const std::string &str) override
translates a string into a symbol
Definition: nfa.hh:140
std::set< State > StateSet
Definition: nfa.hh:41
bool is_prfx_in_lang(const Nfa &aut, const Word &word)
Checks whether the prefix of a string is in the language of an automaton.
void add_initial(State state)
Definition: nfa.hh:235
Word encode_word(const StringToSymbolMap &symbol_map, const std::vector< std::string > &input)
Encodes a vector of strings (each corresponding to one symbol) into a Word instance.
Definition: nfa.hh:521
bool operator==(const const_iterator &rhs) const
Definition: nfa.hh:290
uintptr_t Symbol
Definition: nfa.hh:40
State src
Definition: nfa.hh:62
bool is_lang_empty(const Nfa &aut, Path *cex=nullptr)
Is the language of the automaton empty?
void add_initial(const std::vector< State > vec)
Definition: nfa.hh:236
Trans(State src, Symbol symb, State tgt)
Definition: nfa.hh:67
An NFA.
Definition: nfa.hh:221
StateToPostMap::const_iterator stpmIt
Definition: nfa.hh:273
bool has_initial(State state) const
Definition: nfa.hh:240
void intersection(Nfa *result, const Nfa &lhs, const Nfa &rhs, ProductMap *prod_map=nullptr)
Compute intersection of a pair of automata.
bool has_final(State state) const
Definition: nfa.hh:250