21 template <Automaton Aut>
34 const auto& ws = *res->context().weightset();
37 else if (!ws.is_one(w))
39 res->lmul_weight(t, w);
48 const auto& ws = *res->context().weightset();
51 else if (!ws.is_one(w))
54 for (
auto t:
all_out(res, initial))
55 res->lmul_weight(t, w);
71 template <
typename Tag = general_tag>
75 const auto& ws = *res->context().weightset();
78 else if (!ws.is_one(w))
80 res->rmul_weight(t, w);
107 res->set_initial(res->new_state());
118 template <Automaton Aut,
typename Tag = auto_tag>
126 template <Automaton Aut,
typename Tag = auto_tag>
129 -> fresh_automaton_t_of<Aut>
131 auto res =
copy(aut);
141 template <Automaton Aut,
typename Tag>
149 template <
typename WeightSet, Automaton Aut,
typename String>
152 const std::string& algo)
154 const auto& a1 = aut->as<Aut>();
155 const auto& w1 = weight->as<
WeightSet>();
161 join(w1.weightset(), *a1->weightset()));
164 using automaton_t = decltype(a2);
165 auto w2 = ctx.weightset()->conv(w1.weightset(), w1.weight());
166 using weight_t = decltype(w2);
167 static const auto map
170 "left-multiply algorithm",
172 {
"auto", left_mult_tag<automaton_t, auto_tag>},
173 {
"general", left_mult_tag<automaton_t, general_tag>},
174 {
"standard", left_mult_tag<automaton_t, standard_tag>},
177 return map[algo](w2, a2);
186 template <
typename ValueSet>
190 const typename ValueSet::value_t&
r)
191 -> decltype(
rs.lmul(w,
r))
193 return rs.lmul(w,
r);
200 template <
typename WeightSet,
typename ExpSet>
201 expansionset<expressionset<context<labelset_t_of<ExpSet>,
202 join_t<WeightSet, weightset_t_of<ExpSet>>>>>
215 template <
typename WeightSet,
typename ExpansionSet>
219 const auto& w1 = weight->as<
WeightSet>();
220 const auto& r1 = exp->as<ExpansionSet>();
224 = rs.expressionset().weightset()->conv(w1.weightset(), w1.weight());
225 auto r2 = rs.conv(r1.expansionset(), r1.expansion());
255 template <
typename WeightSet,
typename ExpSet>
256 expressionset<context<labelset_t_of<ExpSet>,
257 join_t<WeightSet, weightset_t_of<ExpSet>>>>
270 template <
typename WeightSet,
typename ExpSet>
274 const auto& w1 = weight->as<
WeightSet>();
275 const auto& r1 = exp->as<ExpSet>();
278 auto w2 = rs.weightset()->conv(w1.weightset(), w1.weight());
279 auto r2 = rs.conv(r1.expressionset(), r1.expression());
291 template <Automaton Aut,
typename Tag = auto_tag>
299 template <Automaton Aut,
typename Tag = auto_tag>
300 fresh_automaton_t_of<Aut>
303 auto res =
copy(aut);
313 template <Automaton Aut,
typename Tag>
321 template <Automaton Aut,
typename WeightSet,
typename String>
324 const std::string& algo)
326 const auto& a1 = aut->as<Aut>();
327 const auto& w1 = weight->as<
WeightSet>();
333 join(w1.weightset(), *a1->weightset()));
336 using automaton_t = decltype(a2);
337 auto w2 = ctx.weightset()->conv(w1.weightset(), w1.weight());
338 using weight_t = decltype(w2);
339 static const auto map
342 "right-multiply algorithm",
344 {
"auto", right_mult_tag<automaton_t, auto_tag>},
345 {
"general", right_mult_tag<automaton_t, general_tag>},
346 {
"standard", right_mult_tag<automaton_t, standard_tag>},
349 return map[algo](a2, w2);
358 template <
typename ValueSet>
359 typename ValueSet::value_t
361 const typename ValueSet::value_t&
r,
364 return rs.rmul(r, w);
376 template <
typename ExpansionSet,
typename WeightSet>
380 const auto& w1 = weight->as<
WeightSet>();
381 const auto& r1 = exp->as<ExpansionSet>();
385 = rs.expressionset().weightset()->conv(w1.weightset(), w1.weight());
386 auto r2 = rs.conv(r1.expansionset(), r1.expansion());
401 template <
typename ExpSet,
typename WeightSet>
405 const auto& w1 = weight->as<
WeightSet>();
406 const auto& r1 = exp->as<ExpSet>();
409 auto w2 = rs.weightset()->conv(w1.weightset(), w1.weight());
410 auto r2 = rs.conv(r1.expressionset(), r1.expression());
Aut & right_mult_here(Aut &res, const weight_t_of< Aut > &w, Tag tag={})
In place right-multiplication of an automaton by a weight.
auto join(const ValueSet &vs) -> ValueSet
The join of a single valueset.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
Tag for operations on all automata.
expression right_mult_expression(const expression &exp, const weight &weight)
Bridge (right_mult).
weight_t_of< context_t > weight_t
static automaton_t & right_mult_here(automaton_t &res, const weight_t &w, auto_tag={})
Same as standard if res is standard, otherwise, general.
static automaton_t & left_mult_here(const weight_t &w, automaton_t &res, standard_tag tag)
Standard-preserving left-multiplication by a weight.
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Implementation of left- and right- multiplication of an automaton by a weight.
std::shared_ptr< const detail::weight_base > weight
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
auto left_mult(const weight_t_of< Aut > &w, const Aut &aut, Tag tag={}) -> fresh_automaton_t_of< Aut >
Left-multiplication of an automaton by a weight.
void copy_into(const AutIn &in, AutOut &out, KeepState keep_state, KeepTrans keep_trans)
Copy selected states and transitions of an automaton.
context_t_of< automaton_t > context_t
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
expressionset< context< labelset_t_of< ExpSet >, join_t< WeightSet, weightset_t_of< ExpSet > > > > join_weightset_expressionset(const WeightSet &ws, const ExpSet &rs)
Join between an expressionset and a weightset.
expansionset< expressionset< context< labelset_t_of< ExpSet >, join_t< WeightSet, weightset_t_of< ExpSet > > > > > join_weightset_expansionset(const WeightSet &ws, const expansionset< ExpSet > &rs)
std::shared_ptr< const detail::expansion_base > expansion
static automaton_t & left_mult_here(const weight_t &w, automaton_t &res, general_tag tag)
Left-multiplication of any automaton by a weight.
automaton right_mult_tag(Aut &aut, const weight_t_of< Aut > &w)
Right-product.
Provide a variadic mul on top of a binary mul(), and one().
static automaton_t & zero_here(automaton_t &res, standard_tag)
Transform res into the (standard) empty automaton.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
static automaton_t & zero_here(automaton_t &res, general_tag)
Transform res into the empty automaton.
A mapping from strings to Values.
context make_context(const std::string &name)
Bridge.
Tag to request the most appropriate version of an algorithm.
expansionset< ExpSet > make_expansionset(const ExpSet &expset)
expansion left_mult_expansion(const weight &weight, const expansion &exp)
Bridge (left_mult).
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
expression left_mult_expression(const weight &weight, const expression &exp)
Bridge (left_mult).
std::shared_ptr< detail::automaton_base > automaton
static automaton_t & left_mult_here(const weight_t &w, automaton_t &res, auto_tag={})
Same as standard if res is standard, otherwise, general.
automaton left_mult_tag(const weight_t_of< Aut > &w, Aut &aut)
Left-product.
state_t_of< automaton_t > state_t
fresh_automaton_t_of< Aut > right_mult(const Aut &aut, const weight_t_of< Aut > &w, Tag tag={})
Right-multiplication of an automaton by a weight.
expressionset< Context > make_expressionset(const Context &ctx, rat::identities identities={})
Shorthand to expressionset constructor.
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
static dyn::context ctx(const driver &d)
Get the context of the driver.
automaton right_mult(const automaton &aut, const weight &weight, const std::string &algo)
Bridge.
Container::value_type front(const Container &container)
The first member of this Container.
automaton left_mult(const weight &weight, const automaton &aut, const std::string &algo)
Bridge.
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
auto final_transitions(const Aut &aut) -> decltype(aut->all_in(aut->post()))
Indexes of transitions from (visible) final states.
std::shared_ptr< detail::expression_base > expression
expansion make_expansion(const ExpansionSet &ps, const typename ExpansionSet::value_t &expansion)
context join(const context &c1, const context &c2)
Bridge.
bool is_standard(const Aut &a)
Whether a is standard.
Tag for operations on standard automata.
weightset_t_of< context_t > weightset_t
static automaton_t & right_mult_here(automaton_t &res, const weight_t &w, Tag tag={})
Right-multiplication of any automaton by a weight.
expression make_expression(const ExpSet &rs, const typename ExpSet::value_t &r)
auto copy(const AutIn &input, KeepState keep_state, KeepTrans keep_trans) -> decltype(keep_state(input->null_state()), keep_trans(input->null_transition()), make_fresh_automaton< AutIn, AutOut >(input))
A copy of input keeping only its states that are accepted by keep_state, and transitions accepted by ...
const expressionset_t & expressionset() const
The expressionset.
Ctx make_context(const std::string &name)
expansion right_mult_expansion(const expansion &exp, const weight &weight)
Bridge (right_mult).
Aut & left_mult_here(const weight_t_of< Aut > &w, Aut &res, Tag tag={})
In place left-multiplication of an automaton by a weight.