43 "derived-term algorithm",
47 {
"breaking_derivation",
"derivation,breaking"},
48 {
"breaking_expansion",
"expansion,breaking"},
50 {
"derivation,breaking", dta{
derivation,
true,
false}},
51 {
"derivation,deterministic",dta{
derivation,
false,
true}},
52 {
"derivation_breaking",
"derivation,breaking"},
53 {
"expansion", dta{
expansion,
false,
false}},
54 {
"expansion,breaking", dta{
expansion,
true,
false}},
55 {
"expansion,deterministic", dta{
expansion,
false,
true}},
56 {
"expansion_breaking",
"expansion,breaking"},
59 if (boost::starts_with(algo,
"lazy,"))
60 algo = algo.substr(5);
79 template <
typename ExpSet,
84 :
gens{rs.labelset()->generators()}
89 using genset_t = decltype(std::declval<ls_t>().generators());
94 template <
typename ExpSet>
129 template <
typename ExpSet>
131 :
public automaton_decorator<expression_automaton<mutable_automaton<context_t_of<ExpSet>>>>
152 static auto res =
symbol{
"derived_term_automaton<"
160 o <<
"derived_term_automaton<";
161 return rs_.print_set(o, fmt) <<
'>';
166 :
super_t{make_shared_ptr<automaton_t>(
rs)}
182 catch (
const std::runtime_error& e)
184 raise(e,
" while computing derived-term of: ",
to_string(
rs_, exp));
192 while (!
aut_->todo_.empty())
194 auto p = std::move(
aut_->todo_.top());
205 while (!
aut_->todo_.empty())
207 auto p = std::move(
aut_->todo_.top());
222 for (
const auto& p:
split(
rs_, exp))
225 aut_->set_initial(exp,
ws_.one());
231 const auto& orig =
aut_->origins();
232 auto sn = orig.at(s);
250 aut_->set_lazy(s,
false);
257 auto m =
ps_.determinize(p);
261 for (
const auto& m: p)
269 aut_->set_lazy(s,
false);
275 for (
const auto& p:
expansion.polynomials)
277 for (
const auto& m1: p.second)
283 auto m =
ps_.determinize(p.second);
287 for (
const auto& m: p.second)
313 template <
typename ExpSet>
315 = std::shared_ptr<detail::derived_term_automaton_impl<ExpSet>>;
317 template <
typename ExpSet>
324 return make_shared_ptr<res_t>(
rs, algo);
332 template <
typename ExpSet>
334 expression_automaton<mutable_automaton<typename ExpSet::context_t>>>
336 const typename ExpSet::value_t&
r,
337 const std::string& algo =
"auto")
341 return dt->operator()(
r);
349 template <
typename ExpSet>
351 expression_automaton<mutable_automaton<typename ExpSet::context_t>>>
353 const typename ExpSet::value_t&
r,
354 const std::string& algo =
"auto")
358 "derived_term: cannot use derivation on non-letterized labelsets");
363 return dt->via_expansion(r);
371 template <
typename ExpSet,
typename String>
374 const auto& e = exp->as<ExpSet>();
375 const auto& rs = e.valueset();
376 const auto&
r = e.value();
377 if (boost::starts_with(algo,
"lazy,"))
381 "derived_term: laziness works only with expansions");
value_impl< detail::expansion_tag > expansion
derived_term_algo algo_
How derived terms are computed.
rat::expression_polynomial_t< ExpSet > derivation(const ExpSet &rs, const typename ExpSet::value_t &e, label_t_of< ExpSet > a, bool breaking=false)
Derive an expression wrt to a letter.
weightset_t ws_
Its weightset.
expression_polynomialset_t< ExpSet > make_expression_polynomialset(const ExpSet &rs)
From a ExpSet to its polynomialset.
auto all_out(state_t s) const -> decltype(vcsn::detail::all_out(aut_, s))
All the outgoing transitions.
derived_term_automaton_members(const ExpSet &)
expression_automaton< mutable_automaton< context_t >> automaton_t
The type of the (strict) automaton we build.
std::shared_ptr< detail::derived_term_automaton_impl< ExpSet >> derived_term_automaton
A derived-term automaton as a shared pointer.
typename expressionset_t::value_t expression_t
Our state names: expressions.
automaton_t via_expansion(const expression_t &exp)
Compute the derived-term automaton via expansion.
Compute the derived-term automaton from an expression.
context_t_of< expressionset_t > context_t
Aggregate an automaton, and forward calls to it.
An input/output format for valuesets.
automaton_t operator()(const expression_t &exp)
Compute the derived-term automaton.
weightset_mixin< detail::r_impl > r
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
auto make_derived_term_automaton(const ExpSet &rs, const detail::derived_term_algo &algo) -> derived_term_automaton< ExpSet >
Provide a variadic mul on top of a binary mul(), and one().
void complete_via_expansion_(state_t s, const expression_t &src)
Compute the outgoing transitions of src.
expressionset_t rs_
The expression's set.
rat::expression_polynomial_t< ExpSet > split(const ExpSet &rs, const typename ExpSet::value_t &e)
Split an expression.
decltype(std::declval< ls_t >().generators()) genset_t
The generators.
std::ostream & print_set(std::ostream &o, format fmt={}) const
to_expansion_t to_expansion_
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
auto is_lazy(Args &&...args) const -> decltype(aut_-> is_lazy(std::forward< Args >(args)...))
Specify a variety of derived-term construction.
void init_(const expression_t &exp)
Initialize the computation: build the initial states.
auto weight_of(Args &&...args) const -> decltype(aut_-> weight_of(std::forward< Args >(args)...))
auto label_of(Args &&...args) const -> decltype(aut_-> label_of(std::forward< Args >(args)...))
algo_t algo
Core algorithm.
derived_term_algo(std::string algo)
From algo name to algo.
automaton_t via_derivation(const expression_t &exp)
Compute the derived-term automaton via derivation.
derived_term_automaton_members(const ExpSet &rs)
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
labelset_t_of< expressionset_t > ls_t
std::shared_ptr< detail::expression_automaton_impl< Aut >> expression_automaton
An expression automaton as a shared pointer.
std::enable_if_t<!is_letterized_t< labelset_t_of< Aut > >{}, bool > is_letterized(const Aut &aut)
derived_term_algo(algo_t a, bool b, bool d)
derived_term_automaton_members< expressionset_t > members_
Possibly the generators.
derived_term_automaton_impl(const expressionset_t &rs, derived_term_algo algo)
void complete_via_derivation_(state_t s, const expression_t &src)
Compute the outgoing transitions of src.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
weight_t_of< ExpSet > constant_term(const ExpSet &rs, const typename ExpSet::value_t &e)
The constant term of e.
std::enable_if_t< labelset_t_of< ExpSet >::is_letterized(), expression_automaton< mutable_automaton< typename ExpSet::context_t > > > derived_term(const ExpSet &rs, const typename ExpSet::value_t &r, const std::string &algo="auto")
The derived-term automaton, for letterized labelsets.
void complete_(state_t s) const
Complete a state: find its outgoing transitions.
state_t_of< automaton_t > state_t
auto map(const std::tuple< Ts... > &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
std::string to_string(direction d)
Conversion to string.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
bool breaking
Whether to break sums.
automaton derived_term(const expression &exp, const std::string &algo)
Bridge.
A mapping from strings to Values.
value_impl< detail::expression_tag > expression
Additional members when the labelset is letterized.
automaton_t aut_
The wrapped automaton, possibly const.
weightset_t_of< context_t > weightset_t
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
bool determinize
Whether to determinize the expansions and produce a deterministic automaton, at the expense of possib...
value_t determinize(const value_t &v) const
Turn the polynomials into (normalized) monomials.