17 #ifndef VCSN_ALGORITHMS_KRAT_EXP_CDERIVATION_HXX
18 # define VCSN_ALGORITHMS_KRAT_EXP_CDERIVATION_HXX
26 template <
class Series,
class T,
class Dispatch>
27 struct KRatExpCDerivation : algebra::KRatExpMatcher<
28 KRatExpCDerivation<Series, T, Dispatch>,
34 typedef KRatExpCDerivation<Series, T, Dispatch> self_t;
35 typedef Element<Series, T> return_type;
36 typedef typename Element<Series, T>::semiring_elt_t semiring_elt_t;
37 typedef typename semiring_elt_t::value_t semiring_elt_value_t;
38 typedef typename Element<Series, T>::monoid_elt_t monoid_elt_t;
39 typedef typename monoid_elt_t::value_t monoid_elt_value_t;
40 typedef typename monoid_elt_t::set_t monoid_t;
41 typedef typename monoid_t::alphabet_t alphabet_t;
42 typedef typename alphabet_t::letter_t letter_t;
43 INHERIT_CONSTRUCTORS(self_t, T, semiring_elt_t, Dispatch);
45 KRatExpCDerivation(
const Element<Series, T>& exp,
51 Element<Series, T> series(
const T& e)
53 return Element<Series, T>(exp_.structure(), e);
56 MATCH__(Product, lhs, rhs)
58 return_type match_lhs =
match(lhs);
61 if (match_lhs != zero_as<T>::of(exp_.structure()))
62 return match_lhs * rhs;
65 std::pair<semiring_elt_t, bool> ret = constant_term(series(lhs));
66 return ret.first *
match(rhs);
71 MATCH__(Sum, lhs, rhs)
73 return_type match_lhs =
match(lhs);
76 if (match_lhs != zero_as<T>::of(exp_.structure()))
86 return match(e) * e.clone().star();
90 MATCH__(LeftWeight, w, e)
92 return semiring_elt_t(w) *
match(e);
96 MATCH__(RightWeight, e, w)
98 return match(e) * semiring_elt_t(w);
107 return identity_as<T>::of(exp_.structure());
109 return Element<Series, T> (exp_.structure(), m.substr(1));
112 return zero_as<T>::of(exp_.structure());
118 return zero_as<T>::of(exp_.structure());
124 return zero_as<T>::of(exp_.structure());
129 Element<Series, T> exp_;
135 template <
class Series,
class T,
class Letter>
140 algebra::KRatExpCDerivation<Series, T, algebra::DispatchFunction<T> >
142 return matcher.match(exp.
value());
145 template <
class Series,
class T,
class Word>
151 for (
typename Word::reverse_iterator a = w.rbegin();
154 algebra::KRatExpCDerivation<Series, T, algebra::DispatchFunction<T> >
156 ret = matcher.match(ret.
value());
163 #endif // ! VCSN_ALGORITHMS_KRAT_EXP_CDERIVATION_HXX