14 template <
typename Context>
15 mutable_automaton<Context>
18 using context_t = Context;
21 const auto& ls = *ctx.labelset();
22 const auto& gens = ls.generators();
23 std::vector<label_t_of<context_t>> letters;
25 letters.emplace_back(ls.value(l));
28 "divkbaseb: divisor cannot be 0");
30 "divkbaseb: base (", base,
") must be at least 2");
32 "divkbaseb: base (", base,
33 ") must be less than or equal to the alphabet size (",
36 automaton_t
res = make_shared_ptr<automaton_t>(
ctx);
42 std::vector<state_t> states;
43 for (
unsigned i = 0; i < divisor; ++i)
44 states.emplace_back(res->new_state());
46 res->set_initial(states[0]);
47 res->set_final(states[0]);
49 for (
unsigned i = 0; i < divisor; ++i)
52 for (
unsigned l = 0; l < base; ++l)
54 int d = (e + l) % divisor;
55 res->new_transition(states[i], states[d], letters[l]);
67 template <
typename Ctx,
typename Un
signed1,
typename Un
signed2>
71 const auto& c = ctx->
as<Ctx>();
mutable_automaton< Context > divkbaseb(const Context &ctx, unsigned divisor, unsigned base)
Build the Boolean automaton which accepts a word n representing a number in base "base" if and only i...
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
auto & as()
Downcast to the exact type.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Template-less root for contexts.
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
automaton divkbaseb(const context &ctx, unsigned divisor, unsigned base)
Bridge.