1 #ifndef VCSN_ALGOS_DERIVED_TERM_HH
2 # define VCSN_ALGOS_DERIVED_TERM_HH
53 template <
typename RatExpSet>
57 using ratexp_t =
typename ratexpset_t::value_t;
72 ,
res_{make_shared_ptr<automaton_t>(
rs_.context())}
81 const auto& ls =
rs_.labelset()->genset();
82 while (!
res_->todo_.empty())
90 res_->new_transition(s, m.first, l, m.second);
101 while (!
res_->todo_.empty())
104 auto s =
res_->state(src);
108 for (
const auto& p:
expansion.polynomials)
110 for (
const auto& m1: p.second)
111 for (
const auto& m2:
split(
rs_, m1.first))
112 res_->new_transition(s, m2.first, p.first,
113 ws_.mul(m1.second, m2.second));
115 for (
const auto& m: p.second)
116 res_->new_transition(s, m.first, p.first, m.second);
125 for (
const auto& p:
split(
rs_, ratexp))
126 res_->set_initial(p.first, p.second);
128 res_->set_initial(ratexp,
ws_.one());
143 template <
typename RatExpSet>
147 const typename RatExpSet::value_t&
r,
148 bool breaking =
false)
155 template <
typename RatExpSet>
157 ratexp_automaton<mutable_automaton<typename RatExpSet::context_t>>
159 const typename RatExpSet::value_t&
r,
160 bool breaking =
false)
171 template <
typename RatExpSet,
typename String>
173 typename std::enable_if<RatExpSet::context_t::labelset_t::is_free(),
177 const auto& e = exp->as<RatExpSet>();
178 const auto& rs = e.ratexpset();
179 const auto&
r = e.ratexp();
181 = algo ==
"derivation"
183 : algo ==
"breaking_derivation"
185 : algo ==
"auto" || algo ==
"expansion"
187 : algo ==
"breaking_expansion"
190 require(!!res,
"derived_term: invalid algorithm: " + algo);
195 template <
typename RatExpSet,
typename String>
197 typename std::enable_if<!RatExpSet::context_t::labelset_t::is_free(),
201 const auto& e = exp->as<RatExpSet>();
202 const auto& rs = e.ratexpset();
203 const auto&
r = e.ratexp();
205 = algo ==
"auto" || algo ==
"expansion"
207 : algo ==
"breaking_expansion"
210 require(!!res,
"derived_term: invalid algorithm: " + algo);
221 #endif // !VCSN_ALGOS_DERIVED_TERM_HH
weightset_t ws_
Its weightset.
Linear combination of labels: map labels to weights.
ratexpset_t rs_
The ratexp's set.
std::shared_ptr< detail::automaton_base > automaton
automaton_t res_
The resulting automaton.
bool breaking_
Whether to break the polynomials.
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
RatExpSet::value_t expand(const RatExpSet &rs, const typename RatExpSet::value_t &e)
Expanding a typed ratexp shared_ptr.
std::shared_ptr< detail::ratexp_base > ratexp
std::shared_ptr< const node< Context >> ratexp
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
#define REGISTER_DECLARE(Name, Signature)
std::shared_ptr< const detail::expansion_base > expansion
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
derived_termer(const ratexpset_t &rs, bool breaking=false)
state_t_of< automaton_t > state_t
typename polynomialset_t::value_t polynomial_t
Provide a variadic mul on top of a binary mul(), and one().
automaton_t via_derivation(const ratexp_t &ratexp)
Compute the derived-term automaton via derivation.
Compute the derived-term automaton from an expression.
context_t_of< ratexpset_t > context_t
automaton_t via_expansion(const ratexp_t &ratexp)
Compute the derived-term automaton via expansion.
weight_t_of< RatExpSet > constant_term(const RatExpSet &rs, const typename RatExpSet::value_t &e)
std::map< label_t, weight_t, vcsn::less< labelset_t >> value_t
std::enable_if<!RatExpSet::context_t::labelset_t::is_free(), automaton >::type derived_term(const ratexp &exp, const std::string &algo)
Bridge.
void init_(const ratexp_t &ratexp)
rat::ratexp_polynomial_t< RatExpSet > derivation(const RatExpSet &rs, const typename RatExpSet::value_t &e, label_t_of< RatExpSet > a, bool breaking=false)
Derive a ratexp wrt to a letter.
std::shared_ptr< detail::ratexp_automaton_impl< Aut >> ratexp_automaton
A ratexp automaton as a shared pointer.
rat::ratexp_polynomial_t< RatExpSet > split(const RatExpSet &rs, const typename RatExpSet::value_t &e)
Split a ratexp.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
weightset_t_of< context_t > weightset_t
ratexp_automaton< mutable_automaton< typename RatExpSet::context_t > > derived_term_derivation(const RatExpSet &rs, const typename RatExpSet::value_t &r, bool breaking=false)
The derived-term automaton, computed by derivation.
ratexp_automaton< mutable_automaton< context_t >> automaton_t
typename ratexpset_t::value_t ratexp_t
ratexp_automaton< mutable_automaton< typename RatExpSet::context_t > > derived_term_expansion(const RatExpSet &rs, const typename RatExpSet::value_t &r, bool breaking=false)
The derived-term automaton, computed by expansion.
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.