17 #ifndef VCSN_ALGORITHMS_KRAT_EXP_DERIVATION_HXX
18 # define VCSN_ALGORITHMS_KRAT_EXP_DERIVATION_HXX
22 # include <vaucanson/algebra/implementation/series/krat_exp_pattern.hh>
27 template <
class Series,
class T,
class Dispatch>
28 struct KRatExpDerivation : algebra::KRatExpMatcher<
29 KRatExpDerivation<Series, T, Dispatch>,
35 typedef KRatExpDerivation<Series, T, Dispatch> self_t;
36 typedef Element<Series, T> return_type;
37 typedef typename Element<Series, T>::semiring_elt_t semiring_elt_t;
38 typedef typename semiring_elt_t::value_t semiring_elt_value_t;
39 typedef typename Element<Series, T>::monoid_elt_t monoid_elt_t;
40 typedef typename monoid_elt_t::value_t monoid_elt_value_t;
41 typedef typename monoid_elt_t::set_t monoid_t;
42 typedef typename monoid_t::alphabet_t alphabet_t;
43 typedef typename alphabet_t::letter_t letter_t;
44 INHERIT_CONSTRUCTORS(self_t, T, semiring_elt_t, Dispatch);
46 KRatExpDerivation(
const Element<Series, T>& exp,
53 Element<Series, T> series(
const T& e)
55 return Element<Series, T>(exp_.structure(), e);
58 MATCH__(Product, lhs, rhs)
60 std::pair<semiring_elt_t, bool> ret = constant_term(series(lhs));
61 if (ret.second ==
false)
64 return return_type(exp_.structure());
66 return (this->
match(lhs) * rhs) + ret.first * this->match(rhs);
70 MATCH__(Sum, lhs, rhs)
78 std::pair<semiring_elt_t, bool> ret = constant_term(series(e));
79 if ((ret.second ==
false) || (ret.first.starable() ==
false))
82 return return_type(exp_.structure());
84 return ret.first.star() * this->
match(e) * e.clone().star();
88 MATCH__(LeftWeight, w, e)
90 return semiring_elt_t(w) * this->
match(e);
94 MATCH__(RightWeight, e, w)
96 return this->
match(e) * semiring_elt_t(w);
105 return algebra::identity_as<T>::of(exp_.structure());
107 return Element<Series, T> (exp_.structure(), m.substr(1));
110 return algebra::zero_as<T>::of(exp_.structure());
116 return algebra::zero_as<T>::of(exp_.structure());
122 return algebra::zero_as<T>::of(exp_.structure());
129 Element<Series, T> exp_;
133 template <
class Series,
class T,
class Letter>
134 std::pair<Element<Series, T>,
bool>
138 KRatExpDerivation<Series, T, algebra::DispatchFunction<T> >
141 if (matcher.undefined)
142 return std::make_pair(ret,
false);
143 return std::make_pair(ret,
true);
146 template <
class Series,
class T,
class Word>
147 std::pair<Element<Series, T>,
bool>
152 for (
typename Word::reverse_iterator a = w.rbegin();
155 KRatExpDerivation<Series, T, algebra::DispatchFunction<T> >
157 ret = matcher.match(ret.
value());
158 if (matcher.undefined)
159 return std::make_pair(ret,
false);
161 return std::make_pair(ret,
true);
166 #endif // ! VCSN_ALGORITHMS_KRAT_EXP_DERIVATION_HXX