1 #ifndef VCSN_ALGOS_DERIVATION_HH
2 # define VCSN_ALGOS_DERIVATION_HH
23 template <
typename RatExpSet>
25 :
public RatExpSet::const_visitor
32 using ratexp_t =
typename ratexpset_t::value_t;
34 using weight_t =
typename weightset_t::value_t;
39 using super_t =
typename ratexpset_t::const_visitor;
40 using node_t =
typename super_t::node_t;
42 constexpr
static const char*
me() {
return "derivation"; }
53 return std::move(
res_);
61 for (
const auto& m: p)
62 res =
rs_.add(res,
rs_.lmul(m.second, m.first));
90 for (
const auto& v: e)
95 res_ = std::move(res);
105 for (
unsigned i = 0, n = e.size(); i < n; ++i)
107 const auto& v = e[i];
109 for (
unsigned j = i + 1; j < n; ++j)
114 res_ = std::move(res);
120 e.head()->accept(*
this);
122 for (
unsigned i = 1, n = e.size(); i < n; ++i)
124 const auto& v = e[i];
128 res_ = std::move(res);
134 for (
unsigned i = 0; i < e.size(); ++i)
137 for (
const auto& m:
res_)
139 typename node_t::values_t ratexps;
140 for (
unsigned j = 0; j < e.size(); ++j)
142 ratexps.emplace_back(m.first);
144 ratexps.emplace_back(e[j]);
147 std::make_shared<shuffle_t>(ratexps),
151 res_ = std::move(res);
156 e.sub()->accept(*
this);
163 e.sub()->accept(*
this);
171 e.sub()->accept(*
this);
177 e.sub()->accept(*
this);
179 for (
const auto& m:
res_)
198 template <
typename RatExpSet>
202 const typename RatExpSet::value_t& e,
204 bool breaking =
false)
206 static_assert(RatExpSet::context_t::labelset_t::is_free(),
207 "derivation: requires free labelset");
211 res =
split(rs, res);
217 template <
typename RatExpSet>
219 rat::ratexp_polynomial_t<RatExpSet>
223 bool breaking =
false)
228 for (
const auto& m: p)
230 ps.lmul(m.second,
derivation(rs, m.first, a, breaking)));
236 template <
typename RatExpSet>
238 rat::ratexp_polynomial_t<RatExpSet>
240 const typename RatExpSet::value_t& e,
241 const typename RatExpSet::labelset_t::word_t& l,
242 bool breaking =
false)
244 auto word = rs.labelset()->letters_of(l);
245 auto i = std::begin(word);
246 auto end = std::end(word);
247 require(i != end,
"derivation: word cannot be empty");
249 for (++i; i != end; ++i)
260 template <
typename RatExpSet,
typename Label,
typename Bool>
264 const auto& e = exp->as<RatExpSet>();
265 const auto& l = lbl->as<Label>().
label();
266 const auto& rs = e.ratexpset();
280 #endif // !VCSN_ALGOS_DERIVATION_HH
typename super_t::node_t node_t
Linear combination of labels: map labels to weights.
typename ratexpset_t::value_t ratexp_t
value_t & add_here(value_t &v, const value_t &p) const
v += p.
An inner node with multiple children.
#define VCSN_RAT_UNSUPPORTED(Type)
typename ratexpset_t::const_visitor super_t
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
VCSN_RAT_VISIT(lweight, e)
VCSN_RAT_VISIT(shuffle, e)
labelset_t_of< context_t > labelset_t
weightset_t ws_
Shorthand to the weightset.
polynomial make_polynomial(const PolynomialSet &ps, const typename PolynomialSet::value_t &polynomial)
ratexp_polynomialset_t< RatExpSet > make_ratexp_polynomialset(const RatExpSet &rs)
From a RatExpSet to its polynomialset.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
VCSN_RAT_VISIT(rweight, e)
typename polynomialset_t::value_t polynomial_t
value_t rmul(const value_t &v, const weight_t &w) const
Right exterior product.
const value_t & zero() const
std::shared_ptr< detail::ratexp_base > ratexp
typename weightset_t::value_t weight_t
value_t lmul(const weight_t &w, const value_t &v) const
Left exterior product.
polynomial_t res_
The result.
polynomial derivation(const ratexp &exp, const label &lbl, bool breaking=false)
Bridge.
ratexp_t ratexp(const polynomial_t p)
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
context_t_of< ratexpset_t > context_t
label_t_of< context_t > label_t
label_t variable_
The derivation variable.
VCSN_RAT_VISIT(conjunction, e)
std::shared_ptr< const detail::label_base > label
polynomial_t operator()(const ratexp_t &v, label_t var)
value_t conjunction(const value_t &l, const value_t &r) const
The conjunction of polynomials l and r.
weightset_t_of< ratexpset_t > weightset_t
An inner node implementing a weight.
weight_t_of< RatExpSet > constant_term(const RatExpSet &rs, const typename RatExpSet::value_t &e)
typename ratexp_polynomialset_t< RatExpSet >::value_t ratexp_polynomial_t
Type of polynomials of ratexps from the RatExpSet type.
std::map< label_t, weight_t, vcsn::less< labelset_t >> value_t
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.
derivation_visitor(const ratexpset_t &rs)
rat::ratexp_polynomial_t< RatExpSet > split(const RatExpSet &rs, const typename RatExpSet::value_t &e)
Split a ratexp.
static constexpr const char * me()
const value_t & one() const
std::shared_ptr< const detail::polynomial_base > polynomial
VCSN_RAT_VISIT(complement, e)
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.