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>
226 template <
size_t... I>
233 std::get<I>(v.sub()),
246 template <
typename Dummy>
275 template <
typename ExpSet>
278 const typename ExpSet::value_t& e,
282 static_assert(ExpSet::context_t::labelset_t::is_free(),
283 "derivation: requires free labelset");
293 template <
typename ExpSet>
294 rat::expression_polynomial_t<ExpSet>
298 bool breaking =
false)
302 auto res = polynomial_t{};
303 for (
const auto& m: p)
319 template <
typename ExpSet,
320 typename = std::enable_if_t<!std::is_same<word_t_of<ExpSet>,
321 label_t_of<ExpSet>>{}>>
322 rat::expression_polynomial_t<ExpSet>
324 const typename ExpSet::value_t& e,
326 bool breaking =
false)
328 auto word = rs.labelset()->letters_of(l);
329 auto i = std::begin(word);
330 auto end = std::end(word);
331 require(i != end,
"derivation: word cannot be empty");
333 for (++i; i != end; ++i)
344 template <
typename ExpSet,
typename Label,
typename Bool>
348 const auto& e = exp->
as<ExpSet>();
349 const auto& l = lbl->
as<Label>().value();
350 const auto&
rs = e.valueset();
polynomial_t res_
The result.
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
weightset_t_of< expressionset_t > weightset_t
context_t_of< expressionset_t > context_t
#define BUILTIN_UNREACHABLE()
typename polynomialset_t::value_t polynomial_t
derivation_visitor(const expressionset_t &rs)
VCSN_RAT_VISIT(complement, e)
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
polynomial_t operator()(const tuple_t &)
VCSN_RAT_VISIT(shuffle, e)
void visit(const tuple_t &v, std::true_type) override
An inner node implementing a weight.
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
typename super_t::tuple_t tuple_t
typename expressionset_t::const_visitor super_t
label_t variable_
The derivation variable.
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_
Shorthand to the weightset.
expression_t prod_(typename mul_t::iterator begin, typename mul_t::iterator end) const
Build a product for these expressions.
VCSN_RAT_VISIT(rweight, e)
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
value_impl< detail::polynomial_tag > polynomial
typename weightset_t::value_t weight_t
polynomial derivation(const expression &exp, const label &lbl, bool breaking)
Bridge.
polynomial_t work_(const tuple_t &v, detail::index_sequence< I... >)
Tuple of derivations of all the tapes.
labelset_t_of< context_t > labelset_t
rat::expression_polynomial_t< ExpSet > split(const ExpSet &rs, const typename ExpSet::value_t &e)
Split an expression.
label_t_of< context_t > label_t
std::string to_string(identities i)
Wrapper around operator<<.
VCSN_RAT_VISIT(lweight, e)
polynomial_t operator()(const expression_t &v, label_t var)
static constexpr const char * me()
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.
auto & as()
Extract wrapped typed value.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
expression_polynomialset_t< ExpSet > make_expression_polynomialset(const ExpSet &rs)
From a ExpSet to its polynomialset.
typename expressionset_t::value_t expression_t
An inner node with multiple children.
#define VCSN_RAT_UNSUPPORTED(Type)
VCSN_RAT_VISIT(conjunction, e)
Provide a variadic mul on top of a binary mul(), and one().
polynomial_t operator()(const tuple_t &v)
Entry point.
weight_t_of< ExpSet > constant_term(const ExpSet &rs, const typename ExpSet::value_t &e)
The constant term of e.
value_impl< detail::expression_tag > expression
typename super_t::node_t node_t
Functor to compute the derivation of an expression.