17 #ifndef AWALI_ALGOS_N_ULTIMATE_HH
18 # define AWALI_ALGOS_N_ULTIMATE_HH
28 namespace awali {
namespace sttc {
49 template <
typename Context>
50 mutable_automaton<Context>
51 n_ultimate(
const Context& ctx,
typename Context::labelset_t::value_t a,
unsigned n)
53 const auto& gens = ctx.labelset()->genset();
54 size_t sz = std::distance(std::begin(gens), std::end(gens));
55 require(2 <= sz,
"n_ultimate: the alphabet needs at least 2 letters");
56 require(
n > 0,
"n_ultimate: automaton defined for n>0");
57 require(gens.has(a),
"n_ultimate: ",
"letter not in alphabet");
58 using context_t = Context;
60 automaton_t res = make_shared_ptr<automaton_t>(ctx);
62 auto init = res->add_state();
63 res->set_initial(init);
65 res->new_transition(init, init, l);
67 auto prev = res->add_state();
68 res->new_transition(init, prev, a);
72 auto next = res->add_state();
74 res->new_transition(prev, next, l);
The semiring of Natural numbers.
Definition: n.hh:34
mutable_automaton< Context > n_ultimate(const Context &ctx, typename Context::labelset_t::value_t a, unsigned n)
Returns an automaton which recognizes words with a specific n-ultimate letter.
Definition: n_ultimate.hh:51
std::shared_ptr< internal::mutable_automaton_impl< Context > > mutable_automaton
Definition: mutable_automaton.hh:45
void require(bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:55
Main namespace of Awali.
Definition: ato.hh:22