19 template <
typename ExpSet>
20 rat::expression_polynomial_t<ExpSet>
22 const typename ExpSet::value_t& e,
24 bool breaking =
false);
31 template <
typename ExpSet>
33 :
public ExpSet::const_visitor
37 using super_t =
typename expressionset_t::const_visitor;
45 using weight_t =
typename weightset_t::value_t;
50 using node_t =
typename super_t::node_t;
52 constexpr
static const char*
me() {
return "derivation"; }
65 return std::move(
res_);
67 catch (
const std::runtime_error& e)
70 " while computing derivative of: ",
to_string(
rs_, v),
"\n"
103 for (
const auto&
v: e)
108 res_ = std::move(res);
118 for (
unsigned i = 0, n = e.size(); i < n; ++i)
120 const auto&
v = e[i];
126 prod_(std::next(e.begin(), i+1), std::end(e)));
129 if (
ws_.is_zero(constant))
140 prod_(
typename mul_t::iterator begin,
141 typename mul_t::iterator end)
const
143 using expressions_t =
typename mul_t::values_t;
146 else if (std::next(begin, 1) == end)
149 return std::make_shared<mul_t>(expressions_t{begin, end});
156 e.head()->accept(*
this);
158 for (
unsigned i = 1, n = e.size(); i < n; ++i)
160 const auto&
v = e[i];
170 for (
unsigned i = 0; i < e.size(); ++i)
173 for (
const auto& m:
res_)
175 typename node_t::values_t expressions;
176 for (
unsigned j = 0; j < e.size(); ++j)
178 expressions.emplace_back(
label_of(m));
180 expressions.emplace_back(e[j]);
183 std::make_shared<shuffle_t>(expressions),
187 res_ = std::move(res);
192 e.sub()->accept(*
this);
198 e.sub()->accept(*
this);
201 ps_.rmul_label(
res_, e.shared_from_this()));
206 e.sub()->accept(*
this);
212 e.sub()->accept(*
this);
221 template <
bool = context_t::is_lat,
222 typename Dummy =
void>
229 const auto& ps =
visitor_.
ps_.template project<I>();
233 return ps.value(rs.one(),
237 std::get<I>(v.sub()),
242 template <
size_t... I>
257 template <
typename Dummy>
285 template <
typename ExpSet>
288 const typename ExpSet::value_t& e,
293 "derivation: requires letterized labelset");
303 template <
typename ExpSet>
304 rat::expression_polynomial_t<ExpSet>
308 bool breaking =
false)
312 auto res = polynomial_t{};
313 for (
const auto& m: p)
329 template <
typename ExpSet,
330 typename = std::enable_if_t<!std::is_same<word_t_of<ExpSet>,
331 label_t_of<ExpSet>>{}>>
332 rat::expression_polynomial_t<ExpSet>
334 const typename ExpSet::value_t& e,
336 bool breaking =
false)
338 auto word = rs.labelset()->letters_of(l);
339 auto i = std::begin(word);
340 auto end = std::end(word);
341 require(i != end,
"derivation: word cannot be empty");
343 for (++i; i != end; ++i)
354 template <
typename ExpSet,
typename Label,
typename Bool>
358 const auto& e = exp->
as<ExpSet>();
359 const auto& l = lbl->
as<Label>().value();
360 const auto&
rs = e.valueset();
typename expressionset_t::value_t expression_t
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.
polynomial_t operator()(const tuple_t &)
void visit(const tuple_t &v, std::true_type) override
expression_polynomialset_t< ExpSet > make_expression_polynomialset(const ExpSet &rs)
From a ExpSet to its polynomialset.
VCSN_RAT_VISIT(conjunction, e)
polynomial derivation(const expression &exp, const label &lbl, bool breaking)
Bridge.
weightset_t ws_
Shorthand to the weightset.
An inner node implementing a weight.
typename expression_polynomialset_t< ExpSet >::value_t expression_polynomial_t
Type of polynomials of expressions from the ExpSet type.
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
typename polynomialset_t::value_t polynomial_t
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Provide a variadic mul on top of a binary mul(), and one().
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
rat::expression_polynomial_t< ExpSet > split(const ExpSet &rs, const typename ExpSet::value_t &e)
Split an expression.
VCSN_RAT_VISIT(rweight, e)
typename weightset_t::value_t weight_t
typename super_t::node_t node_t
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
expression_t prod_(typename mul_t::iterator begin, typename mul_t::iterator end) const
Build a product for these expressions.
label_t variable_
The derivation variable.
auto work_(const tuple_t &v)
Work on tape I.
labelset_t_of< context_t > labelset_t
VCSN_RAT_VISIT(lweight, e)
#define VCSN_RAT_UNSUPPORTED(Type)
VCSN_RAT_VISIT(shuffle, e)
weightset_t_of< expressionset_t > weightset_t
std::enable_if_t<!is_letterized_t< labelset_t_of< Aut > >{}, bool > is_letterized(const Aut &aut)
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
weight_t_of< ExpSet > constant_term(const ExpSet &rs, const typename ExpSet::value_t &e)
The constant term of e.
polynomial_t res_
The result.
VCSN_RAT_VISIT(complement, e)
#define BUILTIN_UNREACHABLE()
polynomial_t work_(const tuple_t &v, detail::index_sequence< I... >)
Tuple of derivations of all the tapes.
An inner node with multiple children.
typename super_t::tuple_t tuple_t
auto & as()
Extract wrapped typed value.
Functor to compute the derivation of an expression.
polynomial_t operator()(const expression_t &v, label_t var)
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
context_t_of< expressionset_t > context_t
static constexpr const char * me()
polynomial_t operator()(const tuple_t &v)
Entry point.
value_impl< detail::expression_tag > expression
label_t_of< context_t > label_t
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
derivation_visitor(const expressionset_t &rs)
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
value_impl< detail::polynomial_tag > polynomial
std::string to_string(identities i)
Wrapper around operator<<.
typename expressionset_t::const_visitor super_t