20 template <
typename ExpSet>
21 rat::expression_polynomial_t<ExpSet>
23 const typename ExpSet::value_t& e,
25 bool breaking =
false);
32 template <
typename ExpSet>
34 :
public ExpSet::const_visitor
38 using super_t =
typename expressionset_t::const_visitor;
46 using weight_t =
typename weightset_t::value_t;
51 using node_t =
typename super_t::node_t;
53 constexpr
static const char*
me() {
return "derivation"; }
64 return std::move(
res_);
93 for (
const auto&
v: e)
98 res_ = std::move(res);
104 auto res =
ps_.zero();
108 for (
unsigned i = 0, n = e.size(); i < n; ++i)
110 const auto&
v = e[i];
116 prod_(std::next(e.begin(), i+1), std::end(e)));
119 if (
ws_.is_zero(constant))
122 res_ = std::move(res);
130 prod_(
typename prod_t::iterator begin,
131 typename prod_t::iterator end)
const
133 using expressions_t =
typename prod_t::values_t;
136 else if (std::next(begin, 1) == end)
139 return std::make_shared<prod_t>(expressions_t{begin, end});
146 e.head()->accept(*
this);
148 for (
unsigned i = 1, n = e.size(); i < n; ++i)
150 const auto&
v = e[i];
152 res =
ps_.conjunction(res,
res_);
154 res_ = std::move(res);
160 for (
unsigned i = 0; i < e.size(); ++i)
163 for (
const auto& m:
res_)
165 typename node_t::values_t expressions;
166 for (
unsigned j = 0; j < e.size(); ++j)
168 expressions.emplace_back(
label_of(m));
170 expressions.emplace_back(e[j]);
173 std::make_shared<shuffle_t>(expressions),
177 res_ = std::move(res);
182 e.sub()->accept(*
this);
188 e.sub()->accept(*
this);
191 ps_.rmul_label(
res_, e.shared_from_this()));
196 e.sub()->accept(*
this);
202 e.sub()->accept(*
this);
211 template <
bool = context_t::is_lat,
212 typename Dummy =
void>
216 template <
size_t... I>
223 std::get<I>(v.sub()),
236 template <
typename Dummy>
265 template <
typename ExpSet>
268 const typename ExpSet::value_t& e,
272 static_assert(ExpSet::context_t::labelset_t::is_free(),
273 "derivation: requires free labelset");
277 res =
split(rs, res);
283 template <
typename ExpSet>
284 rat::expression_polynomial_t<ExpSet>
288 bool breaking =
false)
292 auto res = polynomial_t{};
293 for (
const auto& m: p)
309 template <
typename ExpSet,
310 typename = std::enable_if_t<!std::is_same<word_t_of<ExpSet>,
313 rat::expression_polynomial_t<ExpSet>
315 const typename ExpSet::value_t& e,
317 bool breaking =
false)
319 auto word = rs.labelset()->letters_of(l);
320 auto i = std::begin(word);
321 auto end = std::end(word);
322 require(i != end,
"derivation: word cannot be empty");
324 for (++i; i != end; ++i)
335 template <
typename ExpSet,
typename Label,
typename Bool>
339 const auto& e = exp->as<ExpSet>();
340 const auto& l = lbl->as<Label>().
label();
341 const auto&
rs = e.expressionset();
polynomial_t res_
The result.
typename expression_polynomialset_t< ExpSet >::value_t expression_polynomial_t
Type of polynomials of expressions from the ExpSet type.
#define VCSN_RAT_UNSUPPORTED(Type)
std::shared_ptr< const detail::polynomial_base > polynomial
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
polynomial_t operator()(const expression_t &v, label_t var)
polynomial make_polynomial(const PolynomialSet &ps, const typename PolynomialSet::value_t &p)
typename expressionset_t::const_visitor super_t
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
polynomial_t operator()(const tuple_t &v)
Entry point.
Functor to compute the derivation of an expression.
VCSN_RAT_VISIT(rweight, e)
VCSN_RAT_VISIT(conjunction, e)
VCSN_RAT_VISIT(shuffle, e)
void visit(const tuple_t &v, std::true_type) override
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Provide a variadic mul on top of a binary mul(), and one().
An inner node with multiple children.
weight_t_of< ExpSet > constant_term(const ExpSet &rs, const typename ExpSet::value_t &e)
The constant term of e.
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
weightset_t_of< expressionset_t > weightset_t
static constexpr const char * me()
#define BUILTIN_UNREACHABLE()
std::shared_ptr< const detail::label_base > label
VCSN_RAT_VISIT(lweight, e)
derivation_visitor(const expressionset_t &rs)
polynomial derivation(const expression &exp, const label &lbl, bool breaking)
Bridge.
weightset_t ws_
Shorthand to the weightset.
typename super_t::tuple_t tuple_t
VCSN_RAT_VISIT(complement, e)
expression_t prod_(typename prod_t::iterator begin, typename prod_t::iterator end) const
Build a product for these expressions.
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.
labelset_t_of< context_t > labelset_t
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
An inner node implementing a weight.
polynomial_t operator()(const tuple_t &)
label_t variable_
The derivation variable.
std::shared_ptr< detail::expression_base > expression
polynomial_t work_(const tuple_t &v, detail::index_sequence< I... >)
Tuple of derivations of all the tapes.
context_t_of< expressionset_t > context_t
label_t_of< context_t > label_t
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
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.
expression_polynomialset_t< ExpSet > make_expression_polynomialset(const ExpSet &rs)
From a ExpSet to its polynomialset.
typename polynomialset_t::value_t polynomial_t
typename weightset_t::value_t weight_t
typename super_t::node_t node_t
typename expressionset_t::value_t expression_t
rat::expression_polynomial_t< ExpSet > split(const ExpSet &rs, const typename ExpSet::value_t &e)
Split an expression.