3 #include <unordered_map>
29 template <
typename A,
typename B>
36 const auto& ls = *res->labelset();
37 const auto& bls = *b->labelset();
38 const auto& ws = *res->weightset();
39 const auto& bws = *b->weightset();
45 state_t_of<B> b_initial = b->dst_of(b->initial_transitions().front());
53 const auto& map =
copy.state_map();
69 auto s1 = res->src_of(t1);
70 auto w1 = res->weight_of(t1);
71 res->del_transition(t1);
72 for (
auto t2: b->all_out(b_initial))
73 res->set_transition(s1,
74 map.at(b->dst_of(t2)),
75 ls.conv(bls, b->label_of(t2)),
77 ws.conv(bws, b->weight_of(t2))));
83 template <
typename A,
typename B>
102 template <
typename Lhs,
typename Rhs>
106 const auto& l = lhs->as<Lhs>();
107 const auto&
r = rhs->as<Rhs>();
129 template <
typename Aut>
132 ->
typename Aut::element_type::template fresh_automaton_t<>
148 auto s = res->new_state();
155 for (
int n = 1; n < min; ++n)
163 auto s =
sum->new_state();
167 for (
int n = 1; n <= max - min; ++n)
182 template <
typename Aut,
typename Int1,
typename Int2>
186 const auto& aut = a->as<Aut>();
198 template <
typename ValueSet>
200 typename ValueSet::value_t
202 const typename ValueSet::value_t& lhs,
203 const typename ValueSet::value_t& rhs)
205 return vs.mul(lhs, rhs);
213 template <
typename ExpSetLhs,
typename ExpSetRhs>
217 const auto& l = lhs->as<ExpSetLhs>();
218 const auto&
r = rhs->as<ExpSetRhs>();
219 auto rs =
vcsn::join(l.expressionset(), r.expressionset());
220 auto lr = rs.conv(l.expressionset(), l.expression());
221 auto rr = rs.conv(r.expressionset(), r.expression());
232 template <
typename ExpSetLhs,
typename ExpSetRhs>
236 const auto& l = lhs->as<ExpSetLhs>();
237 const auto&
r = rhs->as<ExpSetRhs>();
238 auto rs =
vcsn::join(l.expressionset(), r.expressionset());
239 auto lr = rs.conv(l.expressionset(), l.expression());
240 auto rr = rs.conv(r.expressionset(), r.expression());
241 auto res = rs.concat(lr, rr);
252 template <
typename ExpSet>
253 typename ExpSet::value_t
257 typename ExpSet::value_t res;
264 res = rs.mul(rs.power(r, min), res);
269 "multiply: invalid exponent: ", min,
", ", max);
270 res = rs.power(r, min);
273 typename ExpSet::value_t
sum = rs.one();
274 for (
int n = 1; n <= max - min; ++n)
275 sum = rs.add(sum, rs.power(r, n));
276 res = rs.mul(res, sum);
287 template <
typename ExpSet,
typename Int1,
typename Int2>
291 const auto&
r = re->as<ExpSet>();
310 template <
typename LabelSetLhs,
typename LabelSetRhs>
314 const auto& l = lhs->as<LabelSetLhs>();
315 const auto&
r = rhs->as<LabelSetRhs>();
316 auto rs =
join(l.labelset(), r.labelset());
317 auto lr = rs.conv(l.labelset(), l.label());
318 auto rr = rs.conv(r.labelset(), r.label());
334 template <
typename PolynomialSetLhs,
typename PolynomialSetRhs>
338 const auto& l = lhs->as<PolynomialSetLhs>();
339 const auto&
r = rhs->as<PolynomialSetRhs>();
340 auto rs =
join(l.polynomialset(), r.polynomialset());
341 auto lr = rs.conv(l.polynomialset(), l.polynomial());
342 auto rr = rs.conv(r.polynomialset(), r.polynomial());
357 template <
typename WeightSetLhs,
typename WeightSetRhs>
361 const auto& l = lhs->as<WeightSetLhs>();
362 const auto&
r = rhs->as<WeightSetRhs>();
363 auto ws =
join(l.weightset(), r.weightset());
364 auto lw = ws.conv(l.weightset(), l.weight());
365 auto rw = ws.conv(r.weightset(), r.weight());
370 template <
typename WeightSet,
typename Int1,
typename Int2>
std::vector< typename Cont::value_type > make_vector(const Cont &cont)
The content of cont as a vector.
expression multiply_expression(const expression &lhs, const expression &rhs)
Bridge (multiply).
automaton multiply_repeated(const automaton &a, int min, int max)
Bridge (multiply).
std::shared_ptr< const detail::label_base > label
weight multiply_weight_repeated(const weight &wgt, int min, int max)
Bridge (multiply).
detail::copier< AutIn, AutOut > make_copier(const AutIn &in, AutOut &out)
Build an automaton copier.
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
auto join(const ValueSet &vs) -> ValueSet
The join of a single valueset.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
weightset_mixin< detail::b_impl > b
A & multiply_here(A &res, const B &b)
Append automaton b to res.
ExpSet::value_t multiply(const ExpSet &rs, const typename ExpSet::value_t &r, int min, int max)
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
AutOut copy(const AutIn &input, KeepState keep_state, KeepTrans keep_trans)
A copy of input keeping only its states that are accepted by keep_state.
std::shared_ptr< const detail::weight_base > weight
polynomial make_polynomial(const PolynomialSet &ps, const typename PolynomialSet::value_t &p)
bool is_standard(const Aut &a)
Whether a is standard.
expression concatenate_expression(const expression &lhs, const expression &rhs)
Bridge (concatenate).
Provide a variadic mul on top of a binary mul(), and one().
weight make_weight(const WeightSet &ws, const typename WeightSet::value_t &w)
fresh_automaton_t_of< Aut > star(const Aut &aut)
Star of a standard automaton.
std::shared_ptr< detail::automaton_base > automaton
automaton multiply(const automaton &lhs, const automaton &rhs)
Bridge.
polynomial multiply_polynomial(const polynomial &lhs, const polynomial &rhs)
Bridge (multiply).
void copy_into(const AutIn &in, AutOut &out, KeepState keep_state, KeepTrans keep_trans)
Copy selected states and transitions of an automaton.
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
weight multiply_weight(const weight &lhs, const weight &rhs)
Bridge (multiply).
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
std::shared_ptr< const detail::polynomial_base > polynomial
expression make_expression(const ExpSet &rs, const typename ExpSet::value_t &r)
label multiply_label(const label &lhs, const label &rhs)
Bridge (multiply).
expression multiply_expression_repeated(const expression &re, int min, int max)
Bridge (multiply).
auto sum(const A &lhs, const B &rhs) -> decltype(join_automata(lhs, rhs))
auto multiply(const A &lhs, const B &rhs) -> decltype(join_automata(lhs, rhs))
Concatenate two standard automata.
auto join_automata(Auts &&...auts) -> decltype(make_mutable_automaton(join(auts->context()...)))
An automaton whose type is the join between those of auts.
std::shared_ptr< detail::expression_base > expression
context join(const context &c1, const context &c2)
Bridge.
label make_label(const LabelSet &ls, const typename LabelSet::value_t &l)